Skip to content

Commit

Permalink
patch by Colin
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcinNowakMacopedia committed Nov 11, 2024
1 parent e3446d2 commit ecaf828
Showing 1 changed file with 18 additions and 41 deletions.
59 changes: 18 additions & 41 deletions app/code/core/Mage/Catalog/Model/Url.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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
Expand All @@ -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.
*
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
}
Expand Down Expand Up @@ -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, []);
Expand All @@ -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) ?: [];
}
Expand All @@ -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);
Expand All @@ -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;
Expand All @@ -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])) {
Expand All @@ -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;
}
Expand All @@ -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) {
Expand Down

0 comments on commit ecaf828

Please sign in to comment.