Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Compare_Item_Collection Class Reference

Inheritance diagram for Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Compare_Item_Collection:

Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection Mage_Catalog_Model_Resource_Eav_Mysql4_Collection_Abstract Mage_Eav_Model_Entity_Collection_Abstract Varien_Data_Collection_Db Varien_Data_Collection

List of all members.

Public Member Functions

 setCustomerId ($customerId)
 setVisitorId ($visitorId)
 getCustomerId ()
 getVisitorId ()
 getConditionForJoin ()
 _addJoinToSelect ()
 getComparableAttributes ()
 loadComparableAttributes ()
 useProductItem ()
 getProductIds ()
 clear ()
 isEnabledFlat ()

Protected Member Functions

 _construct ()
 _getAttributeSetIds ()
 _getAttributeIdsBySetIds (array $setIds)

Protected Attributes

 $_customerId = 0
 $_visitorId = 0
 $_comparableAttributes


Detailed Description

Definition at line 35 of file Collection.php.


Member Function Documentation

_addJoinToSelect (  ) 

Add join to select

Returns:
Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Compare_Item_Collection

Definition at line 139 of file Collection.php.

00140     {
00141         $this->joinField(
00142             'catalog_compare_item_id',
00143             'catalog/compare_item',
00144             'catalog_compare_item_id',
00145             'product_id=entity_id',
00146             $this->getConditionForJoin()
00147         );
00148         $this->joinTable(
00149             'catalog/compare_item',
00150             'catalog_compare_item_id=catalog_compare_item_id',
00151             array('product_id', 'customer_id', 'visitor_id'));
00152         $this->addStoreFilter();
00153         return $this;
00154     }

_construct (  )  [protected]

Initialize resources

Reimplemented from Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection.

Definition at line 62 of file Collection.php.

00063     {
00064         $this->_init('catalog/product_compare_item', 'catalog/product');
00065 
00066         $this->_productWebsiteTable = $this->getResource()->getTable('catalog/product_website');
00067         $this->_productCategoryTable= $this->getResource()->getTable('catalog/category_product');
00068     }

_getAttributeIdsBySetIds ( array setIds  )  [protected]

Retrieve attribute ids by set ids

Parameters:
array $setIds
Returns:
array

Definition at line 206 of file Collection.php.

00207     {
00208         $select = $this->getConnection()->select()
00209             ->distinct(true)
00210             ->from($this->getTable('eav/entity_attribute'), 'attribute_id')
00211             ->where('attribute_set_id IN(?)', $setIds);
00212         return $this->getConnection()->fetchCol($select);
00213     }

_getAttributeSetIds (  )  [protected]

Retrieve comapre products attribute set ids

Returns:
array

Definition at line 161 of file Collection.php.

00162     {
00163         // prepare compare items table conditions
00164         $compareConds = array(
00165             'compare.product_id=entity.entity_id',
00166         );
00167         if ($this->getCustomerId()) {
00168             $compareConds[] = $this->getConnection()
00169                 ->quoteInto('compare.customer_id=?', $this->getCustomerId());
00170         } else {
00171             $compareConds[] = $this->getConnection()
00172                 ->quoteInto('compare.visitor_id=?', $this->getVisitorId());
00173         }
00174 
00175         // prepare website filter
00176         $websiteId    = Mage::app()->getStore($this->getStoreId())->getWebsiteId();
00177         $websiteConds = array(
00178             'website.product_id=entity.entity_id',
00179             $this->getConnection()->quoteInto('website.website_id=?', $websiteId)
00180         );
00181 
00182         // retrieve attribute sets
00183         $select = $this->getConnection()->select()
00184             ->distinct(true)
00185             ->from(
00186                 array('entity' => $this->getEntity()->getEntityTable()),
00187                 'attribute_set_id')
00188             ->join(
00189                 array('website' => $this->getTable('catalog/product_website')),
00190                 join(' AND ', $websiteConds),
00191                 array())
00192             ->join(
00193                 array('compare' => $this->getTable('catalog/compare_item')),
00194                 join(' AND ', $compareConds),
00195                 array()
00196             );
00197         return $this->getConnection()->fetchCol($select);
00198     }

clear (  ) 

Clear compare items by condition

Returns:
Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Compare_Item_Collection

Reimplemented from Varien_Data_Collection.

Definition at line 300 of file Collection.php.

00301     {
00302         $where = array();
00303         if ($this->getCustomerId()) {
00304             $where[] = $this->getConnection()->quoteInto('customer_id=?', $this->getCustomerId());
00305         }
00306         if ($this->getVisitorId()) {
00307             $where[] = $this->getConnection()->quoteInto('visitor_id=?', $this->getVisitorId());
00308         }
00309         if (!$where) {
00310             return $this;
00311         }
00312 
00313         $this->getConnection()->delete($this->getTable('catalog/compare_item'), $where);
00314 
00315         return $this;
00316     }

getComparableAttributes (  ) 

Retrieve Merged comparable attributes for compared product items

Returns:
this

Definition at line 220 of file Collection.php.

00221     {
00222         if (is_null($this->_comparableAttributes)) {
00223             $setIds = $this->_getAttributeSetIds();
00224             if ($setIds) {
00225                 $attributeIds = $this->_getAttributeIdsBySetIds($setIds);
00226 
00227                 $select = $this->getConnection()->select()
00228                     ->from($this->getTable('eav/attribute'))
00229                     ->where('is_comparable=?', 1)
00230                     ->where('attribute_id IN(?)', $attributeIds);
00231                 $attributesData = $this->getConnection()->fetchAll($select);
00232 
00233                 if ($attributesData) {
00234                     $entityType = 'catalog_product';
00235                     Mage::getSingleton('eav/config')
00236                         ->importAttributesData($entityType, $attributesData);
00237                     foreach ($attributesData as $data) {
00238                         $attribute = Mage::getSingleton('eav/config')
00239                             ->getAttribute($entityType, $data['attribute_code']);
00240                         $this->_comparableAttributes[$attribute->getAttributeCode()] = $attribute;
00241                     }
00242                     unset($attributesData);
00243                 }
00244             }
00245             else {
00246                 $this->_comparableAttributes = array();
00247             }
00248         }
00249         return $this->_comparableAttributes;
00250     }

getConditionForJoin (  ) 

Retrieve condition for join filters

Returns:
array|null

Definition at line 121 of file Collection.php.

00122     {
00123         if ($this->getCustomerId()) {
00124             return array('customer_id' => $this->getCustomerId());
00125         }
00126 
00127         if ($this->getVisitorId()) {
00128             return array('visitor_id' => $this->getVisitorId());
00129         }
00130 
00131         return null;
00132     }

getCustomerId (  ) 

Retrieve customer filter applied to collection

Returns:
int

Definition at line 101 of file Collection.php.

00102     {
00103         return $this->_customerId;
00104     }

getProductIds (  ) 

Retrieve product ids from collection

Returns:
array

Definition at line 285 of file Collection.php.

00286     {
00287         $ids = array();
00288         foreach ($this->getItems() as $item) {
00289             $ids[] = $item->getProductId();
00290         }
00291 
00292         return $ids;
00293     }

getVisitorId (  ) 

Retrieve visitor filter applied to collection

Returns:
int

Definition at line 111 of file Collection.php.

00112     {
00113         return $this->_visitorId;
00114     }

isEnabledFlat (  ) 

Retrieve is flat enabled flag Overwrite disable flat for compared item if required EAV resource

Returns:
bool

Reimplemented from Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection.

Definition at line 324 of file Collection.php.

00325     {
00326         if (!Mage::helper('catalog/product_compare')->getAllowUsedFlat()) {
00327             return false;
00328         }
00329         return parent::isEnabledFlat();
00330     }

loadComparableAttributes (  ) 

Load Comparable attributes

Returns:
Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Compare_Item_Collection

Definition at line 257 of file Collection.php.

00258     {
00259         $comparableAttributes = $this->getComparableAttributes();
00260         $attributes = array();
00261         foreach ($comparableAttributes as $attribute) {
00262             $attributes[] = $attribute->getAttributeCode();
00263         }
00264         $this->addAttributeToSelect($attributes);
00265 
00266         return $this;
00267     }

setCustomerId ( customerId  ) 

Set customer filter to collection

Parameters:
int $customerId
Returns:
Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Compare_Item_Collection

Definition at line 76 of file Collection.php.

00077     {
00078         $this->_customerId = $customerId;
00079         $this->_addJoinToSelect();
00080         return $this;
00081     }

setVisitorId ( visitorId  ) 

Set visitor filter to collection

Parameters:
int $visitorId
Returns:
Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Compare_Item_Collection

Definition at line 89 of file Collection.php.

00090     {
00091         $this->_visitorId = $visitorId;
00092         $this->_addJoinToSelect();
00093         return $this;
00094     }

useProductItem (  ) 

Use product as collection item

Returns:
Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Compare_Item_Collection

Definition at line 274 of file Collection.php.

00275     {
00276         $this->setObject('catalog/product');
00277         return $this;
00278     }


Member Data Documentation

$_comparableAttributes [protected]

Definition at line 56 of file Collection.php.

$_customerId = 0 [protected]

Definition at line 42 of file Collection.php.

$_visitorId = 0 [protected]

Definition at line 49 of file Collection.php.


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

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