Public Member Functions | |
setLinkModel ($linkModel) | |
setIsStrongMode () | |
getLinkModel () | |
setProduct ($product) | |
getProduct () | |
addExcludeProductFilter ($products) | |
addAttributeToSort ($attribute, $dir='asc') | |
addProductFilter ($products) | |
setRandomOrder () | |
setGroupBy ($groupBy= 'e.entity_id') | |
setPositionOrder ($dir='asc') | |
Protected Member Functions | |
_beforeLoad () | |
_joinLinks () | |
Protected Attributes | |
$_product | |
$_linkModel | |
$_linkTypeId | |
$_isStrongMode | |
$_hasLinkFilter = false |
Definition at line 35 of file Collection.php.
_beforeLoad | ( | ) | [protected] |
Add tax class id attribute to select and join price rules data if needed
Reimplemented from Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection.
Definition at line 167 of file Collection.php.
00168 { 00169 if ($this->getLinkModel()) { 00170 $this->_joinLinks(); 00171 } 00172 return parent::_beforeLoad(); 00173 }
_joinLinks | ( | ) | [protected] |
Definition at line 175 of file Collection.php.
00176 { 00177 $joinCondition = 'links.linked_product_id=e.entity_id AND links.link_type_id='.$this->_linkTypeId; 00178 00179 if ($this->getProduct() && $this->getProduct()->getId()) { 00180 if ($this->_isStrongMode) { 00181 $joinType = 'join'; 00182 $this->getSelect()->where('links.product_id=?', $this->getProduct()->getId()); 00183 } 00184 else { 00185 $joinType = 'joinLeft'; 00186 $joinCondition.= ' AND links.product_id='. $this->getProduct()->getId(); 00187 } 00188 $this->getSelect()->where('e.entity_id!=?', $this->getProduct()->getId()); 00189 00190 $this->getSelect()->$joinType( 00191 array('links'=>$this->getTable('catalog/product_link')), 00192 $joinCondition, 00193 array('link_id') 00194 ); 00195 00196 $attributes = $this->getLinkModel()->getAttributes(); 00197 $attributesByType = array(); 00198 foreach ($attributes as $attribute) { 00199 $table = $this->getLinkModel()->getAttributeTypeTable($attribute['type']); 00200 $alias = 'link_attribute_'.$attribute['code'].'_'.$attribute['type']; 00201 $this->getSelect()->joinLeft( 00202 array($alias => $table), 00203 $alias.'.link_id=links.link_id AND '.$alias.'.product_link_attribute_id='.$attribute['id'], 00204 array($attribute['code'] => 'value') 00205 ); 00206 } 00207 } 00208 else { 00209 if ($this->_isStrongMode) { 00210 $this->getSelect()->where('e.entity_id=-1'); 00211 } 00212 elseif($this->_hasLinkFilter) { 00213 $this->getSelect()->join( 00214 array('links'=>$this->getTable('catalog/product_link')), 00215 'links.linked_product_id=e.entity_id AND links.link_type_id='.$this->_linkTypeId, 00216 array('link_id') 00217 ); 00218 } 00219 } 00220 return $this; 00221 }
addAttributeToSort | ( | $ | attribute, | |
$ | dir = 'asc' | |||
) |
Add attribute to sort order
string | $attribute | |
string | $dir |
Reimplemented from Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection.
Definition at line 114 of file Collection.php.
00115 { 00116 /* 00117 * position is not eav attributes so we cannot use default attributes to sort 00118 */ 00119 if ($attribute == 'position') { 00120 00121 // dont sort by position, when creating product (#5090) 00122 if (!is_object($this->getProduct())) { 00123 return $this; 00124 } 00125 if (!$this->getProduct()->getId()) { 00126 return $this; 00127 } 00128 00129 $this->getSelect()->order($attribute.' '.$dir); 00130 } 00131 else { 00132 parent::addAttributeToSort($attribute, $dir); 00133 } 00134 return $this; 00135 }
addExcludeProductFilter | ( | $ | products | ) |
Definition at line 97 of file Collection.php.
00098 { 00099 if (is_array($products) && !empty($products)) { 00100 $this->_hasLinkFilter = true; 00101 $this->getSelect()->where('links.linked_product_id NOT IN (?)', $products); 00102 } 00103 return $this; 00104 }
addProductFilter | ( | $ | products | ) |
Definition at line 137 of file Collection.php.
00138 { 00139 $this->_hasLinkFilter = true; 00140 if (is_array($products) && !empty($products)) { 00141 $this->getSelect()->where('links.product_id IN (?)', $products); 00142 } 00143 elseif (is_string($products) || is_numeric($products)) { 00144 $this->getSelect()->where('links.product_id=?', $products); 00145 } 00146 return $this; 00147 }
getLinkModel | ( | ) |
Retrieve collection link model
Definition at line 70 of file Collection.php.
getProduct | ( | ) |
Retrieve collection base product object
Definition at line 92 of file Collection.php.
setGroupBy | ( | $ | groupBy = 'e.entity_id' |
) |
Setting group by to exclude duplications in collection
string | $groupBy |
Definition at line 161 of file Collection.php.
00162 { 00163 $this->getSelect()->group($groupBy); 00164 return $this; 00165 }
setIsStrongMode | ( | ) |
setLinkModel | ( | $ | linkModel | ) |
Declare link model and initialize type attributes join
Mage_Catalog_Model_Product_Link | $linkModel |
Definition at line 50 of file Collection.php.
00051 { 00052 $this->_linkModel = $linkModel; 00053 if ($linkModel->getLinkTypeId()) { 00054 $this->_linkTypeId = $linkModel->getLinkTypeId(); 00055 } 00056 return $this; 00057 }
setPositionOrder | ( | $ | dir = 'asc' |
) |
Definition at line 223 of file Collection.php.
00224 { 00225 if ($this->getProduct() && $this->getProduct()->getId()) { 00226 $this->setOrder('position', $dir); 00227 } 00228 return $this; 00229 }
setProduct | ( | $ | product | ) |
Initialize collection parent product and add limitation join
Mage_Catalog_Model_Product | $product |
Definition at line 81 of file Collection.php.
setRandomOrder | ( | ) |
Definition at line 149 of file Collection.php.
00150 { 00151 $this->getSelect()->order(new Zend_Db_Expr('RAND()')); 00152 return $this; 00153 }
$_hasLinkFilter = false [protected] |
Definition at line 42 of file Collection.php.
$_isStrongMode [protected] |
Definition at line 41 of file Collection.php.
$_linkModel [protected] |
Definition at line 39 of file Collection.php.
$_linkTypeId [protected] |
Definition at line 40 of file Collection.php.
$_product [protected] |
Definition at line 38 of file Collection.php.