Mage_Catalog_Model_Product_Option_Type_Select Class Reference

Inheritance diagram for Mage_Catalog_Model_Product_Option_Type_Select:

Mage_Catalog_Model_Product_Option_Type_Default Varien_Object

List of all members.

Public Member Functions

 validateUserValue ($values)
 prepareForCart ()
 getFormattedOptionValue ($optionValue)
 getPrintableOptionValue ($optionValue)
 getEditableOptionValue ($optionValue)
 parseOptionValue ($optionValue, $productOptionValues)
 prepareOptionValueForRequest ($optionValue)
 getOptionPrice ($optionValue, $basePrice)
 getOptionSku ($optionValue, $skuDelimiter)

Protected Member Functions

 _isSingleSelection ()


Detailed Description

Definition at line 34 of file Select.php.


Member Function Documentation

_isSingleSelection (  )  [protected]

Check if option has single or multiple values selection

Returns:
boolean

Definition at line 234 of file Select.php.

00235     {
00236         $_single = array(
00237             Mage_Catalog_Model_Product_Option::OPTION_TYPE_DROP_DOWN,
00238             Mage_Catalog_Model_Product_Option::OPTION_TYPE_RADIO
00239         );
00240         return in_array($this->getOption()->getType(), $_single);
00241     }

getEditableOptionValue ( optionValue  ) 

Return formatted option value ready to edit, ready to parse

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

Reimplemented from Mage_Catalog_Model_Product_Option_Type_Default.

Definition at line 113 of file Select.php.

00114     {
00115         $option = $this->getOption();
00116         $result = '';
00117         if (!$this->_isSingleSelection()) {
00118             foreach (explode(',', $optionValue) as $_value) {
00119                 $result .= $option->getValueById($_value)->getTitle() . ', ';
00120             }
00121             $result = Mage::helper('core/string')->substr($result, 0, -2);
00122         } elseif ($this->_isSingleSelection()) {
00123             $result = $option->getValueById($optionValue)->getTitle();
00124         } else {
00125             $result = $optionValue;
00126         }
00127         return $result;
00128     }

getFormattedOptionValue ( optionValue  ) 

Return formatted option value for quote option

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

Reimplemented from Mage_Catalog_Model_Product_Option_Type_Default.

Definition at line 86 of file Select.php.

00087     {
00088         if ($this->_formattedOptionValue === null) {
00089             $this->_formattedOptionValue = Mage::helper('core')->htmlEscape(
00090                 $this->getEditableOptionValue($optionValue)
00091             );
00092         }
00093         return $this->_formattedOptionValue;
00094     }

getOptionPrice ( optionValue,
basePrice 
)

Return Price for selected option

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

Reimplemented from Mage_Catalog_Model_Product_Option_Type_Default.

Definition at line 177 of file Select.php.

00178     {
00179         $option = $this->getOption();
00180         $result = 0;
00181 
00182         if (!$this->_isSingleSelection()) {
00183             foreach(explode(',', $optionValue) as $value) {
00184                 $result += $this->_getChargableOptionPrice(
00185                     $option->getValueById($value)->getPrice(),
00186                     $option->getValueById($value)->getPriceType() == 'percent',
00187                     $basePrice
00188                 );
00189             }
00190         } elseif ($this->_isSingleSelection()) {
00191             $result = $this->_getChargableOptionPrice(
00192                 $option->getValueById($optionValue)->getPrice(),
00193                 $option->getValueById($optionValue)->getPriceType() == 'percent',
00194                 $basePrice
00195             );
00196         }
00197 
00198         return $result;
00199     }

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 from Mage_Catalog_Model_Product_Option_Type_Default.

Definition at line 208 of file Select.php.

00209     {
00210         $option = $this->getOption();
00211 
00212         if (!$this->_isSingleSelection()) {
00213             $skus = array();
00214             foreach(explode(',', $optionValue) as $value) {
00215                 if ($optionSku = $option->getValueById($value)->getSku()) {
00216                     $skus[] = $optionSku;
00217                 }
00218             }
00219             $result = implode($skuDelimiter, $skus);
00220         } elseif ($this->_isSingleSelection()) {
00221             $result = $option->getValueById($optionValue)->getSku();
00222         } else {
00223             $result = parent::getOptionSku($optionValue, $skuDelimiter);
00224         }
00225 
00226         return $result;
00227     }

getPrintableOptionValue ( optionValue  ) 

Return printable option value

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

Reimplemented from Mage_Catalog_Model_Product_Option_Type_Default.

Definition at line 102 of file Select.php.

00103     {
00104         return $this->getFormattedOptionValue($optionValue);
00105     }

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 from Mage_Catalog_Model_Product_Option_Type_Default.

Definition at line 137 of file Select.php.

00138     {
00139         $_values = array();
00140         if (!$this->_isSingleSelection()) {
00141             foreach (explode(',', $optionValue) as $_value) {
00142                 $_value = trim($_value);
00143                 if (array_key_exists($_value, $productOptionValues)) {
00144                     $_values[] = $productOptionValues[$_value];
00145                 }
00146             }
00147         } elseif ($this->_isSingleSelection() && array_key_exists($optionValue, $productOptionValues)) {
00148             $_values[] = $productOptionValues[$optionValue];
00149         }
00150         if (count($_values)) {
00151             return implode(',', $_values);
00152         } else {
00153             return null;
00154         }
00155     }

prepareForCart (  ) 

Prepare option value for cart

Exceptions:
Mage_Core_Exception 
Returns:
mixed Prepared option value

Reimplemented from Mage_Catalog_Model_Product_Option_Type_Default.

Definition at line 71 of file Select.php.

00072     {
00073         if ($this->getIsValid() && $this->getUserValue()) {
00074             return is_array($this->getUserValue()) ? implode(',', $this->getUserValue()) : $this->getUserValue();
00075         } else {
00076             return null;
00077         }
00078     }

prepareOptionValueForRequest ( optionValue  ) 

Prepare option value for info buy request

Parameters:
string $optionValue
Returns:
mixed

Reimplemented from Mage_Catalog_Model_Product_Option_Type_Default.

Definition at line 163 of file Select.php.

00164     {
00165         if (!$this->_isSingleSelection()) {
00166             return explode(',', $optionValue);
00167         }
00168         return $optionValue;
00169     }

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 from Mage_Catalog_Model_Product_Option_Type_Default.

Definition at line 43 of file Select.php.

00044     {
00045         parent::validateUserValue($values);
00046 
00047         $option = $this->getOption();
00048         $value = $this->getUserValue();
00049 
00050         if (empty($value) && $option->getIsRequire() && !$this->getProduct()->getSkipCheckRequiredOption()) {
00051             $this->setIsValid(false);
00052             Mage::throwException(Mage::helper('catalog')->__('Please specify the product required option(s)'));
00053         }
00054         if (!$this->_isSingleSelection()) {
00055             $valuesCollection = $option->getOptionValuesByOptionId($value, $this->getProduct()->getStoreId())
00056                 ->load();
00057             if ($valuesCollection->count() != count($value)) {
00058                 $this->setIsValid(false);
00059                 Mage::throwException(Mage::helper('catalog')->__('Please specify the product required option(s)'));
00060             }
00061         }
00062         return $this;
00063     }


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