Definition at line 34 of file Option.php.
_afterSave | ( | ) | [protected] |
Processing object after save data
Reimplemented from Mage_Core_Model_Abstract.
Definition at line 284 of file Option.php.
00285 { 00286 $this->getValueInstance()->unsetValues(); 00287 if (is_array($this->getData('values'))) { 00288 foreach ($this->getData('values') as $value) { 00289 $this->getValueInstance()->addValue($value); 00290 } 00291 00292 $this->getValueInstance()->setOption($this) 00293 ->saveValues(); 00294 } elseif ($this->getGroupByType($this->getType()) == self::OPTION_GROUP_SELECT) { 00295 Mage::throwException(Mage::helper('catalog')->__('Select type options required values rows.')); 00296 } 00297 00298 return parent::_afterSave(); 00299 }
_construct | ( | ) | [protected] |
Enter description here...
Reimplemented from Varien_Object.
Definition at line 60 of file Option.php.
00061 { 00062 $this->_init('catalog/product_option'); 00063 }
addOption | ( | $ | option | ) |
addValue | ( | Mage_Catalog_Model_Product_Option_Value $ | value | ) |
Add value of option to values array
Mage_Catalog_Model_Product_Option_Value | $value |
Definition at line 71 of file Option.php.
deletePrices | ( | $ | option_id | ) |
Delete prices of option
int | $option_id |
Definition at line 324 of file Option.php.
00325 { 00326 $this->getResource()->deletePrices($option_id); 00327 return $this; 00328 }
deleteTitles | ( | $ | option_id | ) |
Delete titles of option
int | $option_id |
Definition at line 336 of file Option.php.
00337 { 00338 $this->getResource()->deleteTitles($option_id); 00339 return $this; 00340 }
duplicate | ( | $ | oldProductId, | |
$ | newProductId | |||
) |
Duplicate options for product
int | $oldProductId | |
int | $newProductId |
Definition at line 417 of file Option.php.
00418 { 00419 $this->getResource()->duplicate($this, $oldProductId, $newProductId); 00420 00421 return $this; 00422 }
getGroupByType | ( | $ | type = null |
) |
Get group name of option by given option type
string | $type |
Definition at line 183 of file Option.php.
00184 { 00185 if (is_null($type)) { 00186 $type = $this->getType(); 00187 } 00188 $optionGroupsToTypes = array( 00189 self::OPTION_TYPE_FIELD => self::OPTION_GROUP_TEXT, 00190 self::OPTION_TYPE_AREA => self::OPTION_GROUP_TEXT, 00191 self::OPTION_TYPE_FILE => self::OPTION_GROUP_FILE, 00192 self::OPTION_TYPE_DROP_DOWN => self::OPTION_GROUP_SELECT, 00193 self::OPTION_TYPE_RADIO => self::OPTION_GROUP_SELECT, 00194 self::OPTION_TYPE_CHECKBOX => self::OPTION_GROUP_SELECT, 00195 self::OPTION_TYPE_MULTIPLE => self::OPTION_GROUP_SELECT, 00196 self::OPTION_TYPE_DATE => self::OPTION_GROUP_DATE, 00197 self::OPTION_TYPE_DATE_TIME => self::OPTION_GROUP_DATE, 00198 self::OPTION_TYPE_TIME => self::OPTION_GROUP_DATE, 00199 ); 00200 00201 return isset($optionGroupsToTypes[$type])?$optionGroupsToTypes[$type]:''; 00202 }
getOptions | ( | ) |
getOptionValuesByOptionId | ( | $ | optionIds, | |
$ | store_id | |||
) |
Get collection of values by given option ids
array | $optionIds | |
int | $store_id |
Definition at line 381 of file Option.php.
00382 { 00383 $collection = Mage::getModel('catalog/product_option_value') 00384 ->getValuesByOption($optionIds, $this->getId(), $store_id); 00385 00386 return $collection; 00387 }
getPrice | ( | $ | flag = false |
) |
Return price. If $flag is true and price is percent return converted percent to price
bool | $flag |
Definition at line 308 of file Option.php.
00309 { 00310 if ($flag && $this->getPriceType() == 'percent') { 00311 $basePrice = $this->getProduct()->getFinalPrice(); 00312 $price = $basePrice*($this->_getData('price')/100); 00313 return $price; 00314 } 00315 return $this->_getData('price'); 00316 }
getProduct | ( | ) |
Retrieve product instance
Definition at line 160 of file Option.php.
getProductOptionCollection | ( | Mage_Catalog_Model_Product $ | product | ) |
get Product Option Collection
Mage_Catalog_Model_Product | $product |
Definition at line 348 of file Option.php.
00349 { 00350 $collection = $this->getCollection() 00351 ->addFieldToFilter('product_id', $product->getId()) 00352 ->addTitleToResult($product->getStoreId()) 00353 ->addPriceToResult($product->getStoreId()) 00354 ->setOrder('sort_order', 'asc') 00355 ->setOrder('title', 'asc') 00356 ->addValuesToResult($product->getStoreId()); 00357 00358 return $collection; 00359 }
getSearchableData | ( | $ | productId, | |
$ | storeId | |||
) |
Retrieve option searchable data
int | $productId | |
int | $storeId |
Definition at line 431 of file Option.php.
00432 { 00433 return $this->_getResource()->getSearchableData($productId, $storeId); 00434 }
getValueById | ( | $ | valueId | ) |
Get value by given id
int | $valueId |
Definition at line 83 of file Option.php.
00084 { 00085 if (isset($this->_values[$valueId])) { 00086 return $this->_values[$valueId]; 00087 } 00088 00089 return null; 00090 }
getValueInstance | ( | ) |
Retrieve value instance
Definition at line 102 of file Option.php.
00103 { 00104 if (!$this->_valueInstance) { 00105 $this->_valueInstance = Mage::getSingleton('catalog/product_option_value'); 00106 } 00107 return $this->_valueInstance; 00108 }
getValues | ( | ) |
getValuesCollection | ( | ) |
Get collection of values for current option
Definition at line 366 of file Option.php.
00367 { 00368 $collection = $this->getValueInstance() 00369 ->getValuesCollection($this); 00370 00371 return $collection; 00372 }
groupFactory | ( | $ | type | ) |
Group model factory
string | $type Option type |
Definition at line 210 of file Option.php.
00211 { 00212 $group = $this->getGroupByType($type); 00213 if (!empty($group)) { 00214 return Mage::getModel('catalog/product_option_type_' . $group); 00215 } 00216 Mage::throwException(Mage::helper('catalog')->__('Wrong option type to get group instance.')); 00217 }
prepareOptionForDuplicate | ( | ) |
Prepare array of options for duplicate
Definition at line 394 of file Option.php.
00395 { 00396 $this->setProductId(null); 00397 $this->setOptionId(null); 00398 $newOption = $this->__toArray(); 00399 if ($_values = $this->getValues()) { 00400 $newValuesArray = array(); 00401 foreach ($_values as $_value) { 00402 $newValuesArray[] = $_value->prepareValueForDuplicate(); 00403 } 00404 $newOption['values'] = $newValuesArray; 00405 } 00406 00407 return $newOption; 00408 }
saveOptions | ( | ) |
Save options.
Definition at line 224 of file Option.php.
00225 { 00226 foreach ($this->getOptions() as $option) { 00227 $this->setData($option) 00228 ->setData('product_id', $this->getProduct()->getId()) 00229 ->setData('store_id', $this->getProduct()->getStoreId()); 00230 00231 if ($this->getData('option_id') == '0') { 00232 $this->unsetData('option_id'); 00233 } else { 00234 $this->setId($this->getData('option_id')); 00235 } 00236 $isEdit = (bool)$this->getId()? true:false; 00237 00238 if ($this->getData('is_delete') == '1') { 00239 if ($isEdit) { 00240 $this->getValueInstance()->deleteValue($this->getId()); 00241 $this->deletePrices($this->getId()); 00242 $this->deleteTitles($this->getId()); 00243 $this->delete(); 00244 } 00245 } else { 00246 if ($this->getData('previous_type') != '') { 00247 $previousType = $this->getData('previous_type'); 00248 //if previous option has dfferent group from one is came now need to remove all data of previous group 00249 if ($this->getGroupByType($previousType) != $this->getGroupByType($this->getData('type'))) { 00250 00251 switch ($this->getGroupByType($previousType)) { 00252 case self::OPTION_GROUP_SELECT: 00253 $this->unsetData('values'); 00254 if ($isEdit) { 00255 $this->getValueInstance()->deleteValue($this->getId()); 00256 } 00257 break; 00258 case self::OPTION_GROUP_FILE: 00259 $this->setData('file_extension', ''); 00260 $this->setData('image_size_x', '0'); 00261 $this->setData('image_size_y', '0'); 00262 break; 00263 case self::OPTION_GROUP_TEXT: 00264 $this->setData('max_characters', '0'); 00265 break; 00266 case self::OPTION_GROUP_DATE: 00267 break; 00268 } 00269 if ($this->getGroupByType($this->getData('type')) == self::OPTION_GROUP_SELECT) { 00270 $this->setData('sku', ''); 00271 $this->unsetData('price'); 00272 $this->unsetData('price_type'); 00273 if ($isEdit) { 00274 $this->deletePrices($this->getId()); 00275 } 00276 } 00277 } 00278 } 00279 $this->save(); } 00280 }//eof foreach() 00281 return $this; 00282 }
setOptions | ( | $ | options | ) |
setProduct | ( | Mage_Catalog_Model_Product $ | product = null |
) |
Set product instance
Mage_Catalog_Model_Product | $product |
Definition at line 171 of file Option.php.
unsetOptions | ( | ) |
Set options to empty array
Definition at line 149 of file Option.php.
00150 { 00151 $this->_options = array(); 00152 return $this; 00153 }
$_options = array() [protected] |
Definition at line 54 of file Option.php.
$_product [protected] |
Definition at line 52 of file Option.php.
$_valueInstance [protected] |
Definition at line 56 of file Option.php.
$_values = array() [protected] |
Definition at line 58 of file Option.php.
const OPTION_GROUP_DATE = 'date' |
Definition at line 39 of file Option.php.
const OPTION_GROUP_FILE = 'file' |
Definition at line 37 of file Option.php.
const OPTION_GROUP_SELECT = 'select' |
Definition at line 38 of file Option.php.
const OPTION_GROUP_TEXT = 'text' |
Definition at line 36 of file Option.php.
const OPTION_TYPE_AREA = 'area' |
Definition at line 42 of file Option.php.
const OPTION_TYPE_CHECKBOX = 'checkbox' |
Definition at line 46 of file Option.php.
const OPTION_TYPE_DATE = 'date' |
Definition at line 48 of file Option.php.
const OPTION_TYPE_DATE_TIME = 'date_time' |
Definition at line 49 of file Option.php.
const OPTION_TYPE_DROP_DOWN = 'drop_down' |
Definition at line 44 of file Option.php.
const OPTION_TYPE_FIELD = 'field' |
Definition at line 41 of file Option.php.
const OPTION_TYPE_FILE = 'file' |
Definition at line 43 of file Option.php.
const OPTION_TYPE_MULTIPLE = 'multiple' |
Definition at line 47 of file Option.php.
const OPTION_TYPE_RADIO = 'radio' |
Definition at line 45 of file Option.php.
const OPTION_TYPE_TIME = 'time' |
Definition at line 50 of file Option.php.