00001 <?php 00002 /** 00003 * Magento 00004 * 00005 * NOTICE OF LICENSE 00006 * 00007 * This source file is subject to the Open Software License (OSL 3.0) 00008 * that is bundled with this package in the file LICENSE.txt. 00009 * It is also available through the world-wide-web at this URL: 00010 * http://opensource.org/licenses/osl-3.0.php 00011 * If you did not receive a copy of the license and are unable to 00012 * obtain it through the world-wide-web, please send an email 00013 * to license@magentocommerce.com so we can send you a copy immediately. 00014 * 00015 * DISCLAIMER 00016 * 00017 * Do not edit or add to this file if you wish to upgrade Magento to newer 00018 * versions in the future. If you wish to customize Magento for your 00019 * needs please refer to http://www.magentocommerce.com for more information. 00020 * 00021 * @category Mage 00022 * @package Mage_CatalogIndex 00023 * @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com) 00024 * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) 00025 */ 00026 00027 00028 /** 00029 * Catalog indexer price processor 00030 * 00031 * @author Magento Core Team <core@magentocommerce.com> 00032 */ 00033 class Mage_CatalogIndex_Model_Indexer_Minimalprice extends Mage_CatalogIndex_Model_Indexer_Abstract 00034 { 00035 protected $_customerGroups = array(); 00036 protected $_runOnce = true; 00037 protected $_processChildren = false; 00038 00039 protected function _construct() 00040 { 00041 $this->_init('catalogindex/indexer_minimalprice'); 00042 $this->_currencyModel = Mage::getModel('directory/currency'); 00043 $this->_customerGroups = Mage::getModel('customer/group')->getCollection(); 00044 00045 return parent::_construct(); 00046 } 00047 00048 public function getTierPriceAttribute() 00049 { 00050 $data = $this->getData('tier_price_attribute'); 00051 if (is_null($data)) { 00052 $data = Mage::getModel('eav/entity_attribute')->loadByCode('catalog_product', 'tier_price'); 00053 $this->setData('tier_price_attribute', $data); 00054 } 00055 return $data; 00056 } 00057 00058 public function getPriceAttribute() 00059 { 00060 $data = $this->getData('price_attribute'); 00061 if (is_null($data)) { 00062 $data = Mage::getModel('eav/entity_attribute')->loadByCode('catalog_product', 'price'); 00063 $this->setData('price_attribute', $data); 00064 } 00065 return $data; 00066 } 00067 00068 public function createIndexData(Mage_Catalog_Model_Product $object, Mage_Eav_Model_Entity_Attribute_Abstract $attribute = null) 00069 { 00070 $searchEntityId = $object->getId(); 00071 $priceAttributeId = $this->getTierPriceAttribute()->getId(); 00072 if ($object->isGrouped()) { 00073 $priceAttributeId = $this->getPriceAttribute()->getId(); 00074 $associated = $object->getTypeInstance(true)->getAssociatedProducts($object); 00075 $searchEntityId = array(); 00076 00077 foreach ($associated as $product) { 00078 $searchEntityId[] = $product->getId(); 00079 } 00080 } 00081 00082 if (!count($searchEntityId)) { 00083 return false; 00084 } 00085 00086 $result = array(); 00087 $data = array(); 00088 00089 $data['store_id'] = $object->getStoreId(); 00090 $data['entity_id'] = $object->getId(); 00091 00092 $search['store_id'] = $object->getStoreId(); 00093 $search['entity_id'] = $searchEntityId; 00094 $search['attribute_id'] = $priceAttributeId; 00095 00096 foreach ($this->_customerGroups as $group) { 00097 $search['customer_group_id'] = $group->getId(); 00098 $data['customer_group_id'] = $group->getId(); 00099 00100 $value = $this->_getResource()->getMinimalValue($search); 00101 if (is_null($value)) 00102 continue; 00103 $data['value'] = $value; 00104 $result[] = $data; 00105 } 00106 00107 return $result; 00108 } 00109 00110 public function isAttributeIdUsed() 00111 { 00112 return false; 00113 } 00114 00115 protected function _isAttributeIndexable(Mage_Eav_Model_Entity_Attribute_Abstract $attribute) 00116 { 00117 if ($attribute->getAttributeCode() != 'minimal_price') 00118 return false; 00119 00120 return true; 00121 } 00122 }