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 abstract class Mage_Catalog_Model_Abstract extends Mage_Core_Model_Abstract
00035 {
00036
00037
00038
00039
00040 const DEFAULT_STORE_ID = 0;
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050 protected $_defaultValues = array();
00051
00052
00053
00054
00055
00056
00057 protected $_lockedAttributes = array();
00058
00059
00060
00061
00062
00063
00064 protected $_isDeleteable = true;
00065
00066
00067
00068
00069
00070
00071 protected $_isReadonly = false;
00072
00073
00074
00075
00076
00077
00078
00079
00080 public function lockAttribute($attributeCode)
00081 {
00082 $this->_lockedAttributes[$attributeCode] = true;
00083 return $this;
00084 }
00085
00086
00087
00088
00089
00090
00091
00092 public function unlockAttribute($attributeCode)
00093 {
00094 if ($this->isLockedAttribute($attributeCode)) {
00095 unset($this->_lockedAttributes[$attributeCode]);
00096 }
00097
00098 return $this;
00099 }
00100
00101
00102
00103
00104
00105
00106 public function unlockAttributes()
00107 {
00108 $this->_lockedAttributes = array();
00109 return $this;
00110 }
00111
00112
00113
00114
00115
00116
00117 public function getLockedAttributes()
00118 {
00119 return array_keys($this->_lockedAttributes);
00120 }
00121
00122
00123
00124
00125
00126
00127 public function hasLockedAttributes()
00128 {
00129 return !empty($this->_lockedAttributes);
00130 }
00131
00132
00133
00134
00135
00136
00137 public function isLockedAttribute($attributeCode)
00138 {
00139 return isset($this->_lockedAttributes[$attributeCode]);
00140 }
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157 public function setData($key, $value=null)
00158 {
00159 if ($this->hasLockedAttributes()) {
00160 if (is_array($key)) {
00161 foreach ($this->getLockedAttributes() as $attribute) {
00162 if (isset($key[$attribute])) {
00163 unset($key[$attribute]);
00164 }
00165 }
00166 } elseif ($this->isLockedAttribute($key)) {
00167 return $this;
00168 }
00169 } elseif ($this->isReadonly()) {
00170 return $this;
00171 }
00172
00173 return parent::setData($key, $value);
00174 }
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187 public function unsetData($key=null)
00188 {
00189 if ((!is_null($key) && $this->isLockedAttribute($key)) ||
00190 $this->isReadonly()) {
00191 return $this;
00192 }
00193
00194 return parent::unsetData($key);
00195 }
00196
00197
00198
00199
00200
00201
00202 public function getResourceCollection()
00203 {
00204 $collection = parent::getResourceCollection()
00205 ->setStoreId($this->getStoreId());
00206 return $collection;
00207 }
00208
00209 public function loadByAttribute($attribute, $value, $additionalAttributes='*')
00210 {
00211 $collection = $this->getResourceCollection()
00212 ->addAttributeToSelect($additionalAttributes)
00213 ->addAttributeToFilter($attribute, $value)
00214 ->setPage(1,1);
00215
00216 foreach ($collection as $object) {
00217 return $object;
00218 }
00219 return false;
00220 }
00221
00222
00223
00224
00225
00226
00227 public function getStore()
00228 {
00229 return Mage::app()->getStore($this->getStoreId());
00230 }
00231
00232
00233
00234
00235
00236
00237 public function getWebsiteStoreIds()
00238 {
00239 return $this->getStore()->getWebsite()->getStoreIds(true);
00240 }
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250 public function setAttributeDefaultValue($attributeCode, $value)
00251 {
00252 $this->_defaultValues[$attributeCode] = $value;
00253 return $this;
00254 }
00255
00256
00257
00258
00259
00260
00261
00262 public function getAttributeDefaultValue($attributeCode)
00263 {
00264 return isset($this->_defaultValues[$attributeCode]) ? $this->_defaultValues[$attributeCode] : null;
00265 }
00266
00267
00268
00269
00270
00271
00272 protected function _beforeSave()
00273 {
00274 $this->unlockAttributes();
00275 return parent::_beforeSave();
00276 }
00277
00278
00279
00280
00281
00282
00283 public function isDeleteable()
00284 {
00285 return $this->_isDeleteable;
00286 }
00287
00288
00289
00290
00291
00292
00293
00294 public function setIsDeleteable($value)
00295 {
00296 $this->_isDeleteable = (boolean) $value;
00297 return $this;
00298 }
00299
00300
00301
00302
00303
00304
00305 public function isReadonly()
00306 {
00307 return $this->_isReadonly;
00308 }
00309
00310
00311
00312
00313
00314
00315
00316 public function setIsReadonly($value)
00317 {
00318 $this->_isReadonly = (boolean) $value;
00319 return $this;
00320 }
00321
00322 }