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
00035 class Mage_Catalog_Model_Product_Status extends Mage_Core_Model_Abstract
00036 {
00037 const STATUS_ENABLED = 1;
00038 const STATUS_DISABLED = 2;
00039
00040
00041
00042
00043
00044
00045 protected $_attribute;
00046
00047
00048
00049
00050
00051 protected function _construct()
00052 {
00053 $this->_init('catalog/product_status');
00054 }
00055
00056
00057
00058
00059
00060
00061 protected function _getResource()
00062 {
00063 return parent::_getResource();
00064 }
00065
00066
00067
00068
00069
00070
00071
00072 public function getProductAttribute($attributeCode)
00073 {
00074 return $this->_getResource()->getProductAttribute($attributeCode);
00075 }
00076
00077
00078
00079
00080
00081
00082
00083
00084 public function addVisibleFilterToCollection(Mage_Eav_Model_Entity_Collection_Abstract $collection)
00085 {
00086
00087 return $this;
00088 }
00089
00090
00091
00092
00093
00094
00095
00096
00097 public function addSaleableFilterToCollection(Mage_Eav_Model_Entity_Collection_Abstract $collection)
00098 {
00099
00100 return $this;
00101 }
00102
00103
00104
00105
00106
00107
00108 public function getVisibleStatusIds()
00109 {
00110 return array(self::STATUS_ENABLED);
00111 }
00112
00113
00114
00115
00116
00117
00118
00119 public function getSaleableStatusIds()
00120 {
00121 return array(self::STATUS_ENABLED);
00122 }
00123
00124
00125
00126
00127
00128
00129 static public function getOptionArray()
00130 {
00131 return array(
00132 self::STATUS_ENABLED => Mage::helper('catalog')->__('Enabled'),
00133 self::STATUS_DISABLED => Mage::helper('catalog')->__('Disabled')
00134 );
00135 }
00136
00137
00138
00139
00140
00141
00142 static public function getAllOption()
00143 {
00144 $options = self::getOptionArray();
00145 array_unshift($options, array('value'=>'', 'label'=>''));
00146 return $options;
00147 }
00148
00149
00150
00151
00152
00153
00154 static public function getAllOptions()
00155 {
00156 $res = array(
00157 array(
00158 'value' => '',
00159 'label' => Mage::helper('catalog')->__('-- Please Select --')
00160 )
00161 );
00162 foreach (self::getOptionArray() as $index => $value) {
00163 $res[] = array(
00164 'value' => $index,
00165 'label' => $value
00166 );
00167 }
00168 return $res;
00169 }
00170
00171
00172
00173
00174
00175
00176
00177 static public function getOptionText($optionId)
00178 {
00179 $options = self::getOptionArray();
00180 return isset($options[$optionId]) ? $options[$optionId] : null;
00181 }
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191 public function updateProductStatus($productId, $storeId, $value)
00192 {
00193 $stores = array();
00194 if ($storeId != 0) {
00195 $attribute = $this->getProductAttribute('status');
00196 if ($attribute->getIsGlobal() == Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE) {
00197 $stores[] = $storeId;
00198 }
00199 elseif ($attribute->getIsGlobal() == Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_WEBSITE) {
00200 $website = Mage::app()->getStore($storeId)->getWebsite();
00201 foreach ($website->getStores() as $store) {
00202 $stores[] = $store->getId();
00203 }
00204 }
00205 else {
00206 $stores[] = 0;
00207 }
00208 }
00209 else {
00210 $stores[] = $storeId;
00211 }
00212
00213 foreach ($stores as $storeId) {
00214 $this->_getResource()->updateProductStatus($productId, $storeId, $value);
00215 Mage::getResourceModel('catalog/category')->refreshProductIndex(
00216 array(),
00217 array($productId),
00218 $storeId ? array($storeId) : array()
00219 );
00220 Mage::dispatchEvent('catalog_product_status_update', array(
00221 'product_id' => $productId,
00222 'store_id' => $storeId,
00223 'status' => $value
00224 ));
00225 }
00226 return $this;
00227 }
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237 public function getProductStatus($productIds, $storeId = null)
00238 {
00239 return $this->getResource()->getProductStatus($productIds, $storeId);
00240 }
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251 public function getFlatColums()
00252 {
00253 return array();
00254 }
00255
00256
00257
00258
00259
00260
00261 public function getFlatIndexes()
00262 {
00263 return array();
00264 }
00265
00266
00267
00268
00269
00270
00271
00272
00273 public function getFlatUpdateSelect($store)
00274 {
00275 return null;
00276 }
00277
00278
00279
00280
00281
00282
00283
00284 public function setAttribute($attribute)
00285 {
00286 $this->_attribute = $attribute;
00287 return $this;
00288 }
00289
00290
00291
00292
00293
00294
00295 public function getAttribute()
00296 {
00297 return $this->_attribute;
00298 }
00299
00300
00301
00302
00303
00304
00305
00306
00307 public function addValueSortToCollection($collection, $dir = 'asc')
00308 {
00309 if ($this->getAttribute()->isScopeGlobal()) {
00310 $tableName = $this->getAttribute()->getAttributeCode() . '_t';
00311 $collection->getSelect()
00312 ->joinLeft(
00313 array($tableName => $this->getAttribute()->getBackend()->getTable()),
00314 "`e`.`entity_id`=`{$tableName}`.`entity_id`"
00315 . " AND `{$tableName}`.`attribute_id`='{$this->getAttribute()->getId()}'"
00316 . " AND `{$tableName}`.`store_id`='0'",
00317 array());
00318 $valueExpr = $tableName . '.value';
00319 }
00320 else {
00321 $valueTable1 = $this->getAttribute()->getAttributeCode() . '_t1';
00322 $valueTable2 = $this->getAttribute()->getAttributeCode() . '_t2';
00323 $collection->getSelect()
00324 ->joinLeft(
00325 array($valueTable1 => $this->getAttribute()->getBackend()->getTable()),
00326 "`e`.`entity_id`=`{$valueTable1}`.`entity_id`"
00327 . " AND `{$valueTable1}`.`attribute_id`='{$this->getAttribute()->getId()}'"
00328 . " AND `{$valueTable1}`.`store_id`='0'",
00329 array())
00330 ->joinLeft(
00331 array($valueTable2 => $this->getAttribute()->getBackend()->getTable()),
00332 "`e`.`entity_id`=`{$valueTable2}`.`entity_id`"
00333 . " AND `{$valueTable2}`.`attribute_id`='{$this->getAttribute()->getId()}'"
00334 . " AND `{$valueTable2}`.`store_id`='{$collection->getStoreId()}'",
00335 array()
00336 );
00337 $valueExpr = new Zend_Db_Expr("IFNULL(`{$valueTable2}`.`value`, `{$valueTable1}`.`value`)");
00338 }
00339
00340 $collection->getSelect()->order($valueExpr . ' ' . $dir);
00341 return $this;
00342 }
00343 }