Jump to content

Show Combination Price Impact On Product Page


Recommended Posts

One way to do this is to change the name of the attribute accordingly. This works well as long as you don't have thousands of products that require this approach.

 

Say, for example, you want to offer 4 variations of the movie "The Matrix".

 

You could create an attribute group called: The Matrix Options. Within that group, create 4 attributes named:

- Blueray - $19.99

- DVD - $14.99

- VHS - $4.99

- Betamax - $0.99

 

Then, in the product for "The Matrix", create your combination products using this attribute group. That will give you 4 combination products and the select list will contain the text (AND price) spelled out in the name of each attribute. You then change the price impact aspect of each combination product to yield the price shown in the select list. The downside is that if you change prices, you also have to change the attributes' names to match the new prices.

 

Worst case scenario, you could create an attribute for every product SKU you have. More likely, some products may require this approach and can be grouped to use a shared attribute group while others will require dedicated attributes.

 

I use explicit attributes like this when I have a family of products with a range of prices that I want to lump into one product page. Then, insert a table within the product description outlining the specific characteristics of each product within the family.

Link to comment
Share on other sites

I found solution.

 

1)/controllers/front/ProductController.php

at line 439 add:

 

 $groups[$row['id_attribute_group']]['name_price'][$row['id_attribute']] = array('name' => $row['attribute_name'],'price' => $row['price']);

 

 

 

2)/themes/YOUR_THEME/product.tpl

 

at ~345 line find : {if ($group.group_type == 'select')}

 

and replace code with this:

 

<select name="{$groupName}" id="group_{$id_attribute_group|intval}" class="form-control attribute_select no-print">
                                                            
{foreach from=$group.name_price key=id_attribute item=group_attribute}
<option value="{$id_attribute|intval}"{if (isset($smarty.get.$groupName) && $smarty.get.$groupName|intval == $id_attribute) || $group.default == $id_attribute} selected="selected"{/if} title="{$group_attribute.name|escape:'html':'UTF-8'}">{$group_attribute.name|escape:'html':'UTF-8'} {if $group_attribute.price>0}+{/if}{if $group_attribute.price!=0}
 {$price_with_tax = $group_attribute.price + ($group_attribute.price*($tax_rate/100))}
 {if $product->specificPrice && $product->specificPrice.reduction_type == 'percentage'}
{$price_with_tax = $price_with_tax - ($price_with_tax*$product->specificPrice.reduction)}
{/if}
{convertPrice price=$price_with_tax}
 {/if}
 </option>
{/foreach}
</select>

 

 

Price showing with tax and discount.

Edited by Tomas LT (see edit history)
  • Like 1
Link to comment
Share on other sites

  • 3 weeks later...
  • 2 years later...

I found solution.

 

1)/controllers/front/ProductController.php

at line 439 add:

 

 $groups[$row['id_attribute_group']]['name_price'][$row['id_attribute']] = array('name' => $row['attribute_name'],'price' => $row['price']);

 

 

 

2)/themes/YOUR_THEME/product.tpl

 

at ~345 line find : {if ($group.group_type == 'select')}

 

and replace code with this:

 

<select name="{$groupName}" id="group_{$id_attribute_group|intval}" class="form-control attribute_select no-print">

                                                            

{foreach from=$group.name_price key=id_attribute item=group_attribute}

<option value="{$id_attribute|intval}"{if (isset($smarty.get.$groupName) && $smarty.get.$groupName|intval == $id_attribute) || $group.default == $id_attribute} selected="selected"{/if} title="{$group_attribute.name|escape:'html':'UTF-8'}">{$group_attribute.name|escape:'html':'UTF-8'} {if $group_attribute.price>0}+{/if}{if $group_attribute.price!=0}

 {$price_with_tax = $group_attribute.price + ($group_attribute.price*($tax_rate/100))}

 {if $product->specificPrice && $product->specificPrice.reduction_type == 'percentage'}

{$price_with_tax = $price_with_tax - ($price_with_tax*$product->specificPrice.reduction)}

{/if}

{convertPrice price=$price_with_tax}

 {/if}

 </option>

{/foreach}

</select>

 

 

Price showing with tax and discount.

your code is logique ;)

Link to comment
Share on other sites

  • 1 year later...
  • 3 years later...
  • 1 year later...

./themes/your_theme/assets/custom.js

If not exists, create it.

After starting JavaScript, all the parameters that you can use will be displayed in the console.

/* after change attributes */
prestashop.on('updatedProduct',function() {
    console.log($.parseJSON($(".js-product-details").attr("data-product")));
});

/* after read page */
$(document).ready(function() {
    var isProductPage = prestashop.page.page_name;
    if (isProductPage == 'product')
    {
	    console.log($.parseJSON($(".js-product-details").attr("data-product")));
    }
});

 

Link to comment
Share on other sites

How to get attributes?

...
var attributesGroup = $.parseJSON($(".js-product-details").attr("data-product")).attributes;
var attributeGroupAndName = [];
var valSep = ' : ';
for (var key in attributesGroup) { 
     attributeGroupAndName.push(' ' + attributesGroup[key].group + valSep + attributesGroup[key].name); 
}
console.log(attributeGroupAndName.join(', ');
/* Color : Red, Size : XXL */

 

Edited by prestashopfree.com (see edit history)
  • Like 1
Link to comment
Share on other sites

Already loading jQuery(document).ready(function($) ...

It needs to be inserted in this section ...

jQuery(document).ready(function($) {
    var isProductPage = prestashop.page.page_name;
    if (isProductPage == 'product')
    {
        console.log($.parseJSON($(".js-product-details").attr("data-product")));
    }

    prestashop.on('updatedProduct',function() {
    
        console.log($.parseJSON($(".js-product-details").attr("data-product")));
   });
.....

 

  • Like 1
Link to comment
Share on other sites

  • 1 month later...
On 1/3/2023 at 5:18 AM, ps8moduly.cz said:

Hi @Pragati P, thank you.

I'm happy to help novice programmers without unnecessary links to extensive articles.

I'd rather give the whole code and the programmer can figure out the rest themselves 😉

 

Good morning.

Could be possible to have access to that module so I can see if it helps in my case please?

Thank you!

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...