We continue to help people who are searching for the answers on Prestashop forum. Today we will help ajnglagla who read our article and had some difficulties with realization of similar functionality for module homefeatured on the main page.
Initial template themes/default/modules/homefeatured/homefeatured.tpl generates the block:
To get data from the module favoriteproducts in module homefeatured we will act the same way as we would act in case with controller CategoryController. So we get information about existence of user’s favorite products in method HomeFeatured:: hookDisplayHome():
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
public function hookDisplayHome($params) { if (!$this->isCached('homefeatured.tpl', $this->getCacheId('homefeatured'))) { $category = new Category(Context::getContext()->shop->getCategory(), (int)Context::getContext()->language->id); $nb = (int)Configuration::get('HOME_FEATURED_NBR'); $products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 8)); /* We already know these lines from previous article. This block adds information on customer’s favorite products into collection used on the main page in block homefeatured */ if (Module::isEnabled('favoriteproducts')) { include_once(_PS_ROOT_DIR_ . '/modules/favoriteproducts/FavoriteProduct.php'); foreach ($products as &$product) { $product['isCustomerFavoriteProduct'] = (FavoriteProduct::isCustomerFavoriteProduct($this->context->customer->id, $product['id_product']) ? 1 : 0); } } $this->smarty->assign(array( 'products' => $products, 'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'), 'homeSize' => Image::getSize(ImageType::getFormatedName('home')), )); } return $this->display(__FILE__, 'homefeatured.tpl', $this->getCacheId('homefeatured')); } |
We also need to edit the template themes/default/modules/homefeatured/homefeatured.tpl. We insert the code in it that we know from the previous article (put it in any place that you think is appropriate. I recommend putting it into li.ajax_block_product div element):
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} … |
Now the template has its data and logics of visualization, but because of fixed width of block on the main page new data doesn’t look good at all. To fix it you need to make changes in the css-file modules/homefeatured/homefeatured.css:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
#featured-products_block_center li { margin-right:10px; padding:10px 0; width:126px; height:280px } #featured-products_block_center .fv_block li{ padding: 0 0 0 20px; margin: 7px 0; height:auto; width:auto; } … |
The final result should look like this. But remember that this can be applied only to authorized users.
favoriteproducts
homefeatured.css
homefeatured.php
homefeatured.tpl
@fernando, please check if the remove link is the same on the product page and my account page
hi i have problem, cant remove products of the list of favorite product in my account, but inside of the product can, what is the problem