Get Free Audit

Displaying Product Combinations With Discounts on a Product Page in Prestashop

Aug 25, 2016

3734 Dima Doroshchenko

Displaying Product Combinations With Discounts on a Product Page in Prestashop

Our goal is to display available product combinations and their prices on a product page. For example, our store proposes some loyalty discount program, and we should show all product prices in a proper way. The following solution will fit for you in case you have a variety of product combinations and a set of user group discount rules.

Among them are: Distributors, Regular customers, Special customers, etc.

There are several methods how to apply a discount in PrestaShop:

Group discount — you can set up a discount in % for a certain User Group:
How to Add Product Combinations Involving the Use of Discount System on a Product Page in PrestaShop

Catalog Price Rules — allow setting up a discount depending on a product quantity, user group, combination, etc. Moreover it’s possible to set up a discount for each product separately (Specific Price):
How to Add Product Combinations Involving the Use of Discount System on a Product Page in PrestaShop

Combination Impact on price — set price for every combination:
How to Add Product Combinations Involving the Use of Discount System on a Product Page in PrestaShop

Moreover there are some types of discount rules based on the cart items (Cart Rules), but we won’t consider this case in this post.

By default a price is displayed only for the selected combination. After a product attribute is changed, a new price is calculated according to the applied discount rules. So we just need to understand the process of these calculations and apply it to all possible combinations.

modules prestashop belvg

PrestaShop Modules

Take your store to the next level with PrestaShop modules from BelVG

Visit the store

Let’s take a look at what happens when you choose a certain combination, and how PrestaShop calculates a new product price.

All described code is taken from the default-bootstrap/js/product.js file.

Selected combination is passed in the URI anchor, so a JavaScript global variable is in our disposal.
How to Add Product Combinations Involving the Use of Discount System on a Product Page in PrestaShop

Let’s take a look at the Combinations array. The following JavaScript object is filled in the product.tpl template by the ProductController class.
How to Add Product Combinations Involving the Use of Discount System on a Product Page in PrestaShop

This object contains price (Combination Impact on price) and specific_price (Catalog Price Rules) elements.

Also we have access to global price variables (ProductPrice, productPriceTaxIncluded, etc.) that affect the final product price with applied group discounts and country based taxes (also calculated in the ProductController).

So now we are able to display prices with Catalog Price Rules and Impact on Price discounts applied.

Here is a custom template with combinations and applied discounts.
How to Add Product Combinations Involving the Use of Discount System on a Product Page in PrestaShop

To achieve the same result you need to develop a custom module with template for calculations according to the available Combinations based on the ProductController. But what if we want to create Price Rule for a purchase of 10+ or even 100+ products? You expect Combinations to contain additional information about all available discounts. Yes, this could be rather helpful. But it is not the way PrestaShop is built.

Igor Dragun

Partner With Us

Let's discuss how to grow your business. Get a Free Quote.
Talk to Igor

If you add a PriceRule with the From quantity parameter and reload a page, you will see that a new Volume Discounts table. And in case you increase the Quantity JavaScript will parse this table and update the current price. Such option does not suit us at all. The data that we need is not passed into JavaScript global variables, we don’t need the Volume Price table as well.

JavaScript adds anchor to the page URL after you select a combination. Thereafter the script calculates the final price with the applied discount and updates value on the page.

How to Add Product Combinations Involving the Use of Discount System on a Product Page in PrestaShop

development_prestashop

PrestaShop Development

Take your online store to the next level with BelVG PrestaShop Development

Visit the page

So the following solution can suit us:
Let’s create a hook in our module


We are going to use 2 native methods from the ProductController: getQuantityDiscounts() and formatQuantityDiscounts():

Igor Dragun
Partner With Us Let's discuss how to grow your business. Get a Free Quote.
Talk to Igor



Now we can create a JavaScript variable in the template:


How to Add Product Combinations Involving the Use of Discount System on a Product Page in PrestaShop
Finally we have all necessary data in order to display “from quantity” discounts properly.

support_prestashop

PrestaShop Support & Maintenance

Take your online store to the next level with BelVG PrestaShop Support & Maintenance

Visit the page
Igor Dragun
Partner With Us Looking for a partner to grow your business? We are the right company to bring your webstore to success. Talk to Igor

2 Comments

Post a new comment

BelVG Newsletter
Subscribe to our mailing list and get interesting stuff and updates to your email inbox.
Email *