diff --git a/classes/Category.php b/classes/Category.php index 06ba653a7..2800bf205 100644 --- a/classes/Category.php +++ b/classes/Category.php @@ -1233,6 +1233,17 @@ class CategoryCore extends ObjectModel return false; return ($this->nleft >= $interval['nleft'] && $this->nright <= $interval['nright']); } + + public static function inShopStatic($id_category, Shop $shop = null) + { + if (!$shop || !is_object($shop)) + $shop = Context::getContext()->shop; + + if (!$interval = Category::getInterval($shop->getCategory())) + return false; + $row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('SELECT nleft, nright FROM `'._DB_PREFIX_.'category` WHERE id_category = '.(int)$id_category); + return ($row['nleft'] >= $interval['nleft'] && $row['nright'] <= $interval['nright']); + } public function getChildrenWs() { diff --git a/classes/Product.php b/classes/Product.php index 6279280d3..ef452762f 100644 --- a/classes/Product.php +++ b/classes/Product.php @@ -3978,18 +3978,19 @@ class ProductCore extends ObjectModel { if (!((int)$id_product > 0) || !is_array($categories) || empty($categories)) return false; - $sql = 'SELECT id_product FROM `'._DB_PREFIX_.'category_product` WHERE `id_product`='.(int)$id_product.' AND `id_category` IN('; + $sql = 'SELECT id_product FROM `'._DB_PREFIX_.'category_product` WHERE `id_product` = '.(int)$id_product.' AND `id_category` IN ('; foreach ($categories as $category) $sql .= (int)$category['id_category'].','; $sql = rtrim($sql, ',').')'; - if (isset(self::$_incat[md5($sql)])) - return self::$_incat[md5($sql)]; - - if (!Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql)) - return false; - self::$_incat[md5($sql)] = (Db::getInstance(_PS_USE_SQL_SLAVE_)->NumRows() > 0 ? true : false); - return self::$_incat[md5($sql)]; + $hash = md5($sql); + if (!isset(self::$_incat[$hash])) + { + if (!Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql)) + return false; + self::$_incat[$hash] = (Db::getInstance(_PS_USE_SQL_SLAVE_)->NumRows() > 0 ? true : false); + } + return self::$_incat[$hash]; } public function getNoPackPrice() diff --git a/modules/blockcategories/blockcategories.php b/modules/blockcategories/blockcategories.php index 83c4e38da..3f1842ae1 100644 --- a/modules/blockcategories/blockcategories.php +++ b/modules/blockcategories/blockcategories.php @@ -203,7 +203,9 @@ class BlockCategories extends Module } if (Tools::isSubmit('id_product')) { - if (!isset($this->context->cookie->last_visited_category) || !Product::idIsOnCategoryId($id_product, array('0' => array('id_category' => $this->context->cookie->last_visited_category)))) + if (!isset($this->context->cookie->last_visited_category) + || !Product::idIsOnCategoryId($id_product, array('0' => array('id_category' => $this->context->cookie->last_visited_category))) + || !Category::inShopStatic($this->context->cookie->last_visited_category, $this->context->shop)) { $product = new Product($id_product); if (isset($product) && Validate::isLoadedObject($product))