diff --git a/app/code/Magento/Catalog/Helper/Product.php b/app/code/Magento/Catalog/Helper/Product.php index 1c2e5ab26b4a3..795e345f7ecce 100644 --- a/app/code/Magento/Catalog/Helper/Product.php +++ b/app/code/Magento/Catalog/Helper/Product.php @@ -441,7 +441,7 @@ public function initProduct($productId, $controller, $params = null) $categoryId = $params->getCategoryId(); if (!$categoryId && $categoryId !== false) { $lastId = $this->_catalogSession->getLastVisitedCategoryId(); - if ($product->canBeShowInCategory($lastId)) { + if ($lastId && $product->canBeShowInCategory($lastId)) { $categoryId = $lastId; } } elseif (!$product->canBeShowInCategory($categoryId)) { diff --git a/app/code/Magento/Catalog/Model/Design.php b/app/code/Magento/Catalog/Model/Design.php index b290bbf13e62c..32bc6957d8919 100644 --- a/app/code/Magento/Catalog/Model/Design.php +++ b/app/code/Magento/Catalog/Model/Design.php @@ -140,7 +140,7 @@ public function getDesignSettings($object) $currentCategory = $object->getCategory(); if (!$currentCategory) { $lastId = $this->catalogSession->getLastVisitedCategoryId(); - if ($object->canBeShowInCategory($lastId)) { + if ($lastId && $object->canBeShowInCategory($lastId)) { $categoryId = $lastId; try { $currentCategory = $this->categoryRepository->get($categoryId);