pkdsgn Posted August 1, 2016 Share Posted August 1, 2016 Hi, I want display in product list (below each product) their accessries. I'm trying override categroyController.php whith new array but something is wrong. How get accessories for each product? Maybe, do you have some manuale for this ? I looked through offcial documentantion but I dont find this.Any help ? Link to comment Share on other sites More sharing options...
rocky Posted August 2, 2016 Share Posted August 2, 2016 You could add code like the following to themes/default-bootstrap/product-list.tpl before the {hook h="displayProductPriceBlock" product=$product type="weight"} line: {assign var='accessories' value=Product::getAccessoriesLight($cookie->id_lang, $product.id_product)} {if $accessories|@count > 0} <p>{l s='Available accessories:'} {foreach from=Product::getAccessoriesLight($cookie->id_lang, $product.id_product) item='accessory' name='accessories'} {$accessory.name}{if $smarty.foreach.accessories.iteration < $accessories|@count},{/if} {/foreach} </p> {/if} This will display "Available accessories:" followed by the names of all available accessories. 1 Link to comment Share on other sites More sharing options...
pkdsgn Posted August 2, 2016 Author Share Posted August 2, 2016 Thank you, It works fine. But I need more data. Price, Image, Link etc. - something like standard product.Could I use getAccessoriesLight for more data? Link to comment Share on other sites More sharing options...
rocky Posted August 2, 2016 Share Posted August 2, 2016 In that case, you'll need to use the Product::getAccessories() function, but that is not static, so it can't be used directly in the TPL file. You'll need to create override/classes/Category.php with the following: <?php class Category extends CategoryCore { public function getProducts($id_lang, $p, $n, $order_by = null, $order_way = null, $get_total = false, $active = true, $random = false, $random_number_products = 1, $check_access = true, Context $context = null) { $products = parent::getProducts($id_lang, $p, $n, $order_by, $order_way, $get_total, $active, $random, $random_number_products, $check_access, $context); if (!$context) { $context = Context::getContext(); } if ($get_total) { return $products; } foreach ($products as &$product) { $productObj = new Product((int)$product['id_product']); if (Validate::isLoadedObject($productObj)) { $product['accessories'] = $productObj->getAccessories((int)$context->language->id); } } return $products; } } Remember to go to the Advanced Parameters > Performance tab and click the "Clear cache" button (or manually delete cache/class_index.php) so PrestaShop can find the override. Then you can use {$product.accessories} in product-list.tpl to get the accessories of the product. 1 Link to comment Share on other sites More sharing options...
ventura Posted August 2, 2016 Share Posted August 2, 2016 Also you could try this https://www.prestashop.com/forums/topic/462986-aporte-mostrar-pack-en-product-list/ Link to comment Share on other sites More sharing options...
pkdsgn Posted August 2, 2016 Author Share Posted August 2, 2016 Hmm, I am trying override but I have problem. I don;t get a data. Can you tell me how use {$product.accessories} in product-list.tpl ? Link to comment Share on other sites More sharing options...
pkdsgn Posted August 2, 2016 Author Share Posted August 2, 2016 Also you could try this https://www.prestashop.com/forums/topic/462986-aporte-mostrar-pack-en-product-list/ It's look interesting, but is it only extra code .tpl ? If I added this to my theme, nothing happen... Do you have module for this or something ? I need accesorie for each product on list, It should be that same like a product.. Or maybe do you can make this module for me ? Of course - extra gift for you Link to comment Share on other sites More sharing options...
ventura Posted August 2, 2016 Share Posted August 2, 2016 1- Upload the .tpl file included in the zip file to your theme folder 2- Add this code in your product-list.tpl, bellow this {if isset($product.on_sale) && $product.on_sale && isset($product.show_price) && $product.show_price && !$PS_CATALOG_MODE} <a class="sale-box" href="{$product.link|escape:'html':'UTF-8'}"> <span class="sale-label">{l s='Sale!'}</span></a>{/if} add this code {if isset($product.packItems) && $product.packItems} <div class="packitems"> <span class="tab_packitems">{l s='Pack content'}</span> {include file="$tpl_dir./product-list-packs.tpl" products=$product.packItems} </div> {/if} 3- Add this css code in your global.css ul.product_list .product-image-container:hover .packitems { display: none; } .packitems .tab_packitems { font-family: georgia; font-style: italic; background: #6ad4ff none repeat scroll 0 0; padding: 3px 20px; color: #ffffff; position: relative; bottom: 10px; text-shadow:1px 1px rgba(0, 0, 0, 0.24) } .packitems .product-image-container { background: #ffffff; } .packitems .pack_quantify { font-family: arial; font-size: 11px; font-weight: bold; position: absolute; top: 0; right: 5%; color: #666666; padding: 1px; text-shadow: 1px 1px rgba(0, 0, 0, 0.24); } .packitems { bottom: 0; left: 0; position: absolute; right: 0; background: rgba(255, 255, 255, 0.75); } This css code it´s for default theme, if you use another theme you must adapt it to your theme Link to comment Share on other sites More sharing options...
pkdsgn Posted August 2, 2016 Author Share Posted August 2, 2016 OO, sorry, my bad, I'm thinking this is for accessorries but it for packs item.I need accessories (one for each product). I want show Master Product and Accessory becouse both's products are similar. Link to comment Share on other sites More sharing options...
ventura Posted August 2, 2016 Share Posted August 2, 2016 Ok, sorry. I didn't understand. Then try with Rocky´s override code and keep in mind that {$product.accessories} it´s an array. To test his variables use {$product.accessories|print_r} and a access them by way foreach Link to comment Share on other sites More sharing options...
pkdsgn Posted August 2, 2016 Author Share Posted August 2, 2016 Hmm, If I am trying use {$product.accessories|print_r} I get only number "1", nothing else. If I try show array, this is empty. Any solution ? Link to comment Share on other sites More sharing options...
ventura Posted August 2, 2016 Share Posted August 2, 2016 This is important, delete cache/class_index.php Link to comment Share on other sites More sharing options...
pkdsgn Posted August 2, 2016 Author Share Posted August 2, 2016 I deleted it, and I I got only number "1".Hmm, I deleted now from override Category.php, and I got number "1" too, so maybe here is problem ? Link to comment Share on other sites More sharing options...
rocky Posted August 3, 2016 Share Posted August 3, 2016 Check to make sure you don't have any modules installed in the "actionProductListOverride" hook, since they will prevent the override from working. Adding the following to controllers/front/CategoryController.php at line 220 (before the if (!$hook_executed) line) will enable the override to work even if you have modules installed in that hook: $hook_executed = false; 2 Link to comment Share on other sites More sharing options...
ventura Posted August 3, 2016 Share Posted August 3, 2016 This module does that you need https://www.prestashop.com/forums/topic/546901-modulo-accesorios-en-product-list/ 1- Install the module 2- Add the hook in your themes/your_theme_/product-list.tpl file, eg in default theme above this <p class="product-desc" itemprop="description"> add the hook {hook h='displayAccesoriesOnList' product=$product} 1 Link to comment Share on other sites More sharing options...
pkdsgn Posted August 3, 2016 Author Share Posted August 3, 2016 I don't know, whats is wrong when I override category, I am trying add $hook_executed = false; but I always got number "1". Also your module is great ! exactly what I need ! Thank you for helping and great module ! Link to comment Share on other sites More sharing options...
ventura Posted August 3, 2016 Share Posted August 3, 2016 You are welcome. I'm glad it Link to comment Share on other sites More sharing options...
rocky Posted August 3, 2016 Share Posted August 3, 2016 I'm sorry my solution didn't work for you. I'm happy you found a module that does what you want. Link to comment Share on other sites More sharing options...
emild Posted July 11, 2018 Share Posted July 11, 2018 hello, can you provide this solution for prestashop 1.7? Regards Link to comment Share on other sites More sharing options...
emild Posted July 11, 2018 Share Posted July 11, 2018 I am looking for a solution to this problem for prestashop 1.7 - can anyone help? Link to comment Share on other sites More sharing options...
El Patron Posted May 20, 2022 Share Posted May 20, 2022 On 7/11/2018 at 5:03 PM, emild said: I am looking for a solution to this problem for prestashop 1.7 - can anyone help? https://addons.prestashop.com/en/cross-selling-product-bundles/23426-multi-accessories-pro.html 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