From ecaf82865e7e444a86262829518510a72ed7ad9c Mon Sep 17 00:00:00 2001 From: Marcin Nowak Date: Mon, 11 Nov 2024 10:45:38 +0100 Subject: [PATCH] patch by Colin --- app/code/core/Mage/Catalog/Model/Url.php | 59 ++++++++---------------- 1 file changed, 18 insertions(+), 41 deletions(-) diff --git a/app/code/core/Mage/Catalog/Model/Url.php b/app/code/core/Mage/Catalog/Model/Url.php index b8180acf443..4b3f580d1e8 100644 --- a/app/code/core/Mage/Catalog/Model/Url.php +++ b/app/code/core/Mage/Catalog/Model/Url.php @@ -36,6 +36,9 @@ class Mage_Catalog_Model_Url */ public const ALLOWED_REQUEST_PATH_OVERFLOW = 10; + public const XML_PATH_PRODUCT_USE_CATEGORIES = 'catalog/seo/product_use_categories'; + public const XML_PATH_CREATE_URL_FOR_DISABLED = 'catalog/seo/create_url_for_disabled'; + /** * Resource model * @@ -71,19 +74,6 @@ class Mage_Catalog_Model_Url */ protected $_rewrite; - /** - * Cache for product rewrite suffix - * - * @var array - */ - protected $_productUrlSuffix = []; - - /** - * Cache for category rewrite suffix - * - * @var array - */ - protected $_categoryUrlSuffix = []; /** * Flag to overwrite config settings for Catalog URL rewrites history maintainance @@ -99,25 +89,6 @@ class Mage_Catalog_Model_Url */ protected static $_categoryForUrlPath; - /** - * @var bool - */ - protected $productUseCategories; - - /** - * @var bool - */ - protected $createForDisabled; - - /** - * Neuca_Base_Model_Url constructor. - */ - public function __construct() - { - $this->productUseCategories = Mage::getStoreConfigFlag('catalog/seo/product_use_categories'); - $this->createForDisabled = Mage::getStoreConfigFlag('catalog/seo/create_url_for_disabled'); - } - /** * Adds url_path property for non-root category - to ensure that url path is not empty. * @@ -441,7 +412,7 @@ protected function _refreshCategoryProductRewrites(Varien_Object $category) public function refreshCategoryRewrite($categoryId, $storeId = null, $refreshProducts = null) { if (is_null($refreshProducts)) { - $refreshProducts = $this->productUseCategories; + $refreshProducts = Mage::getStoreConfigFlag(self::XML_PATH_PRODUCT_USE_CATEGORIES, $storeId); } if (is_null($storeId)) { foreach ($this->getStores() as $store) { @@ -455,7 +426,9 @@ public function refreshCategoryRewrite($categoryId, $storeId = null, $refreshPro return $this; } - if (!$this->createForDisabled && !$category->getIsActive()) { + $createForDisabled = Mage::getStoreConfigFlag(self::XML_PATH_CREATE_URL_FOR_DISABLED, $storeId); + + if (!$createForDisabled && !$category->getIsActive()) { $this->getResource()->clearDisabledCategory($category->getId()); return $this; } @@ -492,7 +465,9 @@ public function refreshProductRewrite($productId, $storeId = null) return $this; } - $product = $this->getResource()->getProduct($productId, $storeId, $this->createForDisabled); + $createForDisabled = Mage::getStoreConfigFlag(self::XML_PATH_CREATE_URL_FOR_DISABLED, $storeId); + + $product = $this->getResource()->getProduct($productId, $storeId, $createForDisabled); if (!$product) { // Product doesn't belong to this store - clear all its url rewrites including root one $this->getResource()->clearProductRewrites($productId, $storeId, []); @@ -504,7 +479,7 @@ public function refreshProductRewrite($productId, $storeId = null) $this->_rewrites = $this->getResource()->prepareRewrites($storeId, '', $productId); - if ($this->productUseCategories) { + if ($createForDisabled) { // List of categories the product is assigned to, filtered by being within the store's categories root $categories = $this->getResource()->getCategories($product->getCategoryIds(), $storeId) ?: []; } @@ -525,7 +500,7 @@ public function refreshProductRewrite($productId, $storeId = null) $excludeCategoryIds = array_keys($categories); // Product is disabled and in configuration set to not create for disabled - clear all its url rewrites including root one - if (!$this->createForDisabled && $product->getStatus() === Mage_Catalog_Model_Product_Status::STATUS_DISABLED) { + if (!$createForDisabled && $product->getStatus() === Mage_Catalog_Model_Product_Status::STATUS_DISABLED) { $excludeCategoryIds = []; } $this->getResource()->clearProductRewrites($productId, $storeId, $excludeCategoryIds); @@ -548,12 +523,14 @@ public function refreshProductRewrites($storeId) $storeRootCategoryId = $this->getStores($storeId)->getRootCategoryId(); $storeRootCategoryPath = $this->getStores($storeId)->getRootCategoryPath(); $this->_categories[$storeRootCategoryId] = $this->getResource()->getCategory($storeRootCategoryId, $storeId); + $createForDisabled = Mage::getStoreConfigFlag(self::XML_PATH_CREATE_URL_FOR_DISABLED, $storeId); + $productUseCategories = Mage::getStoreConfigFlag(self::XML_PATH_PRODUCT_USE_CATEGORIES, $storeId); $lastEntityId = 0; $process = true; while ($process) { - $products = $this->getResource()->getProductsByStore($storeId, $lastEntityId, $this->createForDisabled); + $products = $this->getResource()->getProductsByStore($storeId, $lastEntityId, $createForDisabled); if (!$products) { $process = false; @@ -564,7 +541,7 @@ public function refreshProductRewrites($storeId) $loadCategories = []; - if ($this->productUseCategories) { + if ($productUseCategories) { foreach ($products as $product) { foreach ($product->getCategoryIds() as $categoryId) { if (!isset($this->_categories[$categoryId])) { @@ -574,7 +551,7 @@ public function refreshProductRewrites($storeId) } if ($loadCategories) { - $categories = $this->getResource()->getCategories($loadCategories, $storeId, $this->createForDisabled) ?: []; + $categories = $this->getResource()->getCategories($loadCategories, $storeId, $createForDisabled) ?: []; foreach ($categories as $category) { $this->_categories[$category->getId()] = $category; } @@ -583,7 +560,7 @@ public function refreshProductRewrites($storeId) foreach ($products as $product) { $this->_refreshProductRewrite($product, $this->_categories[$storeRootCategoryId]); - if ($this->productUseCategories) { + if ($productUseCategories) { foreach ($product->getCategoryIds() as $categoryId) { if ($categoryId != $storeRootCategoryId && isset($this->_categories[$categoryId])) { if (strpos($this->_categories[$categoryId]['path'], $storeRootCategoryPath . '/') !== 0) {