Mage_Catalog_Block_Product_View_Type_Configurable Class Reference

Inheritance diagram for Mage_Catalog_Block_Product_View_Type_Configurable:

Mage_Catalog_Block_Product_View_Abstract Mage_Catalog_Block_Product_Abstract Mage_Core_Block_Template Mage_Core_Block_Abstract Varien_Object

List of all members.

Public Member Functions

 getAllowAttributes ()
 getAllowProducts ()
 getJsonConfig ()

Protected Member Functions

 _validateAttributeValue ($attributeId, &$value, &$options)
 _validateAttributeInfo (&$info)
 _preparePrice ($price, $isPercent=false)
 _registerJsPrice ($price)
 _convertPrice ($price, $round=false)

Protected Attributes

 $_prices = array()
 $_resPrices = array()


Detailed Description

Definition at line 35 of file Configurable.php.


Member Function Documentation

_convertPrice ( price,
round = false 
) [protected]

Definition at line 227 of file Configurable.php.

00228     {
00229         if (empty($price)) {
00230             return 0;
00231         }
00232 
00233         $price = Mage::app()->getStore()->convertPrice($price);
00234         if ($round) {
00235             $price = Mage::app()->getStore()->roundPrice($price);
00236         }
00237 
00238 
00239         return $price;
00240     }

_preparePrice ( price,
isPercent = false 
) [protected]

Definition at line 208 of file Configurable.php.

00209     {
00210         if ($isPercent && !empty($price)) {
00211             $price = $this->getProduct()->getFinalPrice()*$price/100;
00212         }
00213 
00214         return $this->_registerJsPrice($this->_convertPrice($price, true));
00215     }

_registerJsPrice ( price  )  [protected]

Definition at line 217 of file Configurable.php.

00218     {
00219         $jsPrice            = str_replace(',', '.', $price);
00220 
00221 //        if (!isset($this->_prices[$jsPrice])) {
00222 //            $this->_prices[$jsPrice] = strip_tags(Mage::app()->getStore()->formatPrice($price));
00223 //        }
00224         return $jsPrice;
00225     }

_validateAttributeInfo ( &$  info  )  [protected]

Validation of super product option

Parameters:
array $info
Returns:
boolean

Definition at line 200 of file Configurable.php.

00201     {
00202         if(count($info['options']) > 0) {
00203             return true;
00204         }
00205         return false;
00206     }

_validateAttributeValue ( attributeId,
&$  value,
&$  options 
) [protected]

Validating of super product option value

Parameters:
array $attribute
array $value
array $options
Returns:
boolean

Definition at line 185 of file Configurable.php.

00186     {
00187         if(isset($options[$attributeId][$value['value_index']])) {
00188             return true;
00189         }
00190 
00191         return false;
00192     }

getAllowAttributes (  ) 

Definition at line 40 of file Configurable.php.

00041     {
00042         return $this->getProduct()->getTypeInstance(true)
00043             ->getConfigurableAttributes($this->getProduct());
00044     }

getAllowProducts (  ) 

Definition at line 60 of file Configurable.php.

00061     {
00062         if (!$this->hasAllowProducts()) {
00063             $products = array();
00064             $allProducts = $this->getProduct()->getTypeInstance(true)
00065                 ->getUsedProducts(null, $this->getProduct());
00066             foreach ($allProducts as $product) {
00067                 if ($product->isSaleable()) {
00068                     $products[] = $product;
00069                 }
00070             }
00071             $this->setAllowProducts($products);
00072         }
00073         return $this->getData('allow_products');
00074     }

getJsonConfig (  ) 

Prepare formated values for options choose

Definition at line 76 of file Configurable.php.

00077     {
00078         $attributes = array();
00079         $options = array();
00080         $store = Mage::app()->getStore();
00081         foreach ($this->getAllowProducts() as $product) {
00082             $productId  = $product->getId();
00083 
00084             foreach ($this->getAllowAttributes() as $attribute) {
00085                 $productAttribute = $attribute->getProductAttribute();
00086                 $attributeValue = $product->getData($productAttribute->getAttributeCode());
00087                 if (!isset($options[$productAttribute->getId()])) {
00088                     $options[$productAttribute->getId()] = array();
00089                 }
00090 
00091                 if (!isset($options[$productAttribute->getId()][$attributeValue])) {
00092                     $options[$productAttribute->getId()][$attributeValue] = array();
00093                 }
00094                 $options[$productAttribute->getId()][$attributeValue][] = $productId;
00095             }
00096         }
00097 
00098         $this->_resPrices = array(
00099             $this->_preparePrice($this->getProduct()->getFinalPrice())
00100         );
00101 
00102         foreach ($this->getAllowAttributes() as $attribute) {
00103             $productAttribute = $attribute->getProductAttribute();
00104             $attributeId = $productAttribute->getId();
00105             $info = array(
00106                'id'        => $productAttribute->getId(),
00107                'code'      => $productAttribute->getAttributeCode(),
00108                'label'     => $attribute->getLabel(),
00109                'options'   => array()
00110             );
00111 
00112             $optionPrices = array();
00113             $prices = $attribute->getPrices();
00114             if (is_array($prices)) {
00115                 foreach ($prices as $value) {
00116                     if(!$this->_validateAttributeValue($attributeId, $value, $options)) {
00117                         continue;
00118                     }
00119 
00120                     $info['options'][] = array(
00121                         'id'    => $value['value_index'],
00122                         'label' => $value['label'],
00123                         'price' => $this->_preparePrice($value['pricing_value'], $value['is_percent']),
00124                         'products'   => isset($options[$attributeId][$value['value_index']]) ? $options[$attributeId][$value['value_index']] : array(),
00125                     );
00126                     $optionPrices[] = $this->_preparePrice($value['pricing_value'], $value['is_percent']);
00127                     //$this->_registerAdditionalJsPrice($value['pricing_value'], $value['is_percent']);
00128                 }
00129             }
00130             /**
00131              * Prepare formated values for options choose
00132              */
00133             foreach ($optionPrices as $optionPrice) {
00134                 foreach ($optionPrices as $additional) {
00135                     $this->_preparePrice(abs($additional-$optionPrice));
00136                 }
00137             }
00138             if($this->_validateAttributeInfo($info)) {
00139                $attributes[$attributeId] = $info;
00140             }
00141         }
00142         /*echo '<pre>';
00143         print_r($this->_prices);
00144         echo '</pre>';die();*/
00145 
00146         $_request = Mage::getSingleton('tax/calculation')->getRateRequest(false, false, false);
00147         $_request->setProductClassId($this->getProduct()->getTaxClassId());
00148         $defaultTax = Mage::getSingleton('tax/calculation')->getRate($_request);
00149 
00150         $_request = Mage::getSingleton('tax/calculation')->getRateRequest();
00151         $_request->setProductClassId($this->getProduct()->getTaxClassId());
00152         $currentTax = Mage::getSingleton('tax/calculation')->getRate($_request);
00153 
00154         $taxConfig = array(
00155             'includeTax'        => Mage::helper('tax')->priceIncludesTax(),
00156             'showIncludeTax'    => Mage::helper('tax')->displayPriceIncludingTax(),
00157             'showBothPrices'    => Mage::helper('tax')->displayBothPrices(),
00158             'defaultTax'        => $defaultTax,
00159             'currentTax'        => $currentTax,
00160             'inclTaxTitle'      => Mage::helper('catalog')->__('Incl. Tax'),
00161         );
00162 
00163         $config = array(
00164             'attributes'        => $attributes,
00165             'template'          => str_replace('%s', '#{price}', $store->getCurrentCurrency()->getOutputFormat()),
00166 //            'prices'          => $this->_prices,
00167             'basePrice'         => $this->_registerJsPrice($this->_convertPrice($this->getProduct()->getFinalPrice())),
00168             'oldPrice'          => $this->_registerJsPrice($this->_convertPrice($this->getProduct()->getPrice())),
00169             'productId'         => $this->getProduct()->getId(),
00170             'chooseText'        => Mage::helper('catalog')->__('Choose option...'),
00171             'taxConfig'         => $taxConfig,
00172         );
00173 
00174         return Zend_Json::encode($config);
00175     }


Member Data Documentation

$_prices = array() [protected]

Definition at line 37 of file Configurable.php.

$_resPrices = array() [protected]

Definition at line 38 of file Configurable.php.


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

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