Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release Version 1.1.12 #135

Merged
merged 8 commits into from
Jan 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions Block/Checkout/Overview.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,15 +188,4 @@ public function productTypeErrorMessage()
{
return $this->_escaper->escapeHtml($this->catalogHelper->getProductTypeMessage());
}

/**
* Check financing by sku
*
* @return bool
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
public function isFinancingBySku()
{
return $this->quoteHelper->isFinancingBySku();
}
}
25 changes: 24 additions & 1 deletion Block/Payment/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,29 @@ class Form extends \Magento\Payment\Block\Form
*/
public $helper;

/**
* @var \Magento\Backend\Model\Session\Quote
*/
public $sessionQuote;

/**
* @var \Magento\Framework\App\CacheInterface
*/
public $cache;

/**
* Constructor
*/
public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
\Bread\BreadCheckout\Helper\Catalog $helper,
\Magento\Backend\Model\Session\Quote $sessionQuote,
\Magento\Framework\App\CacheInterface $cache,
array $data = []
) {

$this->helper = $helper;
$this->sessionQuote = $sessionQuote;
$this->cache = $cache;
parent::__construct($context, $data);
}

Expand Down Expand Up @@ -81,4 +94,14 @@ public function getIsDefaultSize()
{
return (string) $this->helper->getDefaultButtonSizeHtml();
}

/**
* Saves the Store Id in the Magento Cache
*/
public function saveAdminStoreId()
{
$storeId = $this->sessionQuote->getStoreId();
$this->cache->save($storeId, 'admin_store_id');
return $storeId;
}
}
18 changes: 10 additions & 8 deletions Controller/Adminhtml/Bread/GenerateCart.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public function __construct(
*/
public function execute()
{
$storeId = $this->getRequest()->getParam('store_id');

try {
$quote = $this->helper->getSessionQuote();

Expand Down Expand Up @@ -84,7 +86,7 @@ public function execute()
$arr['options']['shippingContact'] = $this->helper->getShippingAddressData();
$arr['options']['billingContact'] = $this->helper->getBillingAddressData();

if (!$this->helper->isHealthcare() && !$quote->getUseRewardPoints()) {
if (!$this->helper->isHealthcare($storeId) && !$quote->getUseRewardPoints()) {
$arr['options']['items'] = $this->helper->getQuoteItemsData();
} else {
$arr['options']['customTotal'] = round($quote->getGrandTotal() * 100);
Expand All @@ -101,16 +103,16 @@ public function execute()

$arr['options']['tax'] = $this->helper->getTaxValue();

if ($this->helper->isTargetedFinancing() && $this->helper->checkFinancingMode('cart')) {
$financingId = $this->helper->getFinancingId();
$threshold = $this->helper->getTargetedFinancingThreshold();
if ($this->helper->isTargetedFinancing($storeId) && $this->helper->checkFinancingMode('cart', $storeId)) {
$financingId = $this->helper->getFinancingId($storeId);
$threshold = $this->helper->getTargetedFinancingThreshold($storeId);

$arr['options']['financingProgramId'] = $quote->getGrandTotal() >= $threshold ? $financingId : null;
} elseif ($this->helper->isTargetedFinancing()
&& $this->helper->checkFinancingMode('sku')
&& $this->helper->isFinancingBySku()
} elseif ($this->helper->isTargetedFinancing($storeId)
&& $this->helper->checkFinancingMode('sku', $storeId)
&& $this->helper->isFinancingBySku($storeId)
) {
$arr['options']['financingProgramId'] = $this->helper->getFinancingId();
$arr['options']['financingProgramId'] = $this->helper->getFinancingId($storeId);
}

$result = $this->paymentApiClient->submitCartData($arr);
Expand Down
10 changes: 6 additions & 4 deletions Controller/Adminhtml/Bread/QuoteData.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public function __construct(
*/
public function execute()
{
$storeId = $this->getRequest()->getParam('store_id');

return $this->resultFactory->create(\Magento\Framework\Controller\ResultFactory::TYPE_JSON)->setData(
[
'quoteItems' => $this->helper->getQuoteItemsData(),
Expand All @@ -47,13 +49,13 @@ public function execute()
'shippingOptions' => $this->helper->getShippingOptions(),
'tax' => $this->helper->getTaxValue(),
'discounts' => $this->helper->getDiscountData(),
'cartSizeFinancing' => $this->helper->getFinancingData(),
'cartSizeFinancing' => $this->helper->getFinancingData($storeId),
'grandTotal' => $this->helper->getGrandTotal(),
'asLowAs' => $this->helper->isAsLowAs(),
'asLowAs' => $this->helper->isAsLowAs($storeId),
'paymentUrl' => $this->helper->getAdminPaymentUrl(),
'buttonCss' => $this->helper->getButtonDesign(),
'buttonCss' => $this->helper->getButtonDesign($storeId),
'buttonLocation' => $this->helperData->getOtherLocation(),
'isHealthcare' => $this->helper->isHealthcare()
'isHealthcare' => $this->helper->isHealthcare($storeId)
]
);
}
Expand Down
5 changes: 0 additions & 5 deletions Helper/Catalog.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,6 @@ protected function getPrice($lineItemPrice, \Magento\Catalog\Model\Product $theP
// For Bundled and Grouped products, final price comes through as 0, so need to use minimum price instead
if (floatval($price) === 0.0) {
$price = $theProduct->getMinimalPrice();
//If we can't grab the minimal price here, try to grab minimal price from the price model
if (!$price) {
$priceModel = $theProduct->getPriceModel();
$price = $priceModel ? $priceModel->getPrices($theProduct)[0] : null;
}
}
}

Expand Down
5 changes: 1 addition & 4 deletions Helper/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,7 @@ public function isEnabledOnCAT($store = \Magento\Store\Model\ScopeInterface::SCO
*/
public function isEnabledForCategory($category)
{
if (!$this->isActive()) {
return false;
}
if (!$this->isEnabledOnCAT()) {
if (!$this->isActive() || !$this->isEnabledOnCAT() || empty($category)) {
return false;
}
return in_array($category->getId(), $this->getBreadCategories());
Expand Down
2 changes: 1 addition & 1 deletion Helper/Checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,6 @@ public function validateTransactionAmount($transactionId)
$this->setBreadTransactionAmount($info['adjustedTotal']);
}

return (bool) ($breadAmount == $quoteTotal);
return (bool) ($breadAmount == $quoteTotal || (abs((int)$breadAmount - (int)$quoteTotal) <= 2));
}
}
54 changes: 29 additions & 25 deletions Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,12 @@ public function __construct(
* Is module active?
*
* @param null $store
* @param null $storeCode
* @return bool
*/
public function isActive($store = \Magento\Store\Model\ScopeInterface::SCOPE_STORE)
public function isActive($store = \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeCode = null)
{
return (bool) $this->scopeConfig->getValue(self::XML_CONFIG_MODULE_ACTIVE, $store);
return (bool) $this->scopeConfig->getValue(self::XML_CONFIG_MODULE_ACTIVE, $store, $storeCode);
}

/**
Expand Down Expand Up @@ -533,10 +534,10 @@ public function isPaymentMethodAtCheckout($store = \Magento\Store\Model\ScopeInt
* @param null $store
* @return bool
*/
public function isHealthcare($store = \Magento\Store\Model\ScopeInterface::SCOPE_STORE)
public function isHealthcare($storeCode = null, $store = \Magento\Store\Model\ScopeInterface::SCOPE_STORE)
{
return (bool) (
$this->isActive($store) && $this->scopeConfig->getValue(self::XML_CONFIG_HEALTHCARE_MODE, $store)
$this->isActive($store, $storeCode) && $this->scopeConfig->getValue(self::XML_CONFIG_HEALTHCARE_MODE, $store, $storeCode)
);
}

Expand All @@ -546,9 +547,9 @@ public function isHealthcare($store = \Magento\Store\Model\ScopeInterface::SCOPE
* @param null $store
* @return bool
*/
public function isAsLowAs($store = \Magento\Store\Model\ScopeInterface::SCOPE_STORE)
public function isAsLowAs($storeCode = null, $store = \Magento\Store\Model\ScopeInterface::SCOPE_STORE)
{
return (bool) ($this->isActive($store) && $this->scopeConfig->getValue(self::XML_CONFIG_AS_LOW_AS, $store));
return (bool) ($this->isActive($store, $storeCode) && $this->scopeConfig->getValue(self::XML_CONFIG_AS_LOW_AS, $store, $storeCode));
}

/**
Expand Down Expand Up @@ -580,30 +581,30 @@ public function getAllowCheckoutCP($store = \Magento\Store\Model\ScopeInterface:
*
* @return bool
*/
public function isTargetedFinancing($store = \Magento\Store\Model\ScopeInterface::SCOPE_STORE)
public function isTargetedFinancing($storeCode = null, $store = \Magento\Store\Model\ScopeInterface::SCOPE_STORE)
{
return (bool) ($this->isActive($store)
&& $this->scopeConfig->getValue(self::XML_CONFIG_ENABLE_TARGETED_FINANCING, $store));
return (bool) ($this->isActive($store, $storeCode)
&& $this->scopeConfig->getValue(self::XML_CONFIG_ENABLE_TARGETED_FINANCING, $store, $storeCode));
}

/**
* Get financing ID associated with cart size threshold
*
* @return string
*/
public function getFinancingId($store = \Magento\Store\Model\ScopeInterface::SCOPE_STORE)
public function getFinancingId($storeCode = null, $store = \Magento\Store\Model\ScopeInterface::SCOPE_STORE)
{
return $this->scopeConfig->getValue(self::XML_CONFIG_TARGETED_FINANCING_ID, $store);
return $this->scopeConfig->getValue(self::XML_CONFIG_TARGETED_FINANCING_ID, $store, $storeCode);
}

/**
* Get cart size over which targeted financing is enabled
*
* @return string
*/
public function getTargetedFinancingThreshold($store = \Magento\Store\Model\ScopeInterface::SCOPE_STORE)
public function getTargetedFinancingThreshold($storeCode = null, $store = \Magento\Store\Model\ScopeInterface::SCOPE_STORE)
{
return round($this->scopeConfig->getValue(self::XML_CONFIG_FINANCING_THRESHOLD, $store), 2);
return round($this->scopeConfig->getValue(self::XML_CONFIG_FINANCING_THRESHOLD, $store, $storeCode), 2);
}

/**
Expand All @@ -612,9 +613,9 @@ public function getTargetedFinancingThreshold($store = \Magento\Store\Model\Scop
* @param string $store
* @return array
*/
public function getTargetedFinancingSkus($store = \Magento\Store\Model\ScopeInterface::SCOPE_STORE)
public function getTargetedFinancingSkus($storeCode = null, $store = \Magento\Store\Model\ScopeInterface::SCOPE_STORE)
{
$list = $this->scopeConfig->getValue(self::XML_CONFIG_FINANCING_SKU, $store);
$list = $this->scopeConfig->getValue(self::XML_CONFIG_FINANCING_SKU, $store, $storeCode);
$list = preg_replace('/\s/', '', $list);

return explode(',', $list);
Expand All @@ -627,9 +628,9 @@ public function getTargetedFinancingSkus($store = \Magento\Store\Model\ScopeInte
* @param string $store
* @return int
*/
public function checkFinancingMode($mode, $store = \Magento\Store\Model\ScopeInterface::SCOPE_STORE)
public function checkFinancingMode($mode, $storeCode = null, $store = \Magento\Store\Model\ScopeInterface::SCOPE_STORE)
{
$configVal = (int)$this->scopeConfig->getValue(self::XML_CONFIG_ENABLE_TARGETED_FINANCING, $store);
$configVal = (int)$this->scopeConfig->getValue(self::XML_CONFIG_ENABLE_TARGETED_FINANCING, $store, $storeCode);
$output = null;

switch ($mode) {
Expand Down Expand Up @@ -670,9 +671,9 @@ public function getBlockCodeCheckoutOverview()
* @param null $store
* @return mixed
*/
public function getButtonDesign($store = \Magento\Store\Model\ScopeInterface::SCOPE_STORE)
public function getButtonDesign($storeCode = null, $store = \Magento\Store\Model\ScopeInterface::SCOPE_STORE)
{
return $this->scopeConfig->getValue(self::XML_CONFIG_BUTTON_DESIGN, $store);
return $this->scopeConfig->getValue(self::XML_CONFIG_BUTTON_DESIGN, $store, $storeCode);
}

/**
Expand Down Expand Up @@ -780,14 +781,17 @@ public function getDefaultCountry()
*
* @return array
*/
public function getFinancingData($store = \Magento\Store\Model\ScopeInterface::SCOPE_STORE)
public function getFinancingData($storeCode = null, $store = \Magento\Store\Model\ScopeInterface::SCOPE_STORE)
{
return [
"enabled" => $this->isTargetedFinancing($store),
"mode" => ['cart'=>$this->checkFinancingMode('cart'), 'sku'=>$this->checkFinancingMode('sku')],
"id" => $this->getFinancingId($store),
"threshold" => $this->getTargetedFinancingThreshold($store),
"sku_limit" => $this->getTargetedFinancingSkus($store)
"enabled" => $this->isTargetedFinancing($storeCode, $store),
"mode" => [
'cart'=> $this->checkFinancingMode('cart', $storeCode, $store),
'sku'=> $this->checkFinancingMode('sku', $storeCode, $store)
],
"id" => $this->getFinancingId($storeCode, $store),
"threshold" => $this->getTargetedFinancingThreshold($storeCode, $store),
"sku_limit" => $this->getTargetedFinancingSkus($storeCode, $store)
];
}

Expand Down
4 changes: 2 additions & 2 deletions Helper/Quote.php
Original file line number Diff line number Diff line change
Expand Up @@ -524,10 +524,10 @@ public function getParentSkus()
* @return bool
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
public function isFinancingBySku()
public function isFinancingBySku($storeCode = null)
{
$quote = $this->getSessionQuote();
$financingAllowedSkus = $this->getTargetedFinancingSkus();
$financingAllowedSkus = $this->getTargetedFinancingSkus($storeCode);

$parentItems = $this->getParentSkus();
$allowed = [];
Expand Down
Loading