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_ProductAlert
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:
27:
28: /**
29: * Product Alert Abstract Email Block
30: *
31: * @category Mage
32: * @package Mage_ProductAlert
33: * @author Magento Core Team <core@magentocommerce.com>
34: */
35: abstract class Mage_ProductAlert_Block_Email_Abstract extends Mage_Core_Block_Template
36: {
37: /**
38: * Product collection array
39: *
40: * @var array
41: */
42: protected $_products = array();
43:
44: /**
45: * Current Store scope object
46: *
47: * @var Mage_Core_Model_Store
48: */
49: protected $_store;
50:
51: /**
52: * Set Store scope
53: *
54: * @param int|string|Mage_Core_Model_Website|Mage_Core_Model_Store $store
55: * @return Mage_ProductAlert_Block_Email_Abstract
56: */
57: public function setStore($store)
58: {
59: if ($store instanceof Mage_Core_Model_Website) {
60: $store = $store->getDefaultStore();
61: }
62: if (!$store instanceof Mage_Core_Model_Store) {
63: $store = Mage::app()->getStore($store);
64: }
65:
66: $this->_store = $store;
67:
68: return $this;
69: }
70:
71: /**
72: * Retrieve current store object
73: *
74: * @return Mage_Core_Model_Store
75: */
76: public function getStore()
77: {
78: if (is_null($this->_store)) {
79: $this->_store = Mage::app()->getStore();
80: }
81: return $this->_store;
82: }
83:
84: /**
85: * Convert price from default currency to current currency
86: *
87: * @param double $price
88: * @param boolean $format Format price to currency format
89: * @param boolean $includeContainer Enclose into <span class="price"><span>
90: * @return double
91: */
92: public function formatPrice($price, $format = true, $includeContainer = true)
93: {
94: return $this->getStore()->convertPrice($price, $format, $includeContainer);
95: }
96:
97: /**
98: * Reset product collection
99: *
100: */
101: public function reset()
102: {
103: $this->_products = array();
104: }
105:
106: /**
107: * Add product to collection
108: *
109: * @param Mage_Catalog_Model_Product $product
110: */
111: public function addProduct(Mage_Catalog_Model_Product $product)
112: {
113: $this->_products[$product->getId()] = $product;
114: }
115:
116: /**
117: * Retrieve product collection array
118: *
119: * @return array
120: */
121: public function getProducts()
122: {
123: return $this->_products;
124: }
125:
126: /**
127: * Get store url params
128: *
129: * @return string
130: */
131: protected function _getUrlParams()
132: {
133: return array(
134: '_store' => $this->getStore(),
135: '_store_to_url' => true
136: );
137: }
138: }
139: