1: <?php
2: /**
3: * Magento
4: *
5: * NOTICE OF LICENSE
6: *
7: * This source file is subject to the Open Software License (OSL 3.0)
8: * that is bundled with this package in the file LICENSE.txt.
9: * It is also available through the world-wide-web at this URL:
10: * http://opensource.org/licenses/osl-3.0.php
11: * If you did not receive a copy of the license and are unable to
12: * obtain it through the world-wide-web, please send an email
13: * to license@magentocommerce.com so we can send you a copy immediately.
14: *
15: * DISCLAIMER
16: *
17: * Do not edit or add to this file if you wish to upgrade Magento to newer
18: * versions in the future. If you wish to customize Magento for your
19: * needs please refer to http://www.magentocommerce.com for more information.
20: *
21: * @category Mage
22: * @package Mage_Rss
23: * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24: * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25: */
26: class Mage_Rss_Block_Catalog_Abstract extends Mage_Rss_Block_Abstract
27: {
28: /**
29: * Stored price block instances
30: * @var array
31: */
32: protected $_priceBlock = array();
33:
34: /**
35: * Stored price blocks info
36: * @var array
37: */
38: protected $_priceBlockTypes = array();
39:
40: /**
41: * Default values for price block and template
42: * @var string
43: */
44: protected $_priceBlockDefaultTemplate = 'catalog/rss/product/price.phtml';
45: protected $_priceBlockDefaultType = 'catalog/product_price';
46:
47: /**
48: * Whether to show "As low as" as a link
49: * @var bool
50: */
51: protected $_useLinkForAsLowAs = true;
52:
53: /**
54: * Default MAP renderer type
55: *
56: * @var string
57: */
58: protected $_mapRenderer = 'msrp_rss';
59:
60: /**
61: * Return Price Block renderer for specified product type
62: *
63: * @param string $productTypeId Catalog Product type
64: * @return Mage_Core_Block_Abstract
65: */
66: protected function _getPriceBlock($productTypeId)
67: {
68: if (!isset($this->_priceBlock[$productTypeId])) {
69: $block = $this->_priceBlockDefaultType;
70: if (isset($this->_priceBlockTypes[$productTypeId])) {
71: if ($this->_priceBlockTypes[$productTypeId]['block'] != '') {
72: $block = $this->_priceBlockTypes[$productTypeId]['block'];
73: }
74: }
75: $this->_priceBlock[$productTypeId] = $this->getLayout()->createBlock($block);
76: }
77: return $this->_priceBlock[$productTypeId];
78: }
79:
80: /**
81: * Return template for Price Block renderer
82: *
83: * @param string $productTypeId Catalog Product type
84: * @return string
85: */
86: protected function _getPriceBlockTemplate($productTypeId)
87: {
88: if (isset($this->_priceBlockTypes[$productTypeId])) {
89: if ($this->_priceBlockTypes[$productTypeId]['template'] != '') {
90: return $this->_priceBlockTypes[$productTypeId]['template'];
91: }
92: }
93: return $this->_priceBlockDefaultTemplate;
94: }
95:
96: /**
97: * Returns product price html for RSS feed
98: *
99: * @param Mage_Catalog_Model_Product $product
100: * @param bool $displayMinimalPrice Display "As low as" etc.
101: * @param string $idSuffix Suffix for HTML containers
102: * @return string
103: */
104: public function getPriceHtml($product, $displayMinimalPrice = false, $idSuffix='')
105: {
106: $type_id = $product->getTypeId();
107: if (Mage::helper('catalog')->canApplyMsrp($product)) {
108: $type_id = $this->_mapRenderer;
109: }
110:
111: return $this->_getPriceBlock($type_id)
112: ->setTemplate($this->_getPriceBlockTemplate($type_id))
113: ->setProduct($product)
114: ->setDisplayMinimalPrice($displayMinimalPrice)
115: ->setIdSuffix($idSuffix)
116: ->setUseLinkForAsLowAs($this->_useLinkForAsLowAs)
117: ->toHtml();
118: }
119:
120: /**
121: * Adding customized price template for product type, used as action in layouts
122: *
123: * @param string $type Catalog Product Type
124: * @param string $block Block Type
125: * @param string $template Template
126: */
127: public function addPriceBlockType($type, $block = '', $template = '')
128: {
129: if ($type) {
130: $this->_priceBlockTypes[$type] = array(
131: 'block' => $block,
132: 'template' => $template
133: );
134: }
135: }
136: }
137: