Mage_Catalog_Model_Product_Option_Type_Default Class Reference

Inheritance diagram for Mage_Catalog_Model_Product_Option_Type_Default:

Varien_Object Mage_Catalog_Model_Product_Option_Type_Date Mage_Catalog_Model_Product_Option_Type_File Mage_Catalog_Model_Product_Option_Type_Select Mage_Catalog_Model_Product_Option_Type_Text

List of all members.

Public Member Functions

 setOption ($option)
 getOption ()
 setProduct ($product)
 getProduct ()
 getQuoteItemOption ()
 getQuoteItem ()
 getRequest ()
 getConfigData ($key)
 validateUserValue ($values)
 prepareForCart ()
 isCustomizedView ()
 getFormattedOptionValue ($optionValue)
 getCustomizedView ($optionInfo)
 getPrintableOptionValue ($optionValue)
 getEditableOptionValue ($optionValue)
 parseOptionValue ($optionValue, $productOptionValues)
 prepareOptionValueForRequest ($optionValue)
 getOptionPrice ($optionValue, $basePrice)
 getOptionSku ($optionValue, $skuDelimiter)
 getProductOptions ()

Protected Member Functions

 _getChargableOptionPrice ($price, $isPercent, $basePrice)

Protected Attributes

 $_option
 $_product
 $_productOptions = array()


Detailed Description

Definition at line 34 of file Default.php.


Member Function Documentation

_getChargableOptionPrice ( price,
isPercent,
basePrice 
) [protected]

Return final chargable price for option

Parameters:
float $price Price of option
boolean $isPercent Price type - percent or fixed
float $basePrice For percent price type
Returns:
float

Definition at line 343 of file Default.php.

00344     {
00345         if($isPercent) {
00346             return ($basePrice * $price / 100);
00347         } else {
00348             return $price;
00349         }
00350     }

getConfigData ( key  ) 

Store Config value

Parameters:
string $key Config value key
Returns:
string

Definition at line 156 of file Default.php.

00157     {
00158         return Mage::getStoreConfig('catalog/custom_options/' . $key);
00159     }

getCustomizedView ( optionInfo  ) 

Return option html

Parameters:
array $optionInfo
Returns:
string

Reimplemented in Mage_Catalog_Model_Product_Option_Type_File.

Definition at line 225 of file Default.php.

00226     {
00227         return isset($optionInfo['value']) ? $optionInfo['value'] : $optionInfo;
00228     }

getEditableOptionValue ( optionValue  ) 

Return formatted option value ready to edit, ready to parse (ex: Admin re-order, see Mage_Adminhtml_Model_Sales_Order_Create)

Parameters:
string $optionValue Prepared for cart option value
Returns:
string

Reimplemented in Mage_Catalog_Model_Product_Option_Type_Date, Mage_Catalog_Model_Product_Option_Type_File, and Mage_Catalog_Model_Product_Option_Type_Select.

Definition at line 248 of file Default.php.

00249     {
00250         return $optionValue;
00251     }

getFormattedOptionValue ( optionValue  ) 

Return formatted option value for quote option

Parameters:
string $optionValue Prepared for cart option value
Returns:
string

Reimplemented in Mage_Catalog_Model_Product_Option_Type_Date, Mage_Catalog_Model_Product_Option_Type_File, Mage_Catalog_Model_Product_Option_Type_Select, and Mage_Catalog_Model_Product_Option_Type_Text.

Definition at line 214 of file Default.php.

00215     {
00216         return $optionValue;
00217     }

getOption (  ) 

Option Instance getter

Exceptions:
Mage_Core_Exception 
Returns:
Mage_Catalog_Model_Product_Option

Definition at line 77 of file Default.php.

00078     {
00079         if ($this->_option instanceof Mage_Catalog_Model_Product_Option) {
00080             return $this->_option;
00081         }
00082         Mage::throwException(Mage::helper('catalog')->__('Wrong option instance type in options group'));
00083     }

getOptionPrice ( optionValue,
basePrice 
)

Return Price for selected option

Parameters:
string $optionValue Prepared for cart option value
float $basePrice For percent price type
Returns:
float

Reimplemented in Mage_Catalog_Model_Product_Option_Type_Select.

Definition at line 283 of file Default.php.

00284     {
00285         $option = $this->getOption();
00286 
00287         return $this->_getChargableOptionPrice(
00288             $option->getPrice(),
00289             $option->getPriceType() == 'percent',
00290             $basePrice
00291         );
00292     }

getOptionSku ( optionValue,
skuDelimiter 
)

Return SKU for selected option

Parameters:
string $optionValue Prepared for cart option value
string $skuDelimiter Delimiter for Sku parts
Returns:
string

Reimplemented in Mage_Catalog_Model_Product_Option_Type_Select.

Definition at line 301 of file Default.php.

00302     {
00303         return $this->getOption()->getSku();
00304     }

getPrintableOptionValue ( optionValue  ) 

Return printable option value

Parameters:
string $optionValue Prepared for cart option value
Returns:
string

Reimplemented in Mage_Catalog_Model_Product_Option_Type_Date, Mage_Catalog_Model_Product_Option_Type_File, and Mage_Catalog_Model_Product_Option_Type_Select.

Definition at line 236 of file Default.php.

00237     {
00238         return $optionValue;
00239     }

getProduct (  ) 

Product Instance getter

Exceptions:
Mage_Core_Exception 
Returns:
Mage_Catalog_Model_Product

Definition at line 103 of file Default.php.

00104     {
00105         if ($this->_product instanceof Mage_Catalog_Model_Product) {
00106             return $this->_product;
00107         }
00108         Mage::throwException(Mage::helper('catalog')->__('Wrong product instance type in options group'));
00109     }

getProductOptions (  ) 

Return value => key all product options (using for parsing)

Returns:
array Array of Product custom options, reversing option values and option ids

Definition at line 311 of file Default.php.

00312     {
00313         if (!isset($this->_productOptions[$this->getProduct()->getId()])) {
00314             foreach ($this->getProduct()->getOptions() as $_option) {
00315                 /* @var $option Mage_Catalog_Model_Product_Option */
00316                 $this->_productOptions[$this->getProduct()->getId()][$_option->getTitle()] = array('option_id' => $_option->getId());
00317                 if ($_option->getGroupByType() == Mage_Catalog_Model_Product_Option::OPTION_GROUP_SELECT) {
00318                     $optionValues = array();
00319                     foreach ($_option->getValues() as $_value) {
00320                         /* @var $value Mage_Catalog_Model_Product_Option_Value */
00321                         $optionValues[$_value->getTitle()] = $_value->getId();
00322                     }
00323                     $this->_productOptions[$this->getProduct()->getId()][$_option->getTitle()]['values'] = $optionValues;
00324                 } else {
00325                     $this->_productOptions[$this->getProduct()->getId()][$_option->getTitle()]['values'] = array();
00326                 }
00327             }
00328         }
00329         if (isset($this->_productOptions[$this->getProduct()->getId()])) {
00330             return $this->_productOptions[$this->getProduct()->getId()];
00331         }
00332         return array();
00333     }

getQuoteItem (  ) 

Getter for Quote Item

Returns:
Mage_Sales_Model_Quote_Item

Definition at line 129 of file Default.php.

00130     {
00131         if ($this->_getData('quote_item') instanceof Mage_Sales_Model_Quote_Item) {
00132             return $this->_getData('quote_item');
00133         }
00134         Mage::throwException(Mage::helper('catalog')->__('Wrong quote item instance in options group'));
00135     }

getQuoteItemOption (  ) 

Getter for Quote Item Option

Returns:
Mage_Sales_Model_Quote_Item_Option

Definition at line 116 of file Default.php.

00117     {
00118         if ($this->_getData('quote_item_option') instanceof Mage_Sales_Model_Quote_Item_Option) {
00119             return $this->_getData('quote_item_option');
00120         }
00121         Mage::throwException(Mage::helper('catalog')->__('Wrong quote item option instance in options group'));
00122     }

getRequest (  ) 

Getter for Buy Request

Returns:
Varien_Object

Definition at line 142 of file Default.php.

00143     {
00144         if ($this->_getData('request') instanceof Varien_Object) {
00145             return $this->_getData('request');
00146         }
00147         Mage::throwException(Mage::helper('catalog')->__('Wrong BuyRequest instance in options group'));
00148     }

isCustomizedView (  ) 

Flag to indicate that custom option has own customized output (blocks, native html etc.)

Returns:
boolean

Reimplemented in Mage_Catalog_Model_Product_Option_Type_File.

Definition at line 203 of file Default.php.

00204     {
00205         return false;
00206     }

parseOptionValue ( optionValue,
productOptionValues 
)

Parse user input value and return cart prepared value, i.e. "one, two" => "1,2"

Parameters:
string $optionValue
array $productOptionValues Values for product option
Returns:
string|null

Reimplemented in Mage_Catalog_Model_Product_Option_Type_Date, Mage_Catalog_Model_Product_Option_Type_File, and Mage_Catalog_Model_Product_Option_Type_Select.

Definition at line 260 of file Default.php.

00261     {
00262         return $optionValue;
00263     }

prepareForCart (  ) 

Prepare option value for cart

Exceptions:
Mage_Core_Exception 
Returns:
mixed Prepared option value

Reimplemented in Mage_Catalog_Model_Product_Option_Type_Date, Mage_Catalog_Model_Product_Option_Type_File, Mage_Catalog_Model_Product_Option_Type_Select, and Mage_Catalog_Model_Product_Option_Type_Text.

Definition at line 190 of file Default.php.

00191     {
00192         if ($this->getIsValid()) {
00193             return $this->getUserValue();
00194         }
00195         Mage::throwException(Mage::helper('catalog')->__('Option validation failed to add product to cart'));
00196     }

prepareOptionValueForRequest ( optionValue  ) 

Prepare option value for info buy request

Parameters:
string $optionValue
Returns:
mixed

Reimplemented in Mage_Catalog_Model_Product_Option_Type_Date, Mage_Catalog_Model_Product_Option_Type_File, and Mage_Catalog_Model_Product_Option_Type_Select.

Definition at line 271 of file Default.php.

00272     {
00273         return $optionValue;
00274     }

setOption ( option  ) 

Option Instance setter

Parameters:
Mage_Catalog_Model_Product_Option $option
Returns:
Mage_Catalog_Model_Product_Option_Type_Default

Definition at line 65 of file Default.php.

00066     {
00067         $this->_option = $option;
00068         return $this;
00069     }

setProduct ( product  ) 

Product Instance setter

Parameters:
Mage_Catalog_Model_Product $product
Returns:
Mage_Catalog_Model_Product_Option_Type_Default

Definition at line 91 of file Default.php.

00092     {
00093         $this->_product = $product;
00094         return $this;
00095     }

validateUserValue ( values  ) 

Validate user input for option

Exceptions:
Mage_Core_Exception 
Parameters:
array $values All product option values, i.e. array (option_id => mixed, option_id => mixed...)
Returns:
Mage_Catalog_Model_Product_Option_Type_Default

Reimplemented in Mage_Catalog_Model_Product_Option_Type_Date, Mage_Catalog_Model_Product_Option_Type_File, Mage_Catalog_Model_Product_Option_Type_Select, and Mage_Catalog_Model_Product_Option_Type_Text.

Definition at line 168 of file Default.php.

00169     {
00170         Mage::getSingleton('checkout/session')->setUseNotice(false);
00171 
00172         $this->setIsValid(false);
00173 
00174         $option = $this->getOption();
00175         if (!isset($values[$option->getId()]) && $option->getIsRequire() && !$this->getProduct()->getSkipCheckRequiredOption()) {
00176             Mage::throwException(Mage::helper('catalog')->__('Please specify the product required option(s)'));
00177         } elseif (isset($values[$option->getId()])) {
00178             $this->setUserValue($values[$option->getId()]);
00179             $this->setIsValid(true);
00180         }
00181         return $this;
00182     }


Member Data Documentation

$_option [protected]

Definition at line 41 of file Default.php.

$_product [protected]

Definition at line 48 of file Default.php.

$_productOptions = array() [protected]

Definition at line 57 of file Default.php.


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

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