Mage_Wishlist_Model_Wishlist Class Reference

Inheritance diagram for Mage_Wishlist_Model_Wishlist:

Mage_Core_Model_Abstract Varien_Object

List of all members.

Public Member Functions

 loadByCustomer ($customer, $create=false)
 loadByCode ($code)
 getItemCollection ()
 getProductCollection ()
 addNewItem ($productId)
 setCustomerId ($customerId)
 getCustomerId ()
 getDataForSave ()
 getSharedStoreIds ()
 setSharedStoreIds ($storeIds)
 getStore ()
 setStore ($store)
 getItemsCount ()
 isSalable ()

Protected Member Functions

 _construct ()
 _getSharingRandomCode ()

Protected Attributes

 $_itemCollection = null
 $_store = null
 $_storeIds = null


Detailed Description

Definition at line 35 of file Wishlist.php.


Member Function Documentation

_construct (  )  [protected]

Initialize resource model

Reimplemented from Varien_Object.

Definition at line 62 of file Wishlist.php.

00063     {
00064         $this->_init('wishlist/wishlist');
00065     }

_getSharingRandomCode (  )  [protected]

Retrieve sharing code (random string)

Returns:
string

Definition at line 111 of file Wishlist.php.

00112     {
00113         return md5(microtime() . rand());
00114     }

addNewItem ( productId  ) 

Add new item to wishlist

Parameters:
int $productId
Returns:
Mage_Wishlist_Model_Item

Definition at line 156 of file Wishlist.php.

00157     {
00158         $item = Mage::getModel('wishlist/item');
00159         $item->loadByProductWishlist($this->getId(), $productId, $this->getSharedStoreIds());
00160 
00161         if (!$item->getId()) {
00162             $item->setProductId($productId)
00163                 ->setWishlistId($this->getId())
00164                 ->setAddedAt(now())
00165                 ->setStoreId($this->getStore()->getId())
00166                 ->save();
00167         }
00168 
00169         return $item;
00170     }

getCustomerId (  ) 

Retrieve customer id

Returns:
Mage_Wishlist_Model_Wishlist

Definition at line 188 of file Wishlist.php.

00189     {
00190         return $this->getData($this->_getResource()->getCustomerIdFieldName());
00191     }

getDataForSave (  ) 

Retrieve data for save

Returns:
array

Definition at line 198 of file Wishlist.php.

00199     {
00200         $data = array();
00201         $data[$this->_getResource()->getCustomerIdFieldName()] = $this->getCustomerId();
00202         $data['shared']      = (int) $this->getShared();
00203         $data['sharing_code']= $this->getSharingCode();
00204         return $data;
00205     }

getItemCollection (  ) 

Retrieve wishlist item collection

Returns:
Mage_Wishlist_Model_Mysql4_Item_Collection

Definition at line 121 of file Wishlist.php.

00122     {
00123         if(is_null($this->_itemCollection)) {
00124             $this->_itemCollection =  Mage::getResourceModel('wishlist/item_collection')
00125                 ->setStoreId($this->getStore()->getId())
00126                 ->addWishlistFilter($this);
00127         }
00128 
00129         return $this->_itemCollection;
00130     }

getItemsCount (  ) 

Retrieve wishlist items count

Returns:
int

Definition at line 262 of file Wishlist.php.

00263     {
00264         return $this->_getResource()->fetchItemsCount($this);
00265     }

getProductCollection (  ) 

Retrieve Product collection

Returns:
Mage_Wishlist_Model_Mysql4_Product_Collection

Definition at line 137 of file Wishlist.php.

00138     {
00139         $collection = $this->getData('product_collection');
00140         if (is_null($collection)) {
00141             $collection = Mage::getResourceModel('wishlist/product_collection')
00142                 ->setStoreId($this->getStore()->getId())
00143                 ->addWishlistFilter($this)
00144                 ->addWishListSortOrder();
00145             $this->setData('product_collection', $collection);
00146         }
00147         return $collection;
00148     }

getSharedStoreIds (  ) 

Retrieve shared store ids

Returns:
array

Definition at line 212 of file Wishlist.php.

00213     {
00214         if (is_null($this->_storeIds)) {
00215             $this->_storeIds = $this->getStore()->getWebsite()->getStoreIds();
00216         }
00217         return $this->_storeIds;
00218     }

getStore (  ) 

Retrieve wishlist store object

Returns:
Mage_Core_Model_Store

Definition at line 237 of file Wishlist.php.

00238     {
00239         if (is_null($this->_store)) {
00240             $this->setStore(Mage::app()->getStore());
00241         }
00242         return $this->_store;
00243     }

isSalable (  ) 

Retrieve wishlist has salable item(s)

Returns:
bool

Definition at line 272 of file Wishlist.php.

00273     {
00274         foreach ($this->getProductCollection() as $product) {
00275             if ($product->getIsSalable()) {
00276                 return true;
00277             }
00278         }
00279         return false;
00280     }

loadByCode ( code  ) 

Load by sharing code

Parameters:
string $code
Returns:
Mage_Wishlist_Model_Wishlist

Definition at line 97 of file Wishlist.php.

00098     {
00099         $this->_getResource()->load($this, $code, 'sharing_code');
00100         if(!$this->getShared()) {
00101             $this->setId(null);
00102         }
00103         return $this;
00104     }

loadByCustomer ( customer,
create = false 
)

Load wishlist by customer

Parameters:
mixed $customer
bool $create Create wishlist if don't exists
Returns:
Mage_Wishlist_Model_Wishlist

Definition at line 74 of file Wishlist.php.

00075     {
00076         if ($customer instanceof Mage_Customer_Model_Customer) {
00077             $customer = $customer->getId();
00078         }
00079 
00080         $customerIdFieldName = $this->_getResource()->getCustomerIdFieldName();
00081         $this->_getResource()->load($this, $customer, $customerIdFieldName);
00082         if (!$this->getId() && $create) {
00083             $this->setCustomerId($customer);
00084             $this->setSharingCode($this->_getSharingRandomCode());
00085             $this->save();
00086         }
00087 
00088         return $this;
00089     }

setCustomerId ( customerId  ) 

Set customer id

Parameters:
int $customerId
Returns:
Mage_Wishlist_Model_Wishlist

Definition at line 178 of file Wishlist.php.

00179     {
00180         return $this->setData($this->_getResource()->getCustomerIdFieldName(), $customerId);
00181     }

setSharedStoreIds ( storeIds  ) 

Set shared store ids

Parameters:
array $storeIds
Returns:
Mage_Wishlist_Model_Wishlist

Definition at line 226 of file Wishlist.php.

00227     {
00228         $this->_storeIds = $storeIds;
00229         return $this;
00230     }

setStore ( store  ) 

Set wishlist store

Parameters:
Mage_Core_Model_Store $store
Returns:
Mage_Wishlist_Model_Wishlist

Definition at line 251 of file Wishlist.php.

00252     {
00253         $this->_store = $store;
00254         return $this;
00255     }


Member Data Documentation

$_itemCollection = null [protected]

Definition at line 42 of file Wishlist.php.

$_store = null [protected]

Definition at line 49 of file Wishlist.php.

$_storeIds = null [protected]

Definition at line 56 of file Wishlist.php.


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

Generated on Sat Jul 4 17:24:57 2009 for Magento by  doxygen 1.5.8