7
7
*/
8
8
namespace Afterpay \Afterpay \Block \Catalog ;
9
9
10
- use Magento \Framework \View \Element \Template ;
11
- use Magento \Catalog \Model \Product as Product ;
12
10
use Magento \Framework \Registry as Registry ;
13
- use Magento \Directory \Model \Currency as Currency ;
14
11
use Afterpay \Afterpay \Model \Config \Payovertime as AfterpayConfig ;
15
12
use Afterpay \Afterpay \Model \Payovertime as AfterpayPayovertime ;
16
- use Magento \Framework \Component \ComponentRegistrar as ComponentRegistrar ;
13
+ use Magento \Framework \View \Element \Template \Context ;
14
+ use Magento \Framework \Locale \Resolver as Resolver ;
17
15
18
- class Installments extends Template
16
+ class Installments extends \ Afterpay \ Afterpay \ Block \JsConfig
19
17
{
20
- /**
21
- * @var Product
22
- */
23
- protected $ product ;
18
+
24
19
protected $ registry ;
25
- protected $ currency ;
26
20
protected $ afterpayConfig ;
27
21
protected $ afterpayPayovertime ;
28
- protected $ componentRegistrar ;
22
+ private $ localeResolver ;
29
23
30
24
/**
31
25
* Installments constructor.
32
- * @param Template\Context $context
33
- * @param Product $product
26
+ * @param Context $context
27
+ * @param AfterpayConfig $afterpayConfig
28
+ * @param AfterpayPayovertime $afterpayPayovertime
34
29
* @param Registry $registry
35
- * @param Currency $currency
36
30
* @param AfterpayConfig $afterpayConfig
37
31
* @param array $data
38
32
*/
39
33
public function __construct (
40
- Template \Context $ context ,
41
- Product $ product ,
34
+ Context $ context ,
42
35
Registry $ registry ,
43
- Currency $ currency ,
44
36
AfterpayConfig $ afterpayConfig ,
45
37
AfterpayPayovertime $ afterpayPayovertime ,
46
- ComponentRegistrar $ componentRegistrar ,
47
- array $ data
38
+ array $ data ,
39
+ Resolver $ localeResolver
48
40
) {
49
- $ this ->product = $ product ;
50
41
$ this ->registry = $ registry ;
51
- $ this ->currency = $ currency ;
52
42
$ this ->afterpayConfig = $ afterpayConfig ;
53
43
$ this ->afterpayPayovertime = $ afterpayPayovertime ;
54
- $ this ->componentRegistrar = $ componentRegistrar ;
55
- parent ::__construct ($ context , $ data );
44
+ $ this ->localeResolver = $ localeResolver ;
45
+ parent ::__construct ($ afterpayConfig , $ context , $ localeResolver , $ data );
56
46
}
57
47
58
48
/**
@@ -63,20 +53,6 @@ protected function _getPaymentIsActive()
63
53
return $ this ->afterpayConfig ->isActive ();
64
54
}
65
55
66
- /**
67
- * @return string
68
- */
69
- public function getInstallmentsAmount ()
70
- {
71
- // get product
72
- $ product = $ this ->registry ->registry ('product ' );
73
-
74
- // set if final price is exist
75
- if ($ price = $ product ->getFinalPrice ()) {
76
- return $ this ->currency ->getCurrencySymbol () . number_format ($ price / 4 , 2 );
77
- }
78
- }
79
-
80
56
/**
81
57
* @return bool
82
58
*/
@@ -111,84 +87,46 @@ public function canShow()
111
87
return false ;
112
88
}
113
89
}
114
- }
115
- /**
116
- * @return bool
117
- */
118
- public function isProductEligible (){
119
-
120
- $ product = $ this ->registry ->registry ('product ' );
121
- if ($ product ->getFinalPrice () > $ this ->afterpayConfig ->getMaxOrderLimit () // greater than max order limit
122
- || $ product ->getFinalPrice () < $ this ->afterpayConfig ->getMinOrderLimit ()) { // lower than min order limit
123
- return false ;
124
- }
125
- return true ;
126
- }
90
+ }
91
+
127
92
128
- /**
129
- * @return boolean
130
- */
131
- public function canUseCurrency ()
132
- {
133
- //Check for Supported currency
134
- if ($ this ->afterpayConfig ->getCurrencyCode ())
135
- {
136
- return $ this ->afterpayPayovertime ->canUseForCurrency ($ this ->afterpayConfig ->getCurrencyCode ());
137
- } else {
138
- return false ;
139
- }
140
- }
141
-
142
- /**
143
- * Calculate region specific Instalment Text
93
+ /**
144
94
* @return string
145
95
*/
146
- public function getInstalmentText ()
96
+ public function getTypeOfProduct ()
147
97
{
148
- $ currencyCode = $ this ->afterpayConfig ->getCurrencyCode ();
149
- $ assetsPath = $ this ->componentRegistrar ->getPath (ComponentRegistrar::MODULE , 'Afterpay_Afterpay ' );
150
- $ assets_product_page = [];
151
- if (file_exists ($ assetsPath .'/assets.ini ' ))
152
- {
153
- $ assets = parse_ini_file ($ assetsPath .'/assets.ini ' ,true );
154
- if (isset ($ assets [$ currencyCode ]['product_page1 ' ]))
155
- {
156
- $ assets_product_page ['snippet1 ' ] = $ assets [$ currencyCode ]['product_page1 ' ];
157
- if ($ this ->getTypeOfProduct ()=="bundle " ){
158
- $ assets_product_page ['snippet1 ' ] = $ assets [$ currencyCode ]['product_page_from ' ];
159
- }
160
- $ assets_product_page ['snippet2 ' ] = $ assets [$ currencyCode ]['product_page2 ' ];
161
- } else {
162
- $ assets_product_page ['snippet1 ' ] = '' ;
163
- $ assets_product_page ['snippet2 ' ] = '' ;
164
- }
165
- }
166
- return $ assets_product_page ;
98
+ $ product = $ this ->registry ->registry ('product ' );
99
+ return $ product ->getTypeId ();
167
100
}
168
-
169
101
170
102
/**
171
- * @return float
103
+ * @return string
172
104
*/
173
- public function getMaxOrderLimit ()
105
+ public function getFinalAmount ()
174
106
{
175
- return $ this ->afterpayConfig ->getMaxOrderLimit ();
176
- }
177
-
107
+ // get product
108
+ $ product = $ this ->registry ->registry ('product ' );
109
+
110
+ // set if final price is exist
111
+ $ price = $ product ->getFinalPrice ();
112
+
113
+ return !empty ($ price )?number_format ($ price , 2 ,". " ,"" ):"0.00 " ;
114
+
115
+ }
178
116
/**
179
- * @return float
180
- */
181
- public function getMinOrderLimit ()
182
- {
183
- return $ this ->afterpayConfig ->getMinOrderLimit ();
184
- }
185
-
186
- /**
187
- * @return string
117
+ * @return boolean
188
118
*/
189
- public function getTypeOfProduct ()
119
+ public function canUseCurrency ()
190
120
{
191
- $ product = $ this ->registry ->registry ('product ' );
192
- return $ product ->getTypeId ();
121
+ $ canUse =false ;
122
+ //Check for Supported currency
123
+ if ($ this ->afterpayConfig ->getCurrencyCode ())
124
+ {
125
+ $ canUse = $ this ->afterpayPayovertime ->canUseForCurrency ($ this ->afterpayConfig ->getCurrencyCode ());
126
+ }
127
+
128
+ return $ canUse ;
129
+
193
130
}
131
+
194
132
}
0 commit comments