lorenzoripa Posted May 26, 2021 Share Posted May 26, 2021 How can I show the color of the attributes in the cart summary? Let me explain, when I look at the trolley I have for example the leather label and the color label. I would like the latter to be the image inserted in the skin-color combination I'm using prestashop 1.7.7.3 Thanks Link to comment Share on other sites More sharing options...
ZHSoft Posted May 27, 2021 Share Posted May 27, 2021 You need front-end engineers to customize your template, do you need us to provide services? Link to comment Share on other sites More sharing options...
ilario Posted December 17, 2022 Share Posted December 17, 2022 hi were you able to find anything? Link to comment Share on other sites More sharing options...
ps8modules Posted December 18, 2022 Share Posted December 18, 2022 Hi. For such modifications, it is necessary to create an override Cart.php (function getProducts) and modifications in the TPL template. There is nothing complicated about the global, but solving it with a module is quite time-consuming, considering that each template can have a different TPL. 2 Link to comment Share on other sites More sharing options...
ilario Posted December 19, 2022 Share Posted December 19, 2022 On 12/18/2022 at 4:08 AM, 4you.software said: Hi. For such modifications, it is necessary to create an override Cart.php (function getProducts) and modifications in the TPL template. There is nothing complicated about the global, but solving it with a module is quite time-consuming, considering that each template can have a different TPL. Thanks a lot for the answer. i looked at the cart.php file and found the function that creates the array. I did some tests, inserted id_attribute in the select and I can pass it in the tpl file. I would like to leave the two arrays (attributes and attributes_small) and create a new one, for example attributes_big where I also insert the id_attribute but if I try to create it it doesn't work well, in the tpl file, it twists 0: and all the id_attributes together example 121125136 and not 121 first item 125 second item etc Could you give me some advice please thanks Ilario Link to comment Share on other sites More sharing options...
ps8modules Posted December 19, 2022 Share Posted December 19, 2022 Hi. You need to add the color column to the sql, not the id_atteibute. Can you share your php edit with the commented edit? 1 Link to comment Share on other sites More sharing options...
ilario Posted December 20, 2022 Share Posted December 20, 2022 hi in cart.php I add 'id_attribute' I use this because then paste put img/co/ ... .jpg and I have the link of the image then I assign new variable and create links the code basically creates a string separated by '-' and everything works fine public static function cacheSomeAttributesLists($ipa_list, $id_lang) .......... 'SELECT pac.`id_attribute`, pac.`id_product_attribute`, agl.`public_name` AS public_group_name, al.`name` AS attribute_name // here add 'id_attribute' ........... self::$_attributesLists[$key]['attributes'] .= $row['public_group_name'] . $colon . $row['attribute_name'] . $separator . ' '; self::$_attributesLists[$key]['attributes_small'] .= $row['attribute_name'] . $separator . ' '; // here i add the new variable and then i do the rtrim self::$_attributesLists[$key]['attributes_url_image'] .= _PS_COL_IMG_DIR_ . $row['id_attribute'] . '.jpg' . $separator . ' ' ; .............. self::$_attributesLists[$id_product_attribute . '-' . $id_lang]['attributes_url_image'] = rtrim( self::$_attributesLists[$id_product_attribute . '-' . $id_lang]['attributes_url_image'], $separator . ' ' ); nel file modal.tpl or file cart-detailed-product-line {foreach from=$product.attributes_url_image key="attribute" item="value"} <div class="product-line-info"> <span class="label"> att {$attribute}:</span> <span class="value">val img {$value}</span> </div> {/foreach} here is an example then I fix it {foreach from=$product.attributes_id_image key="attribute" item="value"} <div class="product-line-info"> <span class="label">{$attribute}:</span> <span class="value">{$value}</span> </div> {/foreach} {$product.attributes|@print_r} here it returns me an array {$product.attributes_url_image|@print_r} here is string I can't find where prestashop transforms the string $product.attributes (which caches function cacheSomeAttributesLists) in an array thanks Ilario 2 Link to comment Share on other sites More sharing options...
ps8modules Posted December 20, 2022 Share Posted December 20, 2022 (edited) Ok, did you mean it like this ? When the color will be like html or color like texture ? Edited December 20, 2022 by 4you.software (see edit history) 2 Link to comment Share on other sites More sharing options...
ps8modules Posted December 20, 2022 Share Posted December 20, 2022 Cart.php public static function cacheSomeAttributesLists($ipa_list, $id_lang) { if (!Combination::isFeatureActive()) { return; } $pa_implode = []; $separator = Configuration::get('PS_ATTRIBUTE_ANCHOR_SEPARATOR'); if ($separator === '-') { // Add a space before the dash between attributes $separator = ' -'; } foreach ($ipa_list as $id_product_attribute) { if ((int) $id_product_attribute && !array_key_exists($id_product_attribute . '-' . $id_lang, self::$_attributesLists)) { $pa_implode[] = (int) $id_product_attribute; self::$_attributesLists[(int) $id_product_attribute . '-' . $id_lang] = self::DEFAULT_ATTRIBUTES_KEYS; } } if (!count($pa_implode)) { return; } $result = Db::getInstance()->executeS( 'SELECT pac.`id_product_attribute`, agl.`public_name` AS public_group_name, al.`name` AS attribute_name, ag.is_color_group, a.id_attribute as color_id_attribute, a.color as color_value FROM `' . _DB_PREFIX_ . 'product_attribute_combination` pac LEFT JOIN `' . _DB_PREFIX_ . 'attribute` a ON a.`id_attribute` = pac.`id_attribute` LEFT JOIN `' . _DB_PREFIX_ . 'attribute_group` ag ON ag.`id_attribute_group` = a.`id_attribute_group` LEFT JOIN `' . _DB_PREFIX_ . 'attribute_lang` al ON ( a.`id_attribute` = al.`id_attribute` AND al.`id_lang` = ' . (int) $id_lang . ' ) LEFT JOIN `' . _DB_PREFIX_ . 'attribute_group_lang` agl ON ( ag.`id_attribute_group` = agl.`id_attribute_group` AND agl.`id_lang` = ' . (int) $id_lang . ' ) WHERE pac.`id_product_attribute` IN (' . implode(',', $pa_implode) . ') ORDER BY ag.`position` ASC, a.`position` ASC' ); $colon = Context::getContext()->getTranslator()->trans(': ', [], 'Shop.Pdf'); foreach ($result as $row) { $key = $row['id_product_attribute'] . '-' . $id_lang; $color = ''; $colorImg = ''; if ($row['is_color_group'] == '1'){ if ($row['color_value']){ $color = '<span style="background-color:red;height:25px;width:25px;display:inline-block;border-radius:50%;border:2px solid grey;margin-bottom:-6px;:margin-left:3px;"></span>'; self::$_attributesLists[$key]['attributes'] .= $row['public_group_name'] . $colon . $color; } else { $colorImg = '<img src="/img/co/'.$row['color_id_attribute'].'.jpg" height="25" style="display:inline-block;margin-bottom:-6px;:margin-left:3px;">'; self::$_attributesLists[$key]['attributes'] .= $row['public_group_name'] . $colon . $colorImg; } } else { self::$_attributesLists[$key]['attributes'] .= $row['public_group_name'] . $colon . $row['attribute_name'] . $separator . ' '; } self::$_attributesLists[$key]['attributes_small'] .= $row['attribute_name'] . $separator . ' '; } foreach ($pa_implode as $id_product_attribute) { self::$_attributesLists[$id_product_attribute . '-' . $id_lang]['attributes'] = rtrim( self::$_attributesLists[$id_product_attribute . '-' . $id_lang]['attributes'], $separator . ' ' ); self::$_attributesLists[$id_product_attribute . '-' . $id_lang]['attributes_small'] = rtrim( self::$_attributesLists[$id_product_attribute . '-' . $id_lang]['attributes_small'], $separator . ' ' ); } } 1 1 Link to comment Share on other sites More sharing options...
ps8modules Posted December 20, 2022 Share Posted December 20, 2022 cart-detailed-product-line.tpl {foreach from=$product.attributes key="attribute" item="value"} <div class="product-line-info {$attribute|lower}"> <span class="label">{$attribute}:</span> <span class="value">{$value nofilter}</span> </div> {/foreach} 1 1 Link to comment Share on other sites More sharing options...
ilario Posted December 20, 2022 Share Posted December 20, 2022 you are a legend thank you very much Ilario 2 Link to comment Share on other sites More sharing options...
ps8modules Posted December 20, 2022 Share Posted December 20, 2022 I gladly helped. You can like my posts by clicking the gray heart below the posts 😉 2 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now