Mage_Catalog_Model_Product_Compare_Item Class Reference

Inheritance diagram for Mage_Catalog_Model_Product_Compare_Item:

Mage_Core_Model_Abstract Varien_Object

List of all members.

Public Member Functions

 addCustomerData (Mage_Customer_Model_Customer $customer)
 addVisitorId ($visitorId)
 loadByProduct ($product)
 addProductData ($product)
 getDataForSave ()
 bindCustomerLogin ()
 bindCustomerLogout (Varien_Event_Observer $observer)
 clean ()

Protected Member Functions

 _construct ()


Detailed Description

Definition at line 35 of file Item.php.


Member Function Documentation

_construct (  )  [protected]

Initialize resourse model

Reimplemented from Varien_Object.

Definition at line 41 of file Item.php.

00042     {
00043         $this->_init('catalog/product_compare_item');
00044     }

addCustomerData ( Mage_Customer_Model_Customer customer  ) 

Add customer data from customer object

Parameters:
Mage_Customer_Model_Customer $customer
Returns:
Mage_Catalog_Model_Product_Compare_Item

Definition at line 52 of file Item.php.

00053     {
00054         $this->setCustomerId($customer->getId());
00055         $this->setVisitorId(0);
00056         return $this;
00057     }

addProductData ( product  ) 

Set product data

Parameters:
mixed $product
Returns:
Mage_Catalog_Model_Product_Compare_Item

Definition at line 89 of file Item.php.

00090     {
00091         if ($product instanceof Mage_Catalog_Model_Product) {
00092             $this->setProductId($product->getId());
00093         }
00094         elseif(intval($product)) {
00095             $this->setProductId(intval($product));
00096         }
00097 
00098         return $this;
00099     }

addVisitorId ( visitorId  ) 

Set visitor

Parameters:
int $visitorId
Returns:
Mage_Catalog_Model_Product_Compare_Item

Definition at line 65 of file Item.php.

00066     {
00067         $this->setVisitorId($visitorId);
00068         return $this;
00069     }

bindCustomerLogin (  ) 

Customer login bind process

Returns:
Mage_Catalog_Model_Product_Compare_Item

Definition at line 121 of file Item.php.

00122     {
00123         $customer = Mage::getSingleton('customer/session')->getCustomer();
00124         $visitorItemCollection = Mage::getResourceModel('catalog/product_compare_item_collection')
00125             ->setObject('catalog/product_compare_item')
00126             ->setVisitorId(Mage::getSingleton('log/visitor')->getId())
00127             ->load();
00128 
00129         $customerItemCollection = $this->getResourceCollection()
00130             ->setCustomerId($customer->getId())
00131             ->useProductItem(true)
00132             ->load();
00133 
00134         $customerProductIds = $customerItemCollection->getProductIds();
00135 
00136         foreach ($visitorItemCollection as $item) {
00137             if (in_array($item->getProductId(), $customerProductIds)) {
00138                 $item->delete();
00139             }
00140             else {
00141                 $item->setCustomerId($customer->getId())
00142                     ->setVisitorId(0)
00143                     ->save();
00144             }
00145         }
00146 
00147         Mage::helper('catalog/product_compare')->calculate();
00148         return $this;
00149     }

bindCustomerLogout ( Varien_Event_Observer observer  ) 

Customer logout bind process

Parameters:
Varien_Event_Observer $observer
Returns:
Mage_Catalog_Model_Product_Compare_Item

Definition at line 157 of file Item.php.

00158     {
00159         Mage::getSingleton('log/visitor')->setCatalogCompareItemsCount(0);
00160         return $this;
00161     }

clean (  ) 

Clean compare items

Returns:
Mage_Catalog_Model_Product_Compare_Item

Definition at line 168 of file Item.php.

00169     {
00170         $this->_getResource()->clean($this);
00171         return $this;
00172     }

getDataForSave (  ) 

Retrieve data for save

Returns:
array

Definition at line 106 of file Item.php.

00107     {
00108         $data = array();
00109         $data['customer_id'] = $this->getCustomerId();
00110         $data['visitor_id']  = $this->getVisitorId();
00111         $data['product_id']  = $this->getProductId();
00112 
00113         return $data;
00114     }

loadByProduct ( product  ) 

Load compare item by product

Parameters:
mixed $product
Returns:
Mage_Catalog_Model_Product_Compare_Item

Definition at line 77 of file Item.php.

00078     {
00079         $this->_getResource()->loadByProduct($this, $product);
00080         return $this;
00081     }


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

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