Skip to content

Commit e16ca5b

Browse files
Release version 3.4.2
1 parent 182d2f9 commit e16ca5b

File tree

27 files changed

+1005
-425
lines changed

27 files changed

+1005
-425
lines changed

Block/Cart/Button.php

Lines changed: 45 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Magento 2 extensions for Afterpay Payment
44
*
55
* @author Afterpay
6-
* @copyright 2016-2020 Afterpay https://www.afterpay.com
6+
* @copyright 2016-2021 Afterpay https://www.afterpay.com
77
*/
88
namespace Afterpay\Afterpay\Block\Cart;
99

@@ -13,6 +13,7 @@
1313
use Magento\Customer\Model\Session as CustomerSession;
1414
use Magento\Framework\View\Element\Template\Context;
1515
use Magento\Framework\Locale\Resolver as Resolver;
16+
use Magento\Framework\Serialize\Serializer\Json as JsonHelper;
1617

1718

1819
class Button extends \Afterpay\Afterpay\Block\JsConfig
@@ -24,6 +25,10 @@ class Button extends \Afterpay\Afterpay\Block\JsConfig
2425
protected $afterpayPayovertime;
2526
protected $checkoutSession;
2627
protected $customerSession;
28+
/**
29+
* @var JsonHelper
30+
*/
31+
protected $_jsonHelper;
2732

2833
/**
2934
* Button constructor.
@@ -32,6 +37,7 @@ class Button extends \Afterpay\Afterpay\Block\JsConfig
3237
* @param AfterpayPayovertime $afterpayPayovertime
3338
* @param CheckoutSession $checkoutSession
3439
* @param CustomerSession $customerSession
40+
* @param JsonHelper $jsonHelper
3541
* @param array $data
3642
* @param Resolver $localeResolver
3743
*/
@@ -41,14 +47,16 @@ public function __construct(
4147
AfterpayPayovertime $afterpayPayovertime,
4248
CheckoutSession $checkoutSession,
4349
CustomerSession $customerSession,
50+
JsonHelper $jsonHelper,
4451
array $data=[],
4552
Resolver $localeResolver
4653
) {
4754
$this->afterpayConfig = $afterpayConfig;
4855
$this->afterpayPayovertime = $afterpayPayovertime;
4956
$this->checkoutSession = $checkoutSession;
5057
$this->customerSession = $customerSession;
51-
parent::__construct($afterpayConfig,$context, $localeResolver,$data);
58+
parent::__construct($afterpayConfig,$afterpayPayovertime,$context, $localeResolver,$jsonHelper,$data);
59+
5260
}
5361

5462
/**
@@ -58,37 +66,37 @@ protected function _getPaymentIsActive()
5866
{
5967
return $this->afterpayConfig->isActive();
6068
}
61-
69+
6270
/**
6371
* @return bool
6472
*/
6573
public function canShow()
6674
{
67-
// check if payment is active
75+
// check if payment is active
6876
if (!$this->_getPaymentIsActive()) {
6977
return false;
7078
}
7179
else{
7280
//Check for Supported currency
7381
if($this->afterpayConfig->getCurrencyCode()){
74-
82+
7583
$quote = $this->checkoutSession->getQuote();
7684
// get grand total (final amount need to be paid)
7785
$grandTotal =$quote->getGrandTotal();
7886
$excluded_categories=$this->afterpayConfig->getExcludedCategories();
79-
80-
if($this->afterpayPayovertime->canUseForCurrency($this->afterpayConfig->getCurrencyCode()) ){
81-
87+
88+
if($this->afterpayPayovertime->canUseForCurrency($this->afterpayConfig->getCurrencyCode()) ){
89+
8290
if($excluded_categories !=""){
8391
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
8492
$productRepository = $objectManager->get('\Magento\Catalog\Model\ProductRepository');
8593
$excluded_categories_array = explode(",",$excluded_categories);
86-
94+
8795
foreach ($quote->getAllVisibleItems() as $item) {
8896
$productid = $item->getProductId();
8997
$product=$productRepository->getById($productid);
9098
$categoryids = $product->getCategoryIds();
91-
99+
92100
foreach($categoryids as $k)
93101
{
94102
if(in_array($k,$excluded_categories_array)){
@@ -102,25 +110,25 @@ public function canShow()
102110
else{
103111
return false;
104112
}
105-
}
113+
}
106114
else {
107115
return false;
108116
}
109117
}
110118
}
111-
119+
112120
/**
113121
* @return string
114122
*/
115123
public function getFinalAmount()
116124
{
117-
125+
118126
$grandTotal = $this->checkoutSession->getQuote()->getGrandTotal();
119-
127+
120128
return !empty($grandTotal)?number_format($grandTotal, 2,".",""):"0.00";
121-
129+
122130
}
123-
/*
131+
/*
124132
* @return boolean
125133
*/
126134
public function canUseCurrency()
@@ -131,8 +139,27 @@ public function canUseCurrency()
131139
{
132140
$canUse= $this->afterpayPayovertime->canUseForCurrency($this->afterpayConfig->getCurrencyCode());
133141
}
134-
142+
135143
return $canUse;
136-
144+
145+
}
146+
/*
147+
* @return boolean
148+
*/
149+
public function isWithinLimits()
150+
{
151+
$isWithinLimits=false;
152+
$grandTotal = $this->checkoutSession->getQuote()->getGrandTotal();
153+
if($grandTotal > 0 && $this->afterpayConfig->getMaxOrderLimit() >= $grandTotal && $this->afterpayConfig->getMinOrderLimit() <= $grandTotal){
154+
$isWithinLimits = true;
155+
}
156+
return $isWithinLimits;
157+
}
158+
/*
159+
* @return boolean
160+
**/
161+
public function isQuoteVirtual()
162+
{
163+
return $this->checkoutSession->getQuote()->isVirtual();
137164
}
138165
}

Block/Catalog/Installments.php

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,18 @@
33
* Magento 2 extensions for Afterpay Payment
44
*
55
* @author Afterpay
6-
* @copyright 2016-2020 Afterpay https://www.afterpay.com
6+
* @copyright 2016-2021 Afterpay https://www.afterpay.com
77
*/
88
namespace Afterpay\Afterpay\Block\Catalog;
99

1010
use Afterpay\Afterpay\Block\JsConfig;
1111
use Afterpay\Afterpay\Model\Config\Payovertime as AfterpayConfig;
1212
use Afterpay\Afterpay\Model\Payovertime as AfterpayPayovertime;
1313
use Magento\Framework\Locale\Resolver as Resolver;
14+
use Magento\Framework\Serialize\Serializer\Json as JsonHelper;
1415
use Magento\Framework\Registry as Registry;
1516
use Magento\Framework\View\Element\Template\Context;
17+
use Magento\Checkout\Model\Session as CheckoutSession;
1618

1719
class Installments extends JsConfig
1820
{
@@ -35,28 +37,41 @@ class Installments extends JsConfig
3537
* @var Resolver
3638
*/
3739
private $localeResolver;
40+
/**
41+
* @var CheckoutSession
42+
*/
43+
protected $checkoutSession;
44+
/**
45+
* @var JsonHelper
46+
*/
47+
protected $_jsonHelper;
3848

3949
/**
4050
* @param Context $context
4151
* @param Registry $registry
4252
* @param AfterpayConfig $afterpayConfig
4353
* @param AfterpayPayovertime $afterpayPayovertime
54+
* @param JsonHelper $jsonHelper
4455
* @param array $data
4556
* @param Resolver $localeResolver
57+
* @param CheckoutSession $checkoutSession
4658
*/
4759
public function __construct(
4860
Context $context,
4961
Registry $registry,
5062
AfterpayConfig $afterpayConfig,
5163
AfterpayPayovertime $afterpayPayovertime,
64+
CheckoutSession $checkoutSession,
65+
JsonHelper $jsonHelper,
5266
array $data,
5367
Resolver $localeResolver
5468
) {
5569
$this->registry = $registry;
5670
$this->afterpayConfig = $afterpayConfig;
5771
$this->afterpayPayovertime = $afterpayPayovertime;
5872
$this->localeResolver = $localeResolver;
59-
parent::__construct($afterpayConfig, $context, $localeResolver, $data);
73+
$this->checkoutSession = $checkoutSession;
74+
parent::__construct($afterpayConfig, $afterpayPayovertime,$context, $localeResolver,$jsonHelper, $data);
6075
}
6176

6277
/**
@@ -65,14 +80,16 @@ public function __construct(
6580
public function canShow(): bool
6681
{
6782
// check if payment is active
83+
$product = $this->registry->registry('product');
84+
6885
if ($this->_getPaymentIsActive() &&
6986
$this->afterpayConfig->getCurrencyCode() &&
70-
$this->afterpayPayovertime->canUseForCurrency($this->afterpayConfig->getCurrencyCode())
87+
$this->afterpayPayovertime->canUseForCurrency($this->afterpayConfig->getCurrencyCode() &&
88+
$product->isSalable())
7189
) {
7290
$excluded_categories = $this->afterpayConfig->getExcludedCategories();
7391
if ($excluded_categories != "") {
7492
$excluded_categories_array = explode(",", $excluded_categories);
75-
$product = $this->registry->registry('product');
7693
$categoryids = $product->getCategoryIds();
7794
foreach ($categoryids as $k) {
7895
if (in_array($k, $excluded_categories_array)) {
@@ -123,4 +140,22 @@ public function canUseCurrency()
123140

124141
return $canUse;
125142
}
143+
/**
144+
* @return boolean
145+
*/
146+
public function isProductVirtual()
147+
{
148+
$isVirtual=false;
149+
150+
$product = $this->registry->registry('product');
151+
152+
if ($product->getIsVirtual()) {
153+
$isVirtual=true;
154+
if ($this->checkoutSession->hasQuote()) {
155+
$isVirtual=$this->checkoutSession->getQuote()->isVirtual();
156+
}
157+
}
158+
159+
return $isVirtual;
160+
}
126161
}

0 commit comments

Comments
 (0)