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 () |
Definition at line 34 of file Select.php.
_isSingleSelection | ( | ) | [protected] |
Check if option has single or multiple values selection
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
string | $optionValue Prepared for cart option value |
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
string | $optionValue Prepared for cart option value |
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
string | $optionValue Prepared for cart option value |
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
string | $optionValue Prepared for cart option value | |
string | $skuDelimiter Delimiter for Sku parts |
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
string | $optionValue Prepared for cart option value |
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"
string | $optionValue | |
array | $productOptionValues Values for product option |
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
Mage_Core_Exception |
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
string | $optionValue |
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
Mage_Core_Exception |
array | $values All product option values, i.e. array (option_id => mixed, option_id => mixed...) |
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 }