ovy79ro Posted March 12, 2015 Share Posted March 12, 2015 Hello, Does anyone know how you can add module "products in the same category" in the page where appears the error "this product is no longer available"? I mean i want to transplant module "products in the same category" in "this product is no longer available" page. I don't know the name of the hook. Thanks in advance. Link to comment Share on other sites More sharing options...
rocky Posted March 13, 2015 Share Posted March 13, 2015 Create override/controllers/front/ProductController.php and insert the following code: <?php class ProductController extends ProductControllerCore { public function initContent() { parent::initContent(); if ($this->errors) $this->context->smarty->assign(array('HOOK_PRODUCT_FOOTER' => Hook::exec('displayFooterProduct', array('product' => $this->product, 'category' => $this->category)))); } } This will make the $HOOK_PRODUCT_FOOTER variable available even when there's an error. You can then change the last line of product.tpl in your theme's directory from {/if} to: {else} {if isset($HOOK_PRODUCT_FOOTER) && $HOOK_PRODUCT_FOOTER}{$HOOK_PRODUCT_FOOTER}{/if} {/if} You should now see the "In the same category" module below the "This product is no longer available" error message. Note that you'll also see any other modules you have installed in the "displayFooterProduct" hook such as the Product Comments module, so make sure you don't have that module installed in the "displayFooterProduct" hook. If you need both the "In the same category" module and "Product comments" modules displayed on the product page, but only the "In the same category" module below the error message, then additional coding will be required. Link to comment Share on other sites More sharing options...
TheWolf Posted March 13, 2015 Share Posted March 13, 2015 Hello, I'm trying to use this awesome tip, and i followed this to the letter, i just get the red error band and nothing below it. Any thoughts? Does the override/controllers/ProductController.php should be outside of the admin and front folders? Link to comment Share on other sites More sharing options...
rocky Posted March 13, 2015 Share Posted March 13, 2015 Oops, that was meant to be the front folder. I corrected my post. Link to comment Share on other sites More sharing options...
TheWolf Posted March 13, 2015 Share Posted March 13, 2015 Hi, it's still not working for me, just on existing product page, not a disabled one. What can I do to debug it? I'm not a programmer of developer but I know my way around a bit. Link to comment Share on other sites More sharing options...
rocky Posted March 13, 2015 Share Posted March 13, 2015 Did you clear the override cache by deleting cache/class_index.php? You must do that every time you add a new override. Link to comment Share on other sites More sharing options...
TheWolf Posted March 13, 2015 Share Posted March 13, 2015 Working now like a charm! Thank you so much. Link to comment Share on other sites More sharing options...
ovy79ro Posted March 13, 2015 Author Share Posted March 13, 2015 Sorry, i forgot to mention that i use prestashop 1.4.8. Perhaps above indications are for prestashop 1.5 or 1.6 because this not work for me. Link to comment Share on other sites More sharing options...
rocky Posted March 14, 2015 Share Posted March 14, 2015 The functions and syntax were different in that version. You'll need to put ProductController.php in override/controllers instead of override/controllers/front. Try the following code instead: <?php class ProductController extends ProductControllerCore { public function process() { parent::process(); if ($this->errors) { /* Category */ $category = false; if (isset($_SERVER['HTTP_REFERER']) AND preg_match('!^(.*)\/([0-9]+)\-(.*[^\.])|(.*)id_category=([0-9]+)(.*)$!', $_SERVER['HTTP_REFERER'], $regs) AND !strstr($_SERVER['HTTP_REFERER'], '.html')) { if (isset($regs[2]) AND is_numeric($regs[2])) { if (Product::idIsOnCategoryId((int)($this->product->id), array('0' => array('id_category' => (int)($regs[2]))))) $category = new Category((int)($regs[2]), (int)(self::$cookie->id_lang)); } elseif (isset($regs[5]) AND is_numeric($regs[5])) { if (Product::idIsOnCategoryId((int)($this->product->id), array('0' => array('id_category' => (int)($regs[5]))))) $category = new Category((int)($regs[5]), (int)(self::$cookie->id_lang)); } } if (!$category) $category = new Category($this->product->id_category_default, (int)(self::$cookie->id_lang)); self::$smarty->assign(array('HOOK_PRODUCT_FOOTER' => Hook::productFooter($this->product, $category))); } } } Unfortunately, I don't have a PrestaShop v1.4.8 test site I can try it on. Hopefully, it will work. Link to comment Share on other sites More sharing options...
ovy79ro Posted March 14, 2015 Author Share Posted March 14, 2015 Thank you, now it's working. Link to comment Share on other sites More sharing options...
Nixnix Posted April 14, 2016 Share Posted April 14, 2016 Create override/controllers/front/ProductController.php and insert the following code: (...) Thanks rocky! Neat. Is there a reasonably easy way to insert a regular product listing here instead of this? The reason I ask is because my theme already put the "same category" on the product page but a bit further down on the page, and it would be nice to have a regular product category list (the sold out products complete parent category) displayed directly below the error message. 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