Jump to content
thirty bees forum
  • 0

Niara theme wrong calculation of volume discounts - Problems and solutions


Enev

Question

Hello guys,

While setting up my own shop, I stumbled upon some nasty bugs in the product page when dealing with volume discounts, different currencies and product combinations.

Background:

It's multi-currency shop. Version is Bleeding Edge 1.1.x (the same problems are present in 1.1.0 too). 

It has EUR and BGN. Default (base) currency is EUR. For the record: 1EUR = 1,9558 BGN

I've set up following discounts for my products (Catalog Price Rules):

1+ - 10%
7+ - 15%
11+ - 20%
16+ - 25%

There are both simple products and products with attributes that affect the price (Impact on price + Impact on unit price).

So, I encountered following problems:

Case 1:

Preconditions:

Product with combinations is loaded.
Currency is set to non-default. 
Admin: Preferences - Product - Display discounted price: Yes

Issue:

Discounted prices both in the Volume discounts table and on the product price when crossing the threshold are wrong. More precisely they equal the correct prices * 1,9558 (the exchange rate). 

Cause:

Wrong calculation in function updateDiscountTable() in product.js

Solution:

\themes\niara\js\product.jsproduct.js

Line 980-984:

    if (displayDiscountPrice != 0 && discountedPrice != 0) {
      $(this).children('td').eq(1).text(formatCurrency(discountedPrice, currencyFormat, currencySign, currencyBlank));
      $(this).attr('data-real-discount-value', formatCurrency(discountedPrice, currencyFormat, currencySign, currencyBlank));
    }
    $(this).children('td').eq(2).text(upToTxt + ' ' + formatCurrency(discountUpTo, currencyFormat, currencySign, currencyBlank));

"* currencyRate" has been removed.

Case 2:

Preconditions:

Product with combinations is loaded.
A combination which affects the prices is selected.
Admin: Preferences - Product - Display discounted price: No

Issue:

Discounted price when crossing the threshold is wrong. It shows the discounted base price of the product.

Example:

A product costs 100 EUR.
An option which increases the price to 110 EUR is selected.
When crossing the threshold of 7 products the displayed price is 85 EUR instead of 93,5%

Cause:

Attribut not set in function updateDiscountTable() in product.js

Solution:

\themes\niara\js\product.js

Again in the Line 980-984 block:

    if (displayDiscountPrice != 0 && discountedPrice != 0) {
      $(this).children('td').eq(1).text(formatCurrency(discountedPrice, currencyFormat, currencySign, currencyBlank));
    }
    $(this).attr('data-real-discount-value', formatCurrency(discountedPrice, currencyFormat, currencySign, currencyBlank));
    $(this).children('td').eq(2).text(upToTxt + ' ' + formatCurrency(discountUpTo, currencyFormat, currencySign, currencyBlank));

The setting of the 'data-real-discount-value' was moved outside the "if" clause.

Case 3:

Preconditions:

Product without combinations is loaded.
Catalog price rules Reduction type: Percentage
Reduction with or without taxes: Tax Excluded
Admin: Preferences - Product - Display discounted price: Yes

Issue:

Discounted prices in the Volume discounts table are wrong. They show the product's base price.
(However the product itself has correct price and proper quantity discounts are applied.)

Cause:

It seems that $quantity_discount.reduction_with_tax returns zero, which is quite logical when the reduction is "Tax Excluded"

Solution:

\themes\niara\product.tpl

Line 521-529:

                      {if $display_discount_price}
                        {convertPrice price = $productPriceWithoutReduction|floatval-($productPriceWithoutReduction*$quantity_discount.reduction)|floatval}                        
                      {else}
                        {$quantity_discount.real_value|floatval}%
                      {/if}

Since mathematically it's equal if you apply the percentage discount before or after tax, I think the code shouldn't branch either, so lines 522, 523, 524 and 526 are removed.

Price * Tax * Discount = Price * Discount * Tax
e.g. 100 EUR * 1,2 (20% Tax) * 0,9 (10% Discount) = 100 EUR * 0,9 (10% Discount) * 1,2 (20% Tax)

 

As attachments I have uploaded my modified files. I'm not very good with github but i tried to commit them there too: https://github.com/enev13/niara

product.tpl

  • Like 2
  • Thanks 1
Link to comment
Share on other sites

10 answers to this question

Recommended Posts

  • 0

Excelent bug report, thank you. I have copied it to github issues so it won't be forgotten:

https://github.com/thirtybees/thirtybees/issues/1098

Note that we need to investigate if this is change in core (impacts all themes), or if it's niara-only related issue.  If it's niara specific issue, I'll review your changes and integrate them directly from your github repository. If it's change in core, it needs to be fixed differently. 

  • Like 1
  • Thanks 2
Link to comment
Share on other sites

  • 0

I'm glad I could help!

Please note I did changes also to product.tpl (regarding Case 3) - https://github.com/thirtybees/niara/pull/21

While we're still at the discounts topic, I've noticed something else, which I'm not sure if is a bug or a feature:

As I've mentioned earlier I have following discounts:

1+ - 10%
7+ - 15%
11+ - 20%
16+ - 25%

So when I open a product I see following:

image.png.bf86777139f4607954d60356c54e3626.png

However, when I select 7 products the price changes but not the discount percentage, it still shows 10%, although it's already 15%:

image.png.5d813c4265bd061e456f05eec364748b.png

I found this somehow misleading for the customer, as I expect this value to change dynamically just as the price changes.

However, I'm not sure if it's intended to be that way by design or is it a bug because for other "non-promotional" products you don't see the price reduction percentage at all. For example I've set this product up to have discount only for 3+ pcs.:

image.png.f7ce94d44dc79cf794fcd830ffa3adc4.png -> image.png.1df9e92ae7d142fea4327460ff6c4db5.png

 

Link to comment
Share on other sites

  • 0
1 hour ago, Enev said:

However, when I select 7 products the price changes but not the discount percentage, it still shows 10%, although it's already 15%:

image.png.5d813c4265bd061e456f05eec364748b.png

I found this somehow misleading for the customer, as I expect this value to change dynamically just as the price changes.

However, I'm not sure if it's intended to be that way by design or is it a bug because for other "non-promotional" products you don't see the price reduction percentage at all. For example I've set this product up to have discount only for 3+ pcs.:

Great catch, I'll try to investigate this JS problem asap.

thank you for fixing the calculation price in the previous post.

  • Like 1
Link to comment
Share on other sites

  • 0

I propose this solution... but Maybe there will be some side effects, here is the product.js files to put into the /js folder of the Niara theme.

It works for discounts based on amount of products bought, please test it and repport it here before I post on github the modifications.

🙂

product.js

Link to comment
Share on other sites

  • 0

I've just tested it and the results are pretty strange. A different behavior is observed whenever the product has combinations or not. I've used the same products from the example above:

Case 1: Product has no combinations

Result: Neither the price, nor the discount are changed:

image.png.f7c46d5f0e72af90670292fb2a99cf11.png

I haven't investigated yet why that happens.

 

Case 2: Product has combinations

Result: The correct price is displayed, discount percentage is totally off, plus we have one more "-" sign:

image.png.690fe8831fcfb4f9eb14309c26dcec05.png

The superfluous '-' is on line 905 and the wrong percentage is because priceWithDiscountsDisplay is 133740 instead of 1337,40. Reason for that is the regex on line 875 that deletes (in my case) the decimal coma. I suppose your test shop is formatted to display long floats like "1,337.40" and mine is "1 337,40". Anyway I don't think this string parsing is sustainable solution, because there are 6 different possible currency formats.

Link to comment
Share on other sites

  • 0
57 minutes ago, x97wehner said:

I just discovered this same issue on my end as well tonight while trying to configure sales for black friday. I'm using the latest BE release and the warehouse theme, but getting exactly the same issues as mentioned above.

You will have to ask theme developer to fix it. Most themes (even commercial) are all derived from the same grandfather theme, so they often share the same set of bugs.  

Link to comment
Share on other sites

  • 0
3 minutes ago, datakick said:

You will have to ask theme developer to fix it. Most themes (even commercial) are all derived from the same grandfather theme, so they often share the same set of bugs.  

As stated above, the issue exists in Niara as well. I realized that this is still a theme and your statement is likely true, but if packaged with TB OOB, it should work right and it does not. I tried a vanilla install of TB as well with Niara and it doesn't work. I get the same issues mentioned above. They recur in the Warehouse theme.

Link to comment
Share on other sites

  • 0
22 minutes ago, x97wehner said:

As stated above, the issue exists in Niara as well. I realized that this is still a theme and your statement is likely true, but if packaged with TB OOB, it should work right and it does not. I tried a vanilla install of TB as well with Niara and it doesn't work. I get the same issues mentioned above. They recur in the Warehouse theme.

I don't understand. These issues were fixed in Niara, and they will be part of the next 1.1.1 release. Of course, the fix is not applied retroactively to 1.1.0  

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...