How Do I Redirect Disabled Product To Category in prestashop 1.6

In backoffice when you edit a product.

Once you disabled the product you can redirect it to another product. But I'm trying to redirect it to a category instead. when the product is selected off (not active),

if you select 301 or 302 redirect

and

if related_product field is empty, redirect will be to a default category (in 301 or 302)

else to the product selected (as standard)

i write this code (Front) but not work, please help

class ProductController extends ProductControllerCore
{
    public function initContent()
    {
        if (!$this->product->active) 
        {
            if (Tools::getValue('adtoken') == Tools::getAdminToken('AdminProducts'.(int)Tab::getIdFromClassName('AdminProducts').(int)Tools::getValue('id_employee')) && $this->product->isAssociatedToShop()) {
                $this->context->smarty->assign('adminActionDisplay', true);
            }
            else 
            {
                $this->context->smarty->assign('adminActionDisplay', false);
                if ($this->product->id_product_redirected == $this->product->id) {
                    $this->product->redirect_type = '404';
                }
                switch ($this->product->redirect_type) 
                {
                    case '301':
                        header('HTTP/1.1 301 Moved Permanently');
                        if (!$this->product->id_product_redirected)
                            {header('Location: '.$this->context->link->getCategoryLink($this->product->id_category_default));}
                        else
                            {header('Location: '.$this->context->link->getProductLink($this->product->id_product_redirected));}
                        exit;
                    break;
                    case '302':
                        header('HTTP/1.1 302 Moved Temporarily');
                        header('Cache-Control: no-cache');
                        if (!$this->product->id_product_redirected)
                            {header('Location: '.$this->context->link->getCategoryLink($this->product->id_category_default));}
                        else
                            {header('Location: '.$this->context->link->getProductLink($this->product->id_product_redirected));}
                        exit;
                    break;
                    case '404':
                    default:
                        header('HTTP/1.1 404 Not Found');
                        header('Status: 404 Not Found');
                        $this->errors[] = Tools::displayError('This product is no longer available.');
                    break;
                }
            }
        }
    }
}