7
7
*/
8
8
namespace Afterpay \Afterpay \Block \Catalog ;
9
9
10
- use Magento \ Framework \ Registry as Registry ;
10
+ use Afterpay \ Afterpay \ Block \ JsConfig ;
11
11
use Afterpay \Afterpay \Model \Config \Payovertime as AfterpayConfig ;
12
12
use Afterpay \Afterpay \Model \Payovertime as AfterpayPayovertime ;
13
- use Magento \Framework \View \Element \Template \Context ;
14
13
use Magento \Framework \Locale \Resolver as Resolver ;
14
+ use Magento \Framework \Registry as Registry ;
15
+ use Magento \Framework \View \Element \Template \Context ;
15
16
16
- class Installments extends \ Afterpay \ Afterpay \ Block \ JsConfig
17
+ class Installments extends JsConfig
17
18
{
18
-
19
- protected $ registry ;
20
- protected $ afterpayConfig ;
21
- protected $ afterpayPayovertime ;
19
+ /**
20
+ * @var Registry
21
+ */
22
+ private $ registry ;
23
+
24
+ /**
25
+ * @var AfterpayConfig
26
+ */
27
+ private $ afterpayConfig ;
28
+
29
+ /**
30
+ * @var AfterpayPayovertime
31
+ */
32
+ private $ afterpayPayovertime ;
33
+
34
+ /**
35
+ * @var Resolver
36
+ */
22
37
private $ localeResolver ;
23
38
24
39
/**
25
- * Installments constructor.
26
40
* @param Context $context
27
- * @param AfterpayConfig $afterpayConfig
28
- * @param AfterpayPayovertime $afterpayPayovertime
29
41
* @param Registry $registry
30
42
* @param AfterpayConfig $afterpayConfig
43
+ * @param AfterpayPayovertime $afterpayPayovertime
31
44
* @param array $data
45
+ * @param Resolver $localeResolver
32
46
*/
33
47
public function __construct (
34
48
Context $ context ,
@@ -42,91 +56,71 @@ public function __construct(
42
56
$ this ->afterpayConfig = $ afterpayConfig ;
43
57
$ this ->afterpayPayovertime = $ afterpayPayovertime ;
44
58
$ this ->localeResolver = $ localeResolver ;
45
- parent ::__construct ($ afterpayConfig ,$ context , $ localeResolver ,$ data );
59
+ parent ::__construct ($ afterpayConfig , $ context , $ localeResolver , $ data );
46
60
}
47
61
48
62
/**
49
63
* @return bool
50
64
*/
51
- protected function _getPaymentIsActive ()
65
+ public function canShow (): bool
52
66
{
53
- return $ this ->afterpayConfig ->isActive ();
54
- }
55
-
56
- /**
57
- * @return bool
58
- */
59
- public function canShow ()
60
- {
61
67
// check if payment is active
62
- if (!$ this ->_getPaymentIsActive ()) {
63
- return false ;
68
+ if ($ this ->_getPaymentIsActive () &&
69
+ $ this ->afterpayConfig ->getCurrencyCode () &&
70
+ $ this ->afterpayPayovertime ->canUseForCurrency ($ this ->afterpayConfig ->getCurrencyCode ())
71
+ ) {
72
+ $ excluded_categories = $ this ->afterpayConfig ->getExcludedCategories ();
73
+ if ($ excluded_categories != "" ) {
74
+ $ excluded_categories_array = explode (", " , $ excluded_categories );
75
+ $ product = $ this ->registry ->registry ('product ' );
76
+ $ categoryids = $ product ->getCategoryIds ();
77
+ foreach ($ categoryids as $ k ) {
78
+ if (in_array ($ k , $ excluded_categories_array )) {
79
+ return false ;
80
+ }
81
+ }
82
+ }
83
+
84
+ return true ;
64
85
}
65
- else {
66
- if ($ this ->afterpayConfig ->getCurrencyCode ()){
67
- if ($ this ->afterpayPayovertime ->canUseForCurrency ($ this ->afterpayConfig ->getCurrencyCode ())){
68
- $ excluded_categories =$ this ->afterpayConfig ->getExcludedCategories ();
69
- if ($ excluded_categories !="" ){
70
- $ excluded_categories_array = explode (", " ,$ excluded_categories );
71
- $ product = $ this ->registry ->registry ('product ' );
72
- $ categoryids = $ product ->getCategoryIds ();
73
- foreach ($ categoryids as $ k )
74
- {
75
- if (in_array ($ k ,$ excluded_categories_array )){
76
- return false ;
77
- }
78
- }
79
- }
80
- return true ;
81
- }
82
- else {
83
- return false ;
84
- }
85
- }
86
- else {
87
- return false ;
88
- }
89
- }
90
- }
91
-
92
86
93
- /**
87
+ return false ;
88
+ }
89
+
90
+ /**
94
91
* @return string
95
92
*/
96
93
public function getTypeOfProduct ()
97
94
{
98
95
$ product = $ this ->registry ->registry ('product ' );
99
- return $ product ->getTypeId ();
96
+ return $ product ->getTypeId ();
100
97
}
101
-
98
+
102
99
/**
103
100
* @return string
104
101
*/
105
102
public function getFinalAmount ()
106
103
{
107
104
// get product
108
105
$ product = $ this ->registry ->registry ('product ' );
109
-
106
+
110
107
// set if final price is exist
111
- $ price = $ product ->getFinalPrice ();
112
-
113
- return !empty ($ price )? number_format ($ price , 2 ,". " ,"" ): "0.00 " ;
114
-
115
- }
108
+ $ price = $ product ->getPriceInfo ()-> getPrice ( ' final_price ' )-> getValue ();
109
+
110
+ return !empty ($ price ) ? number_format ($ price , 2 , ". " , "" ) : "0.00 " ;
111
+ }
112
+
116
113
/**
117
114
* @return boolean
118
115
*/
119
116
public function canUseCurrency ()
120
117
{
121
118
$ canUse =false ;
122
119
//Check for Supported currency
123
- if ($ this ->afterpayConfig ->getCurrencyCode ())
124
- {
120
+ if ($ this ->afterpayConfig ->getCurrencyCode ()) {
125
121
$ canUse = $ this ->afterpayPayovertime ->canUseForCurrency ($ this ->afterpayConfig ->getCurrencyCode ());
126
- }
127
-
122
+ }
123
+
128
124
return $ canUse ;
129
-
130
125
}
131
-
132
126
}
0 commit comments