Definition at line 34 of file Collection.php.
_addFinalPrice | ( | ) | [protected] |
Definition at line 911 of file Collection.php.
00912 { 00913 foreach ($this->_items as $product) { 00914 $basePrice = $product->getPrice(); 00915 $specialPrice = $product->getSpecialPrice(); 00916 $specialPriceFrom = $product->getSpecialFromDate(); 00917 $specialPriceTo = $product->getSpecialToDate(); 00918 if ($this->isEnabledFlat()) { 00919 $rulePrice = null; 00920 if ($product->getData('_rule_price') != $basePrice) { 00921 $rulePrice = $product->getData('_rule_price'); 00922 } 00923 } 00924 else { 00925 $rulePrice = $product->getData('_rule_price'); 00926 } 00927 00928 $finalPrice = $product->getPriceModel()->calculatePrice( 00929 $basePrice, 00930 $specialPrice, 00931 $specialPriceFrom, 00932 $specialPriceTo, 00933 $rulePrice, 00934 null, 00935 null, 00936 $product->getId() 00937 ); 00938 00939 $product->setCalculatedFinalPrice($finalPrice); 00940 } 00941 }
_addMinimalPrice | ( | ) | [protected] |
Definition at line 863 of file Collection.php.
00864 { 00865 Mage::getSingleton('catalogindex/price')->addMinimalPrices($this); 00866 return $this; 00867 }
_addTaxPercents | ( | ) | [protected] |
Definition at line 1033 of file Collection.php.
01034 { 01035 $classToRate = array(); 01036 $request = Mage::getSingleton('tax/calculation')->getRateRequest(); 01037 foreach ($this as &$item) { 01038 if (null === $item->getTaxClassId()) { 01039 $item->setTaxClassId($item->getMinimalTaxClassId()); 01040 } 01041 if (!isset($classToRate[$item->getTaxClassId()])) { 01042 $request->setProductClassId($item->getTaxClassId()); 01043 $classToRate[$item->getTaxClassId()] = Mage::getSingleton('tax/calculation')->getRate($request); 01044 } 01045 $item->setTaxPercent($classToRate[$item->getTaxClassId()]); 01046 } 01047 }
_addUrlRewrite | ( | ) | [protected] |
Definition at line 805 of file Collection.php.
00806 { 00807 $urlRewrites = null; 00808 if ($this->_cacheConf) { 00809 if (!($urlRewrites = Mage::app()->loadCache($this->_cacheConf['prefix'].'urlrewrite'))) { 00810 $urlRewrites = null; 00811 } else { 00812 $urlRewrites = unserialize($urlRewrites); 00813 } 00814 } 00815 00816 if (!$urlRewrites) { 00817 $productIds = array(); 00818 foreach($this->getItems() as $item) { 00819 $productIds[] = $item->getEntityId(); 00820 } 00821 if (!count($productIds)) { 00822 return; 00823 } 00824 00825 $select = $this->getConnection()->select() 00826 ->from($this->getTable('core/url_rewrite'), array('product_id', 'request_path')) 00827 ->where('store_id=?', Mage::app()->getStore()->getId()) 00828 ->where('is_system=?', 1) 00829 ->where('category_id=? OR category_id is NULL', $this->_urlRewriteCategory) 00830 ->where('product_id IN(?)', $productIds) 00831 ->order('category_id DESC'); // more priority is data with category id 00832 $urlRewrites = array(); 00833 00834 foreach ($this->getConnection()->fetchAll($select) as $row) { 00835 if (!isset($urlRewrites[$row['product_id']])) { 00836 $urlRewrites[$row['product_id']] = $row['request_path']; 00837 } 00838 } 00839 00840 if ($this->_cacheConf) { 00841 Mage::app()->saveCache( 00842 serialize($urlRewrites), 00843 $this->_cacheConf['prefix'].'urlrewrite', 00844 array_merge($this->_cacheConf['tags'], array(Mage_Catalog_Model_Product_Url::CACHE_TAG)), 00845 $this->_cacheLifetime 00846 ); 00847 } 00848 } 00849 00850 foreach($this->getItems() as $item) { 00851 if (isset($urlRewrites[$item->getEntityId()])) { 00852 $item->setData('request_path', $urlRewrites[$item->getEntityId()]); 00853 } 00854 } 00855 }
_afterLoad | ( | ) | [protected] |
Processing collection items after loading Adding url rewrites, minimal prices, final prices, tax percents
Reimplemented from Mage_Eav_Model_Entity_Collection_Abstract.
Reimplemented in Mage_Review_Model_Mysql4_Review_Product_Collection, and Mage_Tag_Model_Mysql4_Product_Collection.
Definition at line 343 of file Collection.php.
00344 { 00345 if ($this->_addUrlRewrite) { 00346 $this->_addUrlRewrite($this->_urlRewriteCategory); 00347 } 00348 if ($this->_addMinimalPrice) { 00349 $this->_addMinimalPrice(); 00350 } 00351 if ($this->_addFinalPrice) { 00352 $this->_addFinalPrice(); 00353 } 00354 if (count($this) > 0) { 00355 Mage::dispatchEvent('catalog_product_collection_load_after', array('collection'=>$this)); 00356 } 00357 return $this; 00358 }
_applyProductLimitations | ( | ) | [protected] |
Apply limitation filters to collection
Method allow use one time category product index table (or product website table) for different combinations of store_id/category_id/visibility filter states
Mehod support multiple changes in one collection object for this parameters
Definition at line 1283 of file Collection.php.
01284 { 01285 $this->_prepareProductLimitationFilters(); 01286 $this->_productLimitationJoinWebsite(); 01287 $filters = $this->_productLimitationFilters; 01288 01289 if (!isset($filters['category_id']) && !isset($filters['visibility'])) { 01290 return $this; 01291 } 01292 01293 $conditions = array( 01294 'cat_index.product_id=e.entity_id', 01295 $this->getConnection()->quoteInto('cat_index.store_id=?', $filters['store_id']) 01296 ); 01297 if (isset($filters['visibility'])) { 01298 $conditions[] = $this->getConnection() 01299 ->quoteInto('cat_index.visibility IN(?)', $filters['visibility']); 01300 } 01301 $conditions[] = $this->getConnection() 01302 ->quoteInto('cat_index.category_id=?', $filters['category_id']); 01303 if (isset($filters['category_is_anchor'])) { 01304 $conditions[] = $this->getConnection() 01305 ->quoteInto('cat_index.is_parent=?', $filters['category_is_anchor']); 01306 } 01307 01308 $joinCond = join(' AND ', $conditions); 01309 $fromPart = $this->getSelect()->getPart(Zend_Db_Select::FROM); 01310 if (isset($fromPart['cat_index'])) { 01311 $fromPart['cat_index']['joinCondition'] = $joinCond; 01312 $this->getSelect()->setPart(Zend_Db_Select::FROM, $fromPart); 01313 } 01314 else { 01315 $this->getSelect()->join( 01316 array('cat_index' => $this->getTable('catalog/category_product_index')), 01317 $joinCond, 01318 array('cat_index_position' => 'position') 01319 ); 01320 } 01321 01322 Mage::dispatchEvent('catalog_product_collection_apply_limitations_after', array( 01323 'collection' => $this 01324 )); 01325 01326 return $this; 01327 }
_beforeLoad | ( | ) | [protected] |
Add tax class id attribute to select and join price rules data if needed
Reimplemented from Mage_Eav_Model_Entity_Collection_Abstract.
Reimplemented in Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Link_Product_Collection.
Definition at line 327 of file Collection.php.
00328 { 00329 if ($this->_addFinalPrice) { 00330 $this->_joinPriceRules(); 00331 } 00332 Mage::dispatchEvent('catalog_product_collection_load_before', array('collection'=>$this)); 00333 00334 return parent::_beforeLoad(); 00335 }
_construct | ( | ) | [protected] |
Initialize resources
Reimplemented from Mage_Eav_Model_Entity_Collection_Abstract.
Reimplemented in Mage_Bundle_Model_Mysql4_Selection_Collection, Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Compare_Item_Collection, Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Type_Configurable_Product_Collection, Mage_Reports_Model_Mysql4_Wishlist_Product_Collection, Mage_Review_Model_Mysql4_Review_Product_Collection, and Mage_Wishlist_Model_Mysql4_Item_Collection.
Definition at line 158 of file Collection.php.
00159 { 00160 if ($this->isEnabledFlat()) { 00161 $this->_init('catalog/product', 'catalog/product_flat'); 00162 } 00163 else { 00164 $this->_init('catalog/product'); 00165 } 00166 00167 $this->_productWebsiteTable = $this->getResource()->getTable('catalog/product_website'); 00168 $this->_productCategoryTable= $this->getResource()->getTable('catalog/category_product'); 00169 }
_init | ( | $ | model, | |
$ | entityModel = null | |||
) | [protected] |
Standard resource collection initalization
string | $model |
Reimplemented from Mage_Eav_Model_Entity_Collection_Abstract.
Definition at line 177 of file Collection.php.
00178 { 00179 if ($this->isEnabledFlat()) { 00180 $entityModel = 'catalog/product_flat'; 00181 } 00182 00183 return parent::_init($model, $entityModel); 00184 }
_initSelect | ( | ) | [protected] |
Initialize collection select Redeclared for remove entity_type_id condition in catalog_product_entity we store just products
Reimplemented from Mage_Eav_Model_Entity_Collection_Abstract.
Reimplemented in Mage_Bundle_Model_Mysql4_Selection_Collection, Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Type_Configurable_Product_Collection, Mage_Review_Model_Mysql4_Review_Product_Collection, and Mage_Tag_Model_Mysql4_Product_Collection.
Definition at line 251 of file Collection.php.
00252 { 00253 if ($this->isEnabledFlat()) { 00254 $this->getSelect() 00255 ->from(array('e' => $this->getEntity()->getFlatTableName()), null) 00256 ->from(null, array('status' => new Zend_Db_Expr(Mage_Catalog_Model_Product_Status::STATUS_ENABLED))); 00257 $this->addAttributeToSelect(array('entity_id', 'type_id', 'attribute_set_id')); 00258 if ($this->getFlatHelper()->isAddChildData()) { 00259 $this->getSelect() 00260 ->where('e.is_child=?', 0); 00261 $this->addAttributeToSelect(array('child_id', 'is_child')); 00262 } 00263 } 00264 else { 00265 $this->getSelect()->from(array('e'=>$this->getEntity()->getEntityTable())); 00266 } 00267 return $this; 00268 }
_joinPriceRules | ( | ) | [protected] |
Join prices from price rules to products collection
Definition at line 885 of file Collection.php.
00886 { 00887 if ($this->isEnabledFlat()) { 00888 $customerGroup = Mage::getSingleton('customer/session')->getCustomerGroupId(); 00889 $priceColumn = 'e.display_price_group_' . $customerGroup; 00890 $this->getSelect()->from(null, array('_rule_price' => $priceColumn)); 00891 00892 return $this; 00893 } 00894 $wId = Mage::app()->getWebsite()->getId(); 00895 $gId = Mage::getSingleton('customer/session')->getCustomerGroupId(); 00896 00897 $storeDate = Mage::app()->getLocale()->storeTimeStamp($this->getStoreId()); 00898 $conditions = "_price_rule.product_id = e.entity_id AND "; 00899 $conditions .= "_price_rule.rule_date = '".$this->getResource()->formatDate($storeDate, false)."' AND "; 00900 $conditions .= "_price_rule.website_id = '{$wId}' AND "; 00901 $conditions .= "_price_rule.customer_group_id = '{$gId}'"; 00902 00903 $this->getSelect()->joinLeft( 00904 array('_price_rule'=>$this->getTable('catalogrule/rule_product_price')), 00905 $conditions, 00906 array('_rule_price'=>'rule_price') 00907 ); 00908 return $this; 00909 }
_loadAttributes | ( | $ | printQuery = false , |
|
$ | logQuery = false | |||
) |
Load attributes into loaded entities
bool | $printQuery | |
bool | $logQuery |
Reimplemented from Mage_Eav_Model_Entity_Collection_Abstract.
Definition at line 277 of file Collection.php.
00278 { 00279 if ($this->isEnabledFlat()) { 00280 return $this; 00281 } 00282 return parent::_loadAttributes($printQuery, $logQuery); 00283 }
_prepareProductLimitationFilters | ( | ) | [protected] |
Prepare limitation filters
Definition at line 1198 of file Collection.php.
01199 { 01200 if (isset($this->_productLimitationFilters['visibility']) 01201 && !isset($this->_productLimitationFilters['store_id']) 01202 ) { 01203 $this->_productLimitationFilters['store_id'] = $this->getStoreId(); 01204 } 01205 if (isset($this->_productLimitationFilters['category_id']) 01206 && !isset($this->_productLimitationFilters['store_id']) 01207 ) { 01208 $this->_productLimitationFilters['store_id'] = $this->getStoreId(); 01209 } 01210 if (isset($this->_productLimitationFilters['store_id']) 01211 && isset($this->_productLimitationFilters['visibility']) 01212 && !isset($this->_productLimitationFilters['category_id']) 01213 ) { 01214 $this->_productLimitationFilters['category_id'] = Mage::app() 01215 ->getStore($this->_productLimitationFilters['store_id']) 01216 ->getRootCategoryId(); 01217 } 01218 01219 return $this; 01220 }
_prepareStaticFields | ( | ) | [protected] |
Prepare static entity fields
Reimplemented from Mage_Eav_Model_Entity_Collection_Abstract.
Definition at line 191 of file Collection.php.
00192 { 00193 if ($this->isEnabledFlat()) { 00194 return $this; 00195 } 00196 return parent::_prepareStaticFields(); 00197 }
_productLimitationJoinWebsite | ( | ) | [protected] |
Join website product limitation
Definition at line 1227 of file Collection.php.
01228 { 01229 $joinWebsite = false; 01230 $filters = $this->_productLimitationFilters; 01231 $conditions = array( 01232 'product_website.product_id=e.entity_id' 01233 ); 01234 if (isset($filters['website_ids'])) { 01235 $joinWebsite = true; 01236 if (count($filters['website_ids']) > 1) { 01237 $this->getSelect()->distinct(true); 01238 } 01239 $conditions[] = $this->getConnection() 01240 ->quoteInto('product_website.website_id IN(?)', $filters['website_ids']); 01241 } 01242 elseif (isset($filters['store_id']) 01243 && (!isset($filters['visibility']) && !isset($filters['category_id'])) 01244 && !$this->isEnabledFlat() 01245 ) { 01246 $joinWebsite = true; 01247 $websiteId = Mage::app()->getStore($filters['store_id'])->getWebsiteId(); 01248 $conditions[] = $this->getConnection() 01249 ->quoteInto('product_website.website_id=?', $websiteId); 01250 } 01251 01252 $fromPart = $this->getSelect()->getPart(Zend_Db_Select::FROM); 01253 if (isset($fromPart['product_website'])) { 01254 if (!$joinWebsite) { 01255 unset($fromPart['product_website']); 01256 } 01257 else { 01258 $fromPart['product_website']['joinCondition'] = join(' AND ', $conditions); 01259 } 01260 $this->getSelect()->setPart(Zend_Db_Select::FROM, $fromPart); 01261 } 01262 elseif ($joinWebsite) { 01263 $this->getSelect()->join( 01264 array('product_website' => $this->getTable('catalog/product_website')), 01265 join(' AND ', $conditions), 01266 array() 01267 ); 01268 } 01269 01270 return $this; 01271 }
addAttributeToFilter | ( | $ | attribute, | |
$ | condition = null , |
|||
$ | joinType = 'inner' | |||
) |
Add attribute to filter
Mage_Eav_Model_Entity_Attribute_Abstract|string | $attribute | |
array | $condition | |
string | $joinType |
Reimplemented from Mage_Eav_Model_Entity_Collection_Abstract.
Reimplemented in Mage_Review_Model_Mysql4_Review_Product_Collection.
Definition at line 972 of file Collection.php.
00973 { 00974 if ($this->isEnabledFlat()) { 00975 if ($attribute instanceof Mage_Eav_Model_Entity_Attribute_Abstract) { 00976 $attribute = $attribute->getAttributeCode(); 00977 } 00978 00979 if (is_array($attribute)) { 00980 $sqlArr = array(); 00981 foreach ($attribute as $condition) { 00982 $sqlArr[] = $this->_getAttributeConditionSql($condition['attribute'], $condition, $joinType); 00983 } 00984 $conditionSql = '('.join(') OR (', $sqlArr).')'; 00985 $this->getSelect()->where($conditionSql); 00986 return $this; 00987 } 00988 00989 if (!isset($this->_selectAttributes[$attribute])) { 00990 $this->addAttributeToSelect($attribute); 00991 } 00992 00993 if (isset($this->_selectAttributes[$attribute])) { 00994 $this->getSelect()->where($this->_getConditionSql('e.'.$attribute, $condition)); 00995 } 00996 00997 return $this; 00998 } 00999 01000 $this->_allIdsCache = null; 01001 if (is_string($attribute) && $attribute == 'is_saleable') { 01002 return $this->getSelect()->where($this->_getConditionSql('(IF(manage_stock, is_in_stock, 1))', $condition)); 01003 } 01004 else { 01005 return parent::addAttributeToFilter($attribute, $condition, $joinType); 01006 } 01007 }
addAttributeToSelect | ( | $ | attribute, | |
$ | joinType = false | |||
) |
Add attribute to entities in collection
If $attribute=='*' select all attributes
array|string|integer|Mage_Core_Model_Config_Element | $attribute |
Reimplemented from Mage_Eav_Model_Entity_Collection_Abstract.
Definition at line 293 of file Collection.php.
00294 { 00295 if ($this->isEnabledFlat()) { 00296 if (!is_array($attribute)) { 00297 $attribute = array($attribute); 00298 } 00299 foreach ($attribute as $attributeCode) { 00300 if ($attributeCode == '*') { 00301 foreach ($this->getEntity()->getAllTableColumns() as $column) { 00302 $this->getSelect()->from(null, 'e.'.$column); 00303 $this->_selectAttributes[$column] = $column; 00304 $this->_staticFields[$column] = $column; 00305 } 00306 } 00307 else { 00308 if ($columns = $this->getEntity()->getAttributeForSelect($attributeCode)) { 00309 foreach ($columns as $alias => $column) { 00310 $this->getSelect()->from(null, array($alias => 'e.'.$column)); 00311 $this->_selectAttributes[$column] = $column; 00312 $this->_staticFields[$column] = $column; 00313 } 00314 } 00315 } 00316 } 00317 return $this; 00318 } 00319 return parent::addAttributeToSelect($attribute, $joinType); 00320 }
addAttributeToSort | ( | $ | attribute, | |
$ | dir = 'asc' | |||
) |
Add attribute to sort order
string | $attribute | |
string | $dir |
Distinct we are using for remove duplicates of products which have several rows in price index (like grouped products)
Reimplemented from Mage_Eav_Model_Entity_Collection_Abstract.
Reimplemented in Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Link_Product_Collection, and Mage_Reports_Model_Mysql4_Review_Product_Collection.
Definition at line 1110 of file Collection.php.
01111 { 01112 if ($attribute == 'position') { 01113 if (isset($this->_joinFields[$attribute])) { 01114 $this->getSelect()->order("{$attribute} {$dir}"); 01115 return $this; 01116 } 01117 $this->getSelect()->order("cat_index_position {$dir}"); 01118 // optimize if using cat index 01119 $filters = $this->_productLimitationFilters; 01120 if (isset($filters['category_id']) || isset($filters['visibility'])) { 01121 $this->getSelect()->order('cat_index.product_id ' . $dir); 01122 } 01123 else { 01124 $this->getSelect()->order('e.entity_id ' . $dir); 01125 } 01126 01127 return $this; 01128 } 01129 01130 $storeId = Mage::app()->getStore()->getId(); 01131 if ($attribute == 'price' && $storeId != 0) { 01132 $websiteId = Mage::app()->getStore()->getWebsiteId(); 01133 $customerGroup = Mage::getSingleton('customer/session')->getCustomerGroupId(); 01134 01135 if ($this->isEnabledFlat()) { 01136 $priceColumn = 'e.display_price_group_' . $customerGroup; 01137 $this->getSelect()->order("{$priceColumn} {$dir}"); 01138 } 01139 else { 01140 $priceAttributeId = $this->getAttribute('price')->getId(); 01141 01142 $entityCondition = '_price_order_table.entity_id = e.entity_id'; 01143 $storeCondition = $this->getConnection()->quoteInto( 01144 '_price_order_table.website_id = ?', 01145 $websiteId 01146 ); 01147 $groupCondition = $this->getConnection()->quoteInto( 01148 '_price_order_table.customer_group_id = ?', 01149 $customerGroup 01150 ); 01151 $attributeCondition = $this->getConnection()->quoteInto( 01152 '_price_order_table.attribute_id = ?', 01153 $priceAttributeId 01154 ); 01155 01156 $this->getSelect()->joinLeft( 01157 array('_price_order_table'=>$this->getTable('catalogindex/price')), 01158 "{$entityCondition} AND {$storeCondition} AND {$groupCondition} AND {$attributeCondition}", 01159 array() 01160 ); 01161 $this->getSelect()->order('_price_order_table.value ' . $dir); 01162 01163 /** 01164 * Distinct we are using for remove duplicates of products which have 01165 * several rows in price index (like grouped products) 01166 */ 01167 $this->getSelect()->distinct(true); 01168 } 01169 01170 return $this; 01171 } 01172 01173 if ($this->isEnabledFlat()) { 01174 $column = $this->getEntity()->getAttributeSortColumn($attribute); 01175 01176 if ($column) { 01177 $this->getSelect()->order("e.{$column} {$dir}"); 01178 } 01179 01180 return $this; 01181 } else { 01182 $attrInstance = $this->getEntity()->getAttribute($attribute); 01183 if ($attrInstance && $attrInstance->usesSource()) { 01184 $attrInstance->getSource() 01185 ->addValueSortToCollection($this, $dir); 01186 return $this; 01187 } 01188 } 01189 01190 return parent::addAttributeToSort($attribute, $dir); 01191 }
addCategoryFilter | ( | Mage_Catalog_Model_Category $ | category | ) |
Specify category filter for product collection
Mage_Catalog_Model_Category | $category |
Definition at line 482 of file Collection.php.
00483 { 00484 $this->_productLimitationFilters['category_id'] = $category->getId(); 00485 if ($category->getIsAnchor()) { 00486 unset($this->_productLimitationFilters['category_is_anchor']); 00487 } 00488 else { 00489 $this->_productLimitationFilters['category_is_anchor'] = 1; 00490 } 00491 00492 $this->_applyProductLimitations(); 00493 00494 return $this; 00495 }
addCountToCategories | ( | $ | categoryCollection | ) |
Adding product count to categories collection
Mage_Eav_Model_Entity_Collection_Abstract | $categoryCollection |
Definition at line 699 of file Collection.php.
00700 { 00701 $isAnchor = array(); 00702 $isNotAnchor = array(); 00703 foreach ($categoryCollection as $category) { 00704 if ($category->getIsAnchor()) { 00705 $isAnchor[] = $category->getId(); 00706 } else { 00707 $isNotAnchor[] = $category->getId(); 00708 } 00709 } 00710 $productCounts = array(); 00711 if ($isAnchor || $isNotAnchor) { 00712 $select = $this->getProductCountSelect(); 00713 00714 Mage::dispatchEvent('catalog_product_collection_before_add_count_to_categories', array('collection'=>$this)); 00715 00716 if ($isAnchor) { 00717 $anchorStmt = clone $select; 00718 $anchorStmt->where('count_table.category_id in (?)', $isAnchor); 00719 $productCounts += $this->getConnection()->fetchPairs($anchorStmt, array('category_id'=>'product_count')); 00720 $anchorStmt = null; 00721 } 00722 if ($isNotAnchor) { 00723 $notAnchorStmt = clone $select; 00724 $notAnchorStmt->where('count_table.category_id in (?)', $isNotAnchor); 00725 $notAnchorStmt->where('count_table.is_parent=1'); 00726 $productCounts += $this->getConnection()->fetchPairs($notAnchorStmt, array('category_id'=>'product_count')); 00727 $notAnchorStmt = null; 00728 } 00729 $select = null; 00730 $this->unsProductCountSelect(); 00731 } 00732 00733 foreach ($categoryCollection as $category) { 00734 $_count = 0; 00735 if (isset($productCounts[$category->getId()])) { 00736 $_count = $productCounts[$category->getId()]; 00737 } 00738 $category->setProductCount($_count); 00739 } 00740 // foreach ($categoryCollection as $category) { 00741 // $select = clone $this->getSelect(); 00742 // $select->reset(Zend_Db_Select::COLUMNS); 00743 // $select->reset(Zend_Db_Select::GROUP); 00744 // $select->reset(Zend_Db_Select::ORDER); 00745 // $select->distinct(false); 00746 // $select->join( 00747 // array('category_count_table' => $this->_productCategoryTable), 00748 // 'category_count_table.product_id=e.entity_id', 00749 // array('count_in_category'=>new Zend_Db_Expr('COUNT(DISTINCT e.entity_id)')) 00750 // ); 00751 // 00752 // if ($category->getIsAnchor()) { 00753 // $select->where($this->getConnection()->quoteInto( 00754 // 'category_count_table.category_id IN(?)', 00755 // explode(',', $category->getAllChildren()) 00756 // )); 00757 // } 00758 // else { 00759 // $select->where($this->getConnection()->quoteInto( 00760 // 'category_count_table.category_id=?', 00761 // $category->getId() 00762 // )); 00763 // } 00764 // $category->setProductCount((int) $this->getConnection()->fetchOne($select)); 00765 // } 00766 return $this; 00767 }
addFilterByRequiredOptions | ( | ) |
Filter products with required options
Definition at line 1083 of file Collection.php.
01084 { 01085 $this->addAttributeToFilter('required_options', array(array('neq'=>'1'), array('null'=>true)), 'left'); 01086 return $this; 01087 }
addFinalPrice | ( | ) |
Definition at line 869 of file Collection.php.
00870 { 00871 $this->_addFinalPrice = true; 00872 $this->addAttributeToSelect('price') 00873 ->addAttributeToSelect('special_price') 00874 ->addAttributeToSelect('special_from_date') 00875 ->addAttributeToSelect('special_to_date'); 00876 00877 return $this; 00878 }
addIdFilter | ( | $ | productId, | |
$ | exclude = false | |||
) |
Add collection filters by identifiers
mixed | $productId |
Definition at line 366 of file Collection.php.
00367 { 00368 if (empty($productId)) { 00369 $this->_setIsLoaded(true); 00370 return $this; 00371 } 00372 if (is_array($productId)) { 00373 if (!empty($productId)) { 00374 if ($exclude) { 00375 $condition = array('nin'=>$productId); 00376 } else { 00377 $condition = array('in'=>$productId); 00378 } 00379 } 00380 else { 00381 $condition = ''; 00382 } 00383 } 00384 else { 00385 if ($exclude) { 00386 $condition = array('neq'=>$productId); 00387 } else { 00388 $condition = $productId; 00389 } 00390 } 00391 $this->addFieldToFilter('entity_id', $condition); 00392 return $this; 00393 }
addMinimalPrice | ( | ) |
Definition at line 857 of file Collection.php.
00858 { 00859 $this->_addMinimalPrice = true; 00860 return $this; 00861 }
addOptionsToResult | ( | ) |
Adding product custom options to result collection
Definition at line 1054 of file Collection.php.
01055 { 01056 $productIds = array(); 01057 foreach ($this as $product) { 01058 $productIds[] = $product->getId(); 01059 } 01060 if (!empty($productIds)) { 01061 $options = Mage::getModel('catalog/product_option') 01062 ->getCollection() 01063 ->addTitleToResult(Mage::app()->getStore()->getId()) 01064 ->addPriceToResult(Mage::app()->getStore()->getId()) 01065 ->addProductToFilter($productIds) 01066 ->addValuesToResult(); 01067 01068 foreach ($options as $option) { 01069 if($this->getItemById($option->getProductId())) { 01070 $this->getItemById($option->getProductId())->addOption($option); 01071 } 01072 } 01073 } 01074 01075 return $this; 01076 }
addStoreFilter | ( | $ | store = null |
) |
Add store availability filter. Include availability product for store website
mixed | $store |
Reimplemented in Mage_Review_Model_Mysql4_Review_Product_Collection.
Definition at line 442 of file Collection.php.
00443 { 00444 if (is_null($store)) { 00445 $store = $this->getStoreId(); 00446 } 00447 $store = Mage::app()->getStore($store); 00448 00449 if (!$store->isAdmin()) { 00450 $this->setStoreId($store); 00451 $this->_productLimitationFilters['store_id'] = $store->getId(); 00452 $this->_applyProductLimitations(); 00453 } 00454 00455 return $this; 00456 }
addTaxPercents | ( | ) |
Add requere tax percent flag for product collection
Definition at line 1014 of file Collection.php.
01015 { 01016 $this->_addTaxPercents = true; 01017 return $this; 01018 }
addUrlRewrite | ( | $ | categoryId = '' |
) |
Definition at line 798 of file Collection.php.
00799 { 00800 $this->_addUrlRewrite = true; 00801 $this->_urlRewriteCategory = Mage::getStoreConfig('catalog/seo/product_use_categories') ? $categoryId : 0; 00802 return $this; 00803 }
addWebsiteFilter | ( | $ | websites = null |
) |
Add website filter to collection
Mage_Core_Model_Website|int|string|array | $website |
Definition at line 464 of file Collection.php.
00465 { 00466 if (!is_array($websites)) { 00467 $websites = array(Mage::app()->getWebsite($websites)->getId()); 00468 } 00469 00470 $this->_productLimitationFilters['website_ids'] = $websites; 00471 $this->_applyProductLimitations(); 00472 00473 return $this; 00474 }
addWebsiteNamesToResult | ( | ) |
Adding product website names to result collection Add for each product websites information
Definition at line 401 of file Collection.php.
00402 { 00403 $productStores = array(); 00404 foreach ($this as $product) { 00405 $productWebsites[$product->getId()] = array(); 00406 } 00407 00408 if (!empty($productWebsites)) { 00409 $select = $this->getConnection()->select() 00410 ->from(array('product_website'=>$this->_productWebsiteTable)) 00411 ->join( 00412 array('website'=>$this->getResource()->getTable('core/website')), 00413 'website.website_id=product_website.website_id', 00414 array('name')) 00415 ->where($this->getConnection()->quoteInto( 00416 'product_website.product_id IN (?)', 00417 array_keys($productWebsites)) 00418 ) 00419 ->where('website.website_id>0'); 00420 00421 $data = $this->getConnection()->fetchAll($select); 00422 foreach ($data as $row) { 00423 $productWebsites[$row['product_id']][] = $row['website_id']; 00424 } 00425 } 00426 00427 foreach ($this as $product) { 00428 if (isset($productWebsites[$product->getId()])) { 00429 $product->setData('websites', $productWebsites[$product->getId()]); 00430 } 00431 } 00432 return $this; 00433 }
getAllIds | ( | $ | limit = null , |
|
$ | offset = null | |||
) |
Retrive all ids for collection
Reimplemented from Mage_Eav_Model_Entity_Collection_Abstract.
Reimplemented in Mage_Review_Model_Mysql4_Review_Product_Collection.
Definition at line 644 of file Collection.php.
00645 { 00646 $idsSelect = clone $this->getSelect(); 00647 $idsSelect->reset(Zend_Db_Select::ORDER); 00648 $idsSelect->reset(Zend_Db_Select::LIMIT_COUNT); 00649 $idsSelect->reset(Zend_Db_Select::LIMIT_OFFSET); 00650 $idsSelect->reset(Zend_Db_Select::COLUMNS); 00651 $idsSelect->from(null, 'e.'.$this->getEntity()->getIdFieldName()); 00652 $idsSelect->limit($limit, $offset); 00653 $idsSelect->resetJoinLeft(); 00654 00655 return $this->getConnection()->fetchCol($idsSelect, $this->_bindParams); 00656 }
getAllIdsCache | ( | $ | resetCache = false |
) |
Definition at line 943 of file Collection.php.
00944 { 00945 $ids = null; 00946 if (!$resetCache) { 00947 $ids = $this->_allIdsCache; 00948 } 00949 00950 if (is_null($ids)) { 00951 $ids = $this->getAllIds(); 00952 $this->setAllIdsCache($ids); 00953 } 00954 00955 return $ids; 00956 }
getAttributeValueCount | ( | $ | attribute | ) |
Retrieve product count by some value of attribute
string | $attribute |
Definition at line 586 of file Collection.php.
00587 { 00588 $select = clone $this->getSelect(); 00589 $attribute = $this->getEntity()->getAttribute($attribute); 00590 $attributeCode = $attribute->getAttributeCode(); 00591 $tableAlias = $attributeCode.'_value_count'; 00592 00593 $select->reset(Zend_Db_Select::GROUP); 00594 $condition = 'e.entity_id='.$tableAlias.'.entity_id 00595 AND '.$this->_getConditionSql($tableAlias.'.attribute_id', $attribute->getId()) 00596 //.' AND '.$this->_getConditionSql($tableAlias.'.store_id', $this->getEntity()->getStoreId()) 00597 ; 00598 00599 $select->join( 00600 array($tableAlias => $attribute->getBackend()->getTable()), 00601 $condition, 00602 array( 00603 'count_'.$attributeCode=>new Zend_Db_Expr('COUNT(DISTINCT e.entity_id)'), 00604 'value_'.$attributeCode=>new Zend_Db_Expr($tableAlias.'.value') 00605 ) 00606 ) 00607 ->group('value_'.$attributeCode); 00608 00609 $data = $this->getConnection()->fetchAll($select); 00610 $res = array(); 00611 00612 foreach ($data as $row) { 00613 $res[$row['value_'.$attributeCode]] = $row['count_'.$attributeCode]; 00614 } 00615 return $res; 00616 }
getAttributeValueCountByRange | ( | $ | attribute, | |
$ | range | |||
) |
Retrieve ranging product count for arrtibute range
string | $attribute | |
int | $range |
Definition at line 548 of file Collection.php.
00549 { 00550 $select = clone $this->getSelect(); 00551 $attribute = $this->getEntity()->getAttribute($attribute); 00552 $attributeCode = $attribute->getAttributeCode(); 00553 $tableAlias = $attributeCode.'_range_count_value'; 00554 00555 $condition = 'e.entity_id='.$tableAlias.'.entity_id 00556 AND '.$this->_getConditionSql($tableAlias.'.attribute_id', $attribute->getId()) 00557 //.' AND '.$this->_getConditionSql($tableAlias.'.store_id', $this->getEntity()->getStoreId()) 00558 ; 00559 00560 $select->reset(Zend_Db_Select::GROUP); 00561 $select->join( 00562 array($tableAlias => $attribute->getBackend()->getTable()), 00563 $condition, 00564 array( 00565 'count_'.$attributeCode=>new Zend_Db_Expr('COUNT(DISTINCT e.entity_id)'), 00566 'range_'.$attributeCode=>new Zend_Db_Expr('CEIL(('.$tableAlias.'.value+0.01)/'.$range.')') 00567 ) 00568 ) 00569 ->group('range_'.$attributeCode); 00570 00571 $data = $this->getConnection()->fetchAll($select); 00572 $res = array(); 00573 00574 foreach ($data as $row) { 00575 $res[$row['range_'.$attributeCode]] = $row['count_'.$attributeCode]; 00576 } 00577 return $res; 00578 }
getFlatHelper | ( | ) |
Retrieve Catalog Product Flat Helper object
Definition at line 131 of file Collection.php.
00132 { 00133 return Mage::helper('catalog/product_flat'); 00134 }
getMaxAttributeValue | ( | $ | attribute | ) |
Retrieve max value by attribute
string | $attribute |
Definition at line 515 of file Collection.php.
00516 { 00517 $select = clone $this->getSelect(); 00518 $attribute = $this->getEntity()->getAttribute($attribute); 00519 $attributeCode = $attribute->getAttributeCode(); 00520 $tableAlias = $attributeCode.'_max_value'; 00521 00522 $condition = 'e.entity_id='.$tableAlias.'.entity_id 00523 AND '.$this->_getConditionSql($tableAlias.'.attribute_id', $attribute->getId()) 00524 //.' AND '.$this->_getConditionSql($tableAlias.'.store_id', $this->getEntity()->getStoreId()) 00525 ; 00526 00527 $select->join( 00528 array($tableAlias => $attribute->getBackend()->getTable()), 00529 $condition, 00530 array('max_'.$attributeCode=>new Zend_Db_Expr('MAX('.$tableAlias.'.value)')) 00531 ) 00532 ->group('e.entity_type_id'); 00533 00534 $data = $this->getConnection()->fetchRow($select); 00535 if (isset($data['max_'.$attributeCode])) { 00536 return $data['max_'.$attributeCode]; 00537 } 00538 return null; 00539 }
getNewEmptyItem | ( | ) |
Retrieve collection empty item Redeclared for specifying id field name without getting resource model inside model
Reimplemented from Varien_Data_Collection.
Definition at line 205 of file Collection.php.
00206 { 00207 $object = parent::getNewEmptyItem(); 00208 if ($this->isEnabledFlat()) { 00209 $object->setIdFieldName($this->getEntity()->getIdFieldName()); 00210 } 00211 return $object; 00212 }
getProductCountSelect | ( | ) |
Retreive product count select for categories
Definition at line 663 of file Collection.php.
00664 { 00665 if ($this->_productCountSelect === null) { 00666 $this->_productCountSelect = clone $this->getSelect(); 00667 $this->_productCountSelect->reset(Zend_Db_Select::COLUMNS) 00668 ->reset(Zend_Db_Select::GROUP) 00669 ->reset(Zend_Db_Select::ORDER) 00670 ->distinct(false) 00671 ->join(array('count_table' => $this->getTable('catalog/category_product_index')), 00672 'count_table.product_id = e.entity_id', 00673 array('count_table.category_id', 'product_count' => new Zend_Db_Expr('COUNT(DISTINCT count_table.product_id)')) 00674 ) 00675 ->where('count_table.store_id = ?', $this->getStoreId()) 00676 ->group('count_table.category_id'); 00677 } 00678 00679 return $this->_productCountSelect; 00680 }
getSelectCountSql | ( | ) |
Get SQL for get record count
Reimplemented from Varien_Data_Collection_Db.
Reimplemented in Mage_Reports_Model_Mysql4_Product_Collection, Mage_Reports_Model_Mysql4_Wishlist_Product_Collection, Mage_Review_Model_Mysql4_Review_Product_Collection, and Mage_Tag_Model_Mysql4_Product_Collection.
Definition at line 623 of file Collection.php.
00624 { 00625 $this->_renderFilters(); 00626 00627 $countSelect = clone $this->getSelect(); 00628 $countSelect->reset(Zend_Db_Select::ORDER); 00629 $countSelect->reset(Zend_Db_Select::LIMIT_COUNT); 00630 $countSelect->reset(Zend_Db_Select::LIMIT_OFFSET); 00631 $countSelect->reset(Zend_Db_Select::COLUMNS); 00632 00633 $countSelect->from('', 'COUNT(DISTINCT e.entity_id)'); 00634 $countSelect->resetJoinLeft(); 00635 00636 return $countSelect; 00637 }
getSetIds | ( | ) |
Definition at line 769 of file Collection.php.
00770 { 00771 $select = clone $this->getSelect(); 00772 /* @var $select Zend_Db_Select */ 00773 $select->reset(Zend_Db_Select::COLUMNS); 00774 $select->distinct(true); 00775 $select->from('', 'attribute_set_id'); 00776 return $this->getConnection()->fetchCol($select); 00777 }
isEnabledFlat | ( | ) |
Retrieve is flat enabled flag Return alvays false if magento run admin
Reimplemented in Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Compare_Item_Collection, and Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Type_Configurable_Product_Collection.
Definition at line 142 of file Collection.php.
00143 { 00144 if (Mage::app()->getStore()->isAdmin()) { 00145 return false; 00146 } 00147 if (!isset($this->_flatEnabled[$this->getStoreId()])) { 00148 $this->_flatEnabled[$this->getStoreId()] = $this->getFlatHelper() 00149 ->isEnabled($this->getStoreId()); 00150 } 00151 return $this->_flatEnabled[$this->getStoreId()]; 00152 }
joinMinimalPrice | ( | ) |
Join minimal price attribute to result
Definition at line 502 of file Collection.php.
00503 { 00504 $this->addAttributeToSelect('price') 00505 ->addAttributeToSelect('minimal_price'); 00506 return $this; 00507 }
joinUrlRewrite | ( | ) |
Joins url rewrite rules to collection
Definition at line 784 of file Collection.php.
00785 { 00786 $this->joinTable( 00787 'core/url_rewrite', 00788 'entity_id=entity_id', 00789 array('request_path'), 00790 '{{table}}.type='.Mage_Core_Model_Url_Rewrite::TYPE_PRODUCT, 00791 'left' 00792 ); 00793 00794 return $this; 00795 }
requireTaxPercent | ( | ) |
Get require tax percent flag value
Definition at line 1025 of file Collection.php.
01026 { 01027 return $this->_addTaxPercents; 01028 }
setAllIdsCache | ( | $ | value | ) |
setEntity | ( | $ | entity | ) |
Set entity to use for attributes
Mage_Eav_Model_Entity_Abstract | $entity |
Reimplemented from Mage_Eav_Model_Entity_Collection_Abstract.
Definition at line 220 of file Collection.php.
00221 { 00222 if ($this->isEnabledFlat() && ($entity instanceof Mage_Core_Model_Mysql4_Abstract)) { 00223 $this->_entity = $entity; 00224 return $this; 00225 } 00226 return parent::setEntity($entity); 00227 }
setStore | ( | $ | store | ) |
Set Store scope for collection
mixed | $store |
Reimplemented from Mage_Catalog_Model_Resource_Eav_Mysql4_Collection_Abstract.
Definition at line 235 of file Collection.php.
00236 { 00237 parent::setStore($store); 00238 if ($this->isEnabledFlat()) { 00239 $this->getEntity()->setStoreId($this->getStoreId()); 00240 } 00241 return $this; 00242 }
setVisibility | ( | $ | visibility | ) |
Set product visibility filter for enabled products
array | $visibility |
Definition at line 1095 of file Collection.php.
01096 { 01097 $this->_productLimitationFilters['visibility'] = $visibility; 01098 $this->_applyProductLimitations(); 01099 01100 return $this; 01101 }
unsProductCountSelect | ( | ) |
$_addFinalPrice = false [protected] |
Definition at line 84 of file Collection.php.
$_addMinimalPrice = false [protected] |
Definition at line 77 of file Collection.php.
$_addTaxPercents = false [protected] |
Definition at line 98 of file Collection.php.
$_addUrlRewrite = false [protected] |
Definition at line 63 of file Collection.php.
$_allIdsCache = null [protected] |
Definition at line 91 of file Collection.php.
$_flatEnabled = array() [protected] |
Definition at line 42 of file Collection.php.
$_isWebsiteFilter = false [protected] |
Definition at line 124 of file Collection.php.
$_productCategoryTable [protected] |
Definition at line 56 of file Collection.php.
$_productCountSelect = null [protected] |
Definition at line 119 of file Collection.php.
$_productLimitationFilters = array() [protected] |
Definition at line 112 of file Collection.php.
$_productWebsiteTable [protected] |
Definition at line 49 of file Collection.php.
$_urlRewriteCategory = '' [protected] |
Definition at line 70 of file Collection.php.