1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright (c) 2013-2014 eBay Enterprise, Inc. |
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.md. |
9
|
|
|
* It is also available through the world-wide-web at this URL: |
10
|
|
|
* http://opensource.org/licenses/osl-3.0.php |
11
|
|
|
* |
12
|
|
|
* @copyright Copyright (c) 2013-2014 eBay Enterprise, Inc. (http://www.ebayenterprise.com/) |
13
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
14
|
|
|
*/ |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Block for rendering eBay Enterprise tax data for email templates. |
18
|
|
|
*/ |
19
|
|
|
class EbayEnterprise_Tax_Block_Sales_Order_Tax extends Mage_Core_Block_Abstract |
|
|
|
|
20
|
|
|
{ |
21
|
|
|
const TAX_LABEL = 'EbayEnterprise_Tax_Order_Total_Tax_Title'; |
22
|
|
|
const TOTAL_CODE = 'ebayenterprise_tax'; |
23
|
|
|
|
24
|
|
|
/** @var EbayEnterprise_Tax_Model_Collector */ |
25
|
|
|
protected $taxCollector; |
26
|
|
|
/** @var EbayEnterprise_Tax_Helper_Data */ |
27
|
|
|
protected $helper; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @param array May contain: |
31
|
|
|
* - tax_collector => EbayEnterprise_Tax_Model_Collector |
32
|
|
|
*/ |
33
|
|
View Code Duplication |
public function __construct(array $args = []) |
|
|
|
|
34
|
|
|
{ |
35
|
|
|
list( |
36
|
|
|
$this->taxCollector, |
37
|
|
|
$this->helper |
38
|
|
|
) = $this->checkTypes( |
39
|
|
|
$this->nullCoalesce($args, 'tax_collector', Mage::getModel('ebayenterprise_tax/collector')), |
40
|
|
|
$this->nullCoalesce($args, 'helper', Mage::helper('ebayenterprise_tax')) |
41
|
|
|
); |
42
|
|
|
parent::__construct($args); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Enforce type checks on construct args array. |
47
|
|
|
* |
48
|
|
|
* @param EbayEnterprise_Tax_Model_Collector |
49
|
|
|
* @param EbayEnterprise_Tax_Helper_Data |
50
|
|
|
* @return array |
51
|
|
|
*/ |
52
|
|
|
protected function checkTypes( |
|
|
|
|
53
|
|
|
EbayEnterprise_Tax_Model_Collector $taxCollector, |
54
|
|
|
EbayEnterprise_Tax_Helper_Data $helper |
55
|
|
|
) { |
56
|
|
|
return func_get_args(); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Fill in default values. |
61
|
|
|
* |
62
|
|
|
* @param array |
63
|
|
|
* @param string |
64
|
|
|
* @param mixed |
65
|
|
|
* @return mixed |
66
|
|
|
*/ |
67
|
|
|
protected function nullCoalesce(array $arr, $key, $default) |
68
|
|
|
{ |
69
|
|
|
return isset($arr[$key]) ? $arr[$key] : $default; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Add totals for collected taxes to the parent block. Totals added to the |
74
|
|
|
* parent will be displayed with order totals. |
75
|
|
|
* |
76
|
|
|
* @return self |
77
|
|
|
*/ |
78
|
|
|
public function initTotals() |
79
|
|
|
{ |
80
|
|
|
$parent = $this->getParentBlock(); |
81
|
|
|
|
82
|
|
|
$taxAmount = $this->totalTaxAmount(); |
83
|
|
|
$parent->addTotal( |
84
|
|
|
new Varien_Object([ |
85
|
|
|
'code' => self::TOTAL_CODE, |
86
|
|
|
'value' => $taxAmount, |
87
|
|
|
'base_value' => $taxAmount, |
88
|
|
|
'label' => $this->helper->__(self::TAX_LABEL), |
89
|
|
|
]), |
90
|
|
|
'discount' |
91
|
|
|
); |
92
|
|
|
|
93
|
|
|
return $this; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Total all taxes associated with the current order. |
98
|
|
|
* |
99
|
|
|
* @return float |
100
|
|
|
*/ |
101
|
|
|
protected function totalTaxAmount() |
102
|
|
|
{ |
103
|
|
|
$records = array_reduce($this->taxCollector->getTaxRecords(), function ($total, $item) { return $total + $item->getCalculatedTax(); }, 0.00); |
|
|
|
|
104
|
|
|
$duties = array_reduce($this->taxCollector->getTaxDuties(), function ($total, $item) { return $total + $item->getAmount(); }, 0.00); |
|
|
|
|
105
|
|
|
$fees = array_reduce($this->taxCollector->getTaxFees(), function ($total, $item) { return $total + $item->getAmount(); }, 0.00); |
|
|
|
|
106
|
|
|
|
107
|
|
|
return $records + $duties + $fees; |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.