-
Notifications
You must be signed in to change notification settings - Fork 80
/
Price.php
291 lines (258 loc) · 9.17 KB
/
Price.php
1
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
<?php
/**
* This file is part of a FireGento e.V. module.
*
* This FireGento e.V. module is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This script is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* PHP version 5
*
* @category FireGento
* @package FireGento_MageSetup
* @author FireGento Team <team@firegento.com>
* @copyright 2013-2015 FireGento Team (http://www.firegento.com)
* @license http://opensource.org/licenses/gpl-3.0 GNU General Public License, version 3 (GPLv3)
* @version 2.2.1
* @since 0.1.0
*/
/**
* Enhanced block for product price display of all products in spite of bundles (got own block!).
* Contains the normal price.phtml rendering and additionally a configured static block.
*
* @category FireGento
* @package FireGento_MageSetup
* @author FireGento Team <team@firegento.com>
*/
class FireGento_MageSetup_Block_Catalog_Product_Price
extends FireGento_MageSetup_Block_Catalog_Product_Price_Abstract
{
/**
* @var array Path to common tier price template
*/
protected $_tierPriceDefaultTemplates = array(
'catalog/product/view/tierprices.phtml',
'dermodpro/bcp/catalog/product/view/tierprices.phtml'
);
/**
* Add the tierprice default templates
*
* @return FireGento_MageSetup_Block_Catalog_Product_Price
*/
protected function _beforeToHtml()
{
$templatesNode = Mage::getConfig()->getNode('magesetup/price/tierprice_default_templates');
if ($templatesNode) {
$templates = $templatesNode->asArray();
foreach ($templates as $template) {
$this->addTierpriceDefaultTemplate($template);
}
}
return parent::_beforeToHtml();
}
/**
* Add content of template block below price html if defined in config
*
* @return string Price HTML
*/
public function _toHtml()
{
$html = trim(parent::_toHtml());
if (empty($html) || !Mage::getStoreConfigFlag('catalog/price/display_block_below_price')) {
return $html;
}
if (!in_array($this->getTemplate(), $this->_tierPriceDefaultTemplates)) {
$htmlObject = new Varien_Object();
$htmlObject->setParentHtml($html);
$htmlTemplate = $this->getLayout()->createBlock('core/template')
->setTemplate('magesetup/price_info.phtml')
->setFormattedTaxRate($this->getFormattedTaxRate())
->setIsIncludingTax($this->isIncludingTax())
->setIsIncludingShippingCosts($this->isIncludingShippingCosts())
->setPriceDisplayType(Mage::helper('tax')->getPriceDisplayType())
->setIsShowShippingLink($this->isShowShippingLink())
->setIsShowWeightInfo($this->getIsShowWeightInfo())
->setFormattedWeight($this->getFormattedWeight())
->toHtml();
$htmlObject->setHtml($htmlTemplate);
$this->_addDeliveryTimeHtml($htmlObject);
Mage::dispatchEvent('magesetup_after_product_price',
array(
'html_obj' => $htmlObject,
'block' => $this,
)
);
$html = $htmlObject->getPrefix();
$html .= $htmlObject->getParentHtml();
$html .= $htmlObject->getHtml();
$html .= $htmlObject->getSuffix();
}
return $html;
}
/**
* Add delivery time on category pages only
*
* @param Varien_Object $htmlObject Transport object
*/
protected function _addDeliveryTimeHtml($htmlObject)
{
if (!Mage::getStoreConfigFlag('catalog/price/display_delivery_time_on_categories')) {
return;
}
$pathInfo = Mage::app()->getRequest()->getPathInfo();
if (strpos($pathInfo, 'catalog/category/view') !== false
|| strpos($pathInfo, 'catalogsearch/result') !== false
) {
if ($this->getProduct()->getDeliveryTime()) {
$html = '<p class="delivery-time">';
$html .= $this->__('Delivery Time') . ': ' . $this->getProduct()->getDeliveryTime();
$html .= '</p>';
$htmlObject->setSuffix($html);
}
}
}
/**
* Read tax rate from current product.
*
* @return string Tax Rate
*/
public function getTaxRate()
{
$taxRateKey = 'tax_rate_' . $this->getProduct()->getId();
if (!$this->getData($taxRateKey)) {
$this->setData($taxRateKey, $this->_loadTaxCalculationRate($this->getProduct()));
}
return $this->getData($taxRateKey);
}
/**
* Retrieves formatted string of tax rate for user output
*
* @return string Formatted Tax Rate for the given locale
*/
public function getFormattedTaxRate()
{
if ($this->getTaxRate() === null
|| $this->getProduct()->getTypeId() == 'bundle'
) {
return '';
}
$locale = Mage::app()->getLocale()->getLocaleCode();
$taxRate = Zend_Locale_Format::toFloat($this->getTaxRate(), array('locale' => $locale));
return $this->__('%s%%', $taxRate);
}
/**
* Returns whether or not the price contains taxes
*
* @return bool Flag if prices are shown with including tax
*/
public function isIncludingTax()
{
if (!$this->getData('is_including_tax')) {
$includesTax = Mage::helper('tax')->priceIncludesTax();
$this->setData('is_including_tax', $includesTax);
}
return $this->getData('is_including_tax');
}
/**
* Returns whether or not the price contains taxes
*
* @return bool Flag if shipping costs are including taxes
*/
public function isIncludingShippingCosts()
{
if (!$this->getData('is_including_shipping_costs')) {
$this->setData(
'is_including_shipping_costs',
Mage::getStoreConfig('catalog/price/including_shipping_costs')
);
}
return $this->getData('is_including_shipping_costs');
}
/**
* Returns whether the shipping link needs to be shown
* on the frontend or not.
*
* @return bool Flag if shipping link should be displayed
*/
public function isShowShippingLink()
{
$productTypeId = $this->getProduct()->getTypeId();
$ignoreTypeIds = array('virtual', 'downloadable');
if (in_array($productTypeId, $ignoreTypeIds)) {
return false;
}
return true;
}
/**
* Gets tax percents for current product
*
* @param Mage_Catalog_Model_Product $product Product Model
* @return string Tax Rate
*/
protected function _loadTaxCalculationRate(Mage_Catalog_Model_Product $product)
{
$taxPercent = $product->getTaxPercent();
if (is_null($taxPercent)) {
$taxClassId = $product->getTaxClassId();
if ($taxClassId) {
$storeId = Mage::app()->getStore()->getId();
$groupId = Mage::getSingleton('customer/session')->getCustomerGroupId();
$group = Mage::getModel('customer/group')->load($groupId);
$customerTaxClassId = $group->getData('tax_class_id');
/* @var $calculation Mage_Tax_Model_Calculation */
$calculation = Mage::getSingleton('tax/calculation');
$request = $calculation->getRateRequest(null, null, $customerTaxClassId, $storeId);
$taxPercent = Mage::getSingleton('tax/calculation')->getRate($request->setProductClassId($taxClassId));
}
}
if ($taxPercent) {
return $taxPercent;
}
return 0;
}
/**
* Check if Shipping by Weight is active
*
* @return bool Flag if product weight should be displayed
*/
public function getIsShowWeightInfo()
{
return Mage::getStoreConfigFlag('catalog/price/display_product_weight');
}
/**
* Get formatted weight incl. unit
*
* @return string Formatted weight
*/
public function getFormattedWeight()
{
return floatval($this->getProduct()->getWeight()) . ' ' . Mage::getStoreConfig('catalog/price/weight_unit');
}
/**
* Add a tierprice default template
*
* @param string $template Template
* @return FireGento_MageSetup_Block_Catalog_Product_Price
*/
public function addTierpriceDefaultTemplate($template)
{
$this->_tierPriceDefaultTemplates[] = $template;
return $this;
}
/**
* Translate block sentence
*
* @return string Translated text
*/
public function __()
{
$args = func_get_args();
$expr = new Mage_Core_Model_Translate_Expr(array_shift($args), 'Mage_Catalog');
array_unshift($args, $expr);
return Mage::app()->getTranslator()->translate($args);
}
}