Mage_Catalog_Model_Product_Status Class Reference

Inheritance diagram for Mage_Catalog_Model_Product_Status:

Mage_Core_Model_Abstract Varien_Object

List of all members.

Public Member Functions

 getProductAttribute ($attributeCode)
 addVisibleFilterToCollection (Mage_Eav_Model_Entity_Collection_Abstract $collection)
 addSaleableFilterToCollection (Mage_Eav_Model_Entity_Collection_Abstract $collection)
 getVisibleStatusIds ()
 getSaleableStatusIds ()
 updateProductStatus ($productId, $storeId, $value)
 getProductStatus ($productIds, $storeId=null)
 getFlatColums ()
 getFlatIndexes ()
 getFlatUpdateSelect ($store)
 setAttribute ($attribute)
 getAttribute ()
 addValueSortToCollection ($collection, $dir= 'asc')

Static Public Member Functions

static getOptionArray ()
static getAllOption ()
static getAllOptions ()
static getOptionText ($optionId)

Public Attributes

const STATUS_ENABLED = 1
const STATUS_DISABLED = 2

Protected Member Functions

 _construct ()
 _getResource ()

Protected Attributes

 $_attribute


Detailed Description

Definition at line 35 of file Status.php.


Member Function Documentation

_construct (  )  [protected]

Initialize resource model

Reimplemented from Varien_Object.

Definition at line 51 of file Status.php.

00052     {
00053         $this->_init('catalog/product_status');
00054     }

_getResource (  )  [protected]

Retrieve resource model wraper

Returns:
Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Status

Reimplemented from Mage_Core_Model_Abstract.

Definition at line 61 of file Status.php.

00062     {
00063         return parent::_getResource();
00064     }

addSaleableFilterToCollection ( Mage_Eav_Model_Entity_Collection_Abstract collection  ) 

Add saleable filter to Product Collection

Deprecated:
remove on new builds
Parameters:
Mage_Eav_Model_Entity_Collection_Abstract $collection
Returns:
Mage_Catalog_Model_Product_Status

Definition at line 97 of file Status.php.

00098     {
00099         //$collection->addAttributeToFilter('status', array('in'=>$this->getSaleableStatusIds()));
00100         return $this;
00101     }

addValueSortToCollection ( collection,
dir = 'asc' 
)

Add Value Sort To Collection Select

Parameters:
Mage_Eav_Model_Entity_Collection_Abstract $collection
string $dir direction
Returns:
Mage_Eav_Model_Entity_Attribute_Source_Abstract

Definition at line 307 of file Status.php.

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     }

addVisibleFilterToCollection ( Mage_Eav_Model_Entity_Collection_Abstract collection  ) 

Add visible filter to Product Collection

Deprecated:
remove on new builds
Parameters:
Mage_Eav_Model_Entity_Collection_Abstract $collection
Returns:
Mage_Catalog_Model_Product_Status

Definition at line 84 of file Status.php.

00085     {
00086         //$collection->addAttributeToFilter('status', array('in'=>$this->getVisibleStatusIds()));
00087         return $this;
00088     }

static getAllOption (  )  [static]

Retrieve option array with empty value

Returns:
array

Definition at line 142 of file Status.php.

00143     {
00144         $options = self::getOptionArray();
00145         array_unshift($options, array('value'=>'', 'label'=>''));
00146         return $options;
00147     }

static getAllOptions (  )  [static]

Retrieve option array with empty value

Returns:
array

Definition at line 154 of file Status.php.

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     }

getAttribute (  ) 

Get attribute instance

Returns:
Mage_Catalog_Model_Resource_Eav_Attribute

Definition at line 295 of file Status.php.

00296     {
00297         return $this->_attribute;
00298     }

getFlatColums (  ) 

---------------- Eav Source methods for Flat data ----------------------- Retrieve Column(s) for Flat

Returns:
array

Definition at line 251 of file Status.php.

00252     {
00253         return array();
00254     }

getFlatIndexes (  ) 

Retrieve Indexes for Flat

Returns:
array

Definition at line 261 of file Status.php.

00262     {
00263         return array();
00264     }

getFlatUpdateSelect ( store  ) 

Retrieve Select For Flat Attribute update

Parameters:
Mage_Eav_Model_Entity_Attribute_Abstract $attribute
int $store
Returns:
Varien_Db_Select|null

Definition at line 273 of file Status.php.

00274     {
00275         return null;
00276     }

static getOptionArray (  )  [static]

Retrieve option array

Returns:
array

Definition at line 129 of file Status.php.

00130     {
00131         return array(
00132             self::STATUS_ENABLED    => Mage::helper('catalog')->__('Enabled'),
00133             self::STATUS_DISABLED   => Mage::helper('catalog')->__('Disabled')
00134         );
00135     }

static getOptionText ( optionId  )  [static]

Retrieve option text by option value

Parameters:
string $optionId
Returns:
string

Definition at line 177 of file Status.php.

00178     {
00179         $options = self::getOptionArray();
00180         return isset($options[$optionId]) ? $options[$optionId] : null;
00181     }

getProductAttribute ( attributeCode  ) 

Retrieve Product Attribute by code

Parameters:
string $attributeCode
Returns:
Mage_Eav_Model_Entity_Attribute_Abstract

Definition at line 72 of file Status.php.

00073     {
00074         return $this->_getResource()->getProductAttribute($attributeCode);
00075     }

getProductStatus ( productIds,
storeId = null 
)

Retrieve Product(s) status for store Return array where key is product, value - status

Parameters:
int|array $productIds
int $storeId
Returns:
array

Definition at line 237 of file Status.php.

00238     {
00239         return $this->getResource()->getProductStatus($productIds, $storeId);
00240     }

getSaleableStatusIds (  ) 

Retrieve Saleable Status Ids Default Product Enable status

Returns:
array

Definition at line 119 of file Status.php.

00120     {
00121         return array(self::STATUS_ENABLED);
00122     }

getVisibleStatusIds (  ) 

Retrieve Visible Status Ids

Returns:
array

Definition at line 108 of file Status.php.

00109     {
00110         return array(self::STATUS_ENABLED);
00111     }

setAttribute ( attribute  ) 

Set attribute instance

Parameters:
Mage_Catalog_Model_Resource_Eav_Attribute $attribute
Returns:
Mage_Eav_Model_Entity_Attribute_Frontend_Abstract

Definition at line 284 of file Status.php.

00285     {
00286         $this->_attribute = $attribute;
00287         return $this;
00288     }

updateProductStatus ( productId,
storeId,
value 
)

Update status value for product

Parameters:
int $productId
int $storeId
int $value
Returns:
Mage_Catalog_Model_Product_Status

Definition at line 191 of file Status.php.

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     }


Member Data Documentation

$_attribute [protected]

Definition at line 45 of file Status.php.

const STATUS_DISABLED = 2

Definition at line 38 of file Status.php.

const STATUS_ENABLED = 1

Definition at line 37 of file Status.php.


The documentation for this class was generated from the following file:

Generated on Sat Jul 4 17:23:41 2009 for Magento by  doxygen 1.5.8