*/ class Mage_Sales_Block_Items_Abstract extends Mage_Core_Block_Template { /** * Renderers with render type key * block => the block name * template => the template file * renderer => the block object * * @var array */ protected $_itemRenders = array(); /** * Initialize default item renderer */ protected function _construct() { parent::_construct(); $this->addItemRender('default', 'checkout/cart_item_renderer', 'checkout/cart/item/default.phtml'); } /** * Add renderer for item product type * * @param string $type * @param string $block * @param string $template * @return Mage_Checkout_Block_Cart_Abstract */ public function addItemRender($type, $block, $template) { $this->_itemRenders[$type] = array( 'block' => $block, 'template' => $template, 'renderer' => null ); return $this; } /** * Retrieve item renderer block * * @param string $type * @return Mage_Core_Block_Abstract */ public function getItemRenderer($type) { if (!isset($this->_itemRenders[$type])) { $type = 'default'; } if (is_null($this->_itemRenders[$type]['renderer'])) { $this->_itemRenders[$type]['renderer'] = $this->getLayout() ->createBlock($this->_itemRenders[$type]['block']) ->setTemplate($this->_itemRenders[$type]['template']) ->setRenderedBlock($this); } return $this->_itemRenders[$type]['renderer']; } /** * Prepare item before output * * @param Mage_Core_Block_Abstract $renderer * @return Mage_Sales_Block_Items_Abstract */ protected function _prepareItem(Mage_Core_Block_Abstract $renderer) { return $this; } /** * Return product type for quote/order item * * @param Varien_Object $item * @return string */ protected function _getItemType(Varien_Object $item) { if ($item->getOrderItem()) { $type = $item->getOrderItem()->getProductType(); } elseif ($item instanceof Mage_Sales_Model_Quote_Address_Item) { $type = $item->getQuoteItem()->getProductType(); } else { $type = $item->getProductType(); } return $type; } /** * Get item row html * * @param Varien_Object $item * @return string */ public function getItemHtml(Varien_Object $item) { $type = $this->_getItemType($item); $block = $this->getItemRenderer($type) ->setItem($item); $this->_prepareItem($block); return $block->toHtml(); } }