Public Member Functions | |
getHelper () | |
setProductFilter ($product) | |
orderByPosition ($dir='asc') | |
getStoreId () | |
_addAssociatedProductFilters () | |
getProduct () | |
Protected Member Functions | |
_construct () | |
_afterLoad () | |
_addProductAttributes () | |
_loadLabels () | |
_loadPrices () | |
Protected Attributes | |
$_labelTable | |
$_priceTable | |
$_product |
Definition at line 35 of file Collection.php.
_addAssociatedProductFilters | ( | ) |
Add Associated Product Filters (From Product Type Instance)
Definition at line 158 of file Collection.php.
00159 { 00160 $this->getProduct()->getTypeInstance(true) 00161 ->getUsedProducts($this->getColumnValues('attribute_id'), $this->getProduct()); // Filter associated products 00162 return $this; 00163 }
_addProductAttributes | ( | ) | [protected] |
Add product attributes to collection items
Definition at line 143 of file Collection.php.
00144 { 00145 foreach ($this->_items as $item) { 00146 $productAttribute = $this->getProduct()->getTypeInstance(true) 00147 ->getAttributeById($item->getAttributeId(), $this->getProduct()); 00148 $item->setProductAttribute($productAttribute); 00149 } 00150 return $this; 00151 }
_afterLoad | ( | ) | [protected] |
After load collection process
Reimplemented from Varien_Data_Collection_Db.
Definition at line 120 of file Collection.php.
00121 { 00122 parent::_afterLoad(); 00123 Varien_Profiler::start('TTT1:'.__METHOD__); 00124 $this->_addProductAttributes(); 00125 Varien_Profiler::stop('TTT1:'.__METHOD__); 00126 Varien_Profiler::start('TTT2:'.__METHOD__); 00127 $this->_addAssociatedProductFilters(); 00128 Varien_Profiler::stop('TTT2:'.__METHOD__); 00129 Varien_Profiler::start('TTT3:'.__METHOD__); 00130 $this->_loadLabels(); 00131 Varien_Profiler::stop('TTT3:'.__METHOD__); 00132 Varien_Profiler::start('TTT4:'.__METHOD__); 00133 $this->_loadPrices(); 00134 Varien_Profiler::stop('TTT4:'.__METHOD__); 00135 return $this; 00136 }
_construct | ( | ) | [protected] |
Initialize connection and define table names
Reimplemented from Mage_Core_Model_Mysql4_Collection_Abstract.
Definition at line 63 of file Collection.php.
00064 { 00065 $this->_init('catalog/product_type_configurable_attribute'); 00066 $this->_labelTable = $this->getTable('catalog/product_super_attribute_label'); 00067 $this->_priceTable = $this->getTable('catalog/product_super_attribute_pricing'); 00068 }
_loadLabels | ( | ) | [protected] |
Load attribute labels
Definition at line 170 of file Collection.php.
00171 { 00172 if ($this->count()) { 00173 $select = $this->getConnection()->select() 00174 ->from(array('default'=>$this->_labelTable)) 00175 ->joinLeft( 00176 array('store'=>$this->_labelTable), 00177 'store.product_super_attribute_id=default.product_super_attribute_id AND store.store_id='.$this->getStoreId(), 00178 array( 00179 'store_lebel'=>'value', 00180 'label' => new Zend_Db_Expr('IFNULL(store.value, default.value)') 00181 ) 00182 ) 00183 ->where('default.product_super_attribute_id IN (?)', array_keys($this->_items)) 00184 ->where('default.store_id=0'); 00185 foreach ($this->getConnection()->fetchAll($select) as $data) { 00186 $this->getItemById($data['product_super_attribute_id'])->setLabel($data['label']); 00187 } 00188 } 00189 return $this; 00190 }
_loadPrices | ( | ) | [protected] |
Load attribute prices information
Definition at line 197 of file Collection.php.
00198 { 00199 if ($this->count()) { 00200 $pricings = array( 00201 0 => array() 00202 ); 00203 if ($this->getHelper()->isPriceGlobal()) { 00204 $websiteId = 0; 00205 } 00206 else { 00207 $websiteId = (int)Mage::app()->getStore($this->getStoreId())->getWebsiteId(); 00208 $pricing[$websiteId] = array(); 00209 } 00210 $select = $this->getConnection()->select() 00211 ->from(array('price' => $this->_priceTable)) 00212 ->where('price.product_super_attribute_id IN (?)', array_keys($this->_items)); 00213 if ($websiteId > 0) { 00214 $select->where('price.website_id IN(?)', array(0, $websiteId)); 00215 } 00216 else { 00217 $select->where('price.website_id=0'); 00218 } 00219 $query = $this->getConnection()->query($select); 00220 00221 while ($row = $query->fetch()) { 00222 $pricings[(int)$row['website_id']][] = $row; 00223 } 00224 00225 $values = array(); 00226 00227 foreach ($this->_items as $item) { 00228 $productAttribute = $item->getProductAttribute(); 00229 if (!($productAttribute instanceof Mage_Eav_Model_Entity_Attribute_Abstract)) { 00230 continue; 00231 } 00232 $options = $productAttribute->getFrontend()->getSelectOptions(); 00233 foreach ($options as $option) { 00234 foreach ($this->getProduct()->getTypeInstance(true)->getUsedProducts(null, $this->getProduct()) as $associatedProduct) { 00235 if (!empty($option['value']) 00236 && $option['value'] == $associatedProduct->getData( 00237 $productAttribute->getAttributeCode())) { 00238 // If option aviable in associated product 00239 if (!isset($values[$item->getId() . ':' . $option['value']])) { 00240 // If option not added, we will add it. 00241 $values[$item->getId() . ':' . $option['value']] = array( 00242 'product_super_attribute_id' => $item->getId(), 00243 'value_index' => $option['value'], 00244 'label' => $option['label'], 00245 'default_label' => $option['label'], 00246 'store_label' => $option['label'], 00247 'is_percent' => 0, 00248 'pricing_value' => null, 00249 'use_default_value' => true 00250 ); 00251 } 00252 } 00253 } 00254 } 00255 } 00256 00257 foreach ($pricings[0] as $pricing) { 00258 // Addding pricing to options 00259 $valueKey = $pricing['product_super_attribute_id'] . ':' . $pricing['value_index']; 00260 if (isset($values[$valueKey])) { 00261 $values[$valueKey]['pricing_value'] = $pricing['pricing_value']; 00262 $values[$valueKey]['is_percent'] = $pricing['is_percent']; 00263 $values[$valueKey]['value_id'] = $pricing['value_id']; 00264 $values[$valueKey]['use_default_value'] = true; 00265 } 00266 } 00267 00268 if ($websiteId && isset($pricings[$websiteId])) { 00269 foreach ($pricings[$websiteId] as $pricing) { 00270 $valueKey = $pricing['product_super_attribute_id'] . ':' . $pricing['value_index']; 00271 if (isset($values[$valueKey])) { 00272 $values[$valueKey]['pricing_value'] = $pricing['pricing_value']; 00273 $values[$valueKey]['is_percent'] = $pricing['is_percent']; 00274 $values[$valueKey]['value_id'] = $pricing['value_id']; 00275 $values[$valueKey]['use_default_value'] = false; 00276 } 00277 } 00278 } 00279 00280 foreach ($values as $data) { 00281 $this->getItemById($data['product_super_attribute_id'])->addPrice($data); 00282 } 00283 } 00284 return $this; 00285 }
getHelper | ( | ) |
Retrieve catalog helper
Definition at line 75 of file Collection.php.
00076 { 00077 return Mage::helper('catalog'); 00078 }
getProduct | ( | ) |
Retrive product instance
Definition at line 292 of file Collection.php.
getStoreId | ( | ) |
orderByPosition | ( | $ | dir = 'asc' |
) |
Set order collection by Position
string | $dir |
Definition at line 99 of file Collection.php.
00100 { 00101 $this->getSelect()->order('position '.$dir); 00102 return $this; 00103 }
setProductFilter | ( | $ | product | ) |
Set Product filter (Configurable)
Mage_Catalog_Model_Product | $product |
Definition at line 86 of file Collection.php.
00087 { 00088 $this->_product = $product; 00089 $this->addFieldToFilter('product_id', $product->getId()); 00090 return $this; 00091 }
$_labelTable [protected] |
Definition at line 43 of file Collection.php.
$_priceTable [protected] |
Definition at line 50 of file Collection.php.
$_product [protected] |
Definition at line 57 of file Collection.php.