Mage_Catalog_Helper_Product_Compare Class Reference

Inheritance diagram for Mage_Catalog_Helper_Product_Compare:

Mage_Core_Helper_Url Mage_Core_Helper_Abstract

List of all members.

Public Member Functions

 getListUrl ()
 getAddUrl ($product)
 getAddToWishlistUrl ($product)
 getAddToCartUrl ($product)
 getRemoveUrl ($item)
 getClearListUrl ()
 getItemCollection ()
 calculate ()
 getItemCount ()
 hasItems ()
 setAllowUsedFlat ($flag)
 getAllowUsedFlat ()

Protected Member Functions

 _getUrlParams ($product)

Protected Attributes

 $_itemCollection
 $_hasItems
 $_allowUsedFlat = true


Detailed Description

Definition at line 35 of file Compare.php.


Member Function Documentation

_getUrlParams ( product  )  [protected]

Get parameters used for build add product to compare list urls

Parameters:
Mage_Catalog_Model_Product $product
Returns:
array

Definition at line 84 of file Compare.php.

00085     {
00086         return array(
00087             'product' => $product->getId(),
00088             Mage_Core_Controller_Front_Action::PARAM_NAME_URL_ENCODED => $this->getEncodedUrl()
00089         );
00090     }

calculate (  ) 

Calculate cache product compare collection

Returns:
Mage_Catalog_Helper_Product_Compare

Definition at line 200 of file Compare.php.

00201     {
00202         if (!Mage::getSingleton('customer/session')->isLoggedIn()
00203             and !Mage::getSingleton('log/visitor')->hasCatalogCompareItemsCount()
00204         ) {
00205             Mage::getSingleton('log/visitor')->setCatalogCompareItemsCount(0);
00206             return $this;
00207         }
00208 
00209         $itemCollection = Mage::getResourceModel('catalog/product_compare_item_collection');
00210         /* @var $itemCollection Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Compare_Item_Collection */
00211         $itemCollection->setStoreId(Mage::app()->getStore()->getId());
00212         if (Mage::getSingleton('customer/session')->isLoggedIn()) {
00213             $itemCollection->setCustomerId(Mage::getSingleton('customer/session')->getCustomerId());
00214         }
00215         else {
00216             $itemCollection->setVisitorId(Mage::getSingleton('log/visitor')->getId());
00217         }
00218         Mage::getSingleton('catalog/product_visibility')
00219             ->addVisibleInSiteFilterToCollection($itemCollection);
00220 
00221         Mage::getSingleton('log/visitor')->setCatalogCompareItemsCount($itemCollection->getSize());
00222         return $this;
00223     }

getAddToCartUrl ( product  ) 

Retrive add to cart url

Parameters:
Mage_Catalog_Model_Product $product
Returns:
string

Definition at line 127 of file Compare.php.

00128     {
00129         $beforeCompareUrl = Mage::getSingleton('catalog/session')->getBeforeCompareUrl();
00130         $params = array(
00131             'product'=>$product->getId(),
00132             Mage_Core_Controller_Front_Action::PARAM_NAME_URL_ENCODED => $this->getEncodedUrl($beforeCompareUrl)
00133         );
00134 
00135         return $this->_getUrl('checkout/cart/add', $params);
00136     }

getAddToWishlistUrl ( product  ) 

Retrive add to wishlist url

Parameters:
Mage_Catalog_Model_Product $product
Returns:
string

Definition at line 109 of file Compare.php.

00110     {
00111         $beforeCompareUrl = Mage::getSingleton('catalog/session')->getBeforeCompareUrl();
00112 
00113         $params = array(
00114             'product'=>$product->getId(),
00115             Mage_Core_Controller_Front_Action::PARAM_NAME_URL_ENCODED => $this->getEncodedUrl($beforeCompareUrl)
00116         );
00117 
00118         return $this->_getUrl('wishlist/index/add', $params);
00119     }

getAddUrl ( product  ) 

Retrieve url for adding product to conpare list

Parameters:
Mage_Catalog_Model_Product $product
Returns:
string

Definition at line 98 of file Compare.php.

00099     {
00100         return $this->_getUrl('catalog/product_compare/add', $this->_getUrlParams($product));
00101     }

getAllowUsedFlat (  ) 

Retrieve is allow used flat (for collection)

Returns:
bool

Definition at line 265 of file Compare.php.

00266     {
00267         return $this->_allowUsedFlat;
00268     }

getClearListUrl (  ) 

Retrieve clear compare list url

Returns:
string

Definition at line 158 of file Compare.php.

00159     {
00160         $params = array(
00161             Mage_Core_Controller_Front_Action::PARAM_NAME_URL_ENCODED => $this->getEncodedUrl()
00162         );
00163         return $this->_getUrl('catalog/product_compare/clear', $params);
00164     }

getItemCollection (  ) 

Retrieve compare list items collection

Returns:

Definition at line 171 of file Compare.php.

00172     {
00173         if (!$this->_itemCollection) {
00174             $this->_itemCollection = Mage::getResourceModel('catalog/product_compare_item_collection')
00175                 ->useProductItem(true)
00176                 ->setStoreId(Mage::app()->getStore()->getId());
00177 
00178             if (Mage::getSingleton('customer/session')->isLoggedIn()) {
00179                 $this->_itemCollection->setCustomerId(Mage::getSingleton('customer/session')->getCustomerId());
00180             }
00181             else {
00182                 $this->_itemCollection->setVisitorId(Mage::getSingleton('log/visitor')->getId());
00183             }
00184 
00185             Mage::getSingleton('catalog/product_visibility')->addVisibleInSiteFilterToCollection($this->_itemCollection);
00186 
00187             $this->_itemCollection->addAttributeToSelect('name')
00188                 ->addUrlRewrite()
00189                 ->load();
00190         }
00191 
00192         return $this->_itemCollection;
00193     }

getItemCount (  ) 

Retrieve count of items in compare list

Returns:
int

Definition at line 230 of file Compare.php.

00231     {
00232         if (is_null(Mage::getSingleton('log/visitor')->getCatalogCompareItemsCount())) {
00233             $this->calculate();
00234         }
00235         return Mage::getSingleton('log/visitor')->getCatalogCompareItemsCount();
00236     }

getListUrl (  ) 

Retrieve compare list url

Returns:
string

Definition at line 63 of file Compare.php.

00064     {
00065          $itemIds = array();
00066          foreach ($this->getItemCollection() as $item) {
00067              $itemIds[] = $item->getId();
00068          }
00069 
00070          $params = array(
00071             'items'=>implode(',', $itemIds),
00072             Mage_Core_Controller_Front_Action::PARAM_NAME_URL_ENCODED => $this->getEncodedUrl()
00073          );
00074 
00075          return $this->_getUrl('catalog/product_compare', $params);
00076     }

getRemoveUrl ( item  ) 

Retrieve remove item from compare list url

Parameters:
$item 
Returns:
string

Definition at line 144 of file Compare.php.

00145     {
00146         $params = array(
00147             'product'=>$item->getId(),
00148             Mage_Core_Controller_Front_Action::PARAM_NAME_URL_ENCODED => $this->getEncodedUrl()
00149         );
00150         return $this->_getUrl('catalog/product_compare/remove', $params);
00151     }

hasItems (  ) 

Check has items

Returns:
bool

Definition at line 243 of file Compare.php.

00244     {
00245         return $this->getItemCount() > 0;
00246     }

setAllowUsedFlat ( flag  ) 

Set is allow used flat (for collection)

Parameters:
bool $flag
Returns:
Mage_Catalog_Helper_Product_Compare

Definition at line 254 of file Compare.php.

00255     {
00256         $this->_allowUsedFlat = (bool)$flag;
00257         return $this;
00258     }


Member Data Documentation

$_allowUsedFlat = true [protected]

Definition at line 56 of file Compare.php.

$_hasItems [protected]

Definition at line 49 of file Compare.php.

$_itemCollection [protected]

Definition at line 42 of file Compare.php.


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

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