Skip to content

Commit

Permalink
Release version 3.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
afterpayplugins committed Jan 13, 2021
1 parent 5c7dab4 commit 3c774ef
Show file tree
Hide file tree
Showing 24 changed files with 484 additions and 299 deletions.
110 changes: 32 additions & 78 deletions Block/Cart/Button.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,51 +7,48 @@
*/
namespace Afterpay\Afterpay\Block\Cart;

use Magento\Framework\View\Element\Template;
use Magento\Checkout\Model\Session as CheckoutSession;
use Magento\Directory\Model\Currency as Currency;
use Afterpay\Afterpay\Model\Config\Payovertime as AfterpayConfig;
use Afterpay\Afterpay\Model\Payovertime as AfterpayPayovertime;
use Magento\Customer\Model\Session as CustomerSession;
use Magento\Framework\Component\ComponentRegistrar as ComponentRegistrar;
use Magento\Framework\View\Element\Template\Context;
use Magento\Framework\Locale\Resolver as Resolver;

class Button extends Template

class Button extends \Afterpay\Afterpay\Block\JsConfig
{
/**
* @var AfterpayConfig
*/
protected $afterpayConfig;
protected $afterpayPayovertime;
protected $checkoutSession;
protected $currency;
protected $customerSession;
protected $componentRegistrar;

/**
* Button constructor.
* @param Template\Context $context
* @param Context $context
* @param AfterpayConfig $afterpayConfig
* @param AfterpayPayovertime $afterpayPayovertime
* @param CheckoutSession $checkoutSession
* @param Currency $currency
* @param CustomerSession $customerSession
* @param array $data
* @param Resolver $localeResolver
*/
public function __construct(
Template\Context $context,
Context $context,
AfterpayConfig $afterpayConfig,
AfterpayPayovertime $afterpayPayovertime,
CheckoutSession $checkoutSession,
Currency $currency,
CustomerSession $customerSession,
ComponentRegistrar $componentRegistrar,
array $data
array $data=[],
Resolver $localeResolver
) {
$this->afterpayConfig = $afterpayConfig;
$this->afterpayPayovertime = $afterpayPayovertime;
$this->checkoutSession = $checkoutSession;
$this->currency = $currency;
$this->customerSession = $customerSession;
$this->componentRegistrar = $componentRegistrar;
parent::__construct($context, $data);
parent::__construct($afterpayConfig,$context, $localeResolver,$data);
}

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

/**
* @return float
*/
public function getInstallmentsTotal()
{
$quote = $this->checkoutSession->getQuote();

if ($grandTotal = $quote->getGrandTotal()) {
return $grandTotal / 4;
}
}

/**
* @return string
*/
public function getInstallmentsTotalHtml()
{
return $this->getCurrency()->getCurrencySymbol() . number_format($this->getInstallmentsTotal(), 2);
}

/**
* @return Currency
*/
protected function getCurrency()
{
return $this->currency;
}


/**
* @return bool
*/
Expand All @@ -108,7 +77,7 @@ public function canShow()
$grandTotal =$quote->getGrandTotal();
$excluded_categories=$this->afterpayConfig->getExcludedCategories();

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

if($excluded_categories !=""){
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
Expand Down Expand Up @@ -139,46 +108,31 @@ public function canShow()
}
}
}

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

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

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

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

/**
* Calculate region specific Instalment Text for Cart page
* @return string
*/
public function getCartPageText()
{
$currencyCode = $this->afterpayConfig->getCurrencyCode();
$assetsPath = $this->componentRegistrar->getPath(ComponentRegistrar::MODULE, 'Afterpay_Afterpay');
$assets_cart_page = [];

if(file_exists($assetsPath.'/assets.ini'))
{
$assets = parse_ini_file($assetsPath.'/assets.ini',true);
if(isset($assets[$currencyCode]['cart_page1']))
{
$assets_cart_page['snippet1'] = $assets[$currencyCode]['cart_page1'];
$assets_cart_page['snippet2'] = $assets[$currencyCode]['cart_page2'];
$assets_cart_page['snippet2'] = str_replace(array('[modal-href]'),
array('javascript:void(0)'), $assets_cart_page['snippet2']);
}
else{
$assets_cart_page['snippet1'] = '';
$assets_cart_page['snippet2'] = '';
}
}
return $assets_cart_page;

return $canUse;

}
}
146 changes: 42 additions & 104 deletions Block/Catalog/Installments.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,52 +7,42 @@
*/
namespace Afterpay\Afterpay\Block\Catalog;

use Magento\Framework\View\Element\Template;
use Magento\Catalog\Model\Product as Product;
use Magento\Framework\Registry as Registry;
use Magento\Directory\Model\Currency as Currency;
use Afterpay\Afterpay\Model\Config\Payovertime as AfterpayConfig;
use Afterpay\Afterpay\Model\Payovertime as AfterpayPayovertime;
use Magento\Framework\Component\ComponentRegistrar as ComponentRegistrar;
use Magento\Framework\View\Element\Template\Context;
use Magento\Framework\Locale\Resolver as Resolver;

class Installments extends Template
class Installments extends \Afterpay\Afterpay\Block\JsConfig
{
/**
* @var Product
*/
protected $product;

protected $registry;
protected $currency;
protected $afterpayConfig;
protected $afterpayPayovertime;
protected $componentRegistrar;
private $localeResolver;

/**
* Installments constructor.
* @param Template\Context $context
* @param Product $product
* @param Context $context
* @param AfterpayConfig $afterpayConfig
* @param AfterpayPayovertime $afterpayPayovertime
* @param Registry $registry
* @param Currency $currency
* @param AfterpayConfig $afterpayConfig
* @param array $data
*/
public function __construct(
Template\Context $context,
Product $product,
Context $context,
Registry $registry,
Currency $currency,
AfterpayConfig $afterpayConfig,
AfterpayPayovertime $afterpayPayovertime,
ComponentRegistrar $componentRegistrar,
array $data
array $data,
Resolver $localeResolver
) {
$this->product = $product;
$this->registry = $registry;
$this->currency = $currency;
$this->afterpayConfig = $afterpayConfig;
$this->afterpayPayovertime = $afterpayPayovertime;
$this->componentRegistrar = $componentRegistrar;
parent::__construct($context, $data);
$this->localeResolver = $localeResolver;
parent::__construct($afterpayConfig,$context, $localeResolver,$data);
}

/**
Expand All @@ -63,20 +53,6 @@ protected function _getPaymentIsActive()
return $this->afterpayConfig->isActive();
}

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

// set if final price is exist
if ($price = $product->getFinalPrice()) {
return $this->currency->getCurrencySymbol() . number_format($price / 4, 2);
}
}

/**
* @return bool
*/
Expand Down Expand Up @@ -111,84 +87,46 @@ public function canShow()
return false;
}
}
}
/**
* @return bool
*/
public function isProductEligible(){

$product = $this->registry->registry('product');
if ($product->getFinalPrice() > $this->afterpayConfig->getMaxOrderLimit() // greater than max order limit
|| $product->getFinalPrice() < $this->afterpayConfig->getMinOrderLimit()) { // lower than min order limit
return false;
}
return true;
}
}


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

/**
* Calculate region specific Instalment Text
/**
* @return string
*/
public function getInstalmentText()
public function getTypeOfProduct()
{
$currencyCode = $this->afterpayConfig->getCurrencyCode();
$assetsPath = $this->componentRegistrar->getPath(ComponentRegistrar::MODULE, 'Afterpay_Afterpay');
$assets_product_page = [];
if(file_exists($assetsPath.'/assets.ini'))
{
$assets = parse_ini_file($assetsPath.'/assets.ini',true);
if(isset($assets[$currencyCode]['product_page1']))
{
$assets_product_page['snippet1'] = $assets[$currencyCode]['product_page1'];
if($this->getTypeOfProduct()=="bundle"){
$assets_product_page['snippet1'] = $assets[$currencyCode]['product_page_from'];
}
$assets_product_page['snippet2'] = $assets[$currencyCode]['product_page2'];
} else {
$assets_product_page['snippet1'] = '';
$assets_product_page['snippet2'] = '';
}
}
return $assets_product_page;
$product = $this->registry->registry('product');
return $product->getTypeId();
}


/**
* @return float
* @return string
*/
public function getMaxOrderLimit()
public function getFinalAmount()
{
return $this->afterpayConfig->getMaxOrderLimit();
}

// 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";

}
/**
* @return float
*/
public function getMinOrderLimit()
{
return $this->afterpayConfig->getMinOrderLimit();
}

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

return $canUse;

}

}
Loading

0 comments on commit 3c774ef

Please sign in to comment.