Public Member Functions | |
getAttributeData ($products, $attributes, $store) | |
fetchLinkInformation ($store, $table, $idField, $whereField, $id, $additionalWheres=array()) | |
getMinimalPrice ($products, $priceAttributes, $store) | |
getTierPrices ($products, $website) | |
Protected Member Functions | |
_setLinkSelect ($select) | |
_getLinkSelect () | |
_construct () | |
_prepareLinkFetchSelect ($store, $table, $idField, $whereField, $id, $additionalWheres=array()) | |
_addAttributeFilter (Varien_Db_Select $select, $attributeCode, $table, $field, $store, $value) | |
Protected Attributes | |
$_attributeCodeIds = array() | |
$_linkSelect = null |
Definition at line 27 of file Abstract.php.
_addAttributeFilter | ( | Varien_Db_Select $ | select, | |
$ | attributeCode, | |||
$ | table, | |||
$ | field, | |||
$ | store, | |||
$ | value | |||
) | [protected] |
Add attribute filter to select
Varien_Db_Select | $select | |
string | $attributeCode | |
string | $table the main table name or alias | |
string | $field entity_id field name | |
int | $store | |
int|string|array | $value the filter value |
Definition at line 231 of file Abstract.php.
00232 { 00233 $adapter = $this->_getReadAdapter(); 00234 $attribute = Mage::getSingleton('eav/config') 00235 ->getAttribute('catalog_product', $attributeCode); 00236 /* @var $attribute Mage_Catalog_Model_Resource_Eav_Attribute */ 00237 $attributeTable = $attribute->getBackend()->getTable(); 00238 if ($attribute->getBackendType() == 'static') { 00239 $tableAlias = sprintf('t_%s', $attribute->getAttributeCode()); 00240 $joinCond = join(' AND ', array( 00241 sprintf('`%s`.`%s`=`%s`.`entity_id`', $table, $field, $tableAlias) 00242 )); 00243 $select 00244 ->join( 00245 array($tableAlias => $attributeTable), 00246 $joinCond, 00247 array()) 00248 ->where(sprintf('%s.%s IN(?)', $tableAlias, $attribute->getAttributeCode()), $value); 00249 } 00250 elseif ($attribute->isScopeGlobal()) { 00251 $tableAlias = sprintf('t_%s', $attribute->getAttributeCode()); 00252 $joinCond = join(' AND ', array( 00253 sprintf('`%s`.`%s`=`%s`.`entity_id`', $table, $field, $tableAlias), 00254 $adapter->quoteInto(sprintf('`%s`.`attribute_id`=?', $tableAlias), $attribute->getAttributeId()), 00255 $adapter->quoteInto(sprintf('`%s`.`store_id`=?', $tableAlias), 0) 00256 )); 00257 $select 00258 ->join( 00259 array($tableAlias => $attributeTable), 00260 $joinCond, 00261 array()) 00262 ->where(sprintf('%s.value IN(?)', $tableAlias), $value); 00263 } 00264 else { 00265 $tableGlobal = sprintf('t_global_%s', $attribute->getAttributeCode()); 00266 $tableStore = sprintf('t_store_%s', $attribute->getAttributeCode()); 00267 $joinCondGlobal = join(' AND ', array( 00268 sprintf('`%s`.`%s`=`%s`.`entity_id`', $table, $field, $tableGlobal), 00269 $adapter->quoteInto(sprintf('`%s`.`attribute_id`=?', $tableGlobal), $attribute->getAttributeId()), 00270 $adapter->quoteInto(sprintf('`%s`.`store_id`=?', $tableGlobal), 0) 00271 )); 00272 $joinCondStore = join(' AND ', array( 00273 sprintf('`%s`.`entity_id`=`%s`.`entity_id`', $tableGlobal, $tableStore), 00274 sprintf('`%s`.`attribute_id`=`%s`.`attribute_id`', $tableGlobal, $tableStore), 00275 $adapter->quoteInto(sprintf('`%s`.`store_id`=?', $tableStore), $store) 00276 )); 00277 $whereCond = sprintf('IFNULL(`%s`.`value`, `%s`.`value`) IN(?)', $tableStore, $tableGlobal); 00278 00279 $select 00280 ->join( 00281 array($tableGlobal => $attributeTable), 00282 $joinCondGlobal, 00283 array()) 00284 ->joinLeft( 00285 array($tableStore => $attributeTable), 00286 $joinCondStore, 00287 array()) 00288 ->where($whereCond, $value); 00289 } 00290 00291 return $this; 00292 }
_construct | ( | ) | [protected] |
Resource initialization
Reimplemented from Mage_Core_Model_Resource_Abstract.
Definition at line 64 of file Abstract.php.
00065 { 00066 $this->_init('catalog/product', 'entity_id'); 00067 }
_getLinkSelect | ( | ) | [protected] |
_prepareLinkFetchSelect | ( | $ | store, | |
$ | table, | |||
$ | idField, | |||
$ | whereField, | |||
$ | id, | |||
$ | additionalWheres = array() | |||
) | [protected] |
Prepare select statement before 'fetchLinkInformation' function result fetch
int | $store | |
string | $table | |
string | $idField | |
string | $whereField | |
int | $id | |
array | $additionalWheres |
Reimplemented in Mage_CatalogIndex_Model_Mysql4_Data_Configurable, and Mage_CatalogIndex_Model_Mysql4_Data_Grouped.
Definition at line 159 of file Abstract.php.
_setLinkSelect | ( | $ | select | ) | [protected] |
Set link select
Zend_Db_Select | $select |
Definition at line 48 of file Abstract.php.
00049 { 00050 $this->_linkSelect = $select; 00051 return $this; 00052 }
fetchLinkInformation | ( | $ | store, | |
$ | table, | |||
$ | idField, | |||
$ | whereField, | |||
$ | id, | |||
$ | additionalWheres = array() | |||
) |
Returns an array of product children/parents
int | $store | |
string | $table | |
string | $idField | |
string | $whereField | |
int | $id | |
array | $additionalWheres |
Definition at line 116 of file Abstract.php.
00117 { 00118 $idsConditionSymbol = "= ?"; 00119 if (is_array($id)) { 00120 $idsConditionSymbol = "in (?)"; 00121 } 00122 00123 $select = $this->_getReadAdapter()->select(); 00124 $select->from(array('l'=>$this->getTable($table)), array("l.{$idField}")) 00125 ->where("l.{$whereField} {$idsConditionSymbol}", $id); 00126 foreach ($additionalWheres as $field=>$condition) { 00127 $select->where("l.$field = ?", $condition); 00128 } 00129 00130 // add status filter 00131 $this->_addAttributeFilter($select, 'status', 'l', $idField, $store, 00132 Mage_Catalog_Model_Product_Status::STATUS_ENABLED); 00133 // add website filter 00134 if ($websiteId = Mage::app()->getStore($store)->getWebsiteId()) { 00135 $select->join( 00136 array('w' => $this->getTable('catalog/product_website')), 00137 "l.{$idField}=w.product_id AND w.website_id={$websiteId}", 00138 array() 00139 ); 00140 } 00141 00142 $this->_setLinkSelect($select); 00143 $this->_prepareLinkFetchSelect($store, $table, $idField, $whereField, $id, $additionalWheres); 00144 00145 return $this->_getWriteAdapter()->fetchCol($this->_getLinkSelect()); 00146 }
getAttributeData | ( | $ | products, | |
$ | attributes, | |||
$ | store | |||
) |
Retreive specified attribute data for specified products from specified store
array | $products | |
array | $attributes | |
int | $store |
Definition at line 76 of file Abstract.php.
00077 { 00078 $suffixes = array('decimal', 'varchar', 'int', 'text', 'datetime'); 00079 if (!is_array($products)) { 00080 $products = new Zend_Db_Expr($products); 00081 } 00082 $result = array(); 00083 foreach ($suffixes as $suffix) { 00084 $tableName = "{$this->getTable('catalog/product')}_{$suffix}"; 00085 $condition = "product.entity_id = c.entity_id AND c.store_id = {$store} AND c.attribute_id = d.attribute_id"; 00086 $defaultCondition = "product.entity_id = d.entity_id AND d.store_id = 0"; 00087 $fields = array('entity_id', 'type_id', 'attribute_id'=>'IFNULL(c.attribute_id, d.attribute_id)', 'value'=>'IFNULL(c.value, d.value)'); 00088 00089 $select = $this->_getReadAdapter()->select() 00090 ->from(array('product'=>$this->getTable('catalog/product')), $fields) 00091 ->where('product.entity_id in (?)', $products) 00092 ->joinRight(array('d'=>$tableName), $defaultCondition, array()) 00093 ->joinLeft(array('c'=>$tableName), $condition, array()) 00094 ->where('c.attribute_id IN (?) OR d.attribute_id IN (?)', $attributes); 00095 $part = $this->_getReadAdapter()->fetchAll($select); 00096 00097 if (is_array($part)) { 00098 $result = array_merge($result, $part); 00099 } 00100 } 00101 00102 return $result; 00103 }
getMinimalPrice | ( | $ | products, | |
$ | priceAttributes, | |||
$ | store | |||
) |
Return minimal prices for specified products
array | $products | |
array | $priceAttributes | |
int | $store |
Reimplemented in Mage_CatalogIndex_Model_Mysql4_Data_Grouped.
Definition at line 169 of file Abstract.php.
00170 { 00171 $website = Mage::app()->getStore($store)->getWebsiteId(); 00172 00173 $fields = array('customer_group_id', 'minimal_value'=>'MIN(value)'); 00174 $select = $this->_getReadAdapter()->select() 00175 ->from(array('base'=>$this->getTable('catalogindex/price')), $fields) 00176 ->where('base.entity_id in (?)', $products) 00177 ->where('base.attribute_id in (?)', $priceAttributes) 00178 ->where('base.website_id = ?', $website) 00179 ->group('base.customer_group_id'); 00180 return $this->_getReadAdapter()->fetchAll($select); 00181 }
getTierPrices | ( | $ | products, | |
$ | website | |||
) |
Return tier prices for specified product in specified website
array | $products | |
int | $website |
Definition at line 190 of file Abstract.php.
00191 { 00192 $fields = array( 00193 'entity_id', 00194 'type_id', 00195 'c.customer_group_id', 00196 'c.qty', 00197 'c.value', 00198 'c.all_groups', 00199 ); 00200 $condition = "product.entity_id = c.entity_id"; 00201 00202 $select = $this->_getReadAdapter()->select() 00203 ->from(array('product'=>$this->getTable('catalog/product')), $fields) 00204 ->joinLeft(array('c'=>"{$this->getTable('catalog/product')}_tier_price"), $condition, array()) 00205 ->where('product.entity_id in (?)', $products); 00206 if (Mage::helper('catalog')->isPriceGlobal()) 00207 { 00208 $select->where('c.website_id=?', 0); 00209 } 00210 elseif (Mage::app()->getWebsite($website)->getBaseCurrencyCode() != Mage::app()->getBaseCurrencyCode()) { 00211 $select->where('c.website_id=?', $website); 00212 } 00213 else { 00214 $select->where('c.website_id IN(?)', array(0, $website)); 00215 } 00216 00217 return $this->_getReadAdapter()->fetchAll($select); 00218 }
$_attributeCodeIds = array() [protected] |
Definition at line 34 of file Abstract.php.
$_linkSelect = null [protected] |
Definition at line 41 of file Abstract.php.