Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Status Class Reference

Inheritance diagram for Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Status:

Mage_Core_Model_Mysql4_Abstract Mage_Core_Model_Resource_Abstract

List of all members.

Public Member Functions

 getProductAttribute ($attributeCode)
 refreshEnabledIndex ($productId, $storeId)
 updateProductStatus ($productId, $storId, $value)
 getProductStatus ($productIds, $storeId=null)

Protected Member Functions

 _construct ()
 _getProductAttribute ($attribute)

Protected Attributes

 $_productAttributes = array()


Detailed Description

Definition at line 35 of file Status.php.


Member Function Documentation

_construct (  )  [protected]

Initialize connection

Reimplemented from Mage_Core_Model_Resource_Abstract.

Definition at line 48 of file Status.php.

00049     {
00050         $this->_init('catalog/product_enabled_index', 'product_id');
00051     }

_getProductAttribute ( attribute  )  [protected]

Retrieve product attribute

Returns:
Mage_Eav_Model_Entity_Attribute_Abstract

Definition at line 69 of file Status.php.

00070     {
00071         if (empty($this->_productAttributes[$attribute])) {
00072             $this->_productAttributes[$attribute] = Mage::getSingleton('catalog/product')->getResource()->getAttribute($attribute);
00073         }
00074         return $this->_productAttributes[$attribute];
00075     }

getProductAttribute ( attributeCode  ) 

Retrieve product attribute (public method for status model)

Parameters:
string $attributeCode
Returns:
Mage_Eav_Model_Entity_Attribute_Abstract

Definition at line 59 of file Status.php.

00060     {
00061         return $this->_getProductAttribute($attributeCode);
00062     }

getProductStatus ( productIds,
storeId = null 
)

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

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

Definition at line 185 of file Status.php.

00186     {
00187         $statuses = array();
00188 
00189         $attribute = $this->_getProductAttribute('status');
00190         $attributeTable = $attribute->getBackend()->getTable();
00191 
00192         if (!is_array($productIds)) {
00193             $productIds = array($productIds);
00194         }
00195 
00196         if (is_null($storeId) || $storeId == 0) {
00197             $select = $this->_getReadAdapter()->select()
00198                 ->from($attributeTable, array('entity_id', 'value'))
00199                 ->where('entity_id IN(?)', $productIds)
00200                 ->where('attribute_id=?', $attribute->getAttributeId())
00201                 ->where('store_id=?', 0);
00202             $rows = $this->_getWriteAdapter()->fetchPairs($select);
00203         }
00204         else {
00205             $select = $this->_getReadAdapter()->select()
00206                 ->from(
00207                     array('t1' => $attributeTable),
00208                     array('entity_id', 'IFNULL(t2.value, t1.value) as value'))
00209                 ->joinLeft(
00210                     array('t2' => $attributeTable),
00211                     $this->_getReadAdapter()->quoteInto('t1.entity_id = t2.entity_id AND t1.attribute_id = t2.attribute_id AND t2.store_id=?', $storeId),
00212                     array()
00213                 )
00214                 ->where('t1.store_id = ?', 0)
00215                 ->where('t1.attribute_id = ?', $attribute->getAttributeId())
00216                 ->where('t1.entity_id IN(?)', $productIds);
00217             $rows = $this->_getWriteAdapter()->fetchPairs($select);
00218         }
00219 
00220         foreach ($productIds as $productId) {
00221             if (isset($rows[$productId])) {
00222                 $statuses[$productId] = $rows[$productId];
00223             }
00224             else {
00225                 $statuses[$productId] = -1;
00226             }
00227         }
00228 
00229         return $statuses;
00230     }

refreshEnabledIndex ( productId,
storeId 
)

Refresh enabled index cache

Parameters:
int $productId
int $storeId
Returns:
Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Status

Definition at line 85 of file Status.php.

00086     {
00087         $statusAttributeId      = $this->_getProductAttribute('status')->getId();
00088         $visibilityAttributeId  = $this->_getProductAttribute('visibility')->getId();
00089         $statusTable            = $this->_getProductAttribute('status')->getBackend()->getTable();
00090         $visibilityTable        = $this->_getProductAttribute('visibility')->getBackend()->getTable();
00091 
00092         $indexTable = $this->getTable('catalog/product_enabled_index');
00093 
00094         if ($storeId == 0) {
00095             foreach (Mage::app()->getStores() as $store) {
00096                 $this->refreshEnabledIndex($productId, $store->getId());
00097             }
00098 
00099             return $this;
00100         }
00101 
00102         $this->_getWriteAdapter()->delete($indexTable, array(
00103             $this->_getWriteAdapter()->quoteInto('product_id=?', $productId),
00104             $this->_getWriteAdapter()->quoteInto('store_id=?', $storeId)
00105         ));
00106 
00107         $query = "INSERT INTO $indexTable
00108             SELECT
00109                 {$productId}, {$storeId}, IFNULL(t_v.value, t_v_default.value)
00110             FROM
00111                 {$visibilityTable} AS t_v_default
00112             LEFT JOIN {$visibilityTable} AS `t_v`
00113                 ON (t_v.entity_id = t_v_default.entity_id) AND (t_v.attribute_id='{$visibilityAttributeId}') AND (t_v.store_id='{$storeId}')
00114             INNER JOIN {$statusTable} AS `t_s_default`
00115                 ON (t_s_default.entity_id = t_v_default.entity_id) AND (t_s_default.attribute_id='{$statusAttributeId}') AND t_s_default.store_id=0
00116             LEFT JOIN {$statusTable} AS `t_s`
00117                 ON (t_s.entity_id = t_v_default.entity_id) AND (t_s.attribute_id='{$statusAttributeId}') AND (t_s.store_id='{$storeId}')
00118             WHERE
00119                 t_v_default.entity_id={$productId}
00120                 AND t_v_default.attribute_id='{$visibilityAttributeId}' AND t_v_default.store_id=0
00121                 AND (IFNULL(t_s.value, t_s_default.value)=".Mage_Catalog_Model_Product_Status::STATUS_ENABLED.")";
00122         $this->_getWriteAdapter()->query($query);
00123 
00124         return $this;
00125     }

updateProductStatus ( productId,
storId,
value 
)

Update product status for store

Parameters:
int $productId
int $storId
int $value
Returns:
Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Status

Definition at line 136 of file Status.php.

00137     {
00138         $statusAttributeId  = $this->_getProductAttribute('status')->getId();
00139         $statusEntityTypeId = $this->_getProductAttribute('status')->getEntityTypeId();
00140         $statusTable        = $this->_getProductAttribute('status')->getBackend()->getTable();
00141         $refreshIndex       = true;
00142 
00143         $prop = array(
00144             'entity_type_id' => $statusEntityTypeId,
00145             'attribute_id'   => $statusAttributeId,
00146             'store_id'       => $storId,
00147             'entity_id'      => $productId,
00148             'value'          => $value
00149         );
00150 
00151         $select = $this->_getWriteAdapter()->select()
00152             ->from($statusTable)
00153             ->where('attribute_id=?', $statusAttributeId)
00154             ->where('store_id=?', $storId)
00155             ->where('entity_id=?', $productId);
00156         $row = $this->_getWriteAdapter()->fetchRow($select);
00157 
00158         if ($row) {
00159             if ($row['value'] == $value) {
00160                 $refreshIndex = false;
00161             }
00162             else {
00163                 $this->_getWriteAdapter()->update($statusTable, $prop, $this->_getWriteAdapter()->quoteInto('value_id=?', $row['value_id']));
00164             }
00165         }
00166         else {
00167             $this->_getWriteAdapter()->insert($statusTable, $prop);
00168         }
00169 
00170         if ($refreshIndex) {
00171             $this->refreshEnabledIndex($productId, $storId);
00172         }
00173 
00174         return $this;
00175     }


Member Data Documentation

$_productAttributes = array() [protected]

Definition at line 42 of file Status.php.


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

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