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_Value extends Mage_Core_Model_Abstract
00035 {
00036 protected $_values = array();
00037
00038 protected $_product;
00039
00040 protected $_option;
00041
00042 protected function _construct()
00043 {
00044 $this->_init('catalog/product_option_value');
00045 }
00046
00047 public function addValue($value)
00048 {
00049 $this->_values[] = $value;
00050 return $this;
00051 }
00052
00053 public function getValues()
00054 {
00055 return $this->_values;
00056 }
00057
00058 public function setValues($values)
00059 {
00060 $this->_values = $values;
00061 return $this;
00062 }
00063
00064 public function unsetValues()
00065 {
00066 $this->_values = array();
00067 return $this;
00068 }
00069
00070 public function setOption(Mage_Catalog_Model_Product_Option $option)
00071 {
00072 $this->_option = $option;
00073 return $this;
00074 }
00075
00076 public function unsetOption()
00077 {
00078 $this->_option = null;
00079 return $this;
00080 }
00081
00082
00083
00084
00085
00086
00087 public function getOption()
00088 {
00089 return $this->_option;
00090 }
00091
00092 public function setProduct($product)
00093 {
00094 $this->_product = $product;
00095 return $this;
00096 }
00097
00098 public function getProduct()
00099 {
00100 if (is_null($this->_product)) {
00101 $this->_product = $this->getOption()->getProduct();
00102 }
00103 return $this->_product;
00104 }
00105
00106 public function saveValues()
00107 {
00108 foreach ($this->getValues() as $value) {
00109 $this->setData($value)
00110 ->setData('option_id', $this->getOption()->getId())
00111 ->setData('store_id', $this->getOption()->getStoreId());
00112
00113 if ($this->getData('option_type_id') == '-1') {
00114 $this->unsetData('option_type_id');
00115 } else {
00116 $this->setId($this->getData('option_type_id'));
00117 }
00118
00119 if ($this->getData('is_delete') == '1') {
00120 if ($this->getId()) {
00121 $this->deleteValues($this->getId());
00122 $this->delete();
00123 }
00124 } else {
00125 $this->save();
00126 }
00127 }
00128 return $this;
00129 }
00130
00131
00132
00133
00134
00135
00136
00137
00138 public function getPrice($flag=false)
00139 {
00140 if ($flag && $this->getPriceType() == 'percent') {
00141 $basePrice = $this->getOption()->getProduct()->getFinalPrice();
00142 $price = $basePrice*($this->_getData('price')/100);
00143 return $price;
00144 }
00145 return $this->_getData('price');
00146 }
00147
00148
00149
00150
00151
00152
00153
00154 public function getValuesCollection(Mage_Catalog_Model_Product_Option $option)
00155 {
00156 $collection = Mage::getResourceModel('catalog/product_option_value_collection')
00157 ->addFieldToFilter('option_id', $option->getId())
00158 ->getValues($option->getStoreId());
00159
00160 return $collection;
00161 }
00162
00163 public function getValuesByOption($optionIds, $option_id, $store_id)
00164 {
00165 $collection = Mage::getResourceModel('catalog/product_option_value_collection')
00166 ->addFieldToFilter('option_id', $option_id)
00167 ->getValuesByOption($optionIds, $store_id);
00168
00169 return $collection;
00170 }
00171
00172 public function deleteValue($option_id)
00173 {
00174 $this->getResource()->deleteValue($option_id);
00175 return $this;
00176 }
00177
00178 public function deleteValues($option_type_id)
00179 {
00180 $this->getResource()->deleteValues($option_type_id);
00181 return $this;
00182 }
00183
00184
00185
00186
00187
00188
00189 public function prepareValueForDuplicate()
00190 {
00191 $this->setOptionId(null);
00192 $this->setOptionTypeId(null);
00193
00194 return $this->__toArray();
00195 }
00196
00197
00198
00199
00200
00201
00202
00203
00204 public function duplicate($oldOptionId, $newOptionId)
00205 {
00206 $this->getResource()->duplicate($this, $oldOptionId, $newOptionId);
00207 return $this;
00208 }
00209 }