00001 <?php 00002 /** 00003 * Magento 00004 * 00005 * NOTICE OF LICENSE 00006 * 00007 * This source file is subject to the Open Software License (OSL 3.0) 00008 * that is bundled with this package in the file LICENSE.txt. 00009 * It is also available through the world-wide-web at this URL: 00010 * http://opensource.org/licenses/osl-3.0.php 00011 * If you did not receive a copy of the license and are unable to 00012 * obtain it through the world-wide-web, please send an email 00013 * to license@magentocommerce.com so we can send you a copy immediately. 00014 * 00015 * DISCLAIMER 00016 * 00017 * Do not edit or add to this file if you wish to upgrade Magento to newer 00018 * versions in the future. If you wish to customize Magento for your 00019 * needs please refer to http://www.magentocommerce.com for more information. 00020 * 00021 * @category Mage 00022 * @package Mage_Checkout 00023 * @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com) 00024 * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) 00025 */ 00026 00027 /** 00028 * Shopping cart helper 00029 * 00030 * @author Magento Core Team <core@magentocommerce.com> 00031 */ 00032 class Mage_Checkout_Helper_Cart extends Mage_Core_Helper_Url 00033 { 00034 /** 00035 * Retrieve cart instance 00036 * 00037 * @return Mage_Checkout_Model_Cart 00038 */ 00039 public function getCart() 00040 { 00041 return Mage::getSingleton('checkout/cart'); 00042 } 00043 00044 /** 00045 * Retrieve url for add product to cart 00046 * 00047 * @param Mage_Catalog_Model_Product $product 00048 * @return string 00049 */ 00050 public function getAddUrl($product, $additional = array()) 00051 { 00052 /** 00053 * Identify continue shopping url 00054 */ 00055 // if ($currentProduct = Mage::registry('current_product')) { 00056 // /** 00057 // * go to product view page 00058 // */ 00059 // $continueShoppingUrl = $currentProduct->getProductUrl(); 00060 // } elseif ($currentCategory = Mage::registry('current_category')) { 00061 // /** 00062 // * go to category view page 00063 // */ 00064 // 00065 // $continueShoppingUrl = $currentCategory->getUrl().(count($this->_getRequest()->getQuery())!=0?'?'.http_build_qu//ery($this->_getRequest()->getQuery(), '', '&'):''); 00066 // 00067 // } else { 00068 // $continueShoppingUrl = $this->_getUrl('*/*/*', array('_current'=>true)); 00069 // } 00070 00071 $continueShoppingUrl = $this->getCurrentUrl(); 00072 00073 $params = array( 00074 Mage_Core_Controller_Front_Action::PARAM_NAME_URL_ENCODED => Mage::helper('core')->urlEncode($continueShoppingUrl), 00075 'product' => $product->getId() 00076 ); 00077 00078 if ($this->_getRequest()->getRouteName() == 'checkout' 00079 && $this->_getRequest()->getControllerName() == 'cart') { 00080 $params['in_cart'] = 1; 00081 } 00082 00083 if (count($additional)){ 00084 $params = array_merge($params, $additional); 00085 } 00086 00087 return $this->_getUrl('checkout/cart/add', $params); 00088 } 00089 00090 /** 00091 * Retrieve url for remove product from cart 00092 * 00093 * @param Mage_Sales_Quote_Item $item 00094 * @return string 00095 */ 00096 public function getRemoveUrl($item) 00097 { 00098 $params = array( 00099 'id'=>$item->getId(), 00100 Mage_Core_Controller_Front_Action::PARAM_NAME_BASE64_URL => $this->getCurrentBase64Url() 00101 ); 00102 return $this->_getUrl('checkout/cart/delete', $params); 00103 } 00104 00105 /** 00106 * Retrieve shopping cart url 00107 * 00108 * @return unknown 00109 */ 00110 public function getCartUrl() 00111 { 00112 return $this->_getUrl('checkout/cart'); 00113 } 00114 00115 /** 00116 * Retrieve current quote instance 00117 * 00118 * @return Mage_Sales_Model_Quote 00119 */ 00120 public function getQuote() 00121 { 00122 return Mage::getSingleton('checkout/session')->getQuote(); 00123 } 00124 00125 /** 00126 * Get shopping cart items count 00127 * 00128 * @return int 00129 */ 00130 public function getItemsCount() 00131 { 00132 return $this->getCart()->getItemsCount(); 00133 } 00134 00135 /** 00136 * Get shopping cart summary qty 00137 * 00138 * @return decimal 00139 */ 00140 public function getItemsQty() 00141 { 00142 return $this->getCart()->getItemsQty(); 00143 } 00144 00145 /** 00146 * Get shopping cart items summary (inchlude config settings) 00147 * 00148 * @return decimal 00149 */ 00150 public function getSummaryCount() 00151 { 00152 return $this->getCart()->getSummaryQty(); 00153 } 00154 00155 /** 00156 * Check qoute for virtual products only 00157 * 00158 * @return bool 00159 */ 00160 public function getIsVirtualQuote() 00161 { 00162 return $this->getQuote()->isVirtual(); 00163 } 00164 }