Jump to content

This product is no longer available page


ovy79ro

Recommended Posts

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

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

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

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

  • 1 year later...

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...