00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 abstract class Mage_CatalogIndex_Model_Indexer_Abstract
00034 extends Mage_Core_Model_Abstract
00035 implements Mage_CatalogIndex_Model_Indexer_Interface
00036 {
00037 protected $_processChildren = true;
00038 protected $_processChildrenForConfigurable = true;
00039 protected $_runOnce = false;
00040
00041 public function processAfterSave(Mage_Catalog_Model_Product $object, $forceId = null)
00042 {
00043 $associated = array();
00044 switch ($object->getTypeId()) {
00045 case Mage_Catalog_Model_Product_Type::TYPE_GROUPED:
00046 $associated = $object->getTypeInstance(true)->getAssociatedProducts($object);
00047 break;
00048
00049 case Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE:
00050 $associated = $object->getTypeInstance(true)->getUsedProducts(null, $object);
00051 break;
00052 }
00053
00054 if (!$this->_isObjectIndexable($object) && is_null($forceId)) {
00055 return;
00056 }
00057
00058 $data = array();
00059
00060 if ($this->_runOnce) {
00061 $data = $this->createIndexData($object);
00062 } else {
00063 $attributes = $object->getAttributes();
00064 foreach ($attributes as $attribute) {
00065 if ($this->_isAttributeIndexable($attribute) && $object->getData($attribute->getAttributeCode()) != null) {
00066 $row = $this->createIndexData($object, $attribute);
00067 if ($row && is_array($row)) {
00068 if (isset($row[0]) && is_array($row[0])) {
00069 $data = array_merge($data, $row);
00070 } else {
00071 $data[] = $row;
00072 }
00073 }
00074 }
00075 }
00076 }
00077 $function = 'saveIndex';
00078 if ($data && is_array($data)) {
00079 if (isset($data[0]) && is_array($data[0]))
00080 $function = 'saveIndices';
00081
00082 $this->$function($data, $object->getStoreId(), ($forceId != null ? $forceId : $object->getId()));
00083 }
00084
00085 if (!$this->_processChildrenForConfigurable && $object->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE)
00086 return;
00087
00088 if ($associated && $this->_processChildren) {
00089
00090 foreach ($associated as $child) {
00091 $child
00092 ->setStoreId($object->getStoreId())
00093 ->setWebsiteId($object->getWebsiteId());
00094 $this->processAfterSave($child, $object->getId());
00095 }
00096 }
00097 }
00098
00099 public function saveIndex($data, $storeId, $productId)
00100 {
00101 $this->_getResource()->saveIndex($data, $storeId, $productId);
00102 }
00103
00104 public function saveIndices(array $data, $storeId, $productId)
00105 {
00106 $this->_getResource()->saveIndices($data, $storeId, $productId);
00107 }
00108
00109 protected function _isObjectIndexable(Mage_Catalog_Model_Product $object)
00110 {
00111 if ($object->getStatus() != Mage_Catalog_Model_Product_Status::STATUS_ENABLED) {
00112 return false;
00113 }
00114
00115 if ($object->getVisibility() != Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_CATALOG &&
00116 $object->getVisibility() != Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH) {
00117 return false;
00118 }
00119
00120 return true;
00121 }
00122
00123 public function isAttributeIndexable(Mage_Eav_Model_Entity_Attribute_Abstract $attribute)
00124 {
00125 return $this->_isAttributeIndexable($attribute);
00126 }
00127
00128 protected function _isAttributeIndexable(Mage_Eav_Model_Entity_Attribute_Abstract $attribute)
00129 {
00130 return true;
00131 }
00132
00133 public function getIndexableAttributeCodes()
00134 {
00135 return $this->_getResource()->loadAttributeCodesByCondition($this->_getIndexableAttributeConditions());
00136 }
00137
00138 protected function _getIndexableAttributeConditions()
00139 {
00140 return array();
00141 }
00142
00143 public function cleanup($productId, $storeId = null)
00144 {
00145 $this->_getResource()->cleanup($productId, $storeId);
00146 }
00147
00148 public function isAttributeIdUsed()
00149 {
00150 return true;
00151 }
00152 }