Dave! Posted January 18, 2018 Share Posted January 18, 2018 Hello According the ps 1.7 documentation I created custom tpl file for onecategory in "templates/catalog/listing" and I called it "category-20.tpl" (20 is the category id) After that the custom render is OK, but I have a problem when products are filtered by ps_facetedsearch module. When I click on any filter the render is coming back to the default category.tpl view Is anybody faced this problem or can tell me how manage this problem Thanks! Link to comment Share on other sites More sharing options...
razaro Posted January 18, 2018 Share Posted January 18, 2018 Hi That is interesting question. Could you first give bit more info like your PrestaShop version and do you maybe have custom theme ? Now after looking a code a bit I noticed this in classes/controllers/ProductListingFrontController.php protected function getAjaxProductSearchVariables() { $search = $this->getProductSearchVariables(); $rendered_products_top = $this->render('catalog/_partials/products-top', array('listing' => $search)); $rendered_products = $this->render('catalog/_partials/products', array('listing' => $search)); $rendered_products_bottom = $this->render('catalog/_partials/products-bottom', array('listing' => $search)); $data = array( 'rendered_products_top' => $rendered_products_top, 'rendered_products' => $rendered_products, 'rendered_products_bottom' => $rendered_products_bottom, ); foreach ($search as $key => $value) { $data[$key] = $value; } return $data; } So maybe there it loads default parts of category. Link to comment Share on other sites More sharing options...
Dave! Posted January 21, 2018 Author Share Posted January 21, 2018 Hi My prestashop version is 1.7.2.4 Yes I use custom theme I forget to mention all steps that I implemented: 1. Create file category-20.tpl identical as category.tpl 2. Modify code in category-20.tpl (instead of standard product-list.tpl change to product-list-custom.tpl) {extends file='catalog/listing/product-list-custom.tpl'} 3. Create file product-list-custom.tpl identical as product-list.tpl 4. Modify the code in product-list-custom.tpl (instead of standard product.tpl change to product-custom.tpl) {include file='catalog/_partials/products-custom.tpl' listing=$listing} 5. Create file product-custom.tpl identical as product.tpl 6. Modify the code in product-custom.tpl (instead of standard miniature product.tpl change to custom miniature product-custom.tpl) {include file='catalog/_partials/miniatures/product-custom.tpl' product=$product} 7. Finally in the file catalog/_partials/miniatures/product-custom.tpl I did the hereunder modification to show another image in product listing <img ...... src = "{$product.cover.bySize.home_default_2.url}" ..... > So after this modification when I visited my category "20" page on front office, it was working The problem came when I sored products or filtered them The page reloaded and showed the standard render by using standard category.tpl So I just found some interesting info in the doc about render: http://developers.prestashop.com/themes/templates/100-listing.html#extending-product-list-template The responsible function is updateProductListDOM function updateProductListDOM (data) { $('#search_filters').replaceWith(data.rendered_facets); $('#js-active-search-filters').replaceWith(data.rendered_active_filters); $('#js-product-list-top').replaceWith(data.rendered_products_top); $('#js-product-list').replaceWith(data.rendered_products); $('#js-product-list-bottom').replaceWith(data.rendered_products_bottom); } And the file "classes/controllers/ProductListingFrontController.php" is helped me to fix this problem Thanks Razaro! So this is a solution, but I'm wondering if there isn't another way to resolve this problem because if Prestashop giving the possibility tu customize templates for specific category so there should be a way to have the same render even when sorting or filtering, or they forget this part! 1 Link to comment Share on other sites More sharing options...
razaro Posted January 21, 2018 Share Posted January 21, 2018 Glad you find solution. Thank you for detailed explanation and link to doc. I have read that before but did not found example where that could be used for. But I think you can do this differently. Instead changing few templates just to have different product page. You want to have different product template but for whole category. Not sure if that is possible by default or if there is better place to write override, but I think you could do it this way. Create override of Product Controller that will set new template if category is 20 else do regular. That is override of FrontControllers function public function setTemplate($template, $params = array(), $locale = null) { parent::setTemplate( $this->getTemplateFile($template, $params, $locale) ); } so just set $template variable if id_category_default is 20, few lines of code. Did not test sorry but could work Link to comment Share on other sites More sharing options...
Dave! Posted January 21, 2018 Author Share Posted January 21, 2018 (edited) Well yes it's possible withe setTemplate function too But finally I found another solution without touching controllers I modified code in catalog/_partials/miniatures/product.tpl file So it was not needed to create catalog/_partials/miniatures/product-custom.tpl {if $product.id_category_default<18}{$product.cover.bySize.home_default.url}{else}{$product.cover.bySize.home_default_2.url}{/if} Best Regards Edited January 21, 2018 by Dave! (see edit history) 1 Link to comment Share on other sites More sharing options...
razaro Posted January 23, 2018 Share Posted January 23, 2018 You right that is cleanest solution. Thank you for sharing. 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