Mage_CatalogIndex_Model_Mysql4_Price Class Reference

Inheritance diagram for Mage_CatalogIndex_Model_Mysql4_Price:

Mage_CatalogIndex_Model_Mysql4_Abstract Mage_Core_Model_Mysql4_Abstract Mage_Core_Model_Resource_Abstract

List of all members.

Public Member Functions

 setRate ($rate)
 getRate ()
 setCustomerGroupId ($customerGroupId)
 getCustomerGroupId ()
 getMaxValue ($attribute=null, $entitySelect)
 getCount ($range, $attribute, $entitySelect)
 getFilteredEntities ($range, $index, $attribute, $entityIdsFilter, $tableName= 'price_table')
 applyFilterToCollection ($collection, $attribute, $range, $index, $tableName= 'price_table')
 getMinimalPrices ($ids)

Protected Member Functions

 _construct ()

Protected Attributes

 $_rate = 1
 $_customerGroupId
 $_taxRates = null


Detailed Description

Price index resource model

Author:
Magento Core Team <core@magentocommerce.com>

Definition at line 33 of file Price.php.


Member Function Documentation

_construct (  )  [protected]

Resource initialization

Reimplemented from Mage_CatalogIndex_Model_Mysql4_Abstract.

Definition at line 39 of file Price.php.

00040     {
00041         $this->_init('catalogindex/price', 'index_id');
00042     }

applyFilterToCollection ( collection,
attribute,
range,
index,
tableName = 'price_table' 
)

Distinct required for removing duplicates in case when we have grouped products which contain multiple rows for one product id

Definition at line 173 of file Price.php.

00174     {
00175         /**
00176          * Distinct required for removing duplicates in case when we have grouped products
00177          * which contain multiple rows for one product id
00178          */
00179         $collection->getSelect()->distinct(true);
00180         $tableName = $tableName.'_'.$attribute->getAttributeCode();
00181         $collection->getSelect()->joinLeft(
00182             array($tableName => $this->getMainTable()),
00183             $tableName .'.entity_id=e.entity_id',
00184             array()
00185         );
00186 
00187         $response = new Varien_Object();
00188         $response->setAdditionalCalculations(array());
00189 
00190         $collection->getSelect()
00191             ->where($tableName . '.website_id = ?', $this->getWebsiteId())
00192             ->where($tableName . '.attribute_id = ?', $attribute->getId());
00193 
00194         if ($attribute->getAttributeCode() == 'price') {
00195             $collection->getSelect()->where($tableName . '.customer_group_id = ?', $this->getCustomerGroupId());
00196             $args = array(
00197                 'select'=>$collection->getSelect(),
00198                 'table'=>$tableName,
00199                 'store_id'=>$this->getStoreId(),
00200                 'response_object'=>$response,
00201             );
00202 
00203             Mage::dispatchEvent('catalogindex_prepare_price_select', $args);
00204         }
00205 
00206         $collection->getSelect()->where("(({$tableName}.value".implode('', $response->getAdditionalCalculations()).")*{$this->getRate()}) >= ?", ($index-1)*$range);
00207         $collection->getSelect()->where("(({$tableName}.value".implode('', $response->getAdditionalCalculations()).")*{$this->getRate()}) < ?", $index*$range);
00208 
00209         return $this;
00210     }

getCount ( range,
attribute,
entitySelect 
)

Definition at line 99 of file Price.php.

00100     {
00101         $select = clone $entitySelect;
00102         $select->reset(Zend_Db_Select::COLUMNS);
00103         $select->reset(Zend_Db_Select::ORDER);
00104         $select->reset(Zend_Db_Select::LIMIT_COUNT);
00105         $select->reset(Zend_Db_Select::LIMIT_OFFSET);
00106 
00107         $select->join(array('price_table'=>$this->getMainTable()), 'price_table.entity_id=e.entity_id', array());
00108         $response = new Varien_Object();
00109         $response->setAdditionalCalculations(array());
00110 
00111         if ($attribute->getAttributeCode() == 'price') {
00112             $select->where('price_table.customer_group_id = ?', $this->getCustomerGroupId());
00113             $args = array(
00114                 'select'=>$select,
00115                 'table'=>'price_table',
00116                 'store_id'=>$this->getStoreId(),
00117                 'response_object'=>$response,
00118             );
00119             Mage::dispatchEvent('catalogindex_prepare_price_select', $args);
00120         }
00121 
00122 
00123         $fields = array('count'=>'COUNT(DISTINCT price_table.entity_id)', 'range'=>"FLOOR(((price_table.value".implode('', $response->getAdditionalCalculations()).")*{$this->getRate()})/{$range})+1");
00124 
00125         $select->from('', $fields)
00126             ->group('range')
00127             ->where('price_table.website_id = ?', $this->getWebsiteId())
00128             ->where('price_table.attribute_id = ?', $attribute->getId());
00129 
00130 
00131         $result = $this->_getReadAdapter()->fetchAll($select);
00132 
00133         $counts = array();
00134         foreach ($result as $row) {
00135             $counts[$row['range']] = $row['count'];
00136         }
00137 
00138         return $counts;
00139     }

getCustomerGroupId (  ) 

Definition at line 62 of file Price.php.

00063     {
00064         return $this->_customerGroupId;
00065     }

getFilteredEntities ( range,
index,
attribute,
entityIdsFilter,
tableName = 'price_table' 
)

Definition at line 141 of file Price.php.

00142     {
00143         $select = $this->_getReadAdapter()->select();
00144         $select->from(array($tableName=>$this->getMainTable()), $tableName . '.entity_id');
00145 
00146         $response = new Varien_Object();
00147         $response->setAdditionalCalculations(array());
00148 
00149         $select
00150             ->distinct(true)
00151             ->where($tableName . '.entity_id in (?)', $entityIdsFilter)
00152             ->where($tableName . '.website_id = ?', $this->getWebsiteId())
00153             ->where($tableName . '.attribute_id = ?', $attribute->getId());
00154 
00155         if ($attribute->getAttributeCode() == 'price') {
00156             $select->where($tableName . '.customer_group_id = ?', $this->getCustomerGroupId());
00157             $args = array(
00158                 'select'=>$select,
00159                 'table'=>$tableName,
00160                 'store_id'=>$this->getStoreId(),
00161                 'response_object'=>$response,
00162             );
00163             Mage::dispatchEvent('catalogindex_prepare_price_select', $args);
00164         }
00165 
00166         $select->where("(({$tableName}.value".implode('', $response->getAdditionalCalculations()).")*{$this->getRate()}) >= ?", ($index-1)*$range);
00167         $select->where("(({$tableName}.value".implode('', $response->getAdditionalCalculations()).")*{$this->getRate()}) < ?", $index*$range);
00168 
00169 
00170         return $this->_getReadAdapter()->fetchCol($select);
00171     }

getMaxValue ( attribute = null,
entitySelect 
)

Definition at line 67 of file Price.php.

00068     {
00069         $select = clone $entitySelect;
00070         $select->reset(Zend_Db_Select::COLUMNS);
00071         $select->reset(Zend_Db_Select::ORDER);
00072         $select->reset(Zend_Db_Select::LIMIT_COUNT);
00073         $select->reset(Zend_Db_Select::LIMIT_OFFSET);
00074 
00075         $response = new Varien_Object();
00076         $response->setAdditionalCalculations(array());
00077 
00078         $select->join(array('price_table'=>$this->getMainTable()), 'price_table.entity_id=e.entity_id', array());
00079 
00080         if ($attribute->getAttributeCode() == 'price') {
00081             $select->where('price_table.customer_group_id = ?', $this->getCustomerGroupId());
00082             $args = array(
00083                 'select'=>$select,
00084                 'table'=>'price_table',
00085                 'store_id'=>$this->getStoreId(),
00086                 'response_object'=>$response,
00087             );
00088             Mage::dispatchEvent('catalogindex_prepare_price_select', $args);
00089         }
00090 
00091         $select
00092             ->from('', "MAX(price_table.value".implode('', $response->getAdditionalCalculations()).")")
00093             ->where('price_table.website_id = ?', $this->getWebsiteId())
00094             ->where('price_table.attribute_id = ?', $attribute->getId());
00095 
00096         return $this->_getReadAdapter()->fetchOne($select)*$this->getRate();
00097     }

getMinimalPrices ( ids  ) 

Definition at line 212 of file Price.php.

00213     {
00214         if (!$ids) {
00215             return array();
00216         }
00217         $select = $this->_getReadAdapter()->select();
00218         $select->from(array('price_table'=>$this->getTable('catalogindex/minimal_price')),
00219             array('price_table.entity_id', 'value'=>"(price_table.value)", 'tax_class_id'=>'(price_table.tax_class_id)'))
00220             ->where('price_table.entity_id in (?)', $ids)
00221             ->where('price_table.website_id = ?', $this->getWebsiteId())
00222             ->where('price_table.customer_group_id = ?', $this->getCustomerGroupId());
00223         return $this->_getReadAdapter()->fetchAll($select);
00224     }

getRate (  ) 

Definition at line 49 of file Price.php.

00050     {
00051         if (!$this->_rate) {
00052             $this->_rate = 1;
00053         }
00054         return $this->_rate;
00055     }

setCustomerGroupId ( customerGroupId  ) 

Definition at line 57 of file Price.php.

00058     {
00059         $this->_customerGroupId = $customerGroupId;
00060     }

setRate ( rate  ) 

Definition at line 44 of file Price.php.

00045     {
00046         $this->_rate = $rate;
00047     }


Member Data Documentation

$_customerGroupId [protected]

Definition at line 36 of file Price.php.

$_rate = 1 [protected]

Definition at line 35 of file Price.php.

$_taxRates = null [protected]

Definition at line 37 of file Price.php.


The documentation for this class was generated from the following file:

Generated on Sat Jul 4 17:23:47 2009 for Magento by  doxygen 1.5.8