00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 class Mage_Checkout_Block_Cart_Sidebar extends Mage_Checkout_Block_Cart_Abstract
00036 {
00037 const XML_PATH_CHECKOUT_SIDEBAR_COUNT = 'checkout/sidebar/count';
00038
00039 public function __construct()
00040 {
00041 parent::__construct();
00042 $this->addItemRender('default', 'checkout/cart_item_renderer', 'checkout/cart/sidebar/default.phtml');
00043 }
00044
00045
00046
00047
00048
00049
00050 public function getRecentItems($count = null)
00051 {
00052 if ($count === null) {
00053 $count = $this->getData('item_count');
00054 }
00055 if ($count === null) {
00056 $count = Mage::getStoreConfig(self::XML_PATH_CHECKOUT_SIDEBAR_COUNT);
00057 }
00058 $items = array();
00059 if (!$this->getSummaryCount()) {
00060 return $items;
00061 }
00062 $i = 0;
00063 $allItems = array_reverse($this->getItems());
00064 foreach ($allItems as $item) {
00065 $items[] = $item;
00066 if (++$i == $count) {
00067 break;
00068 }
00069 }
00070 return $items;
00071 }
00072
00073
00074
00075
00076
00077
00078
00079 public function getSubtotal($skipTax = false)
00080 {
00081 $subtotal = 0;
00082 $totals = $this->getTotals();
00083 if (isset($totals['subtotal'])) {
00084 $subtotal = $totals['subtotal']->getValue();
00085 if (!$skipTax) {
00086 if ((!$this->helper('tax')->displayCartBothPrices()) && $this->helper('tax')->displayCartPriceInclTax()) {
00087 $subtotal = $this->_addTax($subtotal);
00088 }
00089 }
00090 }
00091 return $subtotal;
00092 }
00093
00094
00095
00096
00097
00098
00099
00100 public function getSubtotalInclTax()
00101 {
00102 if (!$this->helper('tax')->displayCartBothPrices()) {
00103 return 0;
00104 }
00105 return $this->_addTax($this->getSubtotal(true));
00106 }
00107
00108 private function _addTax($price, $exclShippingTax=true) {
00109 $totals = $this->getTotals();
00110 if (isset($totals['tax'])) {
00111 if ($exclShippingTax) {
00112 $price += $totals['tax']->getValue()-$this->_getShippingTaxAmount();
00113 } else {
00114 $price += $totals['tax']->getValue();
00115 }
00116 }
00117 return $price;
00118 }
00119
00120 protected function _getShippingTaxAmount()
00121 {
00122 return $this->getQuote()->getShippingAddress()->getShippingTaxAmount();
00123 }
00124
00125 public function getSummaryCount()
00126 {
00127 return Mage::getSingleton('checkout/cart')->getSummaryQty();
00128 }
00129
00130 public function getIncExcTax($flag)
00131 {
00132 $text = Mage::helper('tax')->getIncExcText($flag);
00133 return $text ? ' ('.$text.')' : '';
00134 }
00135
00136 public function isPossibleOnepageCheckout()
00137 {
00138 return $this->helper('checkout')->canOnepageCheckout();
00139 }
00140
00141 public function getCheckoutUrl()
00142 {
00143 return $this->helper('checkout/url')->getCheckoutUrl();
00144 }
00145
00146
00147
00148
00149
00150
00151 protected function _toHtml()
00152 {
00153 $html = '';
00154 if ((bool) Mage::app()->getStore()->getConfig('checkout/sidebar/display')) {
00155 $html = parent::_toHtml();
00156 }
00157 return $html;
00158 }
00159 }