From 77019621afb9a79bcdec3cb2ad0e7db870cf20e9 Mon Sep 17 00:00:00 2001
From: aleksa-andersinnovation
<37845675+aleksa-andersinnovation@users.noreply.github.com>
Date: Thu, 31 Oct 2019 16:38:35 +0100
Subject: [PATCH 1/8] catalog search patch (#127)
---
Helper/Category.php | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/Helper/Category.php b/Helper/Category.php
index 50b6a792..43ac04dc 100644
--- a/Helper/Category.php
+++ b/Helper/Category.php
@@ -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());
From 3714e3a8ec90653217b2c70fda9e13725562cd82 Mon Sep 17 00:00:00 2001
From: dfroneberger <12517084+dfroneberger@users.noreply.github.com>
Date: Mon, 4 Nov 2019 16:36:51 -0500
Subject: [PATCH 2/8] ME-125 Admin store Id fix (#125)
* added support for different store views with different Bread settings on the admin backend side
* fixed issue with isActive not working properly
---
Block/Checkout/Overview.php | 11 ----
Block/Payment/Form.php | 25 ++++++++-
Controller/Adminhtml/Bread/GenerateCart.php | 18 ++++---
Controller/Adminhtml/Bread/QuoteData.php | 10 ++--
Helper/Data.php | 54 ++++++++++---------
Helper/Quote.php | 4 +-
Model/Payment/Api/Client.php | 30 +++++++++--
.../templates/breadcheckout/info.phtml | 7 ++-
8 files changed, 103 insertions(+), 56 deletions(-)
diff --git a/Block/Checkout/Overview.php b/Block/Checkout/Overview.php
index 3681338d..cffa9575 100644
--- a/Block/Checkout/Overview.php
+++ b/Block/Checkout/Overview.php
@@ -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();
- }
}
diff --git a/Block/Payment/Form.php b/Block/Payment/Form.php
index d8a3638d..0e506fa5 100644
--- a/Block/Payment/Form.php
+++ b/Block/Payment/Form.php
@@ -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);
}
@@ -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;
+ }
}
diff --git a/Controller/Adminhtml/Bread/GenerateCart.php b/Controller/Adminhtml/Bread/GenerateCart.php
index 990bf02d..24ef8ac0 100644
--- a/Controller/Adminhtml/Bread/GenerateCart.php
+++ b/Controller/Adminhtml/Bread/GenerateCart.php
@@ -41,6 +41,8 @@ public function __construct(
*/
public function execute()
{
+ $storeId = $this->getRequest()->getParam('store_id');
+
try {
$quote = $this->helper->getSessionQuote();
@@ -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);
@@ -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);
diff --git a/Controller/Adminhtml/Bread/QuoteData.php b/Controller/Adminhtml/Bread/QuoteData.php
index f7be8d57..2c378222 100644
--- a/Controller/Adminhtml/Bread/QuoteData.php
+++ b/Controller/Adminhtml/Bread/QuoteData.php
@@ -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(),
@@ -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)
]
);
}
diff --git a/Helper/Data.php b/Helper/Data.php
index 5bb5045a..d6687dd4 100644
--- a/Helper/Data.php
+++ b/Helper/Data.php
@@ -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);
}
/**
@@ -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)
);
}
@@ -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));
}
/**
@@ -580,10 +581,10 @@ 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));
}
/**
@@ -591,9 +592,9 @@ public function isTargetedFinancing($store = \Magento\Store\Model\ScopeInterface
*
* @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);
}
/**
@@ -601,9 +602,9 @@ public function getFinancingId($store = \Magento\Store\Model\ScopeInterface::SCO
*
* @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);
}
/**
@@ -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);
@@ -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) {
@@ -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);
}
/**
@@ -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)
];
}
diff --git a/Helper/Quote.php b/Helper/Quote.php
index 26d0aed7..8d1fb815 100644
--- a/Helper/Quote.php
+++ b/Helper/Quote.php
@@ -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 = [];
diff --git a/Model/Payment/Api/Client.php b/Model/Payment/Api/Client.php
index 75514985..e73aa2e1 100644
--- a/Model/Payment/Api/Client.php
+++ b/Model/Payment/Api/Client.php
@@ -15,7 +15,12 @@ class Client extends \Magento\Framework\Model\AbstractModel
const STATUS_PENDING = 'PENDING';
const STATUS_CANCELED = 'CANCELED';
- public $order = null;
+ public $order = null;
+
+ /**
+ * @var \Magento\Framework\Model\Context
+ */
+ public $context;
/**
* @var \Bread\BreadCheckout\Helper\Data
@@ -32,6 +37,11 @@ class Client extends \Magento\Framework\Model\AbstractModel
*/
public $storeResolver;
+ /**
+ * @var \Magento\Framework\App\CacheInterface
+ */
+ public $cache;
+
public $logger;
public function __construct(
@@ -40,13 +50,15 @@ public function __construct(
\Bread\BreadCheckout\Helper\Data $helper,
\Magento\Framework\Json\Helper\Data $jsonHelper,
\Magento\Store\Model\StoreResolver $storeResolver,
- \Bread\BreadCheckout\Helper\Log $log
+ \Bread\BreadCheckout\Helper\Log $log,
+ \Magento\Framework\App\CacheInterface $cache
) {
-
+ $this->context = $context;
$this->helper = $helper;
$this->jsonHelper = $jsonHelper;
$this->storeResolver = $storeResolver;
$this->logger = $log;
+ $this->cache = $cache;
parent::__construct($context, $registry);
}
@@ -248,7 +260,7 @@ public function getInfo($breadTransactionId)
public function submitCartData($data)
{
return $this->call(
- $this->helper->getCartCreateApiUrl(),
+ $this->helper->getCartCreateApiUrl($this->getStoreId()),
$data,
\Zend_Http_Client::POST
);
@@ -490,6 +502,16 @@ protected function isJson($string)
*/
protected function getStoreId()
{
+ try {
+ $isInAdmin = ($this->context->getAppState()->getAreaCode() == \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE);
+ } catch (\Throwable $e) {
+ $isInAdmin = false;
+ }
+
+ if ($isInAdmin) {
+ return $this->cache->load('admin_store_id');
+ }
+
if (!isset($this->order)) {
return $this->storeResolver->getCurrentStoreId();
}
diff --git a/view/adminhtml/templates/breadcheckout/info.phtml b/view/adminhtml/templates/breadcheckout/info.phtml
index d42f54bd..b3bff627 100644
--- a/view/adminhtml/templates/breadcheckout/info.phtml
+++ b/view/adminhtml/templates/breadcheckout/info.phtml
@@ -3,6 +3,7 @@
* @var \Bread\BreadCheckout\Block\Payment\Form $block
*/
$code = $block->escapeHtml($block->getMethodCode());
+$storeId = $block->saveAdminStoreId();
?>