[Skip to main content](#vessel-content)

#   Negative Discounts not calculating as expected

##

- **[dustinjc](/forum/user/31466-dustinjc "View dustinjc's Profile")**
- [![dustinjc's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar31466.jpg)](/forum/user/31466-dustinjc "View dustinjc's Profile") Topic Author
- [ Offline](/forum/user/31466-dustinjc)

Less More

- Posts: 176
- Thank you received: 5
-
-

9 years 4 months ago -  9 years 4 months ago [\#274798](#274798) by [dustinjc](/forum/user/31466-dustinjc "View dustinjc's Profile")  *[Negative Discounts not calculating as expected](/forum/46-discount-coupon/891300-negative-discounts-not-calculating-as-expected#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....")* was created by *[dustinjc](/forum/user/31466-dustinjc "View dustinjc's Profile")*

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: 9 years 4 months ago by [dustinjc](/forum/user/31466-dustinjc "View dustinjc's Profile").

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzQ2LWRpc2NvdW50LWNvdXBvbi84OTEzMDAtbmVnYXRpdmUtZGlzY291bnRzLW5vdC1jYWxjdWxhdGluZy1hcy1leHBlY3RlZD90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[Jerome](/forum/user/80-jerome "View Jerome's Profile")**
- [![Jerome's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar80.png)](/forum/user/80-jerome "View Jerome's Profile")
- [ Offline](/forum/user/80-jerome)
- HikaShop core developer

Less More

- Posts: 26402
- Thank you received: 4081
-
- [](http://obsi.dev)
-

9 years 4 months ago -  9 years 4 months ago [\#274851](#274851) by [Jerome](/forum/user/80-jerome "View Jerome's Profile")  Replied by *[Jerome](/forum/user/80-jerome "View Jerome's Profile")* on topic *[Negative Discounts not calculating as expected](/forum/46-discount-coupon/891300-negative-discounts-not-calculating-as-expected#274851 "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....")*

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 Code:

$value = sprintf('%09.2f',$discount-&gt;discount_flat_amount).'_'.sprintf('%09.4f',$discount-&gt;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". Code:

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](http://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](http://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 &amp; HikaSerial developer / HikaShop core dev team.

Last edit: 9 years 4 months ago by [Jerome](/forum/user/80-jerome "View Jerome's Profile"). Reason: (adding a bit more of explanation)

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzQ2LWRpc2NvdW50LWNvdXBvbi84OTEzMDAtbmVnYXRpdmUtZGlzY291bnRzLW5vdC1jYWxjdWxhdGluZy1hcy1leHBlY3RlZD90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[dustinjc](/forum/user/31466-dustinjc "View dustinjc's Profile")**
- [![dustinjc's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar31466.jpg)](/forum/user/31466-dustinjc "View dustinjc's Profile") Topic Author
- [ Offline](/forum/user/31466-dustinjc)

Less More

- Posts: 176
- Thank you received: 5
-
-

9 years 4 months ago [\#274868](#274868) by [dustinjc](/forum/user/31466-dustinjc "View dustinjc's Profile")  Replied by *[dustinjc](/forum/user/31466-dustinjc "View dustinjc's Profile")* on topic *[Negative Discounts not calculating as expected](/forum/46-discount-coupon/891300-negative-discounts-not-calculating-as-expected#274868 "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....")*

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](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzQ2LWRpc2NvdW50LWNvdXBvbi84OTEzMDAtbmVnYXRpdmUtZGlzY291bnRzLW5vdC1jYWxjdWxhdGluZy1hcy1leHBlY3RlZD90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[Jerome](/forum/user/80-jerome "View Jerome's Profile")**
- [![Jerome's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar80.png)](/forum/user/80-jerome "View Jerome's Profile")
- [ Offline](/forum/user/80-jerome)
- HikaShop core developer

Less More

- Posts: 26402
- Thank you received: 4081
-
- [](http://obsi.dev)
-

9 years 4 months ago [\#274878](#274878) by [Jerome](/forum/user/80-jerome "View Jerome's Profile")  Replied by *[Jerome](/forum/user/80-jerome "View Jerome's Profile")* on topic *[Negative Discounts not calculating as expected](/forum/46-discount-coupon/891300-negative-discounts-not-calculating-as-expected#274878 "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....")*

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 &amp; HikaSerial developer / HikaShop core dev team.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzQ2LWRpc2NvdW50LWNvdXBvbi84OTEzMDAtbmVnYXRpdmUtZGlzY291bnRzLW5vdC1jYWxjdWxhdGluZy1hcy1leHBlY3RlZD90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[dustinjc](/forum/user/31466-dustinjc "View dustinjc's Profile")**
- [![dustinjc's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar31466.jpg)](/forum/user/31466-dustinjc "View dustinjc's Profile") Topic Author
- [ Offline](/forum/user/31466-dustinjc)

Less More

- Posts: 176
- Thank you received: 5
-
-

8 years 6 months ago [\#293576](#293576) by [dustinjc](/forum/user/31466-dustinjc "View dustinjc's Profile")  Replied by *[dustinjc](/forum/user/31466-dustinjc "View dustinjc's Profile")* on topic *[Negative Discounts not calculating as expected](/forum/46-discount-coupon/891300-negative-discounts-not-calculating-as-expected#293576 "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....")*

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](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzQ2LWRpc2NvdW50LWNvdXBvbi84OTEzMDAtbmVnYXRpdmUtZGlzY291bnRzLW5vdC1jYWxjdWxhdGluZy1hcy1leHBlY3RlZD90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Offline](/forum/user/63-nicolas)

Less More

- Posts: 86593
- Thank you received: 14334
-
-

8 years 6 months ago [\#293586](#293586) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Negative Discounts not calculating as expected](/forum/46-discount-coupon/891300-negative-discounts-not-calculating-as-expected#293586 "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....")*

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](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzQ2LWRpc2NvdW50LWNvdXBvbi84OTEzMDAtbmVnYXRpdmUtZGlzY291bnRzLW5vdC1jYWxjdWxhdGluZy1hcy1leHBlY3RlZD90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

Board Categories HikaShop Install &amp; Update Product &amp; Category Display Content Creation Sales and Orders Orders management Reports &amp; Statistics Customers Checkout Payment Methods Shipping Methods Import &amp; Export (CSV, XLS…) Specific Features Affilation Taxes Wishlist Vote Carousel &amp; Slider Mass Actions Filters &amp; Search Discount &amp; Coupon Feature Request Integrations Showcase General Talk about HikaShop Development HikaShop 3.0 Beta Translation Commercial Jobs HikaShop Components HikaMarket Market: Feature requests Market: How to? Market: Bug Report HikaSerial General talk about HikaSerial Serial: Bug Report Serial: How to? Support en Français de HikaSerial (French Support) HikaSubscription HikaAuction Auction: Feature requests Auction: How to? Auction: Bug report Hikashop around the world Support en Français (French Support) Russian FAQ. Курс выживания с Hikashop. Частые вопросы и о Расширения Hikashop Наши сайты на Hikashop 日本語版サポート(Japanese Support) Thai German Archives Bug Report How to?

[](/forum/topics/feed/mode-topics?format=feed&type=rss)

Time to create page: 0.060 seconds

[Powered by](/forum/credits) [Kunena Forum](https://www.kunena.org)
