/**
  * Initialize product controller
  * @see FrontController::init()
  */
 public function init()
 {
     parent::init();
     if ($id_product = (int) Tools::getValue('id_product')) {
         $this->product = new Product($id_product, true, $this->context->language->id, $this->context->shop->id);
     }
     if (!Validate::isLoadedObject($this->product)) {
         header('HTTP/1.1 404 Not Found');
         header('Status: 404 Not Found');
     } else {
         $this->canonicalRedirection();
     }
     if (!Validate::isLoadedObject($this->product)) {
         $this->errors[] = Tools::displayError('Product not found');
     } else {
         if (Pack::isPack((int) $this->product->id) && !Pack::isInStock((int) $this->product->id)) {
             $this->product->quantity = 0;
         }
         $this->product->description = $this->transformDescriptionWithImg($this->product->description);
         /*
          * If the product is associated to the shop
          * and is active or not active but preview mode (need token + file_exists)
          * allow showing the product
          * In all the others cases => 404 "Product is no longer available"
          */
         if (!$this->product->isAssociatedToShop() || !$this->product->active && (Tools::getValue('adtoken') != Tools::getAdminToken('AdminProducts' . (int) Tab::getIdFromClassName('AdminProducts') . (int) Tools::getValue('id_employee')) || !file_exists(_PS_ROOT_DIR_ . '/' . Tools::getValue('ad') . '/index.php'))) {
             header('HTTP/1.1 404 page not found');
             $this->errors[] = Tools::displayError('Product is no longer available.');
         } else {
             if (!$this->product->checkAccess(isset($this->context->customer) ? $this->context->customer->id : 0)) {
                 $this->errors[] = Tools::displayError('You do not have access to this product.');
             }
         }
         // Load category
         if (isset($_SERVER['HTTP_REFERER']) && !strstr($_SERVER['HTTP_REFERER'], Tools::getHttpHost()) && preg_match('!^(.*)\\/([0-9]+)\\-(.*[^\\.])|(.*)id_category=([0-9]+)(.*)$!', $_SERVER['HTTP_REFERER'], $regs)) {
             // If the previous page was a category and is a parent category of the product use this category as parent category
             if (isset($regs[2]) && is_numeric($regs[2])) {
                 if (Product::idIsOnCategoryId((int) $this->product->id, array('0' => array('id_category' => (int) $regs[2])))) {
                     $this->category = new Category($regs[2], (int) $this->context->cookie->id_lang);
                 }
             } else {
                 if (isset($regs[5]) && is_numeric($regs[5])) {
                     if (Product::idIsOnCategoryId((int) $this->product->id, array('0' => array('id_category' => (int) $regs[5])))) {
                         $this->category = new Category($regs[5], (int) $this->context->cookie->id_lang);
                     }
                 }
             }
         } else {
             // Set default product category
             $this->category = new Category($this->product->id_category_default, (int) $this->context->cookie->id_lang);
         }
     }
 }
Example #2
0
 public function processDuplicate()
 {
     if (Validate::isLoadedObject($product = new Product((int) Tools::getValue('id_product')))) {
         $id_product_old = $product->id;
         if (empty($product->price) && Shop::getContext() == Shop::CONTEXT_GROUP) {
             $shops = ShopGroup::getShopsFromGroup(Shop::getContextShopGroupID());
             foreach ($shops as $shop) {
                 if ($product->isAssociatedToShop($shop['id_shop'])) {
                     $product_price = new Product($id_product_old, false, null, $shop['id_shop']);
                     $product->price = $product_price->price;
                 }
             }
         }
         unset($product->id);
         unset($product->id_product);
         $product->indexed = 0;
         $product->active = 0;
         if ($product->add() && Category::duplicateProductCategories($id_product_old, $product->id) && ($combination_images = Product::duplicateAttributes($id_product_old, $product->id)) !== false && GroupReduction::duplicateReduction($id_product_old, $product->id) && Product::duplicateAccessories($id_product_old, $product->id) && Product::duplicateFeatures($id_product_old, $product->id) && Product::duplicateSpecificPrices($id_product_old, $product->id) && Pack::duplicate($id_product_old, $product->id) && Product::duplicateCustomizationFields($id_product_old, $product->id) && Product::duplicateTags($id_product_old, $product->id) && Product::duplicateDownload($id_product_old, $product->id)) {
             if ($product->hasAttributes()) {
                 Product::updateDefaultAttribute($product->id);
             }
             if (!Tools::getValue('noimage') && !Image::duplicateProductImages($id_product_old, $product->id, $combination_images)) {
                 $this->errors[] = Tools::displayError('An error occurred while copying images.');
             } else {
                 Hook::exec('actionProductAdd', array('product' => $product));
                 if (in_array($product->visibility, array('both', 'search')) && Configuration::get('PS_SEARCH_INDEXATION')) {
                     Search::indexation(false, $product->id);
                 }
                 $this->redirect_after = self::$currentIndex . (Tools::getIsset('id_category') ? '&id_category=' . (int) Tools::getValue('id_category') : '') . '&conf=19&token=' . $this->token;
             }
         } else {
             $this->errors[] = Tools::displayError('An error occurred while creating an object.');
         }
     }
 }
 /**
  * Assign template vars related to page content
  * @see FrontController::initContent()
  */
 public function initContent()
 {
     parent::initContent();
     //Clean compare product table
     CompareProduct::cleanCompareProducts('week');
     $hasProduct = false;
     if (!Configuration::get('PS_COMPARATOR_MAX_ITEM')) {
         return Tools::redirect('index.php?controller=404');
     }
     if (($product_list = Tools::getValue('compare_product_list')) && ($postProducts = isset($product_list) ? rtrim($product_list, '|') : '')) {
         $ids = array_unique(explode('|', $postProducts));
     } else {
         if (isset($this->context->cookie->id_compare)) {
             $ids = CompareProduct::getCompareProducts($this->context->cookie->id_compare);
         } else {
             $ids = null;
         }
     }
     if ($ids) {
         if (count($ids) > 0) {
             if (count($ids) > Configuration::get('PS_COMPARATOR_MAX_ITEM')) {
                 $ids = array_slice($ids, 0, Configuration::get('PS_COMPARATOR_MAX_ITEM'));
             }
             $listProducts = array();
             $listFeatures = array();
             foreach ($ids as $k => &$id) {
                 $curProduct = new Product((int) $id, true, $this->context->language->id);
                 if (!$curProduct->active || !$curProduct->isAssociatedToShop()) {
                     unset($ids[$k]);
                     continue;
                 }
                 if (!$curProduct->active || !$curProduct->isAssociatedToShop()) {
                     unset($ids[$k]);
                     continue;
                 }
                 if (!Validate::isLoadedObject($curProduct)) {
                     continue;
                 }
                 if (!$curProduct->active) {
                     unset($ids[$k]);
                     continue;
                 }
                 foreach ($curProduct->getFrontFeatures($this->context->language->id) as $feature) {
                     $listFeatures[$curProduct->id][$feature['id_feature']] = $feature['value'];
                 }
                 $cover = Product::getCover((int) $id);
                 $curProduct->id_image = Tools::htmlentitiesUTF8(Product::defineProductImage(array('id_image' => $cover['id_image'], 'id_product' => $id), $this->context->language->id));
                 $curProduct->allow_oosp = Product::isAvailableWhenOutOfStock($curProduct->out_of_stock);
                 $listProducts[] = $curProduct;
             }
             if (count($listProducts) > 0) {
                 $width = 80 / count($listProducts);
                 $hasProduct = true;
                 $ordered_features = Feature::getFeaturesForComparison($ids, $this->context->language->id);
                 $this->context->smarty->assign(array('ordered_features' => $ordered_features, 'product_features' => $listFeatures, 'products' => $listProducts, 'width' => $width, 'homeSize' => Image::getSize('home_default')));
                 $this->context->smarty->assign('HOOK_EXTRA_PRODUCT_COMPARISON', Hook::exec('displayProductComparison', array('list_ids_product' => $ids)));
             }
         }
     }
     $this->context->smarty->assign('hasProduct', $hasProduct);
     $this->setTemplate(_PS_THEME_DIR_ . 'products-comparison.tpl');
 }
Example #4
0
         break;
     default:
         Shop::setContext(Shop::CONTEXT_ALL, null);
         echo "-Context is set to " . $type . " ";
 }
 //code v2.4.1
 $id_product = (int) Tools::getValue('id_product');
 $id_lang = (int) Context::getContext()->language->id;
 //$product = new Product($id_product, false, $id_lang,$id_shop_source,$context); //version 5.2 - Ne duplique que dans une seule langue
 $product = new Product($id_product, false, null, $id_shop_source, $context);
 //version 5.3  All languages
 //Class product:  function __construct($id_product = null, $full = false, $id_lang = null, $id_shop = null, Context $context = null)
 if (empty($product->price) && Shop::getContext() == Shop::CONTEXT_GROUP) {
     $shops = ShopGroup::getShopsFromGroup(Shop::getContextShopGroupID());
     foreach ($shops as $shop) {
         if ($product->isAssociatedToShop($shop['id_shop'])) {
             $product_price = new Product($id_product_old, false, null, $shop['id_shop']);
             $product->price = $product_price->price;
         }
     }
 }
 if (Validate::isLoadedObject($product)) {
     $id_product_old = $product->id;
     for ($i = 1; $i <= $quantity; $i++) {
         echo $i;
         unset($product->id);
         unset($product->id_product);
         $product->indexed = 0;
         $product->active = 0;
         if ($product->add() && Category::duplicateProductCategories($id_product_old, $product->id) && ($combination_images = Product::duplicateAttributes($id_product_old, $product->id)) !== false && GroupReduction::duplicateReduction($id_product_old, $product->id) && Product::duplicateAccessories($id_product_old, $product->id) && Product::duplicateFeatures($id_product_old, $product->id) && Product::duplicateSpecificPrices($id_product_old, $product->id) && Pack::duplicate($id_product_old, $product->id) && Product::duplicateCustomizationFields($id_product_old, $product->id) && Product::duplicateTags($id_product_old, $product->id) && Product::duplicateDownload($id_product_old, $product->id)) {
             if ($product->hasAttributes()) {
    /**
     * @param Product $obj
     * @throws Exception
     * @throws SmartyException
     */
    public function initFormImages($obj)
    {
        $data = $this->createTemplate($this->tpl_form);
        if ((bool) $obj->id) {
            if ($this->product_exists_in_shop) {
                $data->assign('product', $this->loadObject());
                $shops = false;
                if (Shop::isFeatureActive()) {
                    $shops = Shop::getShops();
                }
                if ($shops) {
                    foreach ($shops as $key => $shop) {
                        if (!$obj->isAssociatedToShop($shop['id_shop'])) {
                            unset($shops[$key]);
                        }
                    }
                }
                $data->assign('shops', $shops);
                $count_images = Db::getInstance()->getValue('
					SELECT COUNT(id_product)
					FROM ' . _DB_PREFIX_ . 'image
					WHERE id_product = ' . (int) $obj->id);
                $images = Image::getImages($this->context->language->id, $obj->id);
                foreach ($images as $k => $image) {
                    $images[$k] = new Image($image['id_image']);
                }
                if ($this->context->shop->getContext() == Shop::CONTEXT_SHOP) {
                    $current_shop_id = (int) $this->context->shop->id;
                } else {
                    $current_shop_id = 0;
                }
                $languages = Language::getLanguages(true);
                $image_uploader = new HelperImageUploader('file');
                $image_uploader->setMultiple(!(Tools::getUserBrowser() == 'Apple Safari' && Tools::getUserPlatform() == 'Windows'))->setUseAjax(true)->setUrl(Context::getContext()->link->getAdminLink('AdminProducts') . '&ajax=1&id_product=' . (int) $obj->id . '&action=addProductImage');
                $data->assign(array('countImages' => $count_images, 'id_product' => (int) Tools::getValue('id_product'), 'id_category_default' => (int) $this->_category->id, 'images' => $images, 'iso_lang' => $languages[0]['iso_code'], 'token' => $this->token, 'table' => $this->table, 'max_image_size' => $this->max_image_size / 1024 / 1024, 'up_filename' => (string) Tools::getValue('virtual_product_filename_attribute'), 'currency' => $this->context->currency, 'current_shop_id' => $current_shop_id, 'languages' => $this->_languages, 'default_language' => (int) Configuration::get('PS_LANG_DEFAULT'), 'image_uploader' => $image_uploader->render()));
                $type = ImageType::getByNameNType('%', 'products', 'height');
                if (isset($type['name'])) {
                    $data->assign('imageType', $type['name']);
                } else {
                    $data->assign('imageType', ImageType::getFormatedName('small'));
                }
            } else {
                $this->displayWarning($this->l('You must save the product in this shop before adding images.'));
            }
        } else {
            $this->displayWarning($this->l('You must save this product before adding images.'));
        }
        $this->tpl_form_vars['custom_form'] = $data->fetch();
    }
Example #6
0
 /**
  * Initialize product controller
  * @see FrontController::init()
  */
 public function init()
 {
     parent::init();
     if ($id_product = (int) Tools::getValue('id_product')) {
         $this->product = new Product($id_product, true, $this->context->language->id, $this->context->shop->id);
     }
     if (!Validate::isLoadedObject($this->product)) {
         header('HTTP/1.1 404 Not Found');
         header('Status: 404 Not Found');
         $this->errors[] = Tools::displayError('Product not found');
     } else {
         $this->canonicalRedirection();
         /*
          * If the product is associated to the shop
          * and is active or not active but preview mode (need token + file_exists)
          * allow showing the product
          * In all the others cases => 404 "Product is no longer available"
          */
         if (!$this->product->isAssociatedToShop() || !$this->product->active) {
             if (Tools::getValue('adtoken') == Tools::getAdminToken('AdminProducts' . (int) Tab::getIdFromClassName('AdminProducts') . (int) Tools::getValue('id_employee'))) {
                 // If the product is not active, it's the admin preview mode
                 $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');
                         header('Location: ' . $this->context->link->getProductLink($this->product->id_product_redirected));
                         break;
                     case '302':
                         header('HTTP/1.1 302 Moved Temporarily');
                         header('Cache-Control: no-cache');
                         header('Location: ' . $this->context->link->getProductLink($this->product->id_product_redirected));
                         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;
                 }
             }
         } elseif (!$this->product->checkAccess(isset($this->context->customer) ? $this->context->customer->id : 0)) {
             header('HTTP/1.1 403 Forbidden');
             header('Status: 403 Forbidden');
             $this->errors[] = Tools::displayError('You do not have access to this product.');
         } else {
             // Load category
             if (isset($_SERVER['HTTP_REFERER']) && strstr($_SERVER['HTTP_REFERER'], Tools::getHttpHost()) && preg_match('!^(.*)\\/([0-9]+)\\-(.*[^\\.])|(.*)id_category=([0-9]+)(.*)$!', $_SERVER['HTTP_REFERER'], $regs)) {
                 // If the previous page was a category and is a parent category of the product use this category as parent category
                 if (isset($regs[2]) && is_numeric($regs[2])) {
                     if (Product::idIsOnCategoryId((int) $this->product->id, array('0' => array('id_category' => (int) $regs[2])))) {
                         $this->category = new Category($regs[2], (int) $this->context->cookie->id_lang);
                     }
                 } else {
                     if (isset($regs[5]) && is_numeric($regs[5])) {
                         if (Product::idIsOnCategoryId((int) $this->product->id, array('0' => array('id_category' => (int) $regs[5])))) {
                             $this->category = new Category($regs[5], (int) $this->context->cookie->id_lang);
                         }
                     }
                 }
             } else {
                 // Set default product category
                 $this->category = new Category($this->product->id_category_default, (int) $this->context->cookie->id_lang);
             }
         }
     }
 }
Example #7
0
 /**
  * Initialize product controller
  * @see FrontController::init()
  */
 public function init()
 {
     parent::init();
     if ($id_product = (int) Tools::getValue('id_product')) {
         $this->product = new Product($id_product, true, $this->context->language->id, $this->context->shop->id);
     }
     if (!Validate::isLoadedObject($this->product)) {
         header('HTTP/1.1 404 Not Found');
         header('Status: 404 Not Found');
         $this->errors[] = Tools::displayError('Product not found');
     } else {
         $this->canonicalRedirection();
         /*
          * If the product is associated to the shop
          * and is active or not active but preview mode (need token + file_exists)
          * allow showing the product
          * In all the others cases => 404 "Product is no longer available"
          */
         if (!$this->product->isAssociatedToShop() || !$this->product->active) {
             if (Tools::getValue('adtoken') == Tools::getAdminToken('AdminProducts' . (int) Tab::getIdFromClassName('AdminProducts') . (int) Tools::getValue('id_employee')) && $this->product->isAssociatedToShop()) {
                 // If the product is not active, it's the admin preview mode
                 $this->context->smarty->assign('adminActionDisplay', true);
             } else {
                 $this->context->smarty->assign('adminActionDisplay', false);
                 if (!$this->product->id_product_redirected || $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');
                         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');
                         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;
                 }
             }
         } elseif (!$this->product->checkAccess(isset($this->context->customer->id) && $this->context->customer->id ? (int) $this->context->customer->id : 0)) {
             header('HTTP/1.1 403 Forbidden');
             header('Status: 403 Forbidden');
             $this->errors[] = Tools::displayError('You do not have access to this product.');
         } else {
             // Load category
             $id_category = false;
             if (isset($_SERVER['HTTP_REFERER']) && $_SERVER['HTTP_REFERER'] == Tools::secureReferrer($_SERVER['HTTP_REFERER']) && preg_match('~^.*(?<!\\/content)\\/([0-9]+)\\-(.*[^\\.])|(.*)id_(category|product)=([0-9]+)(.*)$~', $_SERVER['HTTP_REFERER'], $regs)) {
                 // If the previous page was a category and is a parent category of the product use this category as parent category
                 $id_object = false;
                 if (isset($regs[1]) && is_numeric($regs[1])) {
                     $id_object = (int) $regs[1];
                 } elseif (isset($regs[5]) && is_numeric($regs[5])) {
                     $id_object = (int) $regs[5];
                 }
                 if ($id_object) {
                     $referers = array($_SERVER['HTTP_REFERER'], urldecode($_SERVER['HTTP_REFERER']));
                     if (in_array($this->context->link->getCategoryLink($id_object), $referers)) {
                         $id_category = (int) $id_object;
                     } elseif (isset($this->context->cookie->last_visited_category) && (int) $this->context->cookie->last_visited_category && in_array($this->context->link->getProductLink($id_object), $referers)) {
                         $id_category = (int) $this->context->cookie->last_visited_category;
                     }
                 }
             }
             if (!$id_category || !Category::inShopStatic($id_category, $this->context->shop) || !Product::idIsOnCategoryId((int) $this->product->id, array('0' => array('id_category' => $id_category)))) {
                 $id_category = (int) $this->product->id_category_default;
             }
             $this->category = new Category((int) $id_category, (int) $this->context->cookie->id_lang);
             if (isset($this->context->cookie) && isset($this->category->id_category) && !(Module::isInstalled('blockcategories') && Module::isEnabled('blockcategories'))) {
                 $this->context->cookie->last_visited_category = (int) $this->category->id_category;
             }
         }
     }
 }
 /**
  * Initialize product controller
  * @see FrontController::init()
  */
 public function init()
 {
     parent::init();
     //by webkul for product page searching
     if (Tools::isSubmit('product_page_search_submit')) {
         $hotel_cat_id = Tools::getValue('hotel_cat_id');
         $check_in = Tools::getValue('check_in_time');
         $check_out = Tools::getValue('check_out_time');
         $error = false;
         if ($hotel_cat_id == '') {
             $error = 1;
         } elseif ($check_in == '' || !Validate::isDate($check_in)) {
             $error = 1;
         } elseif ($check_out == '' || !Validate::isDate($check_out)) {
             $error = 1;
         } elseif ($check_out <= $check_in) {
             $error = 1;
         }
         if (!$error) {
             if (Configuration::get('PS_REWRITING_SETTINGS')) {
                 $redirect_link = $this->context->link->getCategoryLink(new Category($hotel_cat_id, $this->context->language->id), null, $this->context->language->id) . '?date_from=' . $check_in . '&date_to=' . $check_out;
             } else {
                 $redirect_link = $this->context->link->getCategoryLink(new Category($hotel_cat_id, $this->context->language->id), null, $this->context->language->id) . '&date_from=' . $check_in . '&date_to=' . $check_out;
             }
         } else {
             $id_product = Tools::getValue("id_product");
             if (Configuration::get('PS_REWRITING_SETTINGS')) {
                 $redirect_link = $this->context->link->getCategoryLink(new Category($hotel_cat_id, $this->context->language->id), null, $this->context->language->id) . '?error=' . $error;
             } else {
                 $redirect_link = $this->context->link->getProductLink(new Product($id_product, false, $this->context->language->id), null, null, null, $this->context->language->id) . '&error=' . $error;
             }
         }
         Tools::redirect($redirect_link);
     }
     //by webkul to check available rooms quantity on product page
     $product_quantity_up = Tools::getValue('product_quantity_up');
     $product_quantity_down = Tools::getValue('product_quantity_down');
     $change_date = Tools::getValue('change_date');
     if (isset($product_quantity_down) && $product_quantity_down) {
         $id_product = Tools::getValue('id_product');
         $date_from = Tools::getValue('date_from');
         $date_to = Tools::getValue('date_to');
         $quantity = Tools::getValue('qty');
         $result = $this->checkRoomQuantityAvailability($id_product, $date_from, $date_to, $quantity);
         die($result);
     } else {
         if (isset($product_quantity_up) && $product_quantity_up) {
             $id_product = Tools::getValue('id_product');
             $date_from = Tools::getValue('date_from');
             $date_to = Tools::getValue('date_to');
             $quantity = Tools::getValue('qty');
             $result = $this->checkRoomQuantityAvailability($id_product, $date_from, $date_to, $quantity);
             die($result);
         } else {
             if (isset($change_date) && $change_date) {
                 $id_product = Tools::getValue('id_product');
                 $date_from = Tools::getValue('date_from');
                 $date_to = Tools::getValue('date_to');
                 $quantity = Tools::getValue('qty');
                 $result = $this->checkRoomQuantityAvailability($id_product, $date_from, $date_to, $quantity);
                 die($result);
             }
         }
     }
     // // by webkul to delete cart rooms individually
     // $delete_room_from_current_cart = Tools::getValue('delete_room_from_cart');
     // if (isset($delete_room_from_current_cart) && $delete_room_from_current_cart)
     // {
     // 	//code for
     // }
     if ($id_product = (int) Tools::getValue('id_product')) {
         $this->product = new Product($id_product, true, $this->context->language->id, $this->context->shop->id);
     }
     if (!Validate::isLoadedObject($this->product)) {
         header('HTTP/1.1 404 Not Found');
         header('Status: 404 Not Found');
         $this->errors[] = Tools::displayError('Product not found');
     } else {
         $this->canonicalRedirection();
         /*
          * If the product is associated to the shop
          * and is active or not active but preview mode (need token + file_exists)
          * allow showing the product
          * In all the others cases => 404 "Product is no longer available"
          */
         if (!$this->product->isAssociatedToShop() || !$this->product->active) {
             if (Tools::getValue('adtoken') == Tools::getAdminToken('AdminProducts' . (int) Tab::getIdFromClassName('AdminProducts') . (int) Tools::getValue('id_employee')) && $this->product->isAssociatedToShop()) {
                 // If the product is not active, it's the admin preview mode
                 $this->context->smarty->assign('adminActionDisplay', true);
             } else {
                 $this->context->smarty->assign('adminActionDisplay', false);
                 if (!$this->product->id_product_redirected || $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');
                         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');
                         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;
                 }
             }
         } elseif (!$this->product->checkAccess(isset($this->context->customer->id) && $this->context->customer->id ? (int) $this->context->customer->id : 0)) {
             header('HTTP/1.1 403 Forbidden');
             header('Status: 403 Forbidden');
             $this->errors[] = Tools::displayError('You do not have access to this product.');
         } else {
             // Load category
             $id_category = false;
             if (isset($_SERVER['HTTP_REFERER']) && $_SERVER['HTTP_REFERER'] == Tools::secureReferrer($_SERVER['HTTP_REFERER']) && preg_match('~^.*(?<!\\/content)\\/([0-9]+)\\-(.*[^\\.])|(.*)id_(category|product)=([0-9]+)(.*)$~', $_SERVER['HTTP_REFERER'], $regs)) {
                 // If the previous page was a category and is a parent category of the product use this category as parent category
                 $id_object = false;
                 if (isset($regs[1]) && is_numeric($regs[1])) {
                     $id_object = (int) $regs[1];
                 } elseif (isset($regs[5]) && is_numeric($regs[5])) {
                     $id_object = (int) $regs[5];
                 }
                 if ($id_object) {
                     $referers = array($_SERVER['HTTP_REFERER'], urldecode($_SERVER['HTTP_REFERER']));
                     if (in_array($this->context->link->getCategoryLink($id_object), $referers)) {
                         $id_category = (int) $id_object;
                     } elseif (isset($this->context->cookie->last_visited_category) && (int) $this->context->cookie->last_visited_category && in_array($this->context->link->getProductLink($id_object), $referers)) {
                         $id_category = (int) $this->context->cookie->last_visited_category;
                     }
                 }
             }
             if (!$id_category || !Category::inShopStatic($id_category, $this->context->shop) || !Product::idIsOnCategoryId((int) $this->product->id, array('0' => array('id_category' => $id_category)))) {
                 $id_category = (int) $this->product->id_category_default;
             }
             $this->category = new Category((int) $id_category, (int) $this->context->cookie->id_lang);
             if (isset($this->context->cookie) && isset($this->category->id_category) && !(Module::isInstalled('blockcategories') && Module::isEnabled('blockcategories'))) {
                 $this->context->cookie->last_visited_category = (int) $this->category->id_category;
             }
         }
     }
 }