Skip to content

Commit 3c774ef

Browse files
Release version 3.3.0
1 parent 5c7dab4 commit 3c774ef

24 files changed

+484
-299
lines changed

Block/Cart/Button.php

Lines changed: 32 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -7,51 +7,48 @@
77
*/
88
namespace Afterpay\Afterpay\Block\Cart;
99

10-
use Magento\Framework\View\Element\Template;
1110
use Magento\Checkout\Model\Session as CheckoutSession;
12-
use Magento\Directory\Model\Currency as Currency;
1311
use Afterpay\Afterpay\Model\Config\Payovertime as AfterpayConfig;
1412
use Afterpay\Afterpay\Model\Payovertime as AfterpayPayovertime;
1513
use Magento\Customer\Model\Session as CustomerSession;
16-
use Magento\Framework\Component\ComponentRegistrar as ComponentRegistrar;
14+
use Magento\Framework\View\Element\Template\Context;
15+
use Magento\Framework\Locale\Resolver as Resolver;
1716

18-
class Button extends Template
17+
18+
class Button extends \Afterpay\Afterpay\Block\JsConfig
1919
{
2020
/**
2121
* @var AfterpayConfig
2222
*/
2323
protected $afterpayConfig;
2424
protected $afterpayPayovertime;
2525
protected $checkoutSession;
26-
protected $currency;
2726
protected $customerSession;
28-
protected $componentRegistrar;
2927

3028
/**
3129
* Button constructor.
32-
* @param Template\Context $context
30+
* @param Context $context
3331
* @param AfterpayConfig $afterpayConfig
32+
* @param AfterpayPayovertime $afterpayPayovertime
3433
* @param CheckoutSession $checkoutSession
35-
* @param Currency $currency
34+
* @param CustomerSession $customerSession
3635
* @param array $data
36+
* @param Resolver $localeResolver
3737
*/
3838
public function __construct(
39-
Template\Context $context,
39+
Context $context,
4040
AfterpayConfig $afterpayConfig,
4141
AfterpayPayovertime $afterpayPayovertime,
4242
CheckoutSession $checkoutSession,
43-
Currency $currency,
4443
CustomerSession $customerSession,
45-
ComponentRegistrar $componentRegistrar,
46-
array $data
44+
array $data=[],
45+
Resolver $localeResolver
4746
) {
4847
$this->afterpayConfig = $afterpayConfig;
4948
$this->afterpayPayovertime = $afterpayPayovertime;
5049
$this->checkoutSession = $checkoutSession;
51-
$this->currency = $currency;
5250
$this->customerSession = $customerSession;
53-
$this->componentRegistrar = $componentRegistrar;
54-
parent::__construct($context, $data);
51+
parent::__construct($afterpayConfig,$context, $localeResolver,$data);
5552
}
5653

5754
/**
@@ -61,35 +58,7 @@ protected function _getPaymentIsActive()
6158
{
6259
return $this->afterpayConfig->isActive();
6360
}
64-
65-
/**
66-
* @return float
67-
*/
68-
public function getInstallmentsTotal()
69-
{
70-
$quote = $this->checkoutSession->getQuote();
71-
72-
if ($grandTotal = $quote->getGrandTotal()) {
73-
return $grandTotal / 4;
74-
}
75-
}
76-
77-
/**
78-
* @return string
79-
*/
80-
public function getInstallmentsTotalHtml()
81-
{
82-
return $this->getCurrency()->getCurrencySymbol() . number_format($this->getInstallmentsTotal(), 2);
83-
}
84-
85-
/**
86-
* @return Currency
87-
*/
88-
protected function getCurrency()
89-
{
90-
return $this->currency;
91-
}
92-
61+
9362
/**
9463
* @return bool
9564
*/
@@ -108,7 +77,7 @@ public function canShow()
10877
$grandTotal =$quote->getGrandTotal();
10978
$excluded_categories=$this->afterpayConfig->getExcludedCategories();
11079

111-
if($this->afterpayPayovertime->canUseForCurrency($this->afterpayConfig->getCurrencyCode()) && $this->afterpayConfig->getMaxOrderLimit() >= $grandTotal && $this->afterpayConfig->getMinOrderLimit() <= $grandTotal){
80+
if($this->afterpayPayovertime->canUseForCurrency($this->afterpayConfig->getCurrencyCode()) ){
11281

11382
if($excluded_categories !=""){
11483
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
@@ -139,46 +108,31 @@ public function canShow()
139108
}
140109
}
141110
}
142-
111+
143112
/**
144-
* @return boolean
113+
* @return string
145114
*/
115+
public function getFinalAmount()
116+
{
117+
118+
$grandTotal = $this->checkoutSession->getQuote()->getGrandTotal();
119+
120+
return !empty($grandTotal)?number_format($grandTotal, 2,".",""):"0.00";
121+
122+
}
123+
/*
124+
* @return boolean
125+
*/
146126
public function canUseCurrency()
147127
{
128+
$canUse=false;
148129
//Check for Supported currency
149130
if($this->afterpayConfig->getCurrencyCode())
150131
{
151-
return $this->afterpayPayovertime->canUseForCurrency($this->afterpayConfig->getCurrencyCode());
152-
} else {
153-
return false;
132+
$canUse= $this->afterpayPayovertime->canUseForCurrency($this->afterpayConfig->getCurrencyCode());
154133
}
155-
}
156-
157-
/**
158-
* Calculate region specific Instalment Text for Cart page
159-
* @return string
160-
*/
161-
public function getCartPageText()
162-
{
163-
$currencyCode = $this->afterpayConfig->getCurrencyCode();
164-
$assetsPath = $this->componentRegistrar->getPath(ComponentRegistrar::MODULE, 'Afterpay_Afterpay');
165-
$assets_cart_page = [];
166-
167-
if(file_exists($assetsPath.'/assets.ini'))
168-
{
169-
$assets = parse_ini_file($assetsPath.'/assets.ini',true);
170-
if(isset($assets[$currencyCode]['cart_page1']))
171-
{
172-
$assets_cart_page['snippet1'] = $assets[$currencyCode]['cart_page1'];
173-
$assets_cart_page['snippet2'] = $assets[$currencyCode]['cart_page2'];
174-
$assets_cart_page['snippet2'] = str_replace(array('[modal-href]'),
175-
array('javascript:void(0)'), $assets_cart_page['snippet2']);
176-
}
177-
else{
178-
$assets_cart_page['snippet1'] = '';
179-
$assets_cart_page['snippet2'] = '';
180-
}
181-
}
182-
return $assets_cart_page;
134+
135+
return $canUse;
136+
183137
}
184138
}

Block/Catalog/Installments.php

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

10-
use Magento\Framework\View\Element\Template;
11-
use Magento\Catalog\Model\Product as Product;
1210
use Magento\Framework\Registry as Registry;
13-
use Magento\Directory\Model\Currency as Currency;
1411
use Afterpay\Afterpay\Model\Config\Payovertime as AfterpayConfig;
1512
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;
1715

18-
class Installments extends Template
16+
class Installments extends \Afterpay\Afterpay\Block\JsConfig
1917
{
20-
/**
21-
* @var Product
22-
*/
23-
protected $product;
18+
2419
protected $registry;
25-
protected $currency;
2620
protected $afterpayConfig;
2721
protected $afterpayPayovertime;
28-
protected $componentRegistrar;
22+
private $localeResolver;
2923

3024
/**
3125
* Installments constructor.
32-
* @param Template\Context $context
33-
* @param Product $product
26+
* @param Context $context
27+
* @param AfterpayConfig $afterpayConfig
28+
* @param AfterpayPayovertime $afterpayPayovertime
3429
* @param Registry $registry
35-
* @param Currency $currency
3630
* @param AfterpayConfig $afterpayConfig
3731
* @param array $data
3832
*/
3933
public function __construct(
40-
Template\Context $context,
41-
Product $product,
34+
Context $context,
4235
Registry $registry,
43-
Currency $currency,
4436
AfterpayConfig $afterpayConfig,
4537
AfterpayPayovertime $afterpayPayovertime,
46-
ComponentRegistrar $componentRegistrar,
47-
array $data
38+
array $data,
39+
Resolver $localeResolver
4840
) {
49-
$this->product = $product;
5041
$this->registry = $registry;
51-
$this->currency = $currency;
5242
$this->afterpayConfig = $afterpayConfig;
5343
$this->afterpayPayovertime = $afterpayPayovertime;
54-
$this->componentRegistrar = $componentRegistrar;
55-
parent::__construct($context, $data);
44+
$this->localeResolver = $localeResolver;
45+
parent::__construct($afterpayConfig,$context, $localeResolver,$data);
5646
}
5747

5848
/**
@@ -63,20 +53,6 @@ protected function _getPaymentIsActive()
6353
return $this->afterpayConfig->isActive();
6454
}
6555

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-
8056
/**
8157
* @return bool
8258
*/
@@ -111,84 +87,46 @@ public function canShow()
11187
return false;
11288
}
11389
}
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+
12792

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+
/**
14494
* @return string
14595
*/
146-
public function getInstalmentText()
96+
public function getTypeOfProduct()
14797
{
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();
167100
}
168-
169101

170102
/**
171-
* @return float
103+
* @return string
172104
*/
173-
public function getMaxOrderLimit()
105+
public function getFinalAmount()
174106
{
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+
}
178116
/**
179-
* @return float
180-
*/
181-
public function getMinOrderLimit()
182-
{
183-
return $this->afterpayConfig->getMinOrderLimit();
184-
}
185-
186-
/**
187-
* @return string
117+
* @return boolean
188118
*/
189-
public function getTypeOfProduct()
119+
public function canUseCurrency()
190120
{
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+
193130
}
131+
194132
}

0 commit comments

Comments
 (0)