Overview

Packages

  • currencysymbol
  • MAbout
  • Mage
    • Admin
    • Adminhtml
    • AdminNotification
    • Api
    • Api2
    • Authorizenet
    • Backup
    • Bundle
    • Captcha
    • Catalog
    • CatalogIndex
    • CatalogInventory
    • CatalogRule
    • CatalogSearch
    • Centinel
    • Checkout
    • Cms
    • Compiler
    • Connect
    • Contacts
    • Core
    • Cron
    • CurrencySymbol
    • Customer
    • Dataflow
    • Directory
    • DirtectPost
    • Downloadable
    • Eav
    • GiftMessage
    • GoogleAnalytics
    • GoogleBase
    • GoogleCheckout
    • ImportExport
    • Index
    • Install
    • Log
    • Media
    • Newsletter
    • Oauth
    • Page
    • PageCache
    • Paygate
    • Payment
    • Paypal
    • PaypalUk
    • Persistent
    • Poll
    • ProductAlert
    • Rating
    • Reports
    • Review
    • Rss
    • Rule
    • Sales
    • SalesRule
    • Sedfriend
    • Sendfriend
    • Shipping
    • Sitemap
    • Tag
    • Tax
    • Usa
    • Weee
    • Widget
    • Wishlist
    • XmlConnect
  • None
  • Phoenix
    • Moneybookers
  • PHP
  • Zend
    • Date
    • Mime
    • XmlRpc

Classes

  • Mage_CatalogIndex_Model_Aggregation
  • Mage_CatalogIndex_Model_Attribute
  • Mage_CatalogIndex_Model_Catalog_Index_Flag
  • Mage_CatalogIndex_Model_Catalog_Index_Kill_Flag
  • Mage_CatalogIndex_Model_Data_Abstract
  • Mage_CatalogIndex_Model_Data_Configurable
  • Mage_CatalogIndex_Model_Data_Grouped
  • Mage_CatalogIndex_Model_Data_Simple
  • Mage_CatalogIndex_Model_Data_Virtual
  • Mage_CatalogIndex_Model_Indexer
  • Mage_CatalogIndex_Model_Indexer_Abstract
  • Mage_CatalogIndex_Model_Indexer_Eav
  • Mage_CatalogIndex_Model_Indexer_Minimalprice
  • Mage_CatalogIndex_Model_Indexer_Price
  • Mage_CatalogIndex_Model_Indexer_Tierprice
  • Mage_CatalogIndex_Model_Mysql4_Abstract
  • Mage_CatalogIndex_Model_Mysql4_Aggregation
  • Mage_CatalogIndex_Model_Mysql4_Attribute
  • Mage_CatalogIndex_Model_Mysql4_Data_Abstract
  • Mage_CatalogIndex_Model_Mysql4_Data_Configurable
  • Mage_CatalogIndex_Model_Mysql4_Data_Grouped
  • Mage_CatalogIndex_Model_Mysql4_Indexer
  • Mage_CatalogIndex_Model_Mysql4_Indexer_Abstract
  • Mage_CatalogIndex_Model_Mysql4_Indexer_Eav
  • Mage_CatalogIndex_Model_Mysql4_Indexer_Minimalprice
  • Mage_CatalogIndex_Model_Mysql4_Indexer_Price
  • Mage_CatalogIndex_Model_Mysql4_Price
  • Mage_CatalogIndex_Model_Mysql4_Retreiver
  • Mage_CatalogIndex_Model_Mysql4_Setup
  • Mage_CatalogIndex_Model_Observer
  • Mage_CatalogIndex_Model_Price
  • Mage_CatalogIndex_Model_Resource_Abstract
  • Mage_CatalogIndex_Model_Resource_Aggregation
  • Mage_CatalogIndex_Model_Resource_Attribute
  • Mage_CatalogIndex_Model_Resource_Data_Abstract
  • Mage_CatalogIndex_Model_Resource_Data_Configurable
  • Mage_CatalogIndex_Model_Resource_Data_Grouped
  • Mage_CatalogIndex_Model_Resource_Indexer
  • Mage_CatalogIndex_Model_Resource_Indexer_Abstract
  • Mage_CatalogIndex_Model_Resource_Indexer_Eav
  • Mage_CatalogIndex_Model_Resource_Indexer_Minimalprice
  • Mage_CatalogIndex_Model_Resource_Indexer_Price
  • Mage_CatalogIndex_Model_Resource_Price
  • Mage_CatalogIndex_Model_Resource_Retreiver
  • Mage_CatalogIndex_Model_Resource_Setup
  • Mage_CatalogIndex_Model_Retreiver

Interfaces

  • Mage_CatalogIndex_Model_Indexer_Interface
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Magento
  4:  *
  5:  * NOTICE OF LICENSE
  6:  *
  7:  * This source file is subject to the Open Software License (OSL 3.0)
  8:  * that is bundled with this package in the file LICENSE.txt.
  9:  * It is also available through the world-wide-web at this URL:
 10:  * http://opensource.org/licenses/osl-3.0.php
 11:  * If you did not receive a copy of the license and are unable to
 12:  * obtain it through the world-wide-web, please send an email
 13:  * to license@magentocommerce.com so we can send you a copy immediately.
 14:  *
 15:  * DISCLAIMER
 16:  *
 17:  * Do not edit or add to this file if you wish to upgrade Magento to newer
 18:  * versions in the future. If you wish to customize Magento for your
 19:  * needs please refer to http://www.magentocommerce.com for more information.
 20:  *
 21:  * @category    Mage
 22:  * @package     Mage_CatalogIndex
 23:  * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
 24:  * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 25:  */
 26: 
 27: 
 28: /**
 29:  * Price index resource model
 30:  *
 31:  * @category    Mage
 32:  * @package     Mage_CatalogIndex
 33:  * @author      Magento Core Team <core@magentocommerce.com>
 34:  */
 35: class Mage_CatalogIndex_Model_Resource_Price extends Mage_CatalogIndex_Model_Resource_Abstract
 36: {
 37:     /**
 38:      * Enter description here ...
 39:      *
 40:      * @var unknown
 41:      */
 42:     protected $_rate               = 1;
 43: 
 44:     /**
 45:      * Enter description here ...
 46:      *
 47:      * @var unknown
 48:      */
 49:     protected $_customerGroupId;
 50: 
 51:     /**
 52:      * Enter description here ...
 53:      *
 54:      * @var unknown
 55:      */
 56:     protected $_taxRates           = null;
 57: 
 58:     /**
 59:      * Enter description here ...
 60:      *
 61:      */
 62:     protected function _construct()
 63:     {
 64:         $this->_init('catalogindex/price', 'index_id');
 65:     }
 66: 
 67:     /**
 68:      * Enter description here ...
 69:      *
 70:      * @param unknown_type $rate
 71:      */
 72:     public function setRate($rate)
 73:     {
 74:         $this->_rate = $rate;
 75:     }
 76: 
 77:     /**
 78:      * Enter description here ...
 79:      *
 80:      * @return unknown
 81:      */
 82:     public function getRate()
 83:     {
 84:         if (!$this->_rate) {
 85:             $this->_rate = 1;
 86:         }
 87:         return $this->_rate;
 88:     }
 89: 
 90:     /**
 91:      * Enter description here ...
 92:      *
 93:      * @param unknown_type $customerGroupId
 94:      */
 95:     public function setCustomerGroupId($customerGroupId)
 96:     {
 97:         $this->_customerGroupId = $customerGroupId;
 98:     }
 99: 
100:     /**
101:      * Enter description here ...
102:      *
103:      * @return unknown
104:      */
105:     public function getCustomerGroupId()
106:     {
107:         return $this->_customerGroupId;
108:     }
109: 
110:     /**
111:      * Enter description here ...
112:      *
113:      * @param unknown_type $attribute
114:      * @param unknown_type $entitySelect
115:      * @return unknown
116:      */
117:     public function getMaxValue($attribute, $entitySelect)
118:     {
119:         $select = clone $entitySelect;
120:         $select->reset(Zend_Db_Select::COLUMNS);
121:         $select->reset(Zend_Db_Select::ORDER);
122:         $select->reset(Zend_Db_Select::LIMIT_COUNT);
123:         $select->reset(Zend_Db_Select::LIMIT_OFFSET);
124: 
125:         $response = new Varien_Object();
126:         $response->setAdditionalCalculations(array());
127: 
128:         $select->join(array('price_table'=>$this->getMainTable()), 'price_table.entity_id=e.entity_id', array());
129: 
130:         if ($attribute->getAttributeCode() == 'price') {
131:             $select->where('price_table.customer_group_id = ?', $this->getCustomerGroupId());
132:             $args = array(
133:                 'select'=>$select,
134:                 'table'=>'price_table',
135:                 'store_id'=>$this->getStoreId(),
136:                 'response_object'=>$response,
137:             );
138:             Mage::dispatchEvent('catalogindex_prepare_price_select', $args);
139:         }
140: 
141:         $select
142:             ->columns("MAX(price_table.value".implode('', $response->getAdditionalCalculations()).")")
143:             ->where('price_table.website_id = ?', $this->getWebsiteId())
144:             ->where('price_table.attribute_id = ?', $attribute->getId());
145: 
146:         return $this->_getReadAdapter()->fetchOne($select)*$this->getRate();
147:     }
148: 
149:     /**
150:      * Enter description here ...
151:      *
152:      * @param unknown_type $range
153:      * @param unknown_type $attribute
154:      * @param unknown_type $entitySelect
155:      * @return unknown
156:      */
157:     public function getCount($range, $attribute, $entitySelect)
158:     {
159:         $select = clone $entitySelect;
160:         $select->reset(Zend_Db_Select::COLUMNS);
161:         $select->reset(Zend_Db_Select::ORDER);
162:         $select->reset(Zend_Db_Select::LIMIT_COUNT);
163:         $select->reset(Zend_Db_Select::LIMIT_OFFSET);
164: 
165:         $select->join(array('price_table'=>$this->getMainTable()), 'price_table.entity_id=e.entity_id', array());
166:         $response = new Varien_Object();
167:         $response->setAdditionalCalculations(array());
168: 
169:         if ($attribute->getAttributeCode() == 'price') {
170:             $select->where('price_table.customer_group_id = ?', $this->getCustomerGroupId());
171:             $args = array(
172:                 'select'=>$select,
173:                 'table'=>'price_table',
174:                 'store_id'=>$this->getStoreId(),
175:                 'response_object'=>$response,
176:             );
177:             Mage::dispatchEvent('catalogindex_prepare_price_select', $args);
178:         }
179: 
180: 
181:         $fields = array('count'=>'COUNT(DISTINCT price_table.entity_id)', 'range'=>"FLOOR(((price_table.value".implode('', $response->getAdditionalCalculations()).")*{$this->getRate()})/{$range})+1");
182: 
183:         $select->columns($fields)
184:             ->group('range')
185:             ->where('price_table.website_id = ?', $this->getWebsiteId())
186:             ->where('price_table.attribute_id = ?', $attribute->getId());
187: 
188: 
189:         $result = $this->_getReadAdapter()->fetchAll($select);
190: 
191:         $counts = array();
192:         foreach ($result as $row) {
193:             $counts[$row['range']] = $row['count'];
194:         }
195: 
196:         return $counts;
197:     }
198: 
199:     /**
200:      * Enter description here ...
201:      *
202:      * @param unknown_type $range
203:      * @param unknown_type $index
204:      * @param unknown_type $attribute
205:      * @param unknown_type $entityIdsFilter
206:      * @param unknown_type $tableName
207:      * @return unknown
208:      */
209:     public function getFilteredEntities($range, $index, $attribute, $entityIdsFilter, $tableName = 'price_table')
210:     {
211:         $select = $this->_getReadAdapter()->select();
212:         $select->from(array($tableName=>$this->getMainTable()), $tableName . '.entity_id');
213: 
214:         $response = new Varien_Object();
215:         $response->setAdditionalCalculations(array());
216: 
217:         $select
218:             ->distinct(true)
219:             ->where($tableName . '.entity_id in (?)', $entityIdsFilter)
220:             ->where($tableName . '.website_id = ?', $this->getWebsiteId())
221:             ->where($tableName . '.attribute_id = ?', $attribute->getId());
222: 
223:         if ($attribute->getAttributeCode() == 'price') {
224:             $select->where($tableName . '.customer_group_id = ?', $this->getCustomerGroupId());
225:             $args = array(
226:                 'select'=>$select,
227:                 'table'=>$tableName,
228:                 'store_id'=>$this->getStoreId(),
229:                 'response_object'=>$response,
230:             );
231:             Mage::dispatchEvent('catalogindex_prepare_price_select', $args);
232:         }
233: 
234:         $select->where("(({$tableName}.value".implode('', $response->getAdditionalCalculations()).")*{$this->getRate()}) >= ?", ($index-1)*$range);
235:         $select->where("(({$tableName}.value".implode('', $response->getAdditionalCalculations()).")*{$this->getRate()}) < ?", $index*$range);
236: 
237: 
238:         return $this->_getReadAdapter()->fetchCol($select);
239:     }
240: 
241:     /**
242:      * Enter description here ...
243:      *
244:      * @param unknown_type $collection
245:      * @param unknown_type $attribute
246:      * @param unknown_type $range
247:      * @param unknown_type $index
248:      * @param unknown_type $tableName
249:      * @return Mage_CatalogIndex_Model_Resource_Price
250:      */
251:     public function applyFilterToCollection($collection, $attribute, $range, $index, $tableName = 'price_table')
252:     {
253:         /**
254:          * Distinct required for removing duplicates in case when we have grouped products
255:          * which contain multiple rows for one product id
256:          */
257:         $collection->getSelect()->distinct(true);
258:         $tableName = $tableName.'_'.$attribute->getAttributeCode();
259:         $collection->getSelect()->joinLeft(
260:             array($tableName => $this->getMainTable()),
261:             $tableName .'.entity_id=e.entity_id',
262:             array()
263:         );
264: 
265:         $response = new Varien_Object();
266:         $response->setAdditionalCalculations(array());
267: 
268:         $collection->getSelect()
269:             ->where($tableName . '.website_id = ?', $this->getWebsiteId())
270:             ->where($tableName . '.attribute_id = ?', $attribute->getId());
271: 
272:         if ($attribute->getAttributeCode() == 'price') {
273:             $collection->getSelect()->where($tableName . '.customer_group_id = ?', $this->getCustomerGroupId());
274:             $args = array(
275:                 'select'=>$collection->getSelect(),
276:                 'table'=>$tableName,
277:                 'store_id'=>$this->getStoreId(),
278:                 'response_object'=>$response,
279:             );
280: 
281:             Mage::dispatchEvent('catalogindex_prepare_price_select', $args);
282:         }
283: 
284:         $collection->getSelect()->where("(({$tableName}.value".implode('', $response->getAdditionalCalculations()).")*{$this->getRate()}) >= ?", ($index-1)*$range);
285:         $collection->getSelect()->where("(({$tableName}.value".implode('', $response->getAdditionalCalculations()).")*{$this->getRate()}) < ?", $index*$range);
286: 
287:         return $this;
288:     }
289: 
290:     /**
291:      * Enter description here ...
292:      *
293:      * @param unknown_type $ids
294:      * @return unknown
295:      */
296:     public function getMinimalPrices($ids)
297:     {
298:         if (!$ids) {
299:             return array();
300:         }
301:         $select = $this->_getReadAdapter()->select();
302:         $select->from(array('price_table'=>$this->getTable('catalogindex/minimal_price')),
303:             array('price_table.entity_id', 'value'=>"(price_table.value)", 'tax_class_id'=>'(price_table.tax_class_id)'))
304:             ->where('price_table.entity_id in (?)', $ids)
305:             ->where('price_table.website_id = ?', $this->getWebsiteId())
306:             ->where('price_table.customer_group_id = ?', $this->getCustomerGroupId());
307:         return $this->_getReadAdapter()->fetchAll($select);
308:     }
309: }
310: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0