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