Negative Discounts not calculating as expected

  • Posts: 176
  • Thank you received: 5
  • Hikashop Business
6 years 8 months ago #274798

We are utilizing negative discounts to add to our product prices. We are doing this because it is much easier to maintain than 3 prices for each of over 300 products. We used to do it that way. However, when prices change from our supplier it was a nightmare to update (terribly time-consuming). Doing it with negative discounts allows us to create a global markup system while also allowing us to track the 'cost' of the products within Hikashop - which is very convenient.

However, the negative discounts are not overriding each other as expected.

For instance, we are using the following custom ACL groups (each discount restricted to the same product categories):

Public Discount: -$15 (adds $15)
Employee Discount: -$10 (adds $10)
Cost Discount: -$2.50 (adds ($2.50)

Example Product Price: $10

If a user is a member of the Employee and Cost group, they receive the Employee price ($20) not the lower Cost price ($12.50).

Since -$2.50 is 'larger' than -$10 we would expect the price to be $12.50

We can only get it to work if users are members of the Cost OR Employee group - which is not practical. Members of the Cost group are always Employees.

Pls advise.

Thank you,
Dustin

Last edit: 6 years 8 months ago by dustinjc.

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

  • Posts: 26000
  • Thank you received: 4004
  • MODERATOR
6 years 8 months ago #274851

Hello,

I'm afraid that the algorithm for the selection of the discount do not handle the negative prices because it uses a sorting key which is a string.

In the HikaShop currency class, you will find the function "selectDiscount" and in there, a line for the sorting key definition

$value = sprintf('%09.2f',$discount->discount_flat_amount).'_'.sprintf('%09.4f',$discount->discount_percent_amount);
Near the end of the function, there is a selection of the "best" discount and the discounts are sorted by that "value".
krsort($discount);
The thing is, because the key is a string, the symbol "-" will be used a character and not as a number.

See : php.net/manual/en/function.krsort.php
By default the sorting is using the REGULAR mode ; but in your specific case, a natural sorting would be better.
So you'll need to change the flag for the krsort call to set that "SORT_NATURAL" flag (cf: php.net/manual/en/function.sort.php )
But I can't guarantee that it will work fine because it is based on a string and I don't know how it will react with the other half of the key...

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.
Last edit: 6 years 8 months ago by Jerome. Reason: (adding a bit more of explanation)

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

  • Posts: 176
  • Thank you received: 5
  • Hikashop Business
6 years 8 months ago #274868

Thank you. In making this change I'm assuming it will be overwritten when the extension is updated and will have to be re-applied?

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

  • Posts: 26000
  • Thank you received: 4004
  • MODERATOR
6 years 8 months ago #274878

Hello,

You first need to check if it really fix the issue.
Because there is some concatenate content, I'm not sure like that if it will really solve your issue.
If it fix it, I would talk with Nicolas to see if we want to integrate it into the HikaShop core.
As you know the discounts should not be negative and we have to decide if HikaShop should support it or not (because it might have some other effect that we did not know yet).

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

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

  • Posts: 176
  • Thank you received: 5
  • Hikashop Business
5 years 10 months ago #293576

Just a quick update to let you know that we have been using the negative discounts for some time on our production site and they seem to be working fine. Do you know if these will continue to work in the future? Really hoping so, we have a lot of products relying on this functionality.

Thank you,
Dustin

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

  • Posts: 81484
  • Thank you received: 13062
  • MODERATOR
5 years 10 months ago #293586

Hi,

Thanks for the feedback.
We don't have any plans to remove that capability.
You can consider it as an official capability that won't be removed in the future.

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

Time to create page: 0.070 seconds
Powered by Kunena Forum