Skip to content

Commit 4c2f96c

Browse files
Release version 3.4.0
1 parent 3c774ef commit 4c2f96c

File tree

20 files changed

+1430
-146
lines changed

20 files changed

+1430
-146
lines changed

Block/Catalog/Installments.php

Lines changed: 58 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,42 @@
77
*/
88
namespace Afterpay\Afterpay\Block\Catalog;
99

10-
use Magento\Framework\Registry as Registry;
10+
use Afterpay\Afterpay\Block\JsConfig;
1111
use Afterpay\Afterpay\Model\Config\Payovertime as AfterpayConfig;
1212
use Afterpay\Afterpay\Model\Payovertime as AfterpayPayovertime;
13-
use Magento\Framework\View\Element\Template\Context;
1413
use Magento\Framework\Locale\Resolver as Resolver;
14+
use Magento\Framework\Registry as Registry;
15+
use Magento\Framework\View\Element\Template\Context;
1516

16-
class Installments extends \Afterpay\Afterpay\Block\JsConfig
17+
class Installments extends JsConfig
1718
{
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+
*/
2237
private $localeResolver;
2338

2439
/**
25-
* Installments constructor.
2640
* @param Context $context
27-
* @param AfterpayConfig $afterpayConfig
28-
* @param AfterpayPayovertime $afterpayPayovertime
2941
* @param Registry $registry
3042
* @param AfterpayConfig $afterpayConfig
43+
* @param AfterpayPayovertime $afterpayPayovertime
3144
* @param array $data
45+
* @param Resolver $localeResolver
3246
*/
3347
public function __construct(
3448
Context $context,
@@ -42,91 +56,71 @@ public function __construct(
4256
$this->afterpayConfig = $afterpayConfig;
4357
$this->afterpayPayovertime = $afterpayPayovertime;
4458
$this->localeResolver = $localeResolver;
45-
parent::__construct($afterpayConfig,$context, $localeResolver,$data);
59+
parent::__construct($afterpayConfig, $context, $localeResolver, $data);
4660
}
4761

4862
/**
4963
* @return bool
5064
*/
51-
protected function _getPaymentIsActive()
65+
public function canShow(): bool
5266
{
53-
return $this->afterpayConfig->isActive();
54-
}
55-
56-
/**
57-
* @return bool
58-
*/
59-
public function canShow()
60-
{
6167
// 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;
6485
}
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-
9286

93-
/**
87+
return false;
88+
}
89+
90+
/**
9491
* @return string
9592
*/
9693
public function getTypeOfProduct()
9794
{
9895
$product = $this->registry->registry('product');
99-
return $product->getTypeId();
96+
return $product->getTypeId();
10097
}
101-
98+
10299
/**
103100
* @return string
104101
*/
105102
public function getFinalAmount()
106103
{
107104
// get product
108105
$product = $this->registry->registry('product');
109-
106+
110107
// 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+
116113
/**
117114
* @return boolean
118115
*/
119116
public function canUseCurrency()
120117
{
121118
$canUse=false;
122119
//Check for Supported currency
123-
if($this->afterpayConfig->getCurrencyCode())
124-
{
120+
if ($this->afterpayConfig->getCurrencyCode()) {
125121
$canUse= $this->afterpayPayovertime->canUseForCurrency($this->afterpayConfig->getCurrencyCode());
126-
}
127-
122+
}
123+
128124
return $canUse;
129-
130125
}
131-
132126
}

Block/Info.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ protected function _prepareSpecificInformation($transport = null)
2525
$info = $this->getInfo();
2626

2727
// load the data available on additional informations
28-
if ($this->_appState->getAreaCode() === \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE
28+
if ($this->getArea() === \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE
2929
&& $info->getAdditionalInformation()
3030
) {
3131
foreach ($info->getAdditionalInformation() as $field => $value) {

Block/JsConfig.php

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,13 @@ protected function _getPaymentIsActive()
7272
*/
7373
public function getCurrentLocale()
7474
{
75-
return $this->localeResolver->getLocale(); // eg. fr_CA
75+
$currentLocale=$this->localeResolver->getLocale();
76+
$country_code=$this->_payOverTime->getCurrentCountryCode();
77+
if(!empty($country_code) && stripos($currentLocale,$country_code)=== false){
78+
$currentLocale="en_".strtoupper($country_code);
79+
}
80+
81+
return $currentLocale; // eg. fr_CA
7682
}
7783

7884
/**
@@ -124,15 +130,21 @@ public function isDisplayOnProductPage()
124130
/**
125131
* check if payment is active for cart page
126132
*
127-
* @return bool
133+
* @return int
128134
*/
129135
public function isDisplayOnCartPage()
130136
{
131-
$isEnabledForCartPage=true;
132-
if (!$this->_payOverTime->isEnabledForCartPage()) {
133-
$isEnabledForCartPage= false;
134-
}
135-
return $isEnabledForCartPage;
137+
return $this->_payOverTime->isEnabledForCartPage();
136138
}
137139

140+
/**
141+
* Get Express Checkout JS URL
142+
*
143+
* @return bool|string
144+
*/
145+
public function getAfterpayECJsUrl()
146+
{
147+
$express_checkout_key=$this->_payOverTime->getExpressCheckoutKey();
148+
return $this->_payOverTime->getWebUrl('afterpay.js',array("merchant_key"=>!empty($express_checkout_key)?$express_checkout_key:""));
149+
}
138150
}

CHANGELOG.md

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,24 @@
11
# Afterpay Magento 2 Extension Changelog
22

3+
## Version 3.4.0
4+
5+
_Wed 24 Mar 2021_
6+
7+
### Supported Editions & Versions
8+
9+
Tested and verified in clean installations of Magento 2:
10+
11+
- Magento Enterprise Edition (EE) version 2.4.2
12+
13+
### Highlights
14+
15+
- Introduced an implementation of Express Checkout.
16+
- Improved instalment calculations by adding coverage for additional scenarios.
17+
- Improved the asset placement on PDP and cart pages.
18+
- Improved invoice payment context to remove unnecessary details from consumer order notifications.
19+
20+
---
21+
322
## Version 3.3.0
423

524
_Wed 13 Jan 2021_
@@ -14,8 +33,8 @@ Tested and verified in clean installations of Magento 2:
1433
### Highlights
1534

1635
- Implemented the JS Library for asset placement on PDP and Cart page.
17-
- Added new admin options to enable/disable display of Afterpay/Clearpay assets on PDP and Cart page.
18-
- Moved the Afterpay/Clearpay PDP assets for “Bundle” products.
36+
- Added new admin options to enable/disable display of Afterpay assets on PDP and Cart page.
37+
- Moved the Afterpay PDP assets for “Bundle” products.
1938
- Improved Cross Border Trade (CBT) configuration to update automatically in sync with the nominated Merchant account.
2039
- Improved support for multi-currency configurations.
2140
- Improved compatibility with PHP 7.4.

0 commit comments

Comments
 (0)