Discount Only

  • Posts: 24
  • Thank you received: 0
7 years 10 months ago #273330

-- HikaShop version -- : 3.0.1
-- Joomla version -- : 3.7.0
-- PHP version -- : 7
-- Browser(s) name and version -- : chrome

Hello,

I've an issue with product listings which have the option 'discount only' turned on.

When I have products on discounts, the product listing is showing only those products with discounts. This is what I ask with the 'discounted only' option. However, when I haven't any product at all in discount, the listing is showing me ALL my products (which are not discounted). In that case the discounted option is not working.
When I don;t have any discounted products, I don;t want to see anything when the option 'discounted only' is on....

Is this a bug ?

best regards,
Eduard Koks

Please Log in or Create an account to join the conversation.

  • Posts: 24
  • Thank you received: 0
7 years 10 months ago #273333

I've two possible solutions for this problem :

the first one is a 'dirty' workaround.... the second is a workaround in the core hikashop code. Maybe you can integrate this in the next release.
1. create an emtpy category (without products) and further create a discount for this empty category which is alway valid. In this way, the code which generate the discount filters in the query WILL generate filters, however without any products because the only valid discount has no products
2. I've created an extra filter in the com_hikashop\views\product\view.html.php which will result in an empty resultset when no discounts are found at all.... The latter else part '1=0' is added by me.

if(!empty($discounts->max_product_id) || !empty($discounts->max_category_id) || !empty($discounts->max_category_children) || !empty($discounts->max_zone_id)) {
    $on .= ' LEFT JOIN '.hikashop_table('discount').' AS discount '.
    ' ON (('. implode(') OR (', $join_discount_links) . '))';

    $filters[] = 'discount.discount_type = ' . $database->Quote('discount');
    $filters[] = 'discount.discount_published = 1';
    $filters[] = '(discount.discount_quota = 0 OR discount.discount_quota > discount.discount_used_times)';
    $filters[] = 'discount.discount_start < '.time().'';
    $filters[] = '(discount.discount_end = 0 OR discount.discount_end > '.time().')';
    hikashop_addACLFilters($filters, 'discount_access', 'discount', 2, false);

    if(!empty($discounts->max_zone_id)) {
        $zones = array();
        $zone_id = hikashop_getZone(null);
        $zoneClass = hikashop_get('class.zone');
        $zones = $zoneClass->getZoneParents($zone_id);

        if(!empty($zones)) {
            foreach($zones as &$zone) {
                $zone = hikashop_getEscaped($zone, true);
            }
            unset($zone);

            $filters[] = '(discount.discount_zone_id = \'\' OR discount.discount_zone_id LIKE \'%,' .implode(',%\' OR discount.discount_zone_id LIKE \'%,', $zones) . ',%\')';
        } else {
            $filters[] = 'discount.discount_zone_id = \'\'';
        }
    }
}
else {
    $filters[] = '1=0';
}

Last edit: 7 years 10 months ago by eduardkoks.

Please Log in or Create an account to join the conversation.

  • Posts: 83799
  • Thank you received: 13571
  • MODERATOR
7 years 10 months ago #273361

Hi,

The code modification won't work in all cases as far as I can see.
Suppose that you only have one published discount which apply without any restriction on the categories, products or zones (so it applies to all the products).
With your modification, the listing won't display any product even though all the products should appear.
That's actually done like that to properly handle this case. And this creates the side effect of seeing all the products when you don't have any discounted products that should appear.
The only solution I see would be to add an extra query in your additional else which would load all the discounts without these restrictions but with still the $discount_filter conditions in the query. And you would have the 1=0 added to the products loading query only if that query wouldn't return any result.
What do you think ?
Could you try it ?

Please Log in or Create an account to join the conversation.

Time to create page: 0.057 seconds
Powered by Kunena Forum