1: <?php
2: /**
3: * Magento
4: *
5: * NOTICE OF LICENSE
6: *
7: * This source file is subject to the Open Software License (OSL 3.0)
8: * that is bundled with this package in the file LICENSE.txt.
9: * It is also available through the world-wide-web at this URL:
10: * http://opensource.org/licenses/osl-3.0.php
11: * If you did not receive a copy of the license and are unable to
12: * obtain it through the world-wide-web, please send an email
13: * to license@magentocommerce.com so we can send you a copy immediately.
14: *
15: * DISCLAIMER
16: *
17: * Do not edit or add to this file if you wish to upgrade Magento to newer
18: * versions in the future. If you wish to customize Magento for your
19: * needs please refer to http://www.magentocommerce.com for more information.
20: *
21: * @category Mage
22: * @package Mage_Checkout
23: * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24: * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25: */
26:
27: /**
28: * Shopping cart helper
29: *
30: * @author Magento Core Team <core@magentocommerce.com>
31: */
32: class Mage_Checkout_Helper_Cart extends Mage_Core_Helper_Url
33: {
34: const XML_PATH_REDIRECT_TO_CART = 'checkout/cart/redirect_to_cart';
35:
36: /**
37: * Retrieve cart instance
38: *
39: * @return Mage_Checkout_Model_Cart
40: */
41: public function getCart()
42: {
43: return Mage::getSingleton('checkout/cart');
44: }
45:
46: /**
47: * Retrieve url for add product to cart
48: *
49: * @param Mage_Catalog_Model_Product $product
50: * @return string
51: */
52: public function getAddUrl($product, $additional = array())
53: {
54: $continueUrl = Mage::helper('core')->urlEncode($this->getCurrentUrl());
55: $urlParamName = Mage_Core_Controller_Front_Action::PARAM_NAME_URL_ENCODED;
56:
57: $routeParams = array(
58: $urlParamName => $continueUrl,
59: 'product' => $product->getEntityId()
60: );
61:
62: if (!empty($additional)) {
63: $routeParams = array_merge($routeParams, $additional);
64: }
65:
66: if ($product->hasUrlDataObject()) {
67: $routeParams['_store'] = $product->getUrlDataObject()->getStoreId();
68: $routeParams['_store_to_url'] = true;
69: }
70:
71: if ($this->_getRequest()->getRouteName() == 'checkout'
72: && $this->_getRequest()->getControllerName() == 'cart') {
73: $routeParams['in_cart'] = 1;
74: }
75:
76: return $this->_getUrl('checkout/cart/add', $routeParams);
77: }
78:
79: /**
80: * Retrieve url for remove product from cart
81: *
82: * @param Mage_Sales_Quote_Item $item
83: * @return string
84: */
85: public function getRemoveUrl($item)
86: {
87: $params = array(
88: 'id'=>$item->getId(),
89: Mage_Core_Controller_Front_Action::PARAM_NAME_BASE64_URL => $this->getCurrentBase64Url()
90: );
91: return $this->_getUrl('checkout/cart/delete', $params);
92: }
93:
94: /**
95: * Retrieve shopping cart url
96: *
97: * @return unknown
98: */
99: public function getCartUrl()
100: {
101: return $this->_getUrl('checkout/cart');
102: }
103:
104: /**
105: * Retrieve current quote instance
106: *
107: * @return Mage_Sales_Model_Quote
108: */
109: public function getQuote()
110: {
111: return Mage::getSingleton('checkout/session')->getQuote();
112: }
113:
114: /**
115: * Get shopping cart items count
116: *
117: * @return int
118: */
119: public function getItemsCount()
120: {
121: return $this->getCart()->getItemsCount();
122: }
123:
124: /**
125: * Get shopping cart summary qty
126: *
127: * @return decimal
128: */
129: public function getItemsQty()
130: {
131: return $this->getCart()->getItemsQty();
132: }
133:
134: /**
135: * Get shopping cart items summary (inchlude config settings)
136: *
137: * @return decimal
138: */
139: public function getSummaryCount()
140: {
141: return $this->getCart()->getSummaryQty();
142: }
143:
144: /**
145: * Check qoute for virtual products only
146: *
147: * @return bool
148: */
149: public function getIsVirtualQuote()
150: {
151: return $this->getQuote()->isVirtual();
152: }
153:
154: /**
155: * Checks if customer should be redirected to shopping cart after adding a product
156: *
157: * @param int|string|Mage_Core_Model_Store $store
158: * @return bool
159: */
160: public function getShouldRedirectToCart($store = null)
161: {
162: return Mage::getStoreConfigFlag(self::XML_PATH_REDIRECT_TO_CART, $store);
163: }
164: }
165: