Jump to content
thirty bees forum

Price Update with Quantity Discounts


haylau

Recommended Posts

Not sure why I have not spotted this before really. Perhaps because I am now playing with combinations.

We have various tiers of quantity discounts, 10% off for 50, 20% off for 100 etc.

On the product page, when I change combinations the price also changes - great, but when I type or select a quantity the price is not updated. It is fine once added to the cart

(BTW when I tried to upload an animated gif but it would not let me, gave a -200 error, but worked anyway)

So my question is, on the product page should I expect the price to be updated to apply quantity discounts?

If the answer is yes, then i need to work out why it isnt (ideas?

If the answer is no, then is there a module / code hack I can use?

2021-03-18_10-26-14.gif

 

 

image.png

Edited by haylau
Link to comment
Share on other sites

OK, worked out the cause.

In products.tpl I remove a section because I do not want to display the volume discounts table. I want the discounts to work, just do not want to display the big table

So i comment out this code but that stops the functionality. I have tried using display:none but again that stops the functionaility

So looking for clues how to remove / hide the table but retain the functionality

Code I removed (panda theme, but I suspect this may be more generic):

{if !$content_only}
		{if (isset($quantity_discounts) && count($quantity_discounts) > 0)}
			<!-- quantity discount -->
			<section id="product-volume-discounts" class="block section">
				<h3 class="title_block "><span>{l s='Volume discounts'}</span></h3>
				<div id="quantityDiscount">
					<table class="std table-product-discounts">
						<thead>
							<tr>
								<th>{l s='Quantity'}</th>
								<th>{if $display_discount_price}{l s='Price'}{else}{l s='Discount'}{/if}</th>
								<th>{l s='You Save'}</th>
							</tr>
						</thead>
						<tbody>
							{foreach from=$quantity_discounts item='quantity_discount' name='quantity_discounts'}
							{if !$quantity_discount.base_price}{$quantity_discount.base_price=$productPriceWithoutReduction}{/if}
							{if $quantity_discount.price >= 0 || $quantity_discount.reduction_type == 'amount'}
								{$realDiscountPrice=$quantity_discount.base_price|floatval-$quantity_discount.real_value|floatval}
							{else}
								{$realDiscountPrice=$quantity_discount.base_price|floatval*(1 - $quantity_discount.reduction)|floatval}
							{/if}

							<tr class="quantityDiscount_{$quantity_discount.id_product_attribute}" data-real-discount-value="{convertPrice price = $realDiscountPrice}" data-discount-type="{$quantity_discount.reduction_type}" data-discount="{$quantity_discount.real_value|floatval}" data-discount-quantity="{$quantity_discount.quantity|intval}">
								<td>
									{$quantity_discount.quantity|intval}
								</td>
								<td>
									{if $quantity_discount.price >= 0 || $quantity_discount.reduction_type == 'amount'}
										{if $display_discount_price}
											{if $quantity_discount.reduction_tax == 0 && !$quantity_discount.price}
												{convertPrice price = $productPriceWithoutReduction|floatval-($productPriceWithoutReduction*$quantity_discount.reduction_with_tax)|floatval}
											{else}
												{convertPrice price=$productPriceWithoutReduction|floatval-$quantity_discount.real_value|floatval}
											{/if}
										{else}
											{convertPrice price=$quantity_discount.real_value|floatval}
										{/if}
									{else}
										{if $display_discount_price}
											{if $quantity_discount.reduction_tax == 0}
												{convertPrice price = $productPriceWithoutReduction|floatval-($productPriceWithoutReduction*$quantity_discount.reduction_with_tax)|floatval}
											{else}
												{convertPrice price = $productPriceWithoutReduction|floatval-($productPriceWithoutReduction*$quantity_discount.reduction)|floatval}
											{/if}
										{else}
											{$quantity_discount.real_value|floatval}%
										{/if}
									{/if}
								</td>
								<td>
									<span>{l s='Up to'}</span>
									{if $quantity_discount.price >= 0 || $quantity_discount.reduction_type == 'amount'}
										{$discountPrice=$productPriceWithoutReduction|floatval-$quantity_discount.real_value|floatval}
									{else}
										{$discountPrice=$productPriceWithoutReduction|floatval-($productPriceWithoutReduction*$quantity_discount.reduction)|floatval}
									{/if}
									{$discountPrice=$discountPrice * $quantity_discount.quantity}
									{$qtyProductPrice=$productPriceWithoutReduction|floatval * $quantity_discount.quantity}
									{convertPrice price=$qtyProductPrice - $discountPrice}
								</td>
							</tr>
						{/foreach}
						</tbody>
					</table>
				</div>
			</section>
		{/if}

 

Link to comment
Share on other sites

Thanks for the reply. Pretty certain I am doing it correctly, though I am no expert. I have tried removing the code & commenting the code in product.tpl

Also tried adding css to custom.css sections

Also tried directly from the brower Inspect.  If someone wants to try, discounts start at 50 : https://u-bolts-r-us.co.uk/u-bolts-with-convex-base-to-minimise-crevice-corrosion/12123-u-bolt-for-40-nb-483-od-pipe-t316-stainless-steel-with-convex-base-to-minimise-crevice-corrosion-5055624431605.html#.YFOG_q-gLIU)

Always the same

Also tried on another installation with community theme and that is also the same

And lastly tried a free module from presto-chano to move it to below the price. The module did not display properly but the effect was the same. 

Weird

I was going to test the demo but demo.front does not seem to have any volume discounts set, and demo.back is, well, broken

To be honest I would be happy to leave it on if i could move it into a proper tab, or even better in product secondary column, to the right of the current price / buy now button

Edited by haylau
Link to comment
Share on other sites

You are right, making it not visible really break javascript. That's insane. Please file bug on gitub (although that will fix the issue in niara/community theme)

You could try to fix it yourself. Edit file product.js, find function findSpecificPrice, and remove this: .not(':hidden');

image.png.9f2c04216e8f015a1eddf0ce4ec7c33c.png

This is second similar issue I've seen lately. We really need to implement some javascript data layer for themes, and not depend on data stored in dom.

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

I have created the github bug report

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

I have added an html block to the product secondary column to display a static volume discount display

Looks OK, but is fixed. Should it be possible to add the relevant code from products.tpl to the html box to display and automatic table in the html block? That way I can display the actual prices. I have tried but it just displays code. 

Possible?

 

image.thumb.png.a622257bd27f3973fd717b8c3dce8929.png

Link to comment
Share on other sites

On 3/18/2021 at 9:26 PM, haylau said:

Looks OK, but is fixed. Should it be possible to add the relevant code from products.tpl to the html box to display and automatic table in the html block? That way I can display the actual prices. I have tried but it just displays code. 

Possible?

Mmm I think you will have to change the template, because you have to print smarty variables... I think you won't be able to do that with HTML block...

  • Like 1
Link to comment
Share on other sites

So, I managed to move the block of code in products.tpl - and it looks great

Now, there is a calculation issue. This is not to do with moving the code. I have tried leaving the code where it should be. Not to do with the theme because I have tried the code directly from niara. It ust be an inherant bug

I have changed the table to show prices rather than discount level 

Display discounted price set to yes in preferences > Products

 
So, the calculations are all over the place. som times totally wrong, sometimes partially wrong. It is not to do with browsers or caches
 
Some examples
This one shows price is calculated correctly on the main buy box, but the volumes discounts not calcualted at all
 
image.thumb.png.51e639b2cbb31fe335e9e9565670f894.png
 
 
This one shows most of the volume discounts are correct, just not the last one
 
image.thumb.png.e185eb2086b1e618837527be81b8b8b8.png
 
 
 
And this one shows some calculations but they are all wrong
 
image.thumb.png.19000fe729160e47fd4d85dbb3850777.png
 
 
And just for reference all products have got these discounts associated with them
 
image.png.50282d2ac9a4b434f67f46c0ce53a647.png
 
I will have to leave it showing % for now, but this is weird. At first I thought it may just be to do with rounding on small values because I was looking at low value products, but that last one shows that is not the case. Any clues?
 

image.png

Edited by haylau
Link to comment
Share on other sites

@haylau From the information you provided I don't really understand what is wrong, or what expected values should look like.

Plese provide more detailed information:

  • product base price
  • discount settings
  • expected results
  • actual result

It would be best if you could reproduce the problem on vanilla installation of thirty bees, to ensure that the problem is not caused by some of your modules and/or overrides.

Thank you

Link to comment
Share on other sites

6 hours ago, datakick said:

Out of curiosity I have created a test product, with base price = 100. I set not tax for the product. I then set quantity discounts in the same way you did. My result:

image.png.2403e66825f1692424a21e36e7ff0773.png

It looks like it works correctly.

Thanks - because of your results I did some more digging. I found that some products had specific prices embedded within them (Catalog > Products) so there must have been a conflict. So for example the product would have a catalogue price rule and a specific price rule at the same time. I have removed all those embedded into individual products and now all is OK - almost

(We have never embeded specific prices into products it has always been whole cataloge based so wonder if there has been a change in how thirtybees / prestashop has done this since origianlly 1.4 that has perhaps corrupted with various upgrades)

For the almost but I think we have small rounding error. But I will play some more and start a new thread if necessary

Thanks

 

image.png

  • Like 1
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...