[SOLVED] Discount not on list view but only on detail page

  • Posts: 290
  • Thank you received: 22
7 years 5 months ago #271194

-- url of the page with the problem -- : www.viajuul.nl
-- HikaShop version -- : 3.1.1
-- Joomla version -- : 3.7.2
-- PHP version -- : 7.0.19

Hi,
I'm a bit searching for the cause of the discount behaviour on my site.
We have monthly updates of our discounted products and after applying the updates for this month I found that the discounts are not applied when I have the products in a catagory list. When I click on a product, the detail page comes up and the right prices is visible.

Have been removing modified views to see if they are the issue but unfortunately no luck so far.
Any tips are most welcome.
Discount not applied : list view
Discount applied : detail view

Last edit: 7 years 5 months ago by nico.van.leeuwen. Reason: problem solved after update

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

  • Posts: 200
  • Thank you received: 75
7 years 5 months ago #271206

- EDIT -

Hi,

apologies for the previous answer and edit, we can reproduce the same issue, in Hikashop 3.0.1 discounts showed correctly in product listings, but in 3.1.1 not anymore.

Last edit: 7 years 5 months ago by GW.

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
7 years 5 months ago #271197

Hi,

@nico.van.leeuwen : In the settings of your menu item, under the "products options" there is a discount setting where you can configure if you want to see the prices with or without discount on the listing.

@GW : We do not have any issue with the display of the discounted prices on the listings as far as I could test. Please provide screenshots and more information as we can't reproduce.

Last edit: 7 years 5 months ago by nicolas.

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

  • Posts: 290
  • Thank you received: 22
7 years 5 months ago #271221

Hi Nicolas,

This is set to "display discount amount".
It has not been touched for a long time.

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

  • Posts: 200
  • Thank you received: 75
7 years 5 months ago #271274

Hi Nicolas,

we're pretty sure we have the same issue as nico.van.leeuwen, to clarify: in Hikashop 3.0.1 our listings showed discounted prices fine.
When we update to 3.1.1 without touching any settings anywhere, suddenly the listings are not showing discounted prices anymore at all, it's always the original full price.

If we install 3.0.1 back again and refresh frontend, discounted price is back. So something has changed somewhere between 3.0.1 and 3.1.1 but it isn't us who changed anything. The product pages always show discounts fine both in 3.0.1 and 3.1.1.


If you need any screenshots, let us know, but we're fairly sure it's not any of our settings that is at fault.
We did a little bit of searching, perhaps the following is of help to narrow down the issue:
If we set "Discounted only" to Yes, the listing will correctly show all discounted products but still not with the correct discounted price.
If we print_r the variable $this->row in our product/category listing, in 3.1.1 all the discount variables are missing completely.

Hopefully this is of help.

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
7 years 5 months ago #271277

Hi,

I'm not doubting you. It's just that I tested myself on HikaShop 3.1.1 with discounted products and it worked just fine.

So try this:
create a discount without any restriction so that it applies to all the products and make sure that the discount price display setting is properly set in your menu item.
Then, you should see the discounted price on the listing, like me.
So that means that there is something on your website, maybe the way the discount is configured, or the way the products are configured, which makes it not work with changes included in the 3.1.1.
If I check the change log of HikaShop, I see this line:
The price of products without price but with variants with price was not displaying on the products listing due to a side-effect of the code changes to support variants on discounts in HikaShop 3.1.0.
That fix was included in HikaShop 3.1.1.
So maybe it has some unforseen side-effect in your case.

The fix consisted in changing the line:
if($price->price_product_id == $element->product_id) {
to:
if(!empty($element->variant_ids) && in_array($price->price_product_id, $element->variant_ids)) {
in the file administrator/components/com_hikashop/classes/currency.php

Unfortunately, we don't know how your products or how your discounts are configured. So I can't reproduce the problem on my end.
Could you provide screenshots of a discount settings, a product settings, a menu item settings and a link to the page with the issue where that product appears ?
Also, try to revert that patch to see if it comes from that or not.

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

  • Posts: 200
  • Thank you received: 75
7 years 5 months ago #271318

Hi Nicolas,

we've narrowed the issue down in the file currency.php, it wasn't the line you mentioned, but line 496:

$product_matches[] = 'discount_product_id LIKE \'%,'.(int)$all_ids.',%\'';

The variable $all_ids looks to be incorrect, since you're looping $id, this has changed from 3.0.1 to 3.1.1.
If we're not mistaken, you meant to change the variable $ids on line 495 to $all_ids but instead changed the wrong variable.

If we change $all_ids on line 496 to $id the discount prices are correct again in the listings.

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
7 years 5 months ago #271397

Hi,

Actually, the whole:

foreach($ids  as $id) {
				$product_matches[] = 'discount_product_id LIKE \'%,'.(int)$all_ids.',%\'';
			}
should be removed since it is now handled by
$product_matches = array(
				'discount_product_id IN (\'\',\'0\',\''.implode('\',\'', $all_ids) . '\')',
			);
above it.
Try removing the foreach and that should work properly too.

Replacing $all_ids by $id would make it work but only with discounts applied to main products, not for discounts applied to variants, which was the point of changing the code around there.

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

  • Posts: 290
  • Thank you received: 22
7 years 5 months ago #271406

Hi,
Just curious but is this going to be applied in the latest downloads ?
Thanks everybody for helping to sort this!

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

  • Posts: 200
  • Thank you received: 75
7 years 5 months ago #271409

Hmm, no that doesn't work either Nicolas, hopefully you can take a minute to look at your code, because I think you may have it mixed up. Apologies if I'm wrong, but the query

$product_matches = array(
	'discount_product_id IN (\'\',\'0\',\''.implode('\',\'', $all_ids) . '\')',
);
is never going to return any results, right.

- If you create a discount on some products, in the database the discount_product_id's are stored as for example: ,9,13,7,
- In a product listing the $product_matches can look something like: discount_product_id IN ('','0','6','10','14','9','8','7','13','5')

This means it will try to match the entire string ",9,13,7," against '6' or '10' or '14', etc. which is never true, isn't it?
It will compare discount_product_id to each value and look for an exact match, which even with a discount applied to only one product will never happen because discount_product_id will have commas around it and e.g. ',9,' is not equal to '9'.


The LIKE queries created in the foreach loop on the other hand will return true since ,9,13,7, will match %,13,%. So instead of
$product_matches = array(
	'discount_product_id IN (\'\',\'0\',\''.implode('\',\'', $all_ids) . '\')',
);
foreach($ids  as $id) {
	$product_matches[] = 'discount_product_id LIKE \'%,'.(int)$all_ids.',%\'';
}

the IN doesn't do anything and what seems to work correctly so far as we've tested is
$product_matches = array();
foreach($all_ids  as $id) {
	$product_matches[] = 'discount_product_id LIKE \'%,'.(int)$id.',%\'';
}

In any case, hopefully you can take a look at it, thanks!

Last edit: 7 years 5 months ago by GW.

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
7 years 5 months ago #271415

Hi,

Thank you for your feedback. Indeed, I had forgotten about that.
Now your code is missing some bits as it needs to match with 0 and empty, and it should be backward compatible to discounts saved in the database when the discount_product_id column was an integer type.

Thus, the final code should be that I think:

$product_matches = array('discount_product_id IN (\'\',\'0\',\''.implode('\',\'', $ids) . '\')');
			foreach($all_ids  as $id) {
				$product_matches[] = 'discount_product_id LIKE \'%,'.(int)$id.',%\'';
			}
I've tested it on my end and it seems to work.
Please check on your end.

And to answer nico.van.leeuwen, yes that patch will be included. You can easily test it yourself by just replacing the code.

Last edit: 7 years 5 months ago by nicolas.

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

  • Posts: 200
  • Thank you received: 75
7 years 5 months ago #271477

Ah yes, the final code works fine at our end too, thanks!

The following user(s) said Thank You: nicolas

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

  • Posts: 290
  • Thank you received: 22
7 years 5 months ago #271520

Hi, the issue is solved after applying the latest download :)

Thank you all for helping !

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
7 years 5 months ago #271483

The code has been included on our end.
If anyone wants it without applying the patch manually, you can download the install package on our website in the menu My account>My subscriptions and install it on your website and it will be added automatically.

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

Time to create page: 0.092 seconds
Powered by Kunena Forum