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 abstract class Mage_Checkout_Block_Cart_Abstract extends Mage_Core_Block_Template
00035 {
00036 protected $_customer = null;
00037 protected $_checkout = null;
00038 protected $_quote = null;
00039
00040 protected $_totals;
00041 protected $_itemRenders = array();
00042
00043 public function __construct()
00044 {
00045 parent::__construct();
00046 $this->addItemRender('default', 'checkout/cart_item_renderer', 'checkout/cart/item/default.phtml');
00047 }
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057 public function addItemRender($productType, $blockType, $template)
00058 {
00059 $this->_itemRenders[$productType] = array(
00060 'block' => $blockType,
00061 'template' => $template,
00062 'blockInstance' => null
00063 );
00064 return $this;
00065 }
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075 public function getItemRender($type)
00076 {
00077 return $this->getItemRendererInfo();
00078 }
00079
00080
00081
00082
00083
00084
00085
00086 public function getItemRendererInfo($type)
00087 {
00088 if (isset($this->_itemRenders[$type])) {
00089 return $this->_itemRenders[$type];
00090 }
00091 return $this->_itemRenders['default'];
00092 }
00093
00094
00095
00096
00097
00098
00099
00100 public function getItemRenderer($type)
00101 {
00102 if (!isset($this->_itemRenders[$type])) {
00103 $type = 'default';
00104 }
00105 if (is_null($this->_itemRenders[$type]['blockInstance'])) {
00106 $this->_itemRenders[$type]['blockInstance'] = $this->getLayout()
00107 ->createBlock($this->_itemRenders[$type]['block'])
00108 ->setTemplate($this->_itemRenders[$type]['template'])
00109 ->setRenderedBlock($this);
00110 }
00111
00112 return $this->_itemRenders[$type]['blockInstance'];
00113 }
00114
00115
00116
00117
00118
00119
00120
00121 public function getCustomer()
00122 {
00123 if (null === $this->_customer) {
00124 $this->_customer = Mage::getSingleton('customer/session')->getCustomer();
00125 }
00126 return $this->_customer;
00127 }
00128
00129
00130
00131
00132
00133
00134 public function getCheckout()
00135 {
00136 if (null === $this->_checkout) {
00137 $this->_checkout = Mage::getSingleton('checkout/session');
00138 }
00139 return $this->_checkout;
00140 }
00141
00142
00143
00144
00145
00146
00147 public function getQuote()
00148 {
00149 if (null === $this->_quote) {
00150 $this->_quote = $this->getCheckout()->getQuote();
00151 }
00152 return $this->_quote;
00153 }
00154
00155
00156
00157
00158
00159
00160 public function getItems()
00161 {
00162 return $this->getQuote()->getAllVisibleItems();
00163 }
00164
00165
00166
00167
00168
00169
00170
00171 public function getItemHtml(Mage_Sales_Model_Quote_Item $item)
00172 {
00173 $renderer = $this->getItemRenderer($item->getProductType())->setItem($item);
00174 return $renderer->toHtml();
00175 }
00176
00177 public function getTotals()
00178 {
00179 return $this->getTotalsCache();
00180 }
00181
00182 public function getTotalsCache()
00183 {
00184 if (empty($this->_totals)) {
00185 $this->_totals = $this->getQuote()->getTotals();
00186 }
00187 return $this->_totals;
00188 }
00189 }