Skip to content

Commit

Permalink
Release version 3.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
afterpayplugins committed Mar 24, 2021
1 parent 3c774ef commit 4c2f96c
Show file tree
Hide file tree
Showing 20 changed files with 1,430 additions and 146 deletions.
122 changes: 58 additions & 64 deletions Block/Catalog/Installments.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,42 @@
*/
namespace Afterpay\Afterpay\Block\Catalog;

use Magento\Framework\Registry as Registry;
use Afterpay\Afterpay\Block\JsConfig;
use Afterpay\Afterpay\Model\Config\Payovertime as AfterpayConfig;
use Afterpay\Afterpay\Model\Payovertime as AfterpayPayovertime;
use Magento\Framework\View\Element\Template\Context;
use Magento\Framework\Locale\Resolver as Resolver;
use Magento\Framework\Registry as Registry;
use Magento\Framework\View\Element\Template\Context;

class Installments extends \Afterpay\Afterpay\Block\JsConfig
class Installments extends JsConfig
{

protected $registry;
protected $afterpayConfig;
protected $afterpayPayovertime;
/**
* @var Registry
*/
private $registry;

/**
* @var AfterpayConfig
*/
private $afterpayConfig;

/**
* @var AfterpayPayovertime
*/
private $afterpayPayovertime;

/**
* @var Resolver
*/
private $localeResolver;

/**
* Installments constructor.
* @param Context $context
* @param AfterpayConfig $afterpayConfig
* @param AfterpayPayovertime $afterpayPayovertime
* @param Registry $registry
* @param AfterpayConfig $afterpayConfig
* @param AfterpayPayovertime $afterpayPayovertime
* @param array $data
* @param Resolver $localeResolver
*/
public function __construct(
Context $context,
Expand All @@ -42,91 +56,71 @@ public function __construct(
$this->afterpayConfig = $afterpayConfig;
$this->afterpayPayovertime = $afterpayPayovertime;
$this->localeResolver = $localeResolver;
parent::__construct($afterpayConfig,$context, $localeResolver,$data);
parent::__construct($afterpayConfig, $context, $localeResolver, $data);
}

/**
* @return bool
*/
protected function _getPaymentIsActive()
public function canShow(): bool
{
return $this->afterpayConfig->isActive();
}

/**
* @return bool
*/
public function canShow()
{
// check if payment is active
if (!$this->_getPaymentIsActive()) {
return false;
if ($this->_getPaymentIsActive() &&
$this->afterpayConfig->getCurrencyCode() &&
$this->afterpayPayovertime->canUseForCurrency($this->afterpayConfig->getCurrencyCode())
) {
$excluded_categories = $this->afterpayConfig->getExcludedCategories();
if ($excluded_categories != "") {
$excluded_categories_array = explode(",", $excluded_categories);
$product = $this->registry->registry('product');
$categoryids = $product->getCategoryIds();
foreach ($categoryids as $k) {
if (in_array($k, $excluded_categories_array)) {
return false;
}
}
}

return true;
}
else{
if($this->afterpayConfig->getCurrencyCode()){
if($this->afterpayPayovertime->canUseForCurrency($this->afterpayConfig->getCurrencyCode())){
$excluded_categories=$this->afterpayConfig->getExcludedCategories();
if($excluded_categories!=""){
$excluded_categories_array = explode(",",$excluded_categories);
$product = $this->registry->registry('product');
$categoryids = $product->getCategoryIds();
foreach($categoryids as $k)
{
if(in_array($k,$excluded_categories_array)){
return false;
}
}
}
return true;
}
else{
return false;
}
}
else {
return false;
}
}
}


/**
return false;
}

/**
* @return string
*/
public function getTypeOfProduct()
{
$product = $this->registry->registry('product');
return $product->getTypeId();
return $product->getTypeId();
}

/**
* @return string
*/
public function getFinalAmount()
{
// get product
$product = $this->registry->registry('product');

// set if final price is exist
$price = $product->getFinalPrice();
return !empty($price)?number_format($price, 2,".",""):"0.00";
}
$price = $product->getPriceInfo()->getPrice('final_price')->getValue();

return !empty($price) ? number_format($price, 2, ".", "") : "0.00";
}

/**
* @return boolean
*/
public function canUseCurrency()
{
$canUse=false;
//Check for Supported currency
if($this->afterpayConfig->getCurrencyCode())
{
if ($this->afterpayConfig->getCurrencyCode()) {
$canUse= $this->afterpayPayovertime->canUseForCurrency($this->afterpayConfig->getCurrencyCode());
}
}

return $canUse;

}

}
2 changes: 1 addition & 1 deletion Block/Info.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ protected function _prepareSpecificInformation($transport = null)
$info = $this->getInfo();

// load the data available on additional informations
if ($this->_appState->getAreaCode() === \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE
if ($this->getArea() === \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE
&& $info->getAdditionalInformation()
) {
foreach ($info->getAdditionalInformation() as $field => $value) {
Expand Down
26 changes: 19 additions & 7 deletions Block/JsConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,13 @@ protected function _getPaymentIsActive()
*/
public function getCurrentLocale()
{
return $this->localeResolver->getLocale(); // eg. fr_CA
$currentLocale=$this->localeResolver->getLocale();
$country_code=$this->_payOverTime->getCurrentCountryCode();
if(!empty($country_code) && stripos($currentLocale,$country_code)=== false){
$currentLocale="en_".strtoupper($country_code);
}

return $currentLocale; // eg. fr_CA
}

/**
Expand Down Expand Up @@ -124,15 +130,21 @@ public function isDisplayOnProductPage()
/**
* check if payment is active for cart page
*
* @return bool
* @return int
*/
public function isDisplayOnCartPage()
{
$isEnabledForCartPage=true;
if (!$this->_payOverTime->isEnabledForCartPage()) {
$isEnabledForCartPage= false;
}
return $isEnabledForCartPage;
return $this->_payOverTime->isEnabledForCartPage();
}

/**
* Get Express Checkout JS URL
*
* @return bool|string
*/
public function getAfterpayECJsUrl()
{
$express_checkout_key=$this->_payOverTime->getExpressCheckoutKey();
return $this->_payOverTime->getWebUrl('afterpay.js',array("merchant_key"=>!empty($express_checkout_key)?$express_checkout_key:""));
}
}
23 changes: 21 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
# Afterpay Magento 2 Extension Changelog

## Version 3.4.0

_Wed 24 Mar 2021_

### Supported Editions & Versions

Tested and verified in clean installations of Magento 2:

- Magento Enterprise Edition (EE) version 2.4.2

### Highlights

- Introduced an implementation of Express Checkout.
- Improved instalment calculations by adding coverage for additional scenarios.
- Improved the asset placement on PDP and cart pages.
- Improved invoice payment context to remove unnecessary details from consumer order notifications.

---

## Version 3.3.0

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

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

0 comments on commit 4c2f96c

Please sign in to comment.