Jump to content

Variable to Display Attribute Price


AdaminCA

Recommended Posts

Maybe I phrased my last question incorretly.

I would like to be able to show the price impact (increase) of an attribute (option) on the product detail (product.tpl) page.

I know that I could hard code it into the description of the attribute being displayed in the drop down menu, but since I have different customer groups that receive different discounts, this would not work properly for all customers.

Does anyone know how to display the price of the attribute (option) on the product page?

I will deposit $15.00 into your paypal account immeditatly if you can just tell me how to do this.

Thanks!

Adam

Link to comment
Share on other sites

Ok...I am increasing my "reward" for helping me figure this out to $30.00 to your Paypal acct.

I need to be able to display the amount that an attribute will increase the price next to the attribute description in the drop down menu. I need to do this for multiple attributes for the same product:

For example:

Drop down box 1
--------------------------------------
Small - +$0.00
Medium - +$3.00
Large - +$5.00
--------------------------------------

Drop down box 2
--------------------------------------
Green- +$0.00
Red - +$3.00
Blue - +$5.00
--------------------------------------


I also need these amounts to change dynamically depending on which group of customer is logged in, wholesale or retail. That is why I just don't hard code the amount into the description.

Is there a variable, or some coding that anyone can show me that will accomplish this?

I will deposit $30.00 to your Paypal account if you can show me a solution that works.....

Thank you!

Adam

Link to comment
Share on other sites

For the benefit of others who also want price impacts displayed in the attribute dropdowns, here is the solution we came up with:

In product.php, change:

$smarty->assign(array(
   'groups' => $groups,
   'combinaisons' => $combinations, /* Kept for compatibility purpose only */
   'combinations' => $combinations,
   'colors' => (sizeof($colors) AND $product->id_color_default) ? $colors : false,
   'combinationImages' => $combinationImages));



to:

$smarty->assign(array(
   'groups' => $groups,
   'combinaisons' => $combinations, /* Kept for compatibility purpose only */
   'combinations' => $combinations,
   'colors' => (sizeof($colors) AND $product->id_color_default) ? $colors : false,
   'combinationImages' => $combinationImages,
   'attributeImpacts' => Db::getInstance()->ExecuteS('SELECT * FROM `'._DB_PREFIX_.'attribute_impact`'))); 



and in product.tpl in your theme's directory, change:

<!-- attributes -->

{foreach from=$groups key=id_attribute_group item=group}


{$group.name|escape:'htmlall':'UTF-8'} :
   {assign var='groupName' value='group_'|cat:$id_attribute_group}

       {foreach from=$group.attributes key=id_attribute item=group_attribute}
{$group_attribute|escape:'htmlall':'UTF-8'}
       {/foreach}


{/foreach}

{/if}



to:

<!-- attributes -->

{foreach from=$groups key=id_attribute_group item=group}


{$group.name|escape:'htmlall':'UTF-8'} :
   {assign var='groupName' value='group_'|cat:$id_attribute_group}

       {foreach from=$group.attributes key=id_attribute item=group_attribute}
{$group_attribute|escape:'htmlall':'UTF-8'}
           {foreach from=$attributeImpacts key=id_attributeImpact item=attributeImpact}
               {if $id_attribute == $attributeImpact.id_attribute}
                   - {if $attributeImpact.price > 0}+{/if}{convertPrice price=$attributeImpact.price*$group_reduction}
               {/if}
           {/foreach}

       {/foreach}


{/foreach}

{/if}

  • Like 2
Link to comment
Share on other sites

  • 8 months later...

Maybe too late...

If it could help someone, just use the following to avoid this problem

{foreach from=$groups key=id_attribute_group item=group}


{$group.name|escape:'htmlall':'UTF-8'} :
               {assign var='groupName' value='group_'|cat:$id_attribute_group}
0}$('#resetImages').show('slow');{/if}">
                   {foreach from=$group.attributes key=id_attribute item=group_attribute}
{$group_attribute|escape:'htmlall':'UTF-8'}

                       {foreach from=$attributeImpacts key=id_attributeImpact item=attributeImpact}
               {if $id_attribute == $attributeImpact.id_attribute}
                   {if $product->id == $attributeImpact.id_product}
                   {if $attributeImpact.price > 0}(+{convertPrice price=$attributeImpact.price*$group_reduction}){/if}
           {/if}
               {/if}
           {/foreach}

                   {/foreach}


           {/foreach}



The main modification is {if $product->id == $attributeImpact.id_product}

Link to comment
Share on other sites

  • 2 months later...

I've just tried this mod on Prestashop 1.3 and returned nothing, after checking my tables the 'ps_attribute_impact' table contains no data even though I have multiple products with price increases. Has the attribute price sotirng changed since 1.2.5?

Link to comment
Share on other sites

Try changing:

{if $attributeImpact.price > 0}(+{convertPrice price=$attributeImpact.price*$group_reduction}){/if}



to:

{if $attributeImpact.price > 0}({convertPrice price=$product.price+$attributeImpact.price*$group_reduction}){/if}

Link to comment
Share on other sites

Hi,

On some prosucts, the price at the top get changed accordingly when you select the attributre, but the drop down does not show the attribute price impact at all - it is workign for some, but not others. I have:

      {if $id_attribute == $attributeImpact.id_attribute}
                 {if $product->id == $attributeImpact.id_product}
                   {if $attributeImpact.price > 0}(+ {convertPrice price=$attributeImpact.price*$group_reduction}){/if}
                   {/if}
               {/if}

Link to comment
Share on other sites

  • 1 month later...

hi rocky,

even on your own site where you have this module offered for free it is not working right:

http://www.nethercottconstructions.com/prestashop-modules/2-product-attributes.html

it is doing the same on my site, does not show image, weight or prices, just title (exactly the same as your block, not your images).

is this something to do with using the final version 1.3.2? any help appreciated. I haven't found another module I like the looks of as much as this one :(

Link to comment
Share on other sites

by using the product attributes generator I have this mostly working. still can't get images to show up. I wonder if there is a bug on the combinations page in 1.3.4 (or whatever the final is). if I use that page to try to modify contributions it doesn't take. have to go to the generator and there is no option on that page to add the image.

also, does the development team know that the product creation page is now screwed up in firefox? it works in chrome and IE but on firefox there is no tabs, everything is listed in a single column.

Link to comment
Share on other sites

  • 6 months later...

I am back on this again as I really want to get it working. I think I have figured out what the issue is - when I duplicate a product that has attribute with price impacts in the back office, there is no new entry made to the table attribute_impact for that product which is why the attribute price fails to show when I add this:

{if $attributeImpact.id_product == $product->id}



Can anyone suggest a way around this? so that a) the attribute impact price is not repeated and B) it actually shows up properly for the products that have been creating by clicking 'duplicate' in the back office?

Link to comment
Share on other sites

  • 8 months later...
  • 6 months later...
  • 7 months later...
  • 3 weeks later...

Hi, I tried the rocky´s code, but I cant find that code in product.php so the first of the manual is obstacle for me :)

 

I have 1.4.5.1 can somebody help please?

 

In 1.5.3 is similar code in controllers/ProductController.php...

Link to comment
Share on other sites

  • 5 weeks later...

The same problem for me, is there a solution for presta 1.5 ?

 

As far as I know, the solution posted in this topic works for presta 1.5 (I am using 1.5.3.1 and at the moment it works nice, but I have to say I just started adding the first row of products (10 products)).

 

Is there some way I can use the product_attribute and product_attribute_combination tables instead? Please help! :(

 

The only think I can suggest to you is re-generating the combinations with the combinations generator after duplicating a product. It will make your work a little slower but it will work. You have to think that every attribute value has a price impact for each product, which is generated at the moment you click on the "Generate these combinations" button. Checking if the price impacts of each attribute value corresponds to a certain product is mandatory, as it's the only way to avoid the repeated price impacts.

 

Well, if someone knows how to modify the Duplicate product function and make it to check the attributes of the duplicated product and duplicate them with the new product ID, it will solve your problem, but until that person arrives and posts his/her solution, I'm afraid you will have to re-generate them manually.

Edited by jorgeferpas (see edit history)
Link to comment
Share on other sites

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

Hello people

 

I am looking to print the final price (after including impact and specific discount rules) in front of every combination in PS 1.5.4.1

 

Please let me how is it possible ?

In \controllers\front\ProductController.php - after

$groups[$row['id_attribute_group']]['attributes'][$row['id_attribute']] = $row['attribute_name'];

add

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

 

in product.tpl -

{foreach from=$groups key=id_attribute_group item=group}
{if $group.attributes|@count}
	 {foreach from=$group.name_price key=id_attribute item=group_attribute}
		   Name - {$group_attribute.name|escape:'htmlall':'UTF-8'}
		   Price -  {$price+$group_attribute.price}
	 {/foreach}
{/if}
{/foreach}

Edited by kychd (see edit history)
  • Like 2
Link to comment
Share on other sites

In \controllers\front\ProductController.php - after
 $groups[$row['id_attribute_group']]['attributes'][$row['id_attribute']] = $row['attribute_name']; 

add

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

in product.tpl -

 {foreach from=$groups key=id_attribute_group item=group} {if $group.attributes|@count} {foreach from=$group.name_price key=id_attribute item=group_attribute} Name - {$group_attribute.name|escape:'htmlall':'UTF-8'} Price - {$price+$group_attribute.price} {/foreach} {/if} {/foreach} 

 

Hello Kychd

 

I did the changes but its showing zero in front of all the combinations. here is the screenshot for the refereadg6dt.pngnce.

Link to comment
Share on other sites

Hello Kychd

 

I did the changes but its showing zero in front of all the combinations. here is the screenshot for the reference.

For my PrestaShop 1.5.4.1 everything works fine. Check all.

In \controllers\front\ProductController.php - after 418 line. Check the prices in the admin panel.

Link to comment
Share on other sites

  • 2 weeks later...
  • 9 months later...
  • 2 months later...

Add an override class of Attribute and place it into /override/classes/

class Attribute extends AttributeCore
{
    public static function getImpactPrice($id = null) {
        if(!$id)
            return '';
        else {
            $sql = 'SELECT ai.price
                    FROM '._DB_PREFIX_.'attribute_impact ai
                    WHERE ai.id_attribute = '.(int)$id;

            $result = Db::getInstance()->getValue($sql);
            if($result)
                return $result;
            else
                return '';
        }
    }
    
    public static function getImpactPrices() {
        $sql = 'SELECT ai.price, ai.id_attribute
                FROM '._DB_PREFIX_.'attribute_impact ai';

        $result = Db::getInstance()->executeS($sql);
        return $result;
}

Add another override class of ProductController and place it into /override/controllers/front/

class ProductController extends ProductControllerCore {
	public function initContent() {
		parent::initContent();
		
		$this->context->smarty->assign(array(
		'attribute_impacts' => Attribute::getImpactPrices()
		));
	}
}

After adding the override classes, make sure you delete: /cache/class_index.php so Prestashop recognizes that it should search for override classes in the override folders.

 

Goto your theme folder and edit product.tpl and search for the following:

{$group_attribute|escape:'htmlall':'UTF-8'}

In certain cases it might be (such as in the default theme of prestashop 1.6.0.8):

{$group_attribute|escape:'html':'UTF-8'}

Replace it with:

{$group_attribute|escape:'htmlall':'UTF-8'}
{foreach from=$attribute_impacts key=idattribute item=ai}
	{if $ai.id_attribute == $id_attribute}
		 -  {convertPrice price=$ai.price}
	{/if}
{/foreach}

It should look like the following:

http://i.imgur.com/iKb9Hby.png

 

I hope it does help a few people out. It's made for PrestaShop 1.6.0.8. I don't know if it works for previous versions.

 

I know it's an old post and that I'm bumping it to the max but it seems that people are struggling with it and this one will also allow you to update PrestaShop without losing this tiny feature.

 

If anyone else runs into a problem with the same thing, feel free to contact me through private messages or this topic. I checked ''Follow this topic''

Edited by Kevto (see edit history)
  • Like 2
Link to comment
Share on other sites

This is excellent!   I'm close to implementing this change.   Running a fresh install of 1.6.0.8   I created the two class files.... however, in the themes/default-bootstrap/product.tpl file,

I can't find a line:

 

{$group_attribute|escape:'htmlall':'UTF-8'}

 

 

closest is:   ="{$group_attribute|escape:'html':'UTF-8'}">{$group_attribute|escape:'html':'UTF-8'}</option>

 

 

 

found from the group here:

 

<div class="attribute_list">
            {if ($group.group_type == 'select')}
             <select name="{$groupName}" id="group_{$id_attribute_group|intval}" class="form-control attribute_select no-print">
              {foreach from=$group.attributes 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|escape:'html':'UTF-8'}">{$group_attribute|escape:'html':'UTF-8'}</option>
              {/foreach}

 

 

Am I looking in the wrong place?

 

Looking forward to getting this working.   Thanks for the help!

Thanks

Casey

Link to comment
Share on other sites

I also found this further towards the bottom on the product.tpl    So the  {$groupName|escape:'html':'UTF-8'}  without "htmlall" is listed in three places within the file.   What should I change?  Unsure at this point as I couldn't find an exact match to the text posted.

 

 

 

 {foreach from=$group.attributes key=id_attribute item=group_attribute}
               <li>
                <input type="radio" class="attribute_radio" name="{$groupName|escape:'html':'UTF-8'}" value="{$id_attribute}" {if ($group.default == $id_attribute)} checked="checked"{/if} />
                <span>{$group_attribute|escape:'html':'UTF-8'}</span>
               </li>
              {/foreach}

 

 

 

Thanks,
Casey

Link to comment
Share on other sites

I also found this further towards the bottom on the product.tpl    So the  {$groupName|escape:'html':'UTF-8'}  without "htmlall" is listed in three places within the file.   What should I change?  Unsure at this point as I couldn't find an exact match to the text posted.

 

 

 

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

               <li>

                <input type="radio" class="attribute_radio" name="{$groupName|escape:'html':'UTF-8'}" value="{$id_attribute}" {if ($group.default == $id_attribute)} checked="checked"{/if} />

                <span>{$group_attribute|escape:'html':'UTF-8'}</span>

               </li>

              {/foreach}

 

 

 

Thanks,

Casey

Hey Casey,

 

I received your private messages and the file extensions should be .php

 

Correct, there should be three times the following in your product.tpl which display the name of the attribute. However there could be more due the title HTML attribute.

{$group_attribute|escape:'html':'UTF-8'}

Below you will have a more precise piece that'd need to replace to prevent tiny accidents :)

<span>{$group_attribute|escape:'html':'UTF-8'}</span>
>{$group_attribute|escape:'html':'UTF-8'}</option>

And you should only replace the following piece of those two from above:

{$group_attribute|escape:'html':'UTF-8'}

Make sure you delete the following file to make the override classes work: /cache/class_index.php

 

Hope to hear feedback from you soon. As last resort I could modify product.tpl for you.

Edited by Kevto (see edit history)
Link to comment
Share on other sites

I made the changes.  Made certain that I had the two class files created.   Deleted the class_index.php.   Upon refreshing the website page the class_index.php was recreated.   Opening it, I could find where both the Attribute.php and ProductController.php were now referenced within.

However, when navigating the cart and checking various products, I still don't see any difference yet.   The dropdown lists of combinations are still just the options that are normally there for my combinations and no prices added next to them.

I added both a couple dropdown combinations and radio buttons and neither appear to be reacting to this.

I attached a picture of part of the product.tpl file.  Maybe I have the indents wrong or something else?

 

post-815380-0-00332300-1405097598_thumb.jpg

Perhaps if you do have a product.tpl file that I can try?

 

 

No errors though at least.... So so close... :)

 

 

 

 

 

Edited by cswett (see edit history)
Link to comment
Share on other sites

You're using the default theme aren't you? I'm using a different theme and if that's so, I will try it out on the default theme as well and if it works which I assume it does, I will send you my product.tpl okay?

 

Sorry for the late response, had a fun weekend :)

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

  • 3 weeks later...

hi i need to substrate rs 2000 form total amount displayed in cart. and i need to display the result value after subtracting. how to do that can any one help me to do this  ?. Some thing like the screen shot which i have attached below

post-827741-0-36464100-1407779730_thumb.jpg
Link to comment
Share on other sites

  • 3 months later...
  • 10 months later...

Add an override class of Attribute and place it into /override/classes/

class Attribute extends AttributeCore
{
    public static function getImpactPrice($id = null) {
        if(!$id)
            return '';
        else {
            $sql = 'SELECT ai.price
                    FROM '._DB_PREFIX_.'attribute_impact ai
                    WHERE ai.id_attribute = '.(int)$id;

            $result = Db::getInstance()->getValue($sql);
            if($result)
                return $result;
            else
                return '';
        }
    }
    
    public static function getImpactPrices() {
        $sql = 'SELECT ai.price, ai.id_attribute
                FROM '._DB_PREFIX_.'attribute_impact ai';

        $result = Db::getInstance()->executeS($sql);
        return $result;
}

Add another override class of ProductController and place it into /override/controllers/front/

class ProductController extends ProductControllerCore {
	public function initContent() {
		parent::initContent();
		
		$this->context->smarty->assign(array(
		'attribute_impacts' => Attribute::getImpactPrices()
		));
	}
}

After adding the override classes, make sure you delete: /cache/class_index.php so Prestashop recognizes that it should search for override classes in the override folders.

 

Goto your theme folder and edit product.tpl and search for the following:

{$group_attribute|escape:'htmlall':'UTF-8'}

In certain cases it might be (such as in the default theme of prestashop 1.6.0.8):

{$group_attribute|escape:'html':'UTF-8'}

Replace it with:

{$group_attribute|escape:'htmlall':'UTF-8'}
{foreach from=$attribute_impacts key=idattribute item=ai}
	{if $ai.id_attribute == $id_attribute}
		 -  {convertPrice price=$ai.price}
	{/if}
{/foreach}

It should look like the following:

http://i.imgur.com/iKb9Hby.png

 

I hope it does help a few people out. It's made for PrestaShop 1.6.0.8. I don't know if it works for previous versions.

 

I know it's an old post and that I'm bumping it to the max but it seems that people are struggling with it and this one will also allow you to update PrestaShop without losing this tiny feature.

 

If anyone else runs into a problem with the same thing, feel free to contact me through private messages or this topic. I checked ''Follow this topic''

 

Hi, thank you so much for your help.

 

I tried this, I overrided the class and front controller but the array come void in the product.tpl, I check the array in product.tpl with {$attribute_impacts|@debug_print_var} and "null" value is printed.

 

I´m using prestashop 1.6.1.1

 

Best regards.

Link to comment
Share on other sites

  • 1 month later...
  • 9 months later...
  • 2 months later...

I need to bump this thread because I think it will be easier to add this value via javascript. Let me explain what I mean - If You can click on attribute and then the price is changing so the javascript variable needs to know those values so I think they can be easly added by some jquery statement. Maybe someone can look up into this? I tried but I failed.

 

When I tried to use Kevto solution I am getting this thing, like multiple items 

post-1146962-0-46736900-1478267214_thumb.jpg

 

Edit: My solution for my error was this:

 

Attritbute.php in override/classes 

<?php

class Attribute extends AttributeCore
{
    public static function getImpactPrices($id = null)
    {
        $sql = 'SELECT ai.price, ai.id_attribute
                FROM ' . _DB_PREFIX_ . 'attribute_impact ai
                WHERE ai.id_product = '.(int)$id;

        $result = Db::getInstance()->executeS($sql);
        return $result;
    }
}

ProductController.php in override/controlers/front

class ProductController extends ProductControllerCore {
	public function initContent() {
		parent::initContent();
		
		  $this->context->smarty->assign(array(
                  'attribute_impacts' => Attribute::getImpactPrices($this->product->id)
                  ));
	}
}

in product.tpl in the same place where kevto posted

{foreach from=$attribute_impacts key=idattribute item=ai}
 {if $ai.id_attribute == $id_attribute && $ai.price != 0}
  + {convertPrice price=$ai.price}
  {/if}
{/foreach}

and now it is working properly on 1.6.1.4 but I have another question: how to show value if the attribute has impact with percent?

EDIT: Note that those values are not showing price with tax so You can multiply the value by your contry tax value ie: + {convertPrice price=$ai.price*1.23}

Edited by hakeryk2 (see edit history)
Link to comment
Share on other sites

  • 10 months later...

Does not work for 1.6.1.2.

 

This version of prestashop does not store the attribute prices in the attribute_impact table, there are no price values in there at all. Those appear to be stored in the product_attribute table.

 

I've fiddled around with changing the sql query, but it's clear that several other changes are required to the classes, controllers and tpl. And that's where I got lost.

 

This is a hugely critical function if anyone wants to use attributes that have different prices - and appears to be a deliberate by the developers so that you are forced to buy a module to handle this.

 

Who would write code that does NOT show the prices in the selection when a customer is selecting an attribute? It's absolutely nuts.

Edited by FoodAssets (see edit history)
Link to comment
Share on other sites

attribute_impact appears to be for storing the range of price or weight changes, it does not store the actual price or weight - it stores the value of how much it is supposed to change - as far as I can tell, but I'm no expert on this.

 

We did some testing - there is no way to update the attribute_impact price after it has first been created. This cannot be done in back office or in Shop Manager. We used Shop Manager to create the groups, the attributes and the combination generator. This created a record in the attribute_impact table with the range of prices, but we were completely unable to update those prices in Shop Manager - or the back office - making this table utterly useless if you cannot change the values it holds.

 

What we need is to have the select drop-down list show the attributes and the actual price of the attribute. Code samples in this thread do not do this for v1.6.1.2

Link to comment
Share on other sites

  • 7 months later...
  • 3 months later...

I need help. I have changed the codes in few files but when there are more than 2 combinations with more than 2 impact on the price I have that nasty result: (please check the screenshot)

 

Here are the files with what is removed or added:

File 1:  /themes/panda/templates/catalog/_partials/product-variants.tpl - Changeshttps://www.diffchecker.com/OqyIJUUQ

File 2: /controllers/front/ProductController.php  - Changeshttps://www.diffchecker.com/m1DtIhfo

File 3: /classes/Product.php  - Changeshttps://www.diffchecker.com/UwrgJ3fn

I hope that anyone can help me to resolve the problem.

image (3).png

Link to comment
Share on other sites

  • 1 month later...
  • 4 months later...


Hi Friends,

 

Prestashop Version 1.7.5.1

 

As per my client's requirement, I need to display color(Attribute) code instead of value into shopping cart page.

For that please see attached screenshot.

Please suggest me, how can i implement into cart page ?

 

Screenshot_1.png

Link to comment
Share on other sites

5 hours ago, yagnik.ynj said:


Hi Friends,

 

Prestashop Version 1.7.5.1

 

As per my client's requirement, I need to display color(Attribute) code instead of value into shopping cart page.

For that please see attached screenshot.

Please suggest me, how can i implement into cart page ?

 

Screenshot_1.png

you need to modificate code in OrderController.php and shopping-cart-product-line.tpl

Link to comment
Share on other sites

17 hours ago, Prestaweb.org said:

you need to modificate code in OrderController.php and shopping-cart-product-line.tpl

I already check into CartController.php and OrderController.php.

 

In that, there is only we got attribute lable like "Color" and value like "Red/Black, etc".

 

But instead of color value, i need to show it's color code.

 

is there any way to get color value into "shopping-cart-product-line.tpl" this file ?

Link to comment
Share on other sites

  • 4 months later...
On 9/24/2018 at 1:54 PM, hakeryk2 said:

@up I am trying to figure this out since long time ago and I think that the only way to achieve this is through js and combinations variable available in front.

Hi hakeryk2. Do you know how to do it already? Everything I'm trying, doesn't work. Prestashop 1.6.1.19

Thanks!

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