00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 class Mage_Catalog_Model_Product_Compare_List extends Varien_Object
00035 {
00036 public function addProduct($product)
00037 {
00038 $item = Mage::getModel('catalog/product_compare_item');
00039 $this->_addVisitorToItem($item);
00040
00041 $item->loadByProduct($product);
00042
00043 if (!$item->getId()) {
00044 $item->addProductData($product);
00045 $item->save();
00046 }
00047 return $this;
00048 }
00049
00050 public function addProducts($productIds)
00051 {
00052 if (is_array($productIds)) {
00053 foreach ($productIds as $productId) {
00054 $this->addProduct($productId);
00055 }
00056 }
00057 return $this;
00058 }
00059
00060 public function getItemCollection()
00061 {
00062 return Mage::getResourceModel('catalog/product_compare_item_collection');
00063 }
00064
00065 public function removeProduct()
00066 {
00067
00068 }
00069
00070 protected function _addVisitorToItem($item)
00071 {
00072 if (Mage::getSingleton('customer/session')->isLoggedIn()) {
00073 $item->addCustomerData(Mage::getSingleton('customer/session')->getCustomer());
00074 }
00075 else {
00076 $item->addVisitorId(Mage::getSingleton('log/visitor')->getId());
00077 }
00078 return $this;
00079 }
00080
00081 public function hasItems($customerId, $visitorId)
00082 {
00083 return Mage::getResourceSingleton('catalog/product_compare_item')->getCount($customerId, $visitorId);
00084 }
00085 }