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 block
29: *
30: * @category Mage
31: * @package Mage_Checkout
32: * @author Magento Core Team <core@magentocommerce.com>
33: */
34: class Mage_Checkout_Block_Cart extends Mage_Checkout_Block_Cart_Abstract
35: {
36: /**
37: * Prepare Quote Item Product URLs
38: *
39: */
40: public function __construct()
41: {
42: parent::__construct();
43: $this->prepareItemUrls();
44: }
45:
46: /**
47: * prepare cart items URLs
48: */
49: public function prepareItemUrls()
50: {
51: $products = array();
52: /* @var $item Mage_Sales_Model_Quote_Item */
53: foreach ($this->getItems() as $item) {
54: $product = $item->getProduct();
55: $option = $item->getOptionByCode('product_type');
56: if ($option) {
57: $product = $option->getProduct();
58: }
59:
60: if ($item->getStoreId() != Mage::app()->getStore()->getId()
61: && !$item->getRedirectUrl()
62: && !$product->isVisibleInSiteVisibility())
63: {
64: $products[$product->getId()] = $item->getStoreId();
65: }
66: }
67:
68: if ($products) {
69: $products = Mage::getResourceSingleton('catalog/url')
70: ->getRewriteByProductStore($products);
71: foreach ($this->getItems() as $item) {
72: $product = $item->getProduct();
73: $option = $item->getOptionByCode('product_type');
74: if ($option) {
75: $product = $option->getProduct();
76: }
77:
78: if (isset($products[$product->getId()])) {
79: $object = new Varien_Object($products[$product->getId()]);
80: $item->getProduct()->setUrlDataObject($object);
81: }
82: }
83: }
84: }
85:
86: public function chooseTemplate()
87: {
88: $itemsCount = $this->getItemsCount() ? $this->getItemsCount() : $this->getQuote()->getItemsCount();
89: if ($itemsCount) {
90: $this->setTemplate($this->getCartTemplate());
91: } else {
92: $this->setTemplate($this->getEmptyTemplate());
93: }
94: }
95:
96: public function hasError()
97: {
98: return $this->getQuote()->getHasError();
99: }
100:
101: public function getItemsSummaryQty()
102: {
103: return $this->getQuote()->getItemsSummaryQty();
104: }
105:
106: public function isWishlistActive()
107: {
108: $isActive = $this->_getData('is_wishlist_active');
109: if ($isActive === null) {
110: $isActive = Mage::getStoreConfig('wishlist/general/active')
111: && Mage::getSingleton('customer/session')->isLoggedIn();
112: $this->setIsWishlistActive($isActive);
113: }
114: return $isActive;
115: }
116:
117: public function getCheckoutUrl()
118: {
119: return $this->getUrl('checkout/onepage', array('_secure'=>true));
120: }
121:
122: public function getContinueShoppingUrl()
123: {
124: $url = $this->getData('continue_shopping_url');
125: if (is_null($url)) {
126: $url = Mage::getSingleton('checkout/session')->getContinueShoppingUrl(true);
127: if (!$url) {
128: $url = Mage::getUrl();
129: }
130: $this->setData('continue_shopping_url', $url);
131: }
132: return $url;
133: }
134:
135: public function getIsVirtual()
136: {
137: return $this->helper('checkout/cart')->getIsVirtualQuote();
138: }
139:
140: /**
141: * Return list of available checkout methods
142: *
143: * @param string $nameInLayout Container block alias in layout
144: * @return array
145: */
146: public function getMethods($nameInLayout)
147: {
148: if ($this->getChild($nameInLayout) instanceof Mage_Core_Block_Abstract) {
149: return $this->getChild($nameInLayout)->getSortedChildren();
150: }
151: return array();
152: }
153:
154: /**
155: * Return HTML of checkout method (link, button etc.)
156: *
157: * @param string $name Block name in layout
158: * @return string
159: */
160: public function getMethodHtml($name)
161: {
162: $block = $this->getLayout()->getBlock($name);
163: if (!$block) {
164: Mage::throwException(Mage::helper('checkout')->__('Invalid method: %s', $name));
165: }
166: return $block->toHtml();
167: }
168:
169: /**
170: * Return customer quote items
171: *
172: * @return array
173: */
174: public function getItems()
175: {
176: if ($this->getCustomItems()) {
177: return $this->getCustomItems();
178: }
179:
180: return parent::getItems();
181: }
182: }
183: