This article will be useful for those, who are not using multiple special prices in their stores. Using the special price feature you can either simply set a new price for a product or set percent or amount of discount which always attracts customers.
Today we’ll show you how to change the default way of displaying discounts. By default, if we set a new price for 3 products, the product page will contain a block with prices for several items:
But you must agree, that it is better for your customers to see the bulk purchase price near the main price, as well as to display the bulk price on the category page.
So, let’s try to implement our idea! We will need to make changes in the following files:
product-list.tpl:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
<span itemprop="price" class="price product-price"> {if !$priceDisplay} {$productPrice=$product.price} {else} {$productPrice=$product.price} {/if} {if isset($product.quantity_discounts[0])} {if $product.quantity_discounts[0].price >= 0 || $product.quantity_discounts[0].reduction_type == 'amount'} {$discountPrice=$productPrice-$product.quantity_discounts[0].reduction|floatval} {else} {$discountPrice=$productPrice-($productPrice*$product.quantity_discounts[0].reduction)|floatval} {/if} {$discountPrice=$discountPrice*$product.quantity_discounts[0].from_quantity} {convertPrice price=$productPrice} - {$product.quantity_discounts[0].from_quantity} {l s='for'} {convertPrice price=$discountPrice} {else} {convertPrice price=$productPrice} {/if} </span> |
product.tpl:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
... <p id="reduction_amount" {if (!$product->specificPrice || $product->specificPrice.reduction_type != 'amount' || $product->specificPrice.reduction|floatval ==0) && !count($quantity_discounts)} style="display:none"{/if}> <span id="reduction_amount_display"> {if $product->specificPrice && $product->specificPrice.reduction_type == 'amount' && $product->specificPrice.reduction|intval !=0} -{convertPrice price=$productPriceWithoutReduction-$productPrice|floatval} {else} {*specific price for quantity*} {if count($quantity_discounts)} {if $quantity_discounts[0].price >= 0 || $quantity_discounts[0].reduction_type == 'amount'} {$discountPrice=$productPrice-$quantity_discounts[0].real_value|floatval} {else} {$discountPrice=$productPrice-($productPrice*$quantity_discounts[0].reduction)|floatval} {/if} {$discountPrice=$discountPrice*$quantity_discounts[0].quantity} {$qtyProductPrice = $productPrice*$quantity_discounts[0].quantity} {$quantity_discounts[0].quantity|intval} {l s='for'} {convertPrice price=$discountPrice} {/if} {/if} </span> </p> ... |
override/classes/Product.php:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
<?php class Product extends ProductCore { /* new function */ public static function getQtyDiscount($id_product, $id_shop, $id_currency, $id_country, $id_group){ //logic from ProductController::assignPriceAndTax() $quantity_discounts = SpecificPrice::getQuantityDiscounts($id_product, $id_shop, $id_currency, $id_country, $id_group, null, true, (int)Context::getContext()->customer->id); foreach ($quantity_discounts as &$quantity_discount) { if (isset($quantity_discount['id_product_attribute'])) { $combination = new Combination((int)$quantity_discount['id_product_attribute']); $attributes = $combination->getAttributesName((int)Context::getContext()->language->id); foreach ($attributes as $attribute) $quantity_discount['attributes'] = $attribute['name'].' - '; $quantity_discount['attributes'] = rtrim($quantity_discount['attributes'], ' - '); } if ((int)$quantity_discount['id_currency'] == 0 && $quantity_discount['reduction_type'] == 'amount') $quantity_discount['reduction'] = Tools::convertPriceFull($quantity_discount['reduction'], null, Context::getContext()->currency); } unset($quantity_discount); return $quantity_discounts; } // override reason: quantity_discounts row public static function getProductProperties($id_lang, $row, Context $context = null) { $row = parent::getProductProperties($id_lang, $row, $context); $row['quantity_discounts'] = self::getQtyDiscount($row['id_product'], Context::getContext()->shop->id, $row['specific_prices']['id_currency'], $row['specific_prices']['id_country'], $row['specific_prices']['id_group'] ); //override reason return $row; } } |
This is what we have as a result:
thanks a lot for reply!! you save my time also !
Now i got another error , is from product.php :
Notice: Undefined index: attributes in /var/www/xxx/html/xxxx/override/classes/Product.php on line 17
This notice appears in 1 categoryy only.
It can be edited in product-list.tpl file.
It works well but i can`t change the translation of the word “for” into our language, maybe somebody knows how to do ?
how to make it work well on the home page? On the main show unit prices
very nice, you saved my time, cheers ;)
Hello , thank you for that explanation. it works perfectly ( version 1.6.4 ) I would provide all the values in the table , not just the first example quantity / price for 10 for 100 ect .. how can I do? Thank you
Hey Alex
Is it possible to show price for 1 bottle of wine, and the price for 6 bottles, but not the total, but the price pr. bottle if bought 6 bottles.
Prestashop 1.6.0.13
I tried to use your hack but it runs onlu in product.tpl and not in product-list.tpl.
When I go on a product-list based page I only see a duplicate price price of the item but not the price for quantity.
This double price is showed for all items and not only for what have a quantity discount.
How can I make it on prestashop 1.6
Maurizio,
You can contact our support team at [email protected] and will help you.
Ralf,
most likely it depends on the discounts type. You can also contact our support team ([email protected]) for the solution.
Hy
I tried to use your hack but it doesn’t run: when I insert the override in classes/Product.php
(I use PS 1.6.013 and Product.php is not in override/classes/ but in /classes/ dir) the result is a blank screen.
I tried deleting /cache/class_index.php but the result is the same.
Any Idea?
Very nice work! I however need this for the special prices table on the product page.
Now it shows quantity (50, 100, 500, 1000 etc.) and it shows the discount in percentage (-20%, -33.33%, -40%, -46.67% etc.)
What I want is for each to show the unit price too.. ($8, $6, $4, $2 etc.) Or just like your “Volume Discounts” screenshot..