Mage_Catalog_Block_Product_View_Options Class Reference

Inheritance diagram for Mage_Catalog_Block_Product_View_Options:

Mage_Core_Block_Template Mage_Core_Block_Abstract Varien_Object

List of all members.

Public Member Functions

 __construct ()
 getProduct ()
 setProduct (Mage_Catalog_Model_Product $product=null)
 addOptionRenderer ($type, $block, $template)
 getOptionRender ($type)
 getGroupOfOption ($type)
 getOptions ()
 hasOptions ()
 getJsonConfig ()
 getOptionHtml (Mage_Catalog_Model_Product_Option $option)

Protected Attributes

 $_product
 $_optionRenders = array()


Detailed Description

Definition at line 35 of file Options.php.


Constructor & Destructor Documentation

__construct (  ) 

Constructor

By default is looking for first argument as array and assignes it as object attributes This behaviour may change in child classes

Reimplemented from Varien_Object.

Definition at line 41 of file Options.php.

00042     {
00043         parent::__construct();
00044         $this->addOptionRenderer(
00045             'default',
00046             'catalog/product_view_options_type_default',
00047             'catalog/product/view/options/type/default.phtml'
00048         );
00049     }


Member Function Documentation

addOptionRenderer ( type,
block,
template 
)

Add option renderer to renderers array

Parameters:
string $type
string $block
string $template
Returns:
Mage_Catalog_Block_Product_View_Options

Definition at line 88 of file Options.php.

00089     {
00090         $this->_optionRenders[$type] = array(
00091             'block' => $block,
00092             'template' => $template,
00093             'renderer' => null
00094         );
00095         return $this;
00096     }

getGroupOfOption ( type  ) 

Definition at line 113 of file Options.php.

00114     {
00115         $group = Mage::getSingleton('catalog/product_option')->getGroupByType($type);
00116 
00117         return $group == '' ? 'default' : $group;
00118     }

getJsonConfig (  ) 

Definition at line 138 of file Options.php.

00139     {
00140         $config = array();
00141 
00142         foreach ($this->getOptions() as $option) {
00143             /* @var $option Mage_Catalog_Model_Product_Option */
00144             $priceValue = 0;
00145             if ($option->getGroupByType() == Mage_Catalog_Model_Product_Option::OPTION_GROUP_SELECT) {
00146                 $_tmpPriceValues = array();
00147                 foreach ($option->getValues() as $value) {
00148                     /* @var $value Mage_Catalog_Model_Product_Option_Value */
00149                    $_tmpPriceValues[$value->getId()] = Mage::helper('core')->currency($value->getPrice(true), false, false);
00150                 }
00151                 $priceValue = $_tmpPriceValues;
00152             } else {
00153                 $priceValue = Mage::helper('core')->currency($option->getPrice(), false, false);
00154             }
00155             $config[$option->getId()] = $priceValue;
00156         }
00157 
00158         return Zend_Json::encode($config);
00159     }

getOptionHtml ( Mage_Catalog_Model_Product_Option option  ) 

Get option html block

Parameters:
Mage_Catalog_Model_Product_Option $option

Definition at line 166 of file Options.php.

00167     {
00168         $renderer = $this->getOptionRender(
00169             $this->getGroupOfOption($option->getType())
00170         );
00171         if (is_null($renderer['renderer'])) {
00172             $renderer['renderer'] = $this->getLayout()->createBlock($renderer['block'])
00173                 ->setTemplate($renderer['template']);
00174         }
00175         return $renderer['renderer']
00176             ->setProduct($this->getProduct())
00177             ->setOption($option)
00178             ->toHtml();
00179     }

getOptionRender ( type  ) 

Get option render by given type

Parameters:
string $type
Returns:
array

Definition at line 104 of file Options.php.

00105     {
00106         if (isset($this->_optionRenders[$type])) {
00107             return $this->_optionRenders[$type];
00108         }
00109 
00110         return $this->_optionRenders['default'];
00111     }

getOptions (  ) 

Get product options

Returns:
array

Definition at line 125 of file Options.php.

00126     {
00127         return $this->getProduct()->getOptions();
00128     }

getProduct (  ) 

Retrieve product object

Returns:
Mage_Catalog_Model_Product

Definition at line 56 of file Options.php.

00057     {
00058         if (!$this->_product) {
00059             if (Mage::registry('product')) {
00060                 $this->_product = Mage::registry('current_product');
00061             } else {
00062                 $this->_product = Mage::getSingleton('catalog/product');
00063             }
00064         }
00065         return $this->_product;
00066     }

hasOptions (  ) 

Definition at line 130 of file Options.php.

00131     {
00132         if ($this->getOptions()) {
00133             return true;
00134         }
00135         return false;
00136     }

setProduct ( Mage_Catalog_Model_Product product = null  ) 

Set product object

Parameters:
Mage_Catalog_Model_Product $product
Returns:
Mage_Catalog_Block_Product_View_Options

Definition at line 74 of file Options.php.

00075     {
00076         $this->_product = $product;
00077         return $this;
00078     }


Member Data Documentation

$_optionRenders = array() [protected]

Definition at line 39 of file Options.php.

$_product [protected]

Definition at line 37 of file Options.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