1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26:
27:
28: 29: 30: 31: 32: 33: 34:
35: class extends Mage_Checkout_Block_Cart_Abstract
36: {
37: const = 'checkout/sidebar/count';
38:
39: 40: 41:
42: public function __construct()
43: {
44: parent::__construct();
45: $this->addItemRender('default', 'checkout/cart_item_renderer', 'checkout/cart/sidebar/default.phtml');
46: }
47:
48: 49: 50: 51: 52:
53: public function getItemCount()
54: {
55: $count = $this->getData('item_count');
56: if (is_null($count)) {
57: $count = Mage::getStoreConfig(self::XML_PATH_CHECKOUT_SIDEBAR_COUNT);
58: $this->setData('item_count', $count);
59: }
60: return $count;
61: }
62:
63: 64: 65: 66: 67:
68: public function getRecentItems($count = null)
69: {
70: if ($count === null) {
71: $count = $this->getItemCount();
72: }
73:
74: $items = array();
75: if (!$this->getSummaryCount()) {
76: return $items;
77: }
78:
79: $i = 0;
80: $allItems = array_reverse($this->getItems());
81: foreach ($allItems as $item) {
82:
83: if (!$item->getProduct()->isVisibleInSiteVisibility()) {
84: $productId = $item->getProduct()->getId();
85: $products = Mage::getResourceSingleton('catalog/url')
86: ->getRewriteByProductStore(array($productId => $item->getStoreId()));
87: if (!isset($products[$productId])) {
88: continue;
89: }
90: $urlDataObject = new Varien_Object($products[$productId]);
91: $item->getProduct()->setUrlDataObject($urlDataObject);
92: }
93:
94: $items[] = $item;
95: if (++$i == $count) {
96: break;
97: }
98: }
99:
100: return $items;
101: }
102:
103: 104: 105: 106: 107: 108: 109: 110:
111: public function getSubtotal($skipTax = true)
112: {
113: $subtotal = 0;
114: $totals = $this->getTotals();
115: $config = Mage::getSingleton('tax/config');
116: if (isset($totals['subtotal'])) {
117: if ($config->displayCartSubtotalBoth()) {
118: if ($skipTax) {
119: $subtotal = $totals['subtotal']->getValueExclTax();
120: } else {
121: $subtotal = $totals['subtotal']->getValueInclTax();
122: }
123: } elseif($config->displayCartSubtotalInclTax()) {
124: $subtotal = $totals['subtotal']->getValueInclTax();
125: } else {
126: $subtotal = $totals['subtotal']->getValue();
127: if (!$skipTax && isset($totals['tax'])) {
128: $subtotal+= $totals['tax']->getValue();
129: }
130: }
131: }
132: return $subtotal;
133: }
134:
135: 136: 137: 138: 139: 140:
141: public function getSubtotalInclTax()
142: {
143: if (!Mage::getSingleton('tax/config')->displayCartSubtotalBoth()) {
144: return 0;
145: }
146: return $this->getSubtotal(false);
147: }
148:
149: 150: 151: 152: 153: 154: 155:
156: private function _addTax($price, $exclShippingTax=true) {
157: $totals = $this->getTotals();
158: if (isset($totals['tax'])) {
159: if ($exclShippingTax) {
160: $price += $totals['tax']->getValue()-$this->_getShippingTaxAmount();
161: } else {
162: $price += $totals['tax']->getValue();
163: }
164: }
165: return $price;
166: }
167:
168: 169: 170: 171: 172:
173: protected function _getShippingTaxAmount()
174: {
175: $quote = $this->getCustomQuote() ? $this->getCustomQuote() : $this->getQuote();
176: return $quote->getShippingAddress()->getShippingTaxAmount();
177: }
178:
179: 180: 181: 182: 183:
184: public function getSummaryCount()
185: {
186: if ($this->getData('summary_qty')) {
187: return $this->getData('summary_qty');
188: }
189: return Mage::getSingleton('checkout/cart')->getSummaryQty();
190: }
191:
192: 193: 194: 195: 196: 197:
198: public function getIncExcTax($flag)
199: {
200: $text = Mage::helper('tax')->getIncExcText($flag);
201: return $text ? ' ('.$text.')' : '';
202: }
203:
204: 205: 206: 207: 208:
209: public function isPossibleOnepageCheckout()
210: {
211: return $this->helper('checkout')->canOnepageCheckout() && !$this->getQuote()->getHasError();
212: }
213:
214: 215: 216: 217: 218:
219: public function getCheckoutUrl()
220: {
221: return $this->helper('checkout/url')->getCheckoutUrl();
222: }
223:
224: 225: 226: 227: 228:
229: public function ()
230: {
231: return (bool) Mage::app()->getStore()->getConfig('checkout/sidebar/display');
232: }
233:
234: 235: 236: 237: 238:
239: public function getItems()
240: {
241: if ($this->getCustomQuote()) {
242: return $this->getCustomQuote()->getAllVisibleItems();
243: }
244:
245: return parent::getItems();
246: }
247:
248: 249: 250: 251: 252:
253: public function getTotalsCache()
254: {
255: if (empty($this->_totals)) {
256: $quote = $this->getCustomQuote() ? $this->getCustomQuote() : $this->getQuote();
257: $this->_totals = $quote->getTotals();
258: }
259: return $this->_totals;
260: }
261:
262: 263: 264: 265: 266:
267: public function getCacheKeyInfo()
268: {
269: $cacheKeyInfo = parent::getCacheKeyInfo();
270: $cacheKeyInfo['item_renders'] = $this->_serializeRenders();
271: return $cacheKeyInfo;
272: }
273:
274: 275: 276: 277: 278:
279: protected function _serializeRenders()
280: {
281: $result = array();
282: foreach ($this->_itemRenders as $type => $renderer) {
283: $result[] = implode('|', array($type, $renderer['block'], $renderer['template']));
284: }
285: return implode('|', $result);
286: }
287:
288: 289: 290: 291: 292: 293:
294: public function deserializeRenders($renders)
295: {
296: if (!is_string($renders)) {
297: return $this;
298: }
299:
300: $renders = explode('|', $renders);
301: while (!empty($renders)) {
302: $template = array_pop($renders);
303: $block = array_pop($renders);
304: $type = array_pop($renders);
305: if (!$template || !$block || !$type) {
306: continue;
307: }
308: $this->addItemRender($type, $block, $template);
309: }
310:
311: return $this;
312: }
313: }
314: