|
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 gift card totals for email templates. |
|
18
|
|
|
*/ |
|
19
|
|
|
class EbayEnterprise_GiftCard_Block_Sales_Order_Total extends Mage_Core_Block_Template |
|
|
|
|
|
|
20
|
|
|
{ |
|
21
|
|
|
const TOTAL_CODE = 'ebayenterprise_giftcard'; |
|
22
|
|
|
const TOTAL_LABEL = 'EbayEnterprise_GiftCard_Order_Total_Label'; |
|
23
|
|
|
|
|
24
|
|
|
/** @var EbayEnterprise_GiftCard_Model_Container */ |
|
25
|
|
|
protected $giftcardContainer; |
|
26
|
|
|
/** @var EbayEnterprise_GiftCard_Helper_Data */ |
|
27
|
|
|
protected $helper; |
|
28
|
|
|
|
|
29
|
|
View Code Duplication |
public function __construct(array $args = []) |
|
|
|
|
|
|
30
|
|
|
{ |
|
31
|
|
|
list( |
|
32
|
|
|
$this->giftcardContainer, |
|
33
|
|
|
$this->helper |
|
34
|
|
|
) = $this->checkTypes( |
|
35
|
|
|
$this->nullCoalesce($args, 'giftcard_container', Mage::getModel('ebayenterprise_giftcard/container')), |
|
36
|
|
|
$this->nullCoalesce($args, 'helper', Mage::helper('ebayenterprise_giftcard')) |
|
37
|
|
|
); |
|
38
|
|
|
parent::__construct($args); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Enforce type checks on construct args array. |
|
43
|
|
|
* |
|
44
|
|
|
* @param EbayEnterprise_GiftCard_Model_Container |
|
45
|
|
|
* @param EbayEnterprise_GiftCard_Helper_Data |
|
46
|
|
|
* @return array |
|
47
|
|
|
*/ |
|
48
|
|
|
protected function checkTypes( |
|
|
|
|
|
|
49
|
|
|
EbayEnterprise_GiftCard_Model_Container $giftcardContainer, |
|
50
|
|
|
EbayEnterprise_GiftCard_Helper_Data $helper |
|
51
|
|
|
) { |
|
52
|
|
|
return func_get_args(); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Fill in default values. |
|
57
|
|
|
* |
|
58
|
|
|
* @param array |
|
59
|
|
|
* @param string |
|
60
|
|
|
* @param mixed |
|
61
|
|
|
* @return mixed |
|
62
|
|
|
*/ |
|
63
|
|
|
protected function nullCoalesce(array $arr, $key, $default) |
|
64
|
|
|
{ |
|
65
|
|
|
return isset($arr[$key]) ? $arr[$key] : $default; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Get the current order model. |
|
70
|
|
|
* |
|
71
|
|
|
* @return Mage_Sales_Model_Order |
|
72
|
|
|
*/ |
|
73
|
|
|
public function getOrder() |
|
74
|
|
|
{ |
|
75
|
|
|
return $this->getParentBlock()->getOrder(); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* Register gift card totals with the order totals block. |
|
80
|
|
|
* |
|
81
|
|
|
* @return self |
|
82
|
|
|
*/ |
|
83
|
|
|
public function initTotals() |
|
84
|
|
|
{ |
|
85
|
|
|
$total = new Varien_Object([ |
|
86
|
|
|
'code' => self::TOTAL_CODE, |
|
87
|
|
|
// Using a block name instead of just adding values so a template |
|
88
|
|
|
// can be used to render the gift card totals. |
|
89
|
|
|
'block_name' => $this->getNameInLayout(), |
|
90
|
|
|
'label' => $this->helper->__(self::TOTAL_LABEL), |
|
91
|
|
|
]); |
|
92
|
|
|
$this->getParentBlock()->addTotalBefore($total, ['customerbalance', 'grand_total']); |
|
93
|
|
|
return $this; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* Get all gift cards redeemed for the order. |
|
98
|
|
|
* |
|
99
|
|
|
* @return SPLObjectStorage |
|
100
|
|
|
*/ |
|
101
|
|
|
public function getGiftCards() |
|
102
|
|
|
{ |
|
103
|
|
|
return $this->giftcardContainer->getRedeemedGiftCards(); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* Get the label to use for a gift card in the totals. |
|
108
|
|
|
* |
|
109
|
|
|
* @param EbayEnterprise_GiftCard_Model_Giftcard |
|
110
|
|
|
* @return string |
|
111
|
|
|
*/ |
|
112
|
|
|
public function getCardLabel(EbayEnterprise_GiftCard_Model_Giftcard $card) |
|
113
|
|
|
{ |
|
114
|
|
|
return $this->__(self::TOTAL_LABEL, $card->getCardNumber()); |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* Get the value of the gift card to display in the totals. |
|
119
|
|
|
* |
|
120
|
|
|
* @param EbayEnterprise_GiftCard_Model_Giftcard |
|
121
|
|
|
* @return string |
|
122
|
|
|
*/ |
|
123
|
|
|
public function getCardValue(EbayEnterprise_GiftCard_Model_Giftcard $card) |
|
124
|
|
|
{ |
|
125
|
|
|
return $this->getOrder()->formatPrice($card->getAmountRedeemed() * -1); |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* Attributes to add to the html element wrapping the total's label. |
|
130
|
|
|
* |
|
131
|
|
|
* @return string |
|
132
|
|
|
*/ |
|
133
|
|
|
public function getLabelProperties() |
|
134
|
|
|
{ |
|
135
|
|
|
return $this->getParentBlock()->getLabelProperties(); |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
/** |
|
139
|
|
|
* Attributes to add to the html element wrapping the total's value. |
|
140
|
|
|
* |
|
141
|
|
|
* @return string |
|
142
|
|
|
*/ |
|
143
|
|
|
public function getValueProperties() |
|
144
|
|
|
{ |
|
145
|
|
|
return $this->getParentBlock()->getValueProperties(); |
|
146
|
|
|
} |
|
147
|
|
|
} |
|
148
|
|
|
|
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.