Skip to content

Commit

Permalink
Release version 3.4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
afterpayplugins committed Jun 16, 2021
1 parent 182d2f9 commit e16ca5b
Show file tree
Hide file tree
Showing 27 changed files with 1,005 additions and 425 deletions.
63 changes: 45 additions & 18 deletions Block/Cart/Button.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Magento 2 extensions for Afterpay Payment
*
* @author Afterpay
* @copyright 2016-2020 Afterpay https://www.afterpay.com
* @copyright 2016-2021 Afterpay https://www.afterpay.com
*/
namespace Afterpay\Afterpay\Block\Cart;

Expand All @@ -13,6 +13,7 @@
use Magento\Customer\Model\Session as CustomerSession;
use Magento\Framework\View\Element\Template\Context;
use Magento\Framework\Locale\Resolver as Resolver;
use Magento\Framework\Serialize\Serializer\Json as JsonHelper;


class Button extends \Afterpay\Afterpay\Block\JsConfig
Expand All @@ -24,6 +25,10 @@ class Button extends \Afterpay\Afterpay\Block\JsConfig
protected $afterpayPayovertime;
protected $checkoutSession;
protected $customerSession;
/**
* @var JsonHelper
*/
protected $_jsonHelper;

/**
* Button constructor.
Expand All @@ -32,6 +37,7 @@ class Button extends \Afterpay\Afterpay\Block\JsConfig
* @param AfterpayPayovertime $afterpayPayovertime
* @param CheckoutSession $checkoutSession
* @param CustomerSession $customerSession
* @param JsonHelper $jsonHelper
* @param array $data
* @param Resolver $localeResolver
*/
Expand All @@ -41,14 +47,16 @@ public function __construct(
AfterpayPayovertime $afterpayPayovertime,
CheckoutSession $checkoutSession,
CustomerSession $customerSession,
JsonHelper $jsonHelper,
array $data=[],
Resolver $localeResolver
) {
$this->afterpayConfig = $afterpayConfig;
$this->afterpayPayovertime = $afterpayPayovertime;
$this->checkoutSession = $checkoutSession;
$this->customerSession = $customerSession;
parent::__construct($afterpayConfig,$context, $localeResolver,$data);
parent::__construct($afterpayConfig,$afterpayPayovertime,$context, $localeResolver,$jsonHelper,$data);

}

/**
Expand All @@ -58,37 +66,37 @@ protected function _getPaymentIsActive()
{
return $this->afterpayConfig->isActive();
}

/**
* @return bool
*/
public function canShow()
{
// check if payment is active
// check if payment is active
if (!$this->_getPaymentIsActive()) {
return false;
}
else{
//Check for Supported currency
if($this->afterpayConfig->getCurrencyCode()){

$quote = $this->checkoutSession->getQuote();
// get grand total (final amount need to be paid)
$grandTotal =$quote->getGrandTotal();
$excluded_categories=$this->afterpayConfig->getExcludedCategories();
if($this->afterpayPayovertime->canUseForCurrency($this->afterpayConfig->getCurrencyCode()) ){

if($this->afterpayPayovertime->canUseForCurrency($this->afterpayConfig->getCurrencyCode()) ){

if($excluded_categories !=""){
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$productRepository = $objectManager->get('\Magento\Catalog\Model\ProductRepository');
$excluded_categories_array = explode(",",$excluded_categories);

foreach ($quote->getAllVisibleItems() as $item) {
$productid = $item->getProductId();
$product=$productRepository->getById($productid);
$categoryids = $product->getCategoryIds();

foreach($categoryids as $k)
{
if(in_array($k,$excluded_categories_array)){
Expand All @@ -102,25 +110,25 @@ public function canShow()
else{
return false;
}
}
}
else {
return false;
}
}
}

/**
* @return string
*/
public function getFinalAmount()
{

$grandTotal = $this->checkoutSession->getQuote()->getGrandTotal();

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

}
/*
/*
* @return boolean
*/
public function canUseCurrency()
Expand All @@ -131,8 +139,27 @@ public function canUseCurrency()
{
$canUse= $this->afterpayPayovertime->canUseForCurrency($this->afterpayConfig->getCurrencyCode());
}

return $canUse;


}
/*
* @return boolean
*/
public function isWithinLimits()
{
$isWithinLimits=false;
$grandTotal = $this->checkoutSession->getQuote()->getGrandTotal();
if($grandTotal > 0 && $this->afterpayConfig->getMaxOrderLimit() >= $grandTotal && $this->afterpayConfig->getMinOrderLimit() <= $grandTotal){
$isWithinLimits = true;
}
return $isWithinLimits;
}
/*
* @return boolean
**/
public function isQuoteVirtual()
{
return $this->checkoutSession->getQuote()->isVirtual();
}
}
43 changes: 39 additions & 4 deletions Block/Catalog/Installments.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@
* Magento 2 extensions for Afterpay Payment
*
* @author Afterpay
* @copyright 2016-2020 Afterpay https://www.afterpay.com
* @copyright 2016-2021 Afterpay https://www.afterpay.com
*/
namespace Afterpay\Afterpay\Block\Catalog;

use Afterpay\Afterpay\Block\JsConfig;
use Afterpay\Afterpay\Model\Config\Payovertime as AfterpayConfig;
use Afterpay\Afterpay\Model\Payovertime as AfterpayPayovertime;
use Magento\Framework\Locale\Resolver as Resolver;
use Magento\Framework\Serialize\Serializer\Json as JsonHelper;
use Magento\Framework\Registry as Registry;
use Magento\Framework\View\Element\Template\Context;
use Magento\Checkout\Model\Session as CheckoutSession;

class Installments extends JsConfig
{
Expand All @@ -35,28 +37,41 @@ class Installments extends JsConfig
* @var Resolver
*/
private $localeResolver;
/**
* @var CheckoutSession
*/
protected $checkoutSession;
/**
* @var JsonHelper
*/
protected $_jsonHelper;

/**
* @param Context $context
* @param Registry $registry
* @param AfterpayConfig $afterpayConfig
* @param AfterpayPayovertime $afterpayPayovertime
* @param JsonHelper $jsonHelper
* @param array $data
* @param Resolver $localeResolver
* @param CheckoutSession $checkoutSession
*/
public function __construct(
Context $context,
Registry $registry,
AfterpayConfig $afterpayConfig,
AfterpayPayovertime $afterpayPayovertime,
CheckoutSession $checkoutSession,
JsonHelper $jsonHelper,
array $data,
Resolver $localeResolver
) {
$this->registry = $registry;
$this->afterpayConfig = $afterpayConfig;
$this->afterpayPayovertime = $afterpayPayovertime;
$this->localeResolver = $localeResolver;
parent::__construct($afterpayConfig, $context, $localeResolver, $data);
$this->checkoutSession = $checkoutSession;
parent::__construct($afterpayConfig, $afterpayPayovertime,$context, $localeResolver,$jsonHelper, $data);
}

/**
Expand All @@ -65,14 +80,16 @@ public function __construct(
public function canShow(): bool
{
// check if payment is active
$product = $this->registry->registry('product');

if ($this->_getPaymentIsActive() &&
$this->afterpayConfig->getCurrencyCode() &&
$this->afterpayPayovertime->canUseForCurrency($this->afterpayConfig->getCurrencyCode())
$this->afterpayPayovertime->canUseForCurrency($this->afterpayConfig->getCurrencyCode() &&
$product->isSalable())
) {
$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)) {
Expand Down Expand Up @@ -123,4 +140,22 @@ public function canUseCurrency()

return $canUse;
}
/**
* @return boolean
*/
public function isProductVirtual()
{
$isVirtual=false;

$product = $this->registry->registry('product');

if ($product->getIsVirtual()) {
$isVirtual=true;
if ($this->checkoutSession->hasQuote()) {
$isVirtual=$this->checkoutSession->getQuote()->isVirtual();
}
}

return $isVirtual;
}
}
Loading

0 comments on commit e16ca5b

Please sign in to comment.