nisor Posted March 14, 2019 Share Posted March 14, 2019 Hi all, I created a new product template (in catalog/templates folder) for a specific product only. To do that, I just name it product-86.tpl (where 86 is product's id). It works fine and shows up instead the default template. The problem I have is with the varaiations... Whenever I change the size or the color of the product, it just refresh and reloads with the new created url. But then it brings the default template... If I refresh my page manually my new template comes up. I don't know how can I resolve this. Also I don't think is a good idea to avoid the refreshing. Maybe it's bad for the add-to-cart... Here is the link of my product. https://e-store.vsr.gr/index.php?id_product=86&id_product_attribute=2063&rewrite=custom-t-white&controller=product#/-/-4xl If you try to change the size or the color, the last digits of the url will change to mach, but also the default template will be active. (With a refresh you can see that the custom template will be back, but only with manual refresh...) Any ideas? Link to comment Share on other sites More sharing options...
robb84 Posted March 5, 2022 Share Posted March 5, 2022 Same problem for me, did you solved it ? Link to comment Share on other sites More sharing options...
Ress Posted March 5, 2022 Share Posted March 5, 2022 Hi, You should make changes to the ProductController, specifically to the display AjaxRefresh method, where when changing the combination, certain templates on the product page are rendered again. Link to comment Share on other sites More sharing options...
robb84 Posted March 5, 2022 Share Posted March 5, 2022 41 minutes ago, Ress said: Hi, You should make changes to the ProductController, specifically to the display AjaxRefresh method, where when changing the combination, certain templates on the product page are rendered again. Thanks for pointing me to the right direction. The display ajax refresh method i have: public function displayAjaxRefresh() { $product = $this->getTemplateVarProduct(); $minimalProductQuantity = $this->getMinimalProductOrDeclinationQuantity($product); $isPreview = ('1' === Tools::getValue('preview')); ob_end_clean(); header('Content-Type: application/json'); $this->ajaxDie(Tools::jsonEncode(array( 'product_prices' => $this->render('catalog/_partials/product-prices'), 'product_cover_thumbnails' => $this->render('catalog/_partials/product-cover-thumbnails'), 'product_customization' => $this->render( 'catalog/_partials/product-customization', array( 'customizations' => $product['customizations'], ) ), 'product_details' => $this->render('catalog/_partials/product-details'), 'product_variants' => $this->render('catalog/_partials/product-variants'), 'product_discounts' => $this->render('catalog/_partials/product-discounts'), 'product_add_to_cart' => $this->render('catalog/_partials/product-add-to-cart'), 'product_additional_info' => $this->render('catalog/_partials/product-additional-info'), 'product_images_modal' => $this->render('catalog/_partials/product-images-modal'), 'product_url' => $this->context->link->getProductLink( $product['id_product'], null, null, null, $this->context->language->id, null, $product['id_product_attribute'], false, false, true, $isPreview ? array('preview' => '1') : array() ), 'product_minimal_quantity' => $minimalProductQuantity, 'product_has_combinations' => !empty($this->combinations), 'id_product_attribute' => $product['id_product_attribute'], ))); } Is it possible to have the same logic for "product-ID.tpl" files at template level (or something similar) ? Thank you. Link to comment Share on other sites More sharing options...
Ress Posted March 5, 2022 Share Posted March 5, 2022 Yes, you can set a condition depending on the product id, and render another template. Link to comment Share on other sites More sharing options...
robb84 Posted March 6, 2022 Share Posted March 6, 2022 Can you show me please how can be done ? thanks. Link to comment Share on other sites More sharing options...
Ress Posted March 6, 2022 Share Posted March 6, 2022 You could try something like that, I don't know exactly what you did if ($this->product->id == 86) { $product_prices_template = $this->render('catalog/_partials/product-prices-v2'); } else { $product_prices_template = $this->render('catalog/_partials/product-prices'); } $this->ajaxRender(Tools::jsonEncode(array( 'product_prices' => $product_prices_template, .... ) ); Link to comment Share on other sites More sharing options...
robb84 Posted March 6, 2022 Share Posted March 6, 2022 Thanks, this could be a good solution. What I would like to achieve, is to modify the product controller to "host" a different template based on the "product-id.tpl" like product.tpl does. (example product-variants-ID.tpl). in this way I would not go to modify the productcontroller for each product).... hope I was clear in explanation Link to comment Share on other sites More sharing options...
Ress Posted March 6, 2022 Share Posted March 6, 2022 You will still need to make changes to the ProductController, because even if you load another initial tpl, at refresh, all the default tpls will be loaded. You could probably use some variables to automate, not to do individually for each product. Link to comment Share on other sites More sharing options...
robb84 Posted March 9, 2022 Share Posted March 9, 2022 Ok, thanks for your code 1 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