From 5ab75eaa9052d92defe2fbf9e2c58d4858cc068a Mon Sep 17 00:00:00 2001 From: Marcin Nowak Date: Wed, 27 Apr 2022 21:46:39 +0200 Subject: [PATCH] Add mass action event to Mage_Catalog_Model_Indexer_Url for product entities --- .../core/Mage/Catalog/Model/Indexer/Url.php | 35 +++++++++++++++---- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/app/code/core/Mage/Catalog/Model/Indexer/Url.php b/app/code/core/Mage/Catalog/Model/Indexer/Url.php index 3d1db33adfc..74e59b2530c 100644 --- a/app/code/core/Mage/Catalog/Model/Indexer/Url.php +++ b/app/code/core/Mage/Catalog/Model/Indexer/Url.php @@ -48,7 +48,8 @@ class Mage_Catalog_Model_Indexer_Url extends Mage_Index_Model_Indexer_Abstract */ protected $_matchedEntities = array( Mage_Catalog_Model_Product::ENTITY => array( - Mage_Index_Model_Event::TYPE_SAVE + Mage_Index_Model_Event::TYPE_SAVE, + Mage_Index_Model_Event::TYPE_MASS_ACTION ), Mage_Catalog_Model_Category::ENTITY => array( Mage_Index_Model_Event::TYPE_SAVE @@ -181,13 +182,33 @@ 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->dataHasChangedFor('status') - || $product->getIsChangedCategories() - || $product->getIsChangedWebsites(); - if (!$product->getExcludeUrlRewrite() && $dataChange) { - $event->addNewData('rewrite_product_ids', array($product->getId())); + if (is_a($product, Mage_Catalog_Model_Product_Action::class)) { + $attributesData = $product->getData('attributes_data'); + $productsIds = $product->getData('product_ids'); + if ($dataChange = isset($attributesData['status']) && isset($productsIds) && count($productsIds) > 0) { + $products = Mage::getModel('catalog/product')->getCollection() + ->addFieldToFilter('entity_id', array('in'=> $productsIds)); + } else { + return; + } + } + + if (is_a($product, Mage_Catalog_Model_Product::class)) { + $dataChange = + ( + $product->dataHasChangedFor('url_key') + || $product->dataHasChangedFor('status') + || $product->getIsChangedCategories() + || $product->getIsChangedWebsites() + ) && !$product->getExcludeUrlRewrite(); + $products = [$product]; + } + + if ($dataChange) { + foreach ($products as $product) { + $event->addNewData('rewrite_product_ids', array($product->getId())); + } } }