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: 36:
37: class Mage_Checkout_Block_Cart_Item_Renderer extends Mage_Core_Block_Template
38: {
39:
40: protected $_checkoutSession;
41: protected $_item;
42: protected $_productUrl = null;
43: protected $_productThumbnail = null;
44:
45: 46: 47: 48: 49:
50: protected $_strictQtyMode = true;
51:
52: 53: 54: 55: 56:
57: protected $_ignoreProductUrl = false;
58:
59: 60: 61: 62: 63: 64:
65: public function setItem(Mage_Sales_Model_Quote_Item_Abstract $item)
66: {
67: $this->_item = $item;
68: return $this;
69: }
70:
71: 72: 73: 74: 75:
76: public function getItem()
77: {
78: return $this->_item;
79: }
80:
81: 82: 83: 84: 85:
86: public function getProduct()
87: {
88: return $this->getItem()->getProduct();
89: }
90:
91: public function overrideProductThumbnail($productThumbnail)
92: {
93: $this->_productThumbnail = $productThumbnail;
94: return $this;
95: }
96:
97: 98: 99: 100: 101:
102: public function getProductThumbnail()
103: {
104: if (!is_null($this->_productThumbnail)) {
105: return $this->_productThumbnail;
106: }
107: return $this->helper('catalog/image')->init($this->getProduct(), 'thumbnail');
108: }
109:
110: public function overrideProductUrl($productUrl)
111: {
112: $this->_productUrl = $productUrl;
113: return $this;
114: }
115:
116: 117: 118: 119: 120:
121: public function hasProductUrl()
122: {
123: if ($this->_ignoreProductUrl) {
124: return false;
125: }
126:
127: if ($this->_productUrl || $this->getItem()->getRedirectUrl()) {
128: return true;
129: }
130:
131: $product = $this->getProduct();
132: $option = $this->getItem()->getOptionByCode('product_type');
133: if ($option) {
134: $product = $option->getProduct();
135: }
136:
137: if ($product->isVisibleInSiteVisibility()) {
138: return true;
139: }
140: else {
141: if ($product->hasUrlDataObject()) {
142: $data = $product->getUrlDataObject();
143: if (in_array($data->getVisibility(), $product->getVisibleInSiteVisibilities())) {
144: return true;
145: }
146: }
147: }
148:
149: return false;
150: }
151:
152: 153: 154: 155: 156:
157: public function getProductUrl()
158: {
159: if (!is_null($this->_productUrl)) {
160: return $this->_productUrl;
161: }
162: if ($this->getItem()->getRedirectUrl()) {
163: return $this->getItem()->getRedirectUrl();
164: }
165:
166: $product = $this->getProduct();
167: $option = $this->getItem()->getOptionByCode('product_type');
168: if ($option) {
169: $product = $option->getProduct();
170: }
171:
172: return $product->getUrlModel()->getUrl($product);
173: }
174:
175: 176: 177: 178: 179:
180: public function getProductName()
181: {
182: if ($this->hasProductName()) {
183: return $this->getData('product_name');
184: }
185: return $this->getProduct()->getName();
186: }
187:
188: 189: 190: 191: 192:
193: public function getProductOptions()
194: {
195:
196: $helper = Mage::helper('catalog/product_configuration');
197: return $helper->getCustomOptions($this->getItem());
198: }
199:
200: 201: 202: 203: 204:
205: public function getOptionList()
206: {
207: return $this->getProductOptions();
208: }
209:
210: 211: 212: 213: 214:
215: public function getConfigureUrl()
216: {
217: return $this->getUrl(
218: 'checkout/cart/configure',
219: array('id' => $this->getItem()->getId())
220: );
221: }
222:
223: 224: 225: 226: 227:
228: public function getDeleteUrl()
229: {
230: if ($this->hasDeleteUrl()) {
231: return $this->getData('delete_url');
232: }
233:
234: return $this->getUrl(
235: 'checkout/cart/delete',
236: array(
237: 'id'=>$this->getItem()->getId(),
238: Mage_Core_Controller_Front_Action::PARAM_NAME_URL_ENCODED => $this->helper('core/url')->getEncodedUrl()
239: )
240: );
241: }
242:
243: 244: 245: 246: 247:
248: public function getQty()
249: {
250: if (!$this->_strictQtyMode && (string)$this->getItem()->getQty() == '') {
251: return '';
252: }
253: return $this->getItem()->getQty() * 1;
254: }
255:
256: 257: 258: 259: 260: 261:
262: public function getIsInStock()
263: {
264: if ($this->getItem()->getProduct()->isSaleable()) {
265: if ($this->getItem()->getProduct()->getStockItem()->getQty() >= $this->getItem()->getQty()) {
266: return true;
267: }
268: }
269: return false;
270: }
271:
272: 273: 274: 275: 276:
277: public function getCheckoutSession()
278: {
279: if (null === $this->_checkoutSession) {
280: $this->_checkoutSession = Mage::getSingleton('checkout/session');
281: }
282: return $this->_checkoutSession;
283: }
284:
285: 286: 287: 288: 289: 290: 291: 292: 293:
294: public function getMessages()
295: {
296: $messages = array();
297: $quoteItem = $this->getItem();
298:
299:
300: $baseMessages = $quoteItem->getMessage(false);
301: if ($baseMessages) {
302: foreach ($baseMessages as $message) {
303: $messages[] = array(
304: 'text' => $message,
305: 'type' => $quoteItem->getHasError() ? 'error' : 'notice'
306: );
307: }
308: }
309:
310:
311: $checkoutSession = $this->getCheckoutSession();
312: if ($checkoutSession) {
313:
314: $collection = $checkoutSession->getQuoteItemMessages($quoteItem->getId(), true);
315: if ($collection) {
316: $additionalMessages = $collection->getItems();
317: foreach ($additionalMessages as $message) {
318:
319: $messages[] = array(
320: 'text' => $message->getCode(),
321: 'type' => ($message->getType() == Mage_Core_Model_Message::ERROR) ? 'error' : 'notice'
322: );
323: }
324: }
325: }
326:
327: return $messages;
328: }
329:
330: 331: 332: 333: 334: 335: 336: 337: 338: 339: 340: 341: 342: 343: 344: 345: 346: 347: 348: 349:
350: public function getFormatedOptionValue($optionValue)
351: {
352:
353: $helper = Mage::helper('catalog/product_configuration');
354: $params = array(
355: 'max_length' => 55,
356: 'cut_replacer' => ' <a href="#" class="dots" onclick="return false">...</a>'
357: );
358: return $helper->getFormattedOptionValue($optionValue, $params);
359: }
360:
361: 362: 363: 364: 365:
366: public function isProductVisible()
367: {
368: return $this->getProduct()->isVisibleInSiteVisibility();
369: }
370:
371: 372: 373: 374: 375:
376: public function getProductAdditionalInformationBlock()
377: {
378: return $this->getLayout()->getBlock('additional.product.info');
379: }
380:
381: 382: 383: 384: 385: 386:
387: public function getMsrpHtml($item)
388: {
389: return $this->getLayout()->createBlock('catalog/product_price')
390: ->setTemplate('catalog/product/price_msrp_item.phtml')
391: ->setProduct($item->getProduct())
392: ->toHtml();
393: }
394:
395: 396: 397: 398: 399: 400:
401: public function setQtyMode($strict)
402: {
403: $this->_strictQtyMode = $strict;
404: return $this;
405: }
406:
407: 408: 409: 410: 411: 412:
413: public function setIgnoreProductUrl($ignore = true)
414: {
415: $this->_ignoreProductUrl = $ignore;
416: return $this;
417: }
418: }
419: