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 () |
Definition at line 35 of file Item.php.
_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
Mage_Customer_Model_Customer | $customer |
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
mixed | $product |
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 | ) |
bindCustomerLogin | ( | ) |
Customer login bind process
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
Varien_Event_Observer | $observer |
Definition at line 157 of file Item.php.
00158 { 00159 Mage::getSingleton('log/visitor')->setCatalogCompareItemsCount(0); 00160 return $this; 00161 }
clean | ( | ) |
Clean compare items
Definition at line 168 of file Item.php.
00169 { 00170 $this->_getResource()->clean($this); 00171 return $this; 00172 }
getDataForSave | ( | ) |
loadByProduct | ( | $ | product | ) |
Load compare item by product
mixed | $product |
Definition at line 77 of file Item.php.
00078 { 00079 $this->_getResource()->loadByProduct($this, $product); 00080 return $this; 00081 }