/**
  * Modified to pull in all sibling associated products' tier prices and
  * to reindex child tier prices when a parent is saved.
  * 
  * Process product save.
  * Method is responsible for index support
  * when product was saved and changed attribute(s) has an effect on price.
  *
  * @param Mage_Index_Model_Event $event
  * @return Mage_Catalog_Model_Resource_Product_Indexer_Price
  */
 public function catalogProductSave(Mage_Index_Model_Event $event)
 {
     $productId = $event->getEntityPk();
     $data = $event->getNewData();
     /**
      * Check if price attribute values were updated
      */
     if (!isset($data['reindex_price'])) {
         return $this;
     }
     $this->clearTemporaryIndexTable();
     $this->_prepareWebsiteDateTable();
     $indexer = $this->_getIndexer($data['product_type_id']);
     $processIds = array($productId);
     if ($indexer->getIsComposite()) {
         if ($this->getProductTypeById($productId) == 'configurable') {
             $children = $this->getChildIdsByParent($productId);
             $processIds = array_merge($processIds, array_keys($children));
             //Ignore tier and group price data for actual configurable product
             $tierPriceIds = array_keys($children);
         } else {
             $tierPriceIds = $productId;
         }
         $this->_copyRelationIndexData($productId);
         $this->_prepareTierPriceIndex($tierPriceIds);
         $this->_prepareGroupPriceIndex($tierPriceIds);
         $indexer->reindexEntity($productId);
     } else {
         $parentIds = $this->getProductParentsByChild($productId);
         if ($parentIds) {
             $processIds = array_merge($processIds, array_keys($parentIds));
             $siblingIds = array();
             foreach (array_keys($parentIds) as $parentId) {
                 $childIds = $this->getChildIdsByParent($parentId);
                 $siblingIds = array_merge($siblingIds, array_keys($childIds));
             }
             if (count($siblingIds) > 0) {
                 $processIds = array_unique(array_merge($processIds, $siblingIds));
             }
             $this->_copyRelationIndexData(array_keys($parentIds), $productId);
             $this->_prepareTierPriceIndex($processIds);
             $this->_prepareGroupPriceIndex($processIds);
             $indexer->reindexEntity($productId);
             $parentByType = array();
             foreach ($parentIds as $parentId => $parentType) {
                 $parentByType[$parentType][$parentId] = $parentId;
             }
             foreach ($parentByType as $parentType => $entityIds) {
                 $this->_getIndexer($parentType)->reindexEntity($entityIds);
             }
         } else {
             $this->_prepareTierPriceIndex($productId);
             $this->_prepareGroupPriceIndex($productId);
             $indexer->reindexEntity($productId);
         }
     }
     $this->_copyIndexDataToMainTable($processIds);
     return $this;
 }
 /**
  * Process product save.
  * Method is responsible for index support when product was saved.
  *
  * @param Mage_Index_Model_Event $event
  * @return Mage_Tag_Model_Resource_Indexer_Summary
  */
 public function catalogProductSave(Mage_Index_Model_Event $event)
 {
     $data = $event->getNewData();
     if (empty($data['tag_reindex_required'])) {
         return $this;
     }
     $tagIds = Mage::getModel('tag/tag_relation')->setProductId($event->getEntityPk())->getRelatedTagIds();
     return $this->aggregate($tagIds);
 }
Exemple #3
0
 /**
  * Process product save.
  * Method is responsible for index support
  * when product was saved and changed attribute(s) has an effect on price.
  *
  * @param   Mage_Index_Model_Event $event
  * @return  Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Price
  */
 public function catalogProductSave(Mage_Index_Model_Event $event)
 {
     $productId = $event->getEntityPk();
     $data = $event->getNewData();
     /**
      * Check if price attribute values were updated
      */
     if (!isset($data['reindex_price'])) {
         return $this;
     }
     $this->clearTemporaryIndexTable();
     $this->_prepareWebsiteDateTable();
     $indexer = $this->_getIndexer($data['product_type_id']);
     $processIds = array($productId);
     if ($indexer->getIsComposite()) {
         $this->_copyRelationIndexData($productId);
         $this->_prepareTierPriceIndex($productId);
         $indexer->reindexEntity($productId);
     } else {
         $parentIds = $this->getProductParentsByChild($productId);
         if ($parentIds) {
             $processIds = array_merge($processIds, array_keys($parentIds));
             $this->_copyRelationIndexData(array_keys($parentIds), $productId);
             $this->_prepareTierPriceIndex($processIds);
             $indexer->reindexEntity($productId);
             $parentByType = array();
             foreach ($parentIds as $parentId => $parentType) {
                 $parentByType[$parentType][$parentId] = $parentId;
             }
             foreach ($parentByType as $parentType => $entityIds) {
                 $this->_getIndexer($parentType)->reindexEntity($entityIds);
             }
         } else {
             $this->_prepareTierPriceIndex($productId);
             $indexer->reindexEntity($productId);
         }
     }
     $this->_copyIndexDataToMainTable($processIds);
     return $this;
 }
Exemple #4
0
 /**
  * Process Catalog Eav Attribute Save
  *
  * @param Mage_Index_Model_Event $event
  * @return Mage_Catalog_Model_Resource_Product_Indexer_Eav
  */
 public function catalogEavAttributeSave(Mage_Index_Model_Event $event)
 {
     $data = $event->getNewData();
     if (empty($data['reindex_attribute'])) {
         return $this;
     }
     $indexer = $this->getIndexer($data['attribute_index_type']);
     $indexer->reindexAttribute($event->getEntityPk(), !empty($data['is_indexable']));
     return $this;
 }
Exemple #5
0
 /**
  * Process category index after category save
  *
  * @param Mage_Index_Model_Event $event
  */
 public function catalogCategorySave(Mage_Index_Model_Event $event)
 {
     $data = $event->getNewData();
     $checkRootCategories = false;
     $processRootCategories = false;
     $affectedRootCategoryIds = array();
     $rootCategories = $this->_getRootCategories();
     /**
      * Check if we have reindex category move results
      */
     if (isset($data['affected_category_ids'])) {
         $categoryIds = $data['affected_category_ids'];
         $checkRootCategories = true;
     } else {
         if (isset($data['products_was_changed'])) {
             $categoryIds = array($event->getEntityPk());
             if (isset($rootCategories[$event->getEntityPk()])) {
                 $processRootCategories = true;
                 $affectedRootCategoryIds[] = $event->getEntityPk();
             }
         } else {
             return;
         }
     }
     $select = $this->_getWriteAdapter()->select()->from($this->_categoryTable, 'path')->where('entity_id IN (?)', $categoryIds);
     $paths = $this->_getWriteAdapter()->fetchCol($select);
     $allCategoryIds = array();
     foreach ($paths as $path) {
         if ($checkRootCategories) {
             foreach ($rootCategories as $rootCategoryId => $rootCategoryPath) {
                 if (strpos($path, sprintf('%d/', $rootCategoryPath)) === 0 || $path == $rootCategoryPath) {
                     $affectedRootCategoryIds[$rootCategoryId] = $rootCategoryId;
                 }
             }
         }
         $allCategoryIds = array_merge($allCategoryIds, explode('/', $path));
     }
     $allCategoryIds = array_unique($allCategoryIds);
     if ($checkRootCategories && count($affectedRootCategoryIds) > 1) {
         $processRootCategories = true;
     }
     /**
      * retrieve anchor category id
      */
     $anchorInfo = $this->_getAnchorAttributeInfo();
     $bind = array('attribute_id' => $anchorInfo['id'], 'store_id' => Mage_Catalog_Model_Abstract::DEFAULT_STORE_ID, 'e_value' => 1);
     $select = $this->_getReadAdapter()->select()->distinct(true)->from(array('ce' => $this->_categoryTable), array('entity_id'))->joinInner(array('dca' => $anchorInfo['table']), "dca.entity_id=ce.entity_id AND dca.attribute_id=:attribute_id AND dca.store_id=:store_id", array())->where('dca.value=:e_value')->where('ce.entity_id IN (?)', $allCategoryIds);
     $anchorIds = $this->_getWriteAdapter()->fetchCol($select, $bind);
     /**
      * delete only anchor id and category ids
      */
     $deleteCategoryIds = array_merge($anchorIds, $categoryIds);
     $this->_getWriteAdapter()->delete($this->getMainTable(), $this->_getWriteAdapter()->quoteInto('category_id IN(?)', $deleteCategoryIds));
     $directIds = array_diff($categoryIds, $anchorIds);
     if ($anchorIds) {
         $this->_refreshAnchorRelations($anchorIds);
     }
     if ($directIds) {
         $this->_refreshDirectRelations($directIds);
     }
     /**
      * Need to re-index affected root category ids when its are not anchor
      */
     if ($processRootCategories) {
         $reindexRootCategoryIds = array_diff($affectedRootCategoryIds, $anchorIds);
         if ($reindexRootCategoryIds) {
             $this->_refreshNotAnchorRootCategories($reindexRootCategoryIds);
         }
     }
 }
Exemple #6
0
 protected function _registerTag(Mage_Index_Model_Event $event)
 {
     if ($event->getType() == Mage_Index_Model_Event::TYPE_SAVE) {
         $event->addNewData('tag_reindex_tag_id', $event->getEntityPk());
     }
 }
Exemple #7
0
 /**
  * Process category index after category save
  *
  * @param Mage_Index_Model_Event $event
  */
 public function catalogCategorySave(Mage_Index_Model_Event $event)
 {
     $data = $event->getNewData();
     /**
      * Check if we have reindex category move results
      */
     if (isset($data['affected_category_ids'])) {
         $categoryIds = $event->getNewData('affected_category_ids');
     } else {
         if (isset($data['products_was_changed'])) {
             $categoryIds = array($event->getEntityPk());
         } else {
             return;
         }
     }
     $select = $this->_getWriteAdapter()->select()->from($this->_categoryTable, 'path')->where('entity_id IN (?)', $categoryIds);
     $paths = $this->_getWriteAdapter()->fetchCol($select);
     $allCategoryIds = array();
     foreach ($paths as $path) {
         $allCategoryIds = array_merge($allCategoryIds, explode('/', $path));
     }
     $allCategoryIds = array_unique($allCategoryIds);
     /**
      * retrieve anchor category id
      */
     $anchorInfo = $this->_getAnchorAttributeInfo();
     $select = $this->_getReadAdapter()->select()->distinct(true)->from(array('ce' => $this->_categoryTable), array('entity_id'))->joinInner(array('dca' => $anchorInfo['table']), "dca.entity_id=ce.entity_id AND dca.attribute_id={$anchorInfo['id']} AND dca.store_id=0", array())->where('dca.value=1')->where('ce.entity_id IN (?)', $allCategoryIds);
     $anchorIds = $this->_getWriteAdapter()->fetchCol($select);
     /**
      * delete only anchor id and category ids
      */
     $deleteCategoryIds = array_merge($anchorIds, $categoryIds);
     $this->_getWriteAdapter()->delete($this->getMainTable(), $this->_getWriteAdapter()->quoteInto('category_id IN(?)', $deleteCategoryIds));
     $anchorIds = array_diff($anchorIds, $categoryIds);
     $this->_refreshAnchorRelations($anchorIds);
     $this->_refreshDirectRelations($categoryIds);
 }
    public function catalogProductSave(Mage_Index_Model_Event $event)
    {
        $productId = $event->getEntityPk();
        $data = $event->getNewData();

        /**
         * Check if price attribute values were updated
         */
        if (!isset($data['reindex_price'])) {
            return $this;
        }
        //$this->cloneIndexTable(true);
        $this->clearTemporaryIndexTable(); // OM - 2012-03-16 - Added this function and commented above to fix an integrity violation
        $this->_prepareWebsiteDateTable();
        

        $indexer = $this->_getIndexer($data['product_type_id']);
        $processIds = array($productId);

        if ($indexer->getIsComposite()) {
            #Mage::log("catalogProductSave: " . "saving composite");
            if ($this->getProductTypeById($productId) == 'configurable') {
                #Mage::log("catalogProductSave: " . "saving composite - is configurable");
                $children = $this->getChildIdsByParent($productId);
                $processIds = array_merge($processIds, array_keys($children));
                #Ignore tier price data for actual configurable product
                $tierPriceIds = array_keys($children);
            } else {
                $tierPriceIds = $productId;
            }
            #Mage::log("catalogProductSave: " . "copyRelationIndexData for: " . $productId);
            $this->_copyRelationIndexData($productId);
            #Mage::log("catalogProductSave: " . "_prepareTierPriceIndex for: " . print_r($tierPriceIds, true));
            $this->_prepareTierPriceIndex($tierPriceIds);
            #Mage::log("catalogProductSave: " . "reindexEntity for: " . $productId);
            $indexer->reindexEntity($productId);
        } else {
            #Mage::log("catalogProductSave: " . "saving non-composite");
            $parentIds = $this->getProductParentsByChild($productId);

            if ($parentIds) {
                #Mage::log("catalogProductSave: " . "non-composite product: " . $productId . " has parents: " . print_r($parentIds, true));

                #Prepare to process parents too
                $processIds = array_merge($processIds, array_keys($parentIds));

                $siblingIds = array();
                foreach (array_keys($parentIds) as $parentId) {
                    $childIds = $this->getChildIdsByParent($parentId);
                    #Mage::log("catalogProductSave: For parent_id: $parentId, adding childIds of: " . print_r($childIds, true));
                    $siblingIds = array_merge($siblingIds, array_keys($childIds));
                }
                #Mage::log("catalogProductSave: siblingIds are: " . print_r($siblingIds, true));
                if(count($siblingIds)>0) {
                    $processIds = array_unique(array_merge($processIds, $siblingIds));
                }
                #Mage::log("catalogProductSave: " . "copyRelationIndexData for: " . print_r(array_keys($parentIds), true) . "ignoring relation: " . $productId);
                $this->_copyRelationIndexData(array_keys($parentIds), $productId);

                #Mage::log("catalogProductSave: " . "_prepareTierPriceIndex for: " . print_r($processIds, true));
                $this->_prepareTierPriceIndex($processIds);
                #Mage::log("catalogProductSave: " . "reindexEntity for: " . $productId);
                $indexer->reindexEntity($productId);

                $parentByType = array();
                foreach ($parentIds as $parentId => $parentType) {
                    $parentByType[$parentType][$parentId] = $parentId;
                }

                foreach ($parentByType as $parentType => $entityIds) {
                    #Mage::log("catalogProductSave: " . "reindexEntity using indexer of type: " . $parentType . " for: " . print_r($entityIds, true));
                    $this->_getIndexer($parentType)->reindexEntity($entityIds);
                }

            } else {
                #Mage::log("catalogProductSave: " . "non-composite product: " . $productId . " has no parents");
                $this->_prepareTierPriceIndex($productId);
                $indexer->reindexEntity($productId);
            }
        }
       
        $this->_copyIndexDataToMainTable($processIds);
        return $this;
    }