In this article we will continue helping our blog and forum readers to expand default Prestаshоp functionalities.
We have noticed that one of our forum participants complained about certain difficulties, so we would like to share our solution with the community.
For these purposes we have modified the following files in the module “Favorite products”:
- modules/favoriteproducts/favoriteproducts.js
- themes/default/product-list.tpl
- modules/favoriteproducts/favoriteproducts.css
- controllers/front/CategoryController.php (the function assignProductList())
To add information about the Favorite Product to our collection of products we need to modify the function аssignPrоduсtList().
1 2 3 4 5 6 7 |
…. if (Module::isEnabled('favoriteproducts')) { include_once(_PS_ROOT_DIR_ . '/modules/favoriteproducts/FavoriteProduct.php'); foreach ($this->cat_products as &$cat_product) { $cat_product['isCustomerFavoriteProduct'] = (FavoriteProduct::isCustomerFavoriteProduct($this->context->customer->id, $cat_product['id_product']) ? 1 : 0); } } |
Add the below code to the product-list.tpl template:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
…. {if isset($product.isCustomerFavoriteProduct) AND Context::getContext()->customer->logged} <ul class="fv_block" id="fv_block_{$product.id_product}"> {if !$product.isCustomerFavoriteProduct} <li class="pl_favoriteproducts_block_extra_add" rel="{$product.id_product}"> {l s='Add this product to my list of favorites.'} </li> {/if} {if $product.isCustomerFavoriteProduct AND Context::getContext()->customer->logged} <li class="pl_favoriteproducts_block_extra_remove" rel="{$product.id_product}"> {l s='Remove this product from my favorite\'s list. '} </li> {/if} <li class="pl_favoriteproducts_block_extra_added" rel="{$product.id_product}"> {l s='Remove this product from my favorite\'s list. '} </li> <li class="pl_favoriteproducts_block_extra_removed" rel="{$product.id_product}"> {l s='Add this product to my list of favorites.'} </li> </ul> {/if} …. |
The last changes are applied to the module’s css file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
#product_list .fv_block li { padding: 0px 0px 0px 10px; margin-bottom: 5px; list-style: none; } #usefull_link_block li#favoriteproducts_block_extra_add, .fv_block li.pl_favoriteproducts_block_extra_add { padding-left:20px; background:url(img/add_favorite.gif) no-repeat 0 0; cursor: pointer; } #usefull_link_block li#favoriteproducts_block_extra_remove, .fv_block li.pl_favoriteproducts_block_extra_remove { padding-left:20px; background:url(img/del_favorite.gif) no-repeat 0 0; cursor: pointer; } ul#usefull_link_block li#favoriteproducts_block_extra_added, .fv_block li.pl_favoriteproducts_block_extra_added { padding-left:20px; background:url(img/del_favorite.gif) no-repeat 0 0; cursor: pointer; display: none; } ul#usefull_link_block li#favoriteproducts_block_extra_removed, .fv_block li.pl_favoriteproducts_block_extra_removed { padding-left:20px; background:url(img/add_favorite.gif) no-repeat 0 0; cursor: pointer; display: none; } |
Download:
FavoriteProducts.zip
CategoryController
Product-List
PrestaShop Development
Take your online store to the next level with BelVG PrestaShop Development
Visit the page
Hello,
I tried download categorycontroller but your link dont work. Do you know say me where I should add code in categorycontroller ?
I tried add your code within “public function init()” and in “public function initContent()” but it dont work 100% good because if you reload page then Prestashop not remember favorite product added by the user(cookie) like when you come again to favorite product added in product page that show “remove”
Denise,
To make some module (which changes content on the category page) work properly with the Blocklayered module, you need to modify the Blocklayered module itself, that is, that the filters module would know about this data. But we do not describe this case in our article.
But, it doesn’t work when using the filters from blocklayered. Is that normal?
Gulhan,
Actually I wrote an article on this. Here’s the link http://blog.belvg.com/favorite-products-feature-for-products-on-the-home-page-in-prestashop.html
Distortion,
Yes, it does’t work anymore for v1.6, and thank you for sharing the module adapted for v1.6 with the community.
Doesn’t work anymore with Ps 1.6
How to Add “Add to Favorites” Button on “Home Featured”? How should i modify the code to use it in Home Featured?
Demo url: http://belvg.info/demo/prestashop/pricematch/index.php?id_category=4&controller=category&id_lang=1