Skip to content

Commit

Permalink
Add mass action event to Mage_Catalog_Model_Indexer_Url for product e…
Browse files Browse the repository at this point in the history
…ntities
  • Loading branch information
MarcinNowakMacopedia authored and tmotyl committed Jun 20, 2022
1 parent eaf3615 commit 5ab75ea
Showing 1 changed file with 28 additions and 7 deletions.
35 changes: 28 additions & 7 deletions app/code/core/Mage/Catalog/Model/Indexer/Url.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()));
}
}
}

Expand Down

0 comments on commit 5ab75ea

Please sign in to comment.