00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 class Mage_Catalog_Model_Product_Option_Type_Default extends Varien_Object
00035 {
00036
00037
00038
00039
00040
00041 protected $_option;
00042
00043
00044
00045
00046
00047
00048 protected $_product;
00049
00050
00051
00052
00053
00054
00055
00056
00057 protected $_productOptions = array();
00058
00059
00060
00061
00062
00063
00064
00065 public function setOption($option)
00066 {
00067 $this->_option = $option;
00068 return $this;
00069 }
00070
00071
00072
00073
00074
00075
00076
00077 public function getOption()
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 }
00084
00085
00086
00087
00088
00089
00090
00091 public function setProduct($product)
00092 {
00093 $this->_product = $product;
00094 return $this;
00095 }
00096
00097
00098
00099
00100
00101
00102
00103 public function getProduct()
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 }
00110
00111
00112
00113
00114
00115
00116 public function getQuoteItemOption()
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 }
00123
00124
00125
00126
00127
00128
00129 public function getQuoteItem()
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 }
00136
00137
00138
00139
00140
00141
00142 public function getRequest()
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 }
00149
00150
00151
00152
00153
00154
00155
00156 public function getConfigData($key)
00157 {
00158 return Mage::getStoreConfig('catalog/custom_options/' . $key);
00159 }
00160
00161
00162
00163
00164
00165
00166
00167
00168 public function validateUserValue($values)
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 }
00183
00184
00185
00186
00187
00188
00189
00190 public function prepareForCart()
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 }
00197
00198
00199
00200
00201
00202
00203 public function isCustomizedView()
00204 {
00205 return false;
00206 }
00207
00208
00209
00210
00211
00212
00213
00214 public function getFormattedOptionValue($optionValue)
00215 {
00216 return $optionValue;
00217 }
00218
00219
00220
00221
00222
00223
00224
00225 public function getCustomizedView($optionInfo)
00226 {
00227 return isset($optionInfo['value']) ? $optionInfo['value'] : $optionInfo;
00228 }
00229
00230
00231
00232
00233
00234
00235
00236 public function getPrintableOptionValue($optionValue)
00237 {
00238 return $optionValue;
00239 }
00240
00241
00242
00243
00244
00245
00246
00247
00248 public function getEditableOptionValue($optionValue)
00249 {
00250 return $optionValue;
00251 }
00252
00253
00254
00255
00256
00257
00258
00259
00260 public function parseOptionValue($optionValue, $productOptionValues)
00261 {
00262 return $optionValue;
00263 }
00264
00265
00266
00267
00268
00269
00270
00271 public function prepareOptionValueForRequest($optionValue)
00272 {
00273 return $optionValue;
00274 }
00275
00276
00277
00278
00279
00280
00281
00282
00283 public function getOptionPrice($optionValue, $basePrice)
00284 {
00285 $option = $this->getOption();
00286
00287 return $this->_getChargableOptionPrice(
00288 $option->getPrice(),
00289 $option->getPriceType() == 'percent',
00290 $basePrice
00291 );
00292 }
00293
00294
00295
00296
00297
00298
00299
00300
00301 public function getOptionSku($optionValue, $skuDelimiter)
00302 {
00303 return $this->getOption()->getSku();
00304 }
00305
00306
00307
00308
00309
00310
00311 public function getProductOptions()
00312 {
00313 if (!isset($this->_productOptions[$this->getProduct()->getId()])) {
00314 foreach ($this->getProduct()->getOptions() as $_option) {
00315
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
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 }
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343 protected function _getChargableOptionPrice($price, $isPercent, $basePrice)
00344 {
00345 if($isPercent) {
00346 return ($basePrice * $price / 100);
00347 } else {
00348 return $price;
00349 }
00350 }
00351
00352 }