diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Seo.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Seo.php
new file mode 100644
index 00000000000..706e8bb456d
--- /dev/null
+++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Seo.php
@@ -0,0 +1,46 @@
+isValueChanged()) {
+ Mage::getModel('index/indexer')
+ ->getProcessByCode(Mage_Catalog_Helper_Category_Flat::CATALOG_CATEGORY_FLAT_PROCESS_CODE)
+ ->changeStatus(Mage_Index_Model_Process::STATUS_REQUIRE_REINDEX);
+
+ Mage::getModel('index/indexer')
+ ->getProcessByCode(Mage_Catalog_Helper_Product_Flat::CATALOG_FLAT_PROCESS_CODE)
+ ->changeStatus(Mage_Index_Model_Process::STATUS_REQUIRE_REINDEX);
+ }
+ return $this;
+ }
+}
diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Seo/Product.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Seo/Product.php
index a67df035ab4..825eec01ddf 100644
--- a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Seo/Product.php
+++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Seo/Product.php
@@ -27,12 +27,18 @@
class Mage_Adminhtml_Model_System_Config_Backend_Seo_Product extends Mage_Core_Model_Config_Data
{
/**
- * Refresh category url rewrites if configuration was changed
+ * Refresh products url rewrites if configuration was changed
*
* @return $this
*/
protected function _afterSave()
{
+ if ($this->isValueChanged()) {
+ Mage::getModel('index/indexer')
+ ->getProcessByCode(Mage_Catalog_Helper_Product_Flat::CATALOG_FLAT_PROCESS_CODE)
+ ->changeStatus(Mage_Index_Model_Process::STATUS_REQUIRE_REINDEX);
+ }
+
return $this;
}
}
diff --git a/app/code/core/Mage/Catalog/Model/Indexer/Url.php b/app/code/core/Mage/Catalog/Model/Indexer/Url.php
index d780a846e99..bb57b5fb227 100644
--- a/app/code/core/Mage/Catalog/Model/Indexer/Url.php
+++ b/app/code/core/Mage/Catalog/Model/Indexer/Url.php
@@ -47,7 +47,8 @@ class Mage_Catalog_Model_Indexer_Url extends Mage_Index_Model_Indexer_Abstract
*/
protected $_matchedEntities = [
Mage_Catalog_Model_Product::ENTITY => [
- Mage_Index_Model_Event::TYPE_SAVE
+ Mage_Index_Model_Event::TYPE_SAVE,
+ Mage_Index_Model_Event::TYPE_MASS_ACTION
],
Mage_Catalog_Model_Category::ENTITY => [
Mage_Index_Model_Event::TYPE_SAVE
@@ -180,12 +181,36 @@ protected function _registerEvent(Mage_Index_Model_Event $event)
protected function _registerProductEvent(Mage_Index_Model_Event $event)
{
$product = $event->getDataObject();
- $dataChange = $product->dataHasChangedFor('url_key')
- || $product->getIsChangedCategories()
- || $product->getIsChangedWebsites();
+ $dataChange = false;
+ $products = [];
+
+ if ($product instanceof Mage_Catalog_Model_Product_Action) {
+ $attributesData = $product->getData('attributes_data');
+ $productsIds = $product->getData('product_ids');
+ $dataChange = isset($attributesData['status']) && isset($productsIds) && count($productsIds) > 0;
+ if ($dataChange) {
+ $products = Mage::getModel('catalog/product')->getCollection()
+ ->addFieldToFilter('entity_id', ['in'=> $productsIds]);
+ } else {
+ return;
+ }
+ }
+
+ if ($product instanceof Mage_Catalog_Model_Product) {
+ $dataChange =
+ (
+ $product->dataHasChangedFor('url_key')
+ || $product->dataHasChangedFor('status')
+ || $product->getIsChangedCategories()
+ || $product->getIsChangedWebsites()
+ ) && !$product->getExcludeUrlRewrite();
+ $products = [$product];
+ }
- if (!$product->getExcludeUrlRewrite() && $dataChange) {
- $event->addNewData('rewrite_product_ids', [$product->getId()]);
+ if ($dataChange) {
+ foreach ($products as $product) {
+ $event->addNewData('rewrite_product_ids', [$product->getId()]);
+ }
}
}
@@ -198,7 +223,11 @@ protected function _registerCategoryEvent(Mage_Index_Model_Event $event)
{
$category = $event->getDataObject();
if (!$category->getInitialSetupFlag() && $category->getLevel() > 1) {
- if ($category->dataHasChangedFor('url_key') || $category->getIsChangedProductList()) {
+ if (
+ $category->dataHasChangedFor('url_key')
+ || $category->getIsChangedProductList()
+ || $category->dataHasChangedFor('is_active')
+ ) {
$event->addNewData('rewrite_category_ids', [$category->getId()]);
}
/**
diff --git a/app/code/core/Mage/Catalog/Model/Resource/Url.php b/app/code/core/Mage/Catalog/Model/Resource/Url.php
index d19093e51cd..4c4278b01f1 100644
--- a/app/code/core/Mage/Catalog/Model/Resource/Url.php
+++ b/app/code/core/Mage/Catalog/Model/Resource/Url.php
@@ -63,6 +63,16 @@ class Mage_Catalog_Model_Resource_Url extends Mage_Core_Model_Resource_Db_Abstra
*/
protected $_rootChildrenIds = [];
+ /**
+ * @var int
+ */
+ protected $_productEntityTypeId;
+
+ /**
+ * @var int
+ */
+ protected $_statusAttributeId;
+
/**
* Load core Url rewrite model
*
@@ -70,6 +80,9 @@ class Mage_Catalog_Model_Resource_Url extends Mage_Core_Model_Resource_Db_Abstra
protected function _construct()
{
$this->_init('core/url_rewrite', 'url_rewrite_id');
+ $this->_productEntityTypeId = Mage::getSingleton('eav/config')->getEntityType(Mage_Catalog_Model_Product::ENTITY)->getId();
+ $this->_statusAttributeId = Mage::getModel('catalog/resource_eav_attribute')
+ ->loadByCode($this->_productEntityTypeId, 'status')->getId();
}
/**
@@ -685,9 +698,10 @@ protected function _prepareStoreRootCategories($stores)
* @param int|array $categoryIds
* @param int $storeId
* @param string $path
+ * @param bool $withDisabled
* @return array
*/
- protected function _getCategories($categoryIds, $storeId = null, $path = null)
+ protected function _getCategories($categoryIds, $storeId = null, $path = null, $withDisabled = true)
{
$isActiveAttribute = Mage::getSingleton('eav/config')
->getAttribute(Mage_Catalog_Model_Category::ENTITY, 'is_active');
@@ -735,6 +749,10 @@ protected function _getCategories($categoryIds, $storeId = null, $path = null)
$rootCategoryPath = $this->getStores($storeId)->getRootCategoryPath();
$rootCategoryPathLength = strlen($rootCategoryPath);
}
+ if (!$withDisabled) {
+ $select->where('IF(c.value_id > 0, c.value, d.value) = 1');
+ }
+
$bind = [
'attribute_id' => (int)$isActiveAttribute->getId(),
'store_id' => (int)$storeId
@@ -802,15 +820,16 @@ public function getCategory($categoryId, $storeId)
*
* @param int|array $categoryIds
* @param int $storeId
+ * @param bool $withDisabled
* @return Mage_Catalog_Model_Category[]|false
*/
- public function getCategories($categoryIds, $storeId)
+ public function getCategories($categoryIds, $storeId, $withDisabled = true)
{
if (!$categoryIds || !$storeId) {
return false;
}
- return $this->_getCategories($categoryIds, $storeId);
+ return $this->_getCategories($categoryIds, $storeId, null, $withDisabled);
}
/**
@@ -933,9 +952,11 @@ public function getProductIdsByCategory($category)
* @param int $storeId
* @param int $entityId
* @param int $lastEntityId
+ * @param bool $withDisabled
* @return array
+ * @throws Mage_Core_Model_Store_Exception
*/
- protected function _getProducts($productIds, $storeId, $entityId, &$lastEntityId)
+ protected function _getProducts($productIds, $storeId, $entityId, &$lastEntityId, $withDisabled = true)
{
$products = [];
$websiteId = Mage::app()->getStore($storeId)->getWebsiteId();
@@ -963,6 +984,14 @@ protected function _getProducts($productIds, $storeId, $entityId, &$lastEntityId
if ($productIds !== null) {
$select->where('e.entity_id IN(?)', $productIds);
}
+ if (!$withDisabled) {
+ $select->join(
+ ['cpei' => 'catalog_product_entity_int'],
+ 'cpei.entity_id = e.entity_id AND cpei.entity_type_id = ' . $this->_productEntityTypeId . ' AND cpei.attribute_id = ' . $this->_statusAttributeId,
+ []
+ );
+ $select->where('cpei.value <> ' . Mage_Catalog_Model_Product_Status::STATUS_DISABLED);
+ }
$rowSet = $adapter->fetchAll($select, $bind);
foreach ($rowSet as $row) {
@@ -1007,9 +1036,11 @@ protected function _getProducts($productIds, $storeId, $entityId, &$lastEntityId
*
* @param int $productId
* @param int $storeId
+ * @param bool $withDisabled
* @return Varien_Object|false
+ * @throws Mage_Core_Model_Store_Exception
*/
- public function getProduct($productId, $storeId)
+ public function getProduct($productId, $storeId, $withDisabled = true)
{
$entityId = 0;
$products = $this->_getProducts($productId, $storeId, 0, $entityId);
@@ -1021,11 +1052,12 @@ public function getProduct($productId, $storeId)
*
* @param int $storeId
* @param int $lastEntityId
+ * @param bool $withDisabled
* @return Mage_Catalog_Model_Product[]
*/
- public function getProductsByStore($storeId, &$lastEntityId)
+ public function getProductsByStore($storeId, &$lastEntityId, $withDisabled = true)
{
- return $this->_getProducts(null, $storeId, $lastEntityId, $lastEntityId);
+ return $this->_getProducts(null, $storeId, $lastEntityId, $lastEntityId, $withDisabled);
}
/**
@@ -1045,27 +1077,92 @@ public function getProductsByCategory(Varien_Object $category, &$lastEntityId)
}
/**
- * Find and remove unused products rewrites - a case when products were moved away from the category
- * (either to other category or deleted), so rewrite "category_id-product_id" is invalid
+ * Unused function. Left for backward compatibility
*
* @param int $storeId
* @return $this
*/
public function clearCategoryProduct($storeId)
{
+ return $this->clearRewrites($storeId);
+ }
+
+ /**
+ * Find and remove unused rewrites a case when
+ * - products were moved away from the category (either to other category or deleted), so rewrite "category_id-product_id" is invalid
+ * - category
+ *
+ * @param int $storeId
+ * @return $this
+ */
+ public function clearRewrites($storeId)
+ {
+ $adapter = $this->_getWriteAdapter();
+ list($select, $bind) = $this->getSelectToClearRewrites($adapter, $storeId);
+
+ $rewriteIds = $adapter->fetchCol($select, $bind);
+ if ($rewriteIds) {
+ $where = [$this->getIdFieldName() . ' IN(?)' => $rewriteIds];
+ $adapter->delete($this->getMainTable(), $where);
+ }
+
+ return $this;
+ }
+
+ /**
+ * Find and remove unused category rewrites - a case when category is disabled and in config field
+ * catalog/seo/create_url_for_disabled is set as false
+ *
+ * @param int $categoryId
+ * @param int|Mage_Core_Model_Store|null $storeId
+ * @return $this
+ */
+ public function clearDisabledCategory($categoryId, $storeId = null)
+ {
+ if (Mage::getStoreConfigFlag('catalog/seo/create_url_for_disabled')) {
+ return $this;
+ }
+
+ if (is_null($storeId)) {
+ foreach ($this->getStores() as $store) {
+ $this->clearDisabledCategory($categoryId, $store);
+ }
+ return $this;
+ }
+ if ($storeId instanceof Mage_Core_Model_Store) {
+ $storeId = $storeId->getStoreId();
+ } elseif (!is_int($storeId)) {
+ throw new Exception('StoreId must by int or Mage_Core_Model_Store');
+ }
+
$adapter = $this->_getWriteAdapter();
+
+ $table = $this->getTable(['catalog/category', 'int']);
$select = $adapter->select()
->from(['tur' => $this->getMainTable()], $this->getIdFieldName())
->joinLeft(
- ['tcp' => $this->getTable('catalog/category_product')],
- 'tur.category_id = tcp.category_id AND tur.product_id = tcp.product_id',
+ ['ccei1' => $table],
+ 'ccei1.attribute_id = :is_active_category_attribute_id AND ccei1.store_id = 0 AND ccei1.entity_id = tur.category_id',
[]
)
+ ->joinLeft(
+ ['ccei2' => $table],
+ 'ccei2.attribute_id = :is_active_category_attribute_id AND ccei2.store_id = :store_id AND ccei2.entity_id = tur.category_id',
+ []
+ )
+ ->where('IF(ccei2.value_id > 0, ccei2.value, ccei1.value) = 0')
->where('tur.store_id = :store_id')
- ->where('tur.category_id IS NOT NULL')
- ->where('tur.product_id IS NOT NULL')
- ->where('tcp.category_id IS NULL');
- $rewriteIds = $adapter->fetchCol($select, ['store_id' => $storeId]);
+ ->where('tur.category_id = :category_id');
+
+ $isActiveCategoryAttribute = Mage::getSingleton('eav/config')
+ ->getAttribute(Mage_Catalog_Model_Category::ENTITY, 'is_active');
+ $bind = [
+ 'store_id' => $storeId,
+ 'is_active_category_attribute_id' => $isActiveCategoryAttribute->getId(),
+ 'category_id' => $categoryId
+ ];
+
+ $rewriteIds = $adapter->fetchCol($select, $bind);
if ($rewriteIds) {
$where = [$this->getIdFieldName() . ' IN(?)' => $rewriteIds];
$adapter->delete($this->getMainTable(), $where);
@@ -1074,6 +1171,93 @@ public function clearCategoryProduct($storeId)
return $this;
}
+ /**
+ * Prepare select to find unused rewrites
+ * as set in configuration fields catalog/seo/product_use_categories and catalog/seo/create_url_for_disabled
+ *
+ * @param Magento_Db_Adapter_Pdo_Mysql $adapter
+ * @param int $storeId
+ * @return array
+ */
+ protected function getSelectToClearRewrites($adapter, $storeId)
+ {
+ $productUseCategories = Mage::getStoreConfigFlag('catalog/seo/product_use_categories');
+ $createUrlForDisabled = Mage::getStoreConfigFlag('catalog/seo/create_url_for_disabled');
+
+ $bind = ['store_id' => $storeId];
+ $select = $adapter->select()
+ ->from(['tur' => $this->getMainTable()], $this->getIdFieldName())
+ ->where('tur.store_id = :store_id')
+ ->where('tur.is_system = 1');
+
+ if ($createUrlForDisabled) {
+
+ // Find rewrites for cartegory/product
+ $select->where('tur.category_id IS NOT NULL')
+ ->where('tur.product_id IS NOT NULL');
+
+ // Find unused products rewrites - a case when products were moved away from the category
+ // (either to other category or deleted), so rewrite "category_id-product_id" is invalid
+ if ($productUseCategories) {
+ $select->joinLeft(
+ ['tcp' => $this->getTable('catalog/category_product')],
+ 'tur.category_id = tcp.category_id AND tur.product_id = tcp.product_id',
+ []
+ )
+ ->where('tcp.category_id IS NULL');
+ }
+
+ } else {
+ // Find products, cartegories and cartegory/product rewrites for disabled products or cartegories
+ $productTable = $this->getTable(['catalog/product', 'int']);
+ $categoryTable = $this->getTable(['catalog/category', 'int']);
+ $select->joinLeft(
+ ['cpei' => $productTable],
+ 'cpei.entity_id = tur.product_id AND cpei.attribute_id = :product_status_attribute_id',
+ []
+ )
+ ->joinLeft(
+ ['ccei1' => $categoryTable],
+ 'ccei1.attribute_id = :is_active_category_attribute_id AND ccei1.store_id = 0 AND ccei1.entity_id = tur.category_id',
+ []
+ )
+ ->joinLeft(
+ ['ccei2' => $categoryTable],
+ 'ccei2.attribute_id = :is_active_category_attribute_id AND ccei2.store_id = :store_id AND ccei2.entity_id = tur.category_id',
+ []
+ );
+ $productStatusAttributeId = Mage::getSingleton('eav/config')
+ ->getAttribute(Mage_Catalog_Model_Product::ENTITY, 'status');
+ $bind['product_status_attribute_id'] = $productStatusAttributeId->getId();
+
+ $isActiveCategoryAttribute = Mage::getSingleton('eav/config')
+ ->getAttribute(Mage_Catalog_Model_Category::ENTITY, 'is_active');
+ $bind['is_active_category_attribute_id'] = $isActiveCategoryAttribute->getId();
+
+ // product_is_disabled OR (category is disabled) OR (cartegory/product rewrite)
+ $where = '(cpei.value = 2 OR (IF(ccei2.value_id > 0, ccei2.value, ccei1.value) = 0) OR (tur.category_id IS NOT NULL AND tur.product_id IS NOT NULL) )';
+
+ // Find products, categories and cartegory/product rewrites for disabled products or categories
+ if ($productUseCategories) {
+ $select
+ ->joinLeft(
+ ['tcp' => $this->getTable('catalog/category_product')],
+ 'tcp.category_id = tur.category_id AND tcp.product_id = tur.product_id',
+ []
+ );
+ // product_is_disabled OR (category is disabled) OR (cartegory/product rewrite AND product were moved away from the category)
+ $where ='(cpei.value = 2 OR (IF(ccei2.value_id > 0, ccei2.value, ccei1.value) = 0) OR (tur.category_id IS NOT NULL AND tur.product_id IS NOT NULL AND tcp.category_id IS NULL))';
+ }
+ $select->where($where);
+ }
+ $select->group('url_rewrite_id');
+
+ return [
+ $select,
+ $bind
+ ];
+ }
+
/**
* Remove unused rewrites for product - called after we created all needed rewrites for product and know the categories
* where the product is contained ($excludeCategoryIds), so we can remove all invalid product rewrites that have other category ids
diff --git a/app/code/core/Mage/Catalog/Model/Url.php b/app/code/core/Mage/Catalog/Model/Url.php
index d1a7e048649..79591a37d55 100644
--- a/app/code/core/Mage/Catalog/Model/Url.php
+++ b/app/code/core/Mage/Catalog/Model/Url.php
@@ -106,6 +106,22 @@ class Mage_Catalog_Model_Url
*/
static protected $_categoryForUrlPath;
+ /**
+ * @var bool
+ */
+ protected $productUseCategories;
+
+ /**
+ * @var bool
+ */
+ protected $createForDisabled;
+
+ 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.
*
@@ -245,7 +261,7 @@ public function refreshRewrites($storeId = null)
$this->clearStoreInvalidRewrites($storeId);
$this->refreshCategoryRewrite($this->getStores($storeId)->getRootCategoryId(), $storeId, false);
$this->refreshProductRewrites($storeId);
- $this->getResource()->clearCategoryProduct($storeId);
+ $this->getResource()->clearRewrites($storeId);
return $this;
}
@@ -371,7 +387,7 @@ protected function _refreshProductRewrite(Varien_Object $product, Varien_Object
}
/**
- * Refresh products for catwgory
+ * Refresh products for category
*
* @param Varien_Object|Mage_Catalog_Model_Category $category
* @return $this
@@ -426,8 +442,11 @@ protected function _refreshCategoryProductRewrites(Varien_Object $category)
* @param bool $refreshProducts
* @return $this
*/
- public function refreshCategoryRewrite($categoryId, $storeId = null, $refreshProducts = true)
+ public function refreshCategoryRewrite($categoryId, $storeId = null, $refreshProducts = null)
{
+ if (is_null($refreshProducts)) {
+ $refreshProducts = $this->productUseCategories;
+ }
if (is_null($storeId)) {
foreach ($this->getStores() as $store) {
$this->refreshCategoryRewrite($categoryId, $store->getId(), $refreshProducts);
@@ -440,6 +459,11 @@ public function refreshCategoryRewrite($categoryId, $storeId = null, $refreshPro
return $this;
}
+ if (!$this->createForDisabled && !$category->getIsActive()) {
+ $this->getResource()->clearDisabledCategory($category->getId());
+ return $this;
+ }
+
// Load all childs and refresh all categories
$category = $this->getResource()->loadCategoryChilds($category);
$categoryIds = [$category->getId()];
@@ -472,37 +496,47 @@ public function refreshProductRewrite($productId, $storeId = null)
return $this;
}
- $product = $this->getResource()->getProduct($productId, $storeId);
- if ($product) {
- $store = $this->getStores($storeId);
- $storeRootCategoryId = $store->getRootCategoryId();
+ $product = $this->getResource()->getProduct($productId, $storeId, $this->createForDisabled);
+ if (!$product) {
+ // Product doesn't belong to this store - clear all its url rewrites including root one
+ $this->getResource()->clearProductRewrites($productId, $storeId, []);
+ return $this;
+ }
+
+ $store = $this->getStores($storeId);
+ $storeRootCategoryId = $store->getRootCategoryId();
+
+ $this->_rewrites = $this->getResource()->prepareRewrites($storeId, '', $productId);
+ $categories = [];
+ if ($this->productUseCategories) {
// List of categories the product is assigned to, filtered by being within the store's categories root
$categories = $this->getResource()->getCategories($product->getCategoryIds(), $storeId);
- $this->_rewrites = $this->getResource()->prepareRewrites($storeId, '', $productId);
+ }
- // Add rewrites for all needed categories
- // If product is assigned to any of store's categories -
- // we also should use store root category to create root product url rewrite
- if (!isset($categories[$storeRootCategoryId])) {
- $categories[$storeRootCategoryId] = $this->getResource()->getCategory($storeRootCategoryId, $storeId);
- }
+ // Add rewrites for all needed categories
+ // If product is assigned to any of store's categories -
+ // we also should use store root category to create root product url rewrite
+ if (!isset($categories[$storeRootCategoryId])) {
+ $categories[$storeRootCategoryId] = $this->getResource()->getCategory($storeRootCategoryId, $storeId);
+ }
- // Create product url rewrites
- foreach ($categories as $category) {
- $this->_refreshProductRewrite($product, $category);
- }
+ // Create product url rewrites
+ foreach ($categories as $category) {
+ $this->_refreshProductRewrite($product, $category);
+ }
- // Remove all other product rewrites created earlier for this store - they're invalid now
- $excludeCategoryIds = array_keys($categories);
- $this->getResource()->clearProductRewrites($productId, $storeId, $excludeCategoryIds);
+ // Remove all other product rewrites created earlier for this store - they're invalid now
+ $excludeCategoryIds = array_keys($categories);
- unset($categories);
- unset($product);
- } else {
- // Product doesn't belong to this store - clear all its url rewrites including root one
- $this->getResource()->clearProductRewrites($productId, $storeId, []);
+ // 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) {
+ $excludeCategoryIds = [];
}
+ $this->getResource()->clearProductRewrites($productId, $storeId, $excludeCategoryIds);
+
+ unset($categories);
+ unset($product);
return $this;
}
@@ -524,7 +558,8 @@ public function refreshProductRewrites($storeId)
$process = true;
while ($process == true) {
- $products = $this->getResource()->getProductsByStore($storeId, $lastEntityId);
+ $products = $this->getResource()->getProductsByStore($storeId, $lastEntityId, $this->createForDisabled);
+
if (!$products) {
$process = false;
break;
@@ -533,28 +568,33 @@ public function refreshProductRewrites($storeId)
$this->_rewrites = $this->getResource()->prepareRewrites($storeId, false, array_keys($products));
$loadCategories = [];
- foreach ($products as $product) {
- foreach ($product->getCategoryIds() as $categoryId) {
- if (!isset($this->_categories[$categoryId])) {
- $loadCategories[$categoryId] = $categoryId;
+
+ if ($this->productUseCategories) {
+ foreach ($products as $product) {
+ foreach ($product->getCategoryIds() as $categoryId) {
+ if (!isset($this->_categories[$categoryId])) {
+ $loadCategories[$categoryId] = $categoryId;
+ }
}
}
- }
- if ($loadCategories) {
- foreach ($this->getResource()->getCategories($loadCategories, $storeId) as $category) {
- $this->_categories[$category->getId()] = $category;
+ if ($loadCategories) {
+ foreach ($this->getResource()->getCategories($loadCategories, $storeId, $this->createForDisabled) as $category) {
+ $this->_categories[$category->getId()] = $category;
+ }
}
}
foreach ($products as $product) {
$this->_refreshProductRewrite($product, $this->_categories[$storeRootCategoryId]);
- foreach ($product->getCategoryIds() as $categoryId) {
- if ($categoryId != $storeRootCategoryId && isset($this->_categories[$categoryId])) {
- if (strpos($this->_categories[$categoryId]['path'], $storeRootCategoryPath . '/') !== 0) {
- continue;
+ if ($this->productUseCategories) {
+ foreach ($product->getCategoryIds() as $categoryId) {
+ if ($categoryId != $storeRootCategoryId && isset($this->_categories[$categoryId])) {
+ if (strpos($this->_categories[$categoryId]['path'], $storeRootCategoryPath . '/') !== 0) {
+ continue;
+ }
+ $this->_refreshProductRewrite($product, $this->_categories[$categoryId]);
}
- $this->_refreshProductRewrite($product, $this->_categories[$categoryId]);
}
}
}
diff --git a/app/code/core/Mage/Catalog/etc/config.xml b/app/code/core/Mage/Catalog/etc/config.xml
index 0060126e00f..df68b0fe9c6 100644
--- a/app/code/core/Mage/Catalog/etc/config.xml
+++ b/app/code/core/Mage/Catalog/etc/config.xml
@@ -809,6 +809,7 @@
.html
.html
1
+ 1
1
-
0
diff --git a/app/code/core/Mage/Catalog/etc/system.xml b/app/code/core/Mage/Catalog/etc/system.xml
index ca9325647ad..e356de1674a 100644
--- a/app/code/core/Mage/Catalog/etc/system.xml
+++ b/app/code/core/Mage/Catalog/etc/system.xml
@@ -271,6 +271,16 @@
1
1
+
+
+ select
+ adminhtml/system_config_source_yesno
+ adminhtml/system_config_backend_seo
+ 4
+ 1
+ 0
+ 1
+
select