This commit is contained in:
gRoussac committed 2013-12-03 19:24:31 +01:00
1 parent 03239a32ea
commit 81481d6105
1 file changed
+20 -14
+20 -14
View File
@@ -136,25 +136,31 @@ class ProductControllerCore extends FrontController
else else
{ {
// Load category // Load category
if (isset($_SERVER['HTTP_REFERER']) $id_category = false;
&& strstr($_SERVER['HTTP_REFERER'], Tools::getHttpHost()) // Assure us the previous page was one of the shop if (isset($_SERVER['HTTP_REFERER']) && $_SERVER['HTTP_REFERER'] == Tools::secureReferrer($_SERVER['HTTP_REFERER']) // Assure us the previous page was one of the shop
&& (stripos($_SERVER['HTTP_REFERER'], '.html') === false) && preg_match('~^.*(?<!\/content)\/([0-9]+)\-(.*[^\.])|(.*)id_(category|product)=([0-9]+)(.*)$~', $_SERVER['HTTP_REFERER'], $regs))
&& preg_match('~^(.*)\/([0-9]+)\-((?![.]+html).*)|(.*)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 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])) $id_object = false;
if (isset($regs[1]) && is_numeric($regs[1]))
$id_object = (int)$regs[2];
elseif (isset($regs[5]) && is_numeric($regs[5]))
$id_object = (int)$regs[6];
if ($id_object)
{ {
if (Product::idIsOnCategoryId((int)$this->product->id, array('0' => array('id_category' => (int)$regs[2])))) $referers = array($_SERVER['HTTP_REFERER'],urldecode($_SERVER['HTTP_REFERER']));
$this->category = new Category($regs[2], (int)$this->context->cookie->id_lang); if (in_array($this->context->link->getCategoryLink($id_object), $referers))
} $id_category = (int)$id_object;
else if (isset($regs[5]) && is_numeric($regs[5])) 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 (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);
} }
} }
if (!isset($this->category)) if (!$id_category || !Category::inShopStatic($id_category, $this->context->shop) || !Product::idIsOnCategoryId((int)$this->product->id, array('0' => array('id_category' => $id_category))))
$this->category = new Category($this->product->id_category_default, (int)$this->context->cookie->id_lang); $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;
} }
} }
} }