From 4b112960bf6530340e880dacfef2ebbba2865454 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Mon, 23 Mar 2020 16:59:31 +0100 Subject: [PATCH 1/5] MAG2-146 - Fixed getter of current scope --- Model/Source/Currency.php | 34 +++++++++++++++---- Test/Unit/Model/Source/CurrencyTest.php | 45 ++++++++++++++++++++++++- 2 files changed, 72 insertions(+), 7 deletions(-) diff --git a/Model/Source/Currency.php b/Model/Source/Currency.php index 2a92ef66..77a5e76c 100644 --- a/Model/Source/Currency.php +++ b/Model/Source/Currency.php @@ -29,6 +29,7 @@ use Magento\Framework\Option\ArrayInterface; use Magento\Store\Model\Store; use Magento\Store\Model\StoreManagerInterface; +use Magento\Framework\View\Element\Template\Context; /** * Source class for currency to transmit @@ -39,18 +40,39 @@ class Currency implements ArrayInterface /** * Store object * - * @var Store + * @var Context */ - private $store; + private $context; /** * Constructor * - * @param StoreManagerInterface $storeManager + * @param Context $context */ - public function __construct(StoreManagerInterface $storeManager) + public function __construct(Context $context) { - $this->store = $storeManager->getStore(); + $this->context = $context; + } + + /** + * Returns current base currency code + * Seems like Magento2 framework doesn't have a reliable method to get the current scope in backend configuration.. + * + * @return string + */ + protected function getBaseCurrencyCode() + { + $aRequestParams = $this->context->getRequest()->getParams(); + $oStoreManager = $this->context->getStoreManager(); + if (isset($aRequestParams['website'])) { + return $oStoreManager->getWebsite($aRequestParams['website'])->getBaseCurrencyCode(); + } + + if (isset($aRequestParams['store'])) { + return $oStoreManager->getStore($aRequestParams['store'])->getBaseCurrencyCode(); + } + + return $oStoreManager->getStore()->getBaseCurrencyCode(); } /** @@ -63,7 +85,7 @@ public function toOptionArray() return [ [ 'value' => 'base', - 'label' => __('Base Currency').' ('.$this->store->getBaseCurrencyCode().')' + 'label' => __('Base Currency').' ('.$this->getBaseCurrencyCode().')' ], [ 'value' => 'display', diff --git a/Test/Unit/Model/Source/CurrencyTest.php b/Test/Unit/Model/Source/CurrencyTest.php index da04ab5c..ff0b0e4b 100644 --- a/Test/Unit/Model/Source/CurrencyTest.php +++ b/Test/Unit/Model/Source/CurrencyTest.php @@ -32,6 +32,9 @@ use Payone\Core\Test\Unit\PayoneObjectManager; use Magento\Store\Model\StoreManagerInterface; use Magento\Store\Model\Store; +use Magento\Store\Model\Website; +use Magento\Framework\View\Element\Template\Context; +use Magento\Framework\App\RequestInterface; class CurrencyTest extends BaseTestCase { @@ -40,6 +43,16 @@ class CurrencyTest extends BaseTestCase */ private $classToTest; + /** + * @var Context + */ + private $context; + + /** + * @var RequestInterface + */ + private $request; + protected function setUp() { $store = $this->getMockBuilder(Store::class) @@ -49,12 +62,26 @@ protected function setUp() $store->method('getDefaultCurrencyCode')->willReturn('EUR'); $store->method('getBaseCurrencyCode')->willReturn('USD'); + $website = $this->getMockBuilder(Website::class) + ->disableOriginalConstructor() + ->setMethods(['getDefaultCurrencyCode', 'getBaseCurrencyCode']) + ->getMock(); + $store->method('getDefaultCurrencyCode')->willReturn('EUR'); + $store->method('getBaseCurrencyCode')->willReturn('USD'); + $storeManager = $this->getMockBuilder(StoreManagerInterface::class)->disableOriginalConstructor()->getMock(); $storeManager->method('getStore')->willReturn($store); + $storeManager->method('getWebsite')->willReturn($website); + + $this->request = $this->getMockBuilder(RequestInterface::class)->disableOriginalConstructor()->getMock(); + + $this->context = $this->getMockBuilder(Context::class)->disableOriginalConstructor()->getMock(); + $this->context->method('getStoreManager')->willReturn($storeManager); + $this->context->method('getRequest')->willReturn($this->request); $objectManager = $this->getObjectManager(); $this->classToTest = $objectManager->getObject(ClassToTest::class, [ - 'storeManager' => $storeManager + 'context' => $this->context ]); } @@ -63,4 +90,20 @@ public function testToOptionArray() $result = $this->classToTest->toOptionArray(); $this->assertCount(2, $result); } + + public function testToOptionArrayWebsiteParam() + { + $this->request->method('getParams')->willReturn(['website' => '2']); + + $result = $this->classToTest->toOptionArray(); + $this->assertCount(2, $result); + } + + public function testToOptionArrayStoreParam() + { + $this->request->method('getParams')->willReturn(['store' => '2']); + + $result = $this->classToTest->toOptionArray(); + $this->assertCount(2, $result); + } } From 35c523937d2c71ce1c5d39f103b898781e1dfe4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Fri, 29 May 2020 13:04:24 +0200 Subject: [PATCH 2/5] MAG2-146 - Added javascript mixin to hide base currency value if needed --- Model/ConfigProvider.php | 1 + view/frontend/requirejs-config.js | 6 +++ .../js/action/select-payment-method-mixin.js | 45 +++++++++++++++++ .../checkout/summary/grand-total-mixin.js | 49 +++++++++++++++++++ 4 files changed, 101 insertions(+) create mode 100644 view/frontend/web/js/action/select-payment-method-mixin.js create mode 100644 view/frontend/web/js/view/checkout/summary/grand-total-mixin.js diff --git a/Model/ConfigProvider.php b/Model/ConfigProvider.php index 1c17c6f3..cd565504 100644 --- a/Model/ConfigProvider.php +++ b/Model/ConfigProvider.php @@ -253,6 +253,7 @@ protected function getPayoneConfig() 'saveCCDataEnabled' => (bool)$this->requestHelper->getConfigParam('save_data_enabled', PayoneConfig::METHOD_CREDITCARD, 'payone_payment'), 'savedPaymentData' => $this->savedPaymentData->getSavedPaymentData($this->checkoutSession->getQuote()->getCustomerId()), 'isPaydirektOneKlickDisplayable' => $this->isPaydirektOneKlickDisplayable(), + 'currency' => $this->requestHelper->getConfigParam('currency'), ]; } diff --git a/view/frontend/requirejs-config.js b/view/frontend/requirejs-config.js index 550b8775..47fbea3f 100644 --- a/view/frontend/requirejs-config.js +++ b/view/frontend/requirejs-config.js @@ -37,6 +37,12 @@ var config = { }, 'Magento_Checkout/js/model/error-processor': { 'Payone_Core/js/model/error-processor-mixin': true + }, + 'Magento_Tax/js/view/checkout/summary/grand-total': { + 'Payone_Core/js/view/checkout/summary/grand-total-mixin': true + }, + 'Magento_Checkout/js/action/select-payment-method': { + 'Payone_Core/js/action/select-payment-method-mixin': true } } } diff --git a/view/frontend/web/js/action/select-payment-method-mixin.js b/view/frontend/web/js/action/select-payment-method-mixin.js new file mode 100644 index 00000000..4fd458c3 --- /dev/null +++ b/view/frontend/web/js/action/select-payment-method-mixin.js @@ -0,0 +1,45 @@ +/** + * PAYONE Magento 2 Connector is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * PAYONE Magento 2 Connector is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with PAYONE Magento 2 Connector. If not, see . + * + * PHP version 5 + * + * @category Payone + * @package Payone_Magento2_Plugin + * @author FATCHIP GmbH + * @copyright 2003 - 2020 Payone GmbH + * @license GNU Lesser General Public License + * @link http://www.payone.de + */ +/*jshint browser:true jquery:true*/ +/*global alert*/ +define([ + 'jquery', + 'mage/utils/wrapper', + 'Magento_Tax/js/view/checkout/summary/grand-total' +], function ($, wrapper, grandTotal) { + 'use strict'; + + return function (selectPaymentMethodAction) { + return wrapper.wrap(selectPaymentMethodAction, function (originalAction, paymentMethod) { + if (window.checkoutConfig.payment.payone.currency === "display" && grandTotal().isBaseGrandTotalDisplayNeeded() === true) { + if (paymentMethod.method.indexOf('payone') !== -1) { + $('.opc-block-summary .totals.charge').hide(); + } else { + $('.opc-block-summary .totals.charge').show(); + } + } + return originalAction(paymentMethod); + }); + }; +}); diff --git a/view/frontend/web/js/view/checkout/summary/grand-total-mixin.js b/view/frontend/web/js/view/checkout/summary/grand-total-mixin.js new file mode 100644 index 00000000..a2bc51a3 --- /dev/null +++ b/view/frontend/web/js/view/checkout/summary/grand-total-mixin.js @@ -0,0 +1,49 @@ +/** + * PAYONE Magento 2 Connector is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * PAYONE Magento 2 Connector is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with PAYONE Magento 2 Connector. If not, see . + * + * PHP version 5 + * + * @category Payone + * @package Payone_Magento2_Plugin + * @author FATCHIP GmbH + * @copyright 2003 - 2020 Payone GmbH + * @license GNU Lesser General Public License + * @link http://www.payone.de + */ +/*jshint browser:true jquery:true*/ +/*global alert*/ +define([ + 'jquery', + 'Magento_Checkout/js/model/quote' +], function ($, quote) { + 'use strict'; + + var mixin = { + isBaseGrandTotalDisplayNeeded: function () { + var parentReturn = this._super(); + if (window.checkoutConfig.payment.payone.currency === "display" && parentReturn === true && quote.paymentMethod()) { + if (quote.paymentMethod().method.indexOf('payone') !== -1) { + $('.opc-block-summary .totals.charge').hide(); + } else { + $('.opc-block-summary .totals.charge').show(); + } + } + return this._super(); + } + }; + + return function (grand_total) { + return grand_total.extend(mixin); + }; +}); From 6bba73fe713c0e784c8619e893f218c79da4fb29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Mon, 15 Jun 2020 15:58:18 +0200 Subject: [PATCH 3/5] MAG2-146 - Fixed problem with wrong config scope --- Helper/Api.php | 12 +++++++---- Test/Unit/Helper/ApiTest.php | 39 ++++++++++++++++++++++++++++-------- 2 files changed, 39 insertions(+), 12 deletions(-) diff --git a/Helper/Api.php b/Helper/Api.php index d2d3a377..2dcb5e42 100644 --- a/Helper/Api.php +++ b/Helper/Api.php @@ -278,7 +278,11 @@ public function addPayoneOrderData(SalesOrder $oOrder, $aRequest, $aResponse) */ public function isInvoiceDataNeeded(PayoneMethod $oPayment) { - $blInvoiceEnabled = (bool)$this->getConfigParam('transmit_enabled', 'invoicing'); // invoicing enabled? + $sStoreCode = null; + if ($oPayment->getInfoInstance()->getOrder()) { + $sStoreCode = $oPayment->getInfoInstance()->getOrder()->getStore()->getCode(); + } + $blInvoiceEnabled = (bool)$this->getConfigParam('transmit_enabled', 'invoicing', 'payone_general', $sStoreCode); // invoicing enabled? if ($blInvoiceEnabled || $oPayment->needsProductInfo()) { return true; // invoice data needed } @@ -294,7 +298,7 @@ public function isInvoiceDataNeeded(PayoneMethod $oPayment) public function getCurrencyFromOrder(SalesOrder $oOrder) { $sCurrency = $oOrder->getBaseCurrencyCode(); - if ($this->getConfigParam('currency') == 'display') { + if ($this->getConfigParam('currency', 'global', 'payone_general', $oOrder->getStore()->getCode()) == 'display') { $sCurrency = $oOrder->getOrderCurrencyCode(); } return $sCurrency; @@ -309,7 +313,7 @@ public function getCurrencyFromOrder(SalesOrder $oOrder) public function getCurrencyFromQuote(Quote $oQuote) { $sCurrency = $oQuote->getBaseCurrencyCode(); - if ($this->getConfigParam('currency') == 'display') { + if ($this->getConfigParam('currency', 'global', 'payone_general', $oQuote->getStore()->getCode()) == 'display') { $sCurrency = $oQuote->getQuoteCurrencyCode(); } return $sCurrency; @@ -324,7 +328,7 @@ public function getCurrencyFromQuote(Quote $oQuote) public function getQuoteAmount(Quote $oQuote) { $dAmount = $oQuote->getBaseGrandTotal(); - if ($this->getConfigParam('currency') == 'display') { + if ($this->getConfigParam('currency', 'global', 'payone_general', $oQuote->getStore()->getCode()) == 'display') { $dAmount = $oQuote->getGrandTotal(); // send display amount instead of base amount } return $dAmount; diff --git a/Test/Unit/Helper/ApiTest.php b/Test/Unit/Helper/ApiTest.php index 44d443d1..6efea3a6 100644 --- a/Test/Unit/Helper/ApiTest.php +++ b/Test/Unit/Helper/ApiTest.php @@ -26,6 +26,7 @@ namespace Payone\Core\Test\Unit\Helper; +use Magento\Payment\Model\Info; use Magento\Quote\Model\Quote; use Payone\Core\Helper\Api; use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; @@ -79,19 +80,35 @@ class ApiTest extends BaseTestCase */ private $connFsockopen; + /** + * @var StoreInterface|\PHPUnit_Framework_MockObject_MockObject + */ + private $store; + protected function setUp() { $this->objectManager = $this->getObjectManager(); + $this->store = $this->getMockBuilder(StoreInterface::class)->disableOriginalConstructor()->getMock(); + $this->store->method('getCode')->willReturn('test'); + + $order = $this->getMockBuilder(Order::class)->disableOriginalConstructor()->getMock(); + $order->method('getStore')->willReturn($this->store); + + $paymentInfo = $this->getMockBuilder(Info::class) + ->disableOriginalConstructor() + ->setMethods(['getOrder']) + ->getMock(); + $paymentInfo->method('getOrder')->willReturn($order); + $this->payment = $this->getMockBuilder(PayoneMethod::class)->disableOriginalConstructor()->getMock(); + $this->payment->method('getInfoInstance')->willReturn($paymentInfo); + $this->scopeConfig = $this->getMockBuilder(ScopeConfigInterface::class)->disableOriginalConstructor()->getMock(); $context = $this->objectManager->getObject(Context::class, ['scopeConfig' => $this->scopeConfig]); - $store = $this->getMockBuilder(StoreInterface::class)->disableOriginalConstructor()->getMock(); - $store->method('getCode')->willReturn('test'); - $storeManager = $this->getMockBuilder(StoreManagerInterface::class)->disableOriginalConstructor()->getMock(); - $storeManager->method('getStore')->willReturn($store); + $storeManager->method('getStore')->willReturn($this->store); $this->connCurlPhp = $this->getMockBuilder(CurlPhp::class)->disableOriginalConstructor()->getMock(); $this->connCurlCli = $this->getMockBuilder(CurlCli::class)->disableOriginalConstructor()->getMock(); @@ -299,6 +316,7 @@ public function testGetCurrencyFromOrderBase() $oOrder = $this->getMockBuilder(Order::class)->disableOriginalConstructor()->getMock(); $oOrder->method('getBaseCurrencyCode')->willReturn($expected); + $oOrder->method('getStore')->willReturn($this->store); $result = $this->api->getCurrencyFromOrder($oOrder); $this->assertEquals($expected, $result); @@ -312,6 +330,7 @@ public function testGetCurrencyFromOrderDisplay() $oOrder = $this->getMockBuilder(Order::class)->disableOriginalConstructor()->getMock(); $oOrder->method('getBaseCurrencyCode')->willReturn('USD'); $oOrder->method('getOrderCurrencyCode')->willReturn($expected); + $oOrder->method('getStore')->willReturn($this->store); $result = $this->api->getCurrencyFromOrder($oOrder); $this->assertEquals($expected, $result); @@ -323,9 +342,10 @@ public function testGetCurrencyFromQuoteBase() $oOrder = $this->getMockBuilder(Quote::class) ->disableOriginalConstructor() - ->setMethods(['getBaseCurrencyCode']) + ->setMethods(['getBaseCurrencyCode', 'getStore']) ->getMock(); $oOrder->method('getBaseCurrencyCode')->willReturn($expected); + $oOrder->method('getStore')->willReturn($this->store); $result = $this->api->getCurrencyFromQuote($oOrder); $this->assertEquals($expected, $result); @@ -338,10 +358,11 @@ public function testGetCurrencyFromQuoteDisplay() $oOrder = $this->getMockBuilder(Quote::class) ->disableOriginalConstructor() - ->setMethods(['getBaseCurrencyCode', 'getQuoteCurrencyCode']) + ->setMethods(['getBaseCurrencyCode', 'getQuoteCurrencyCode', 'getStore']) ->getMock(); $oOrder->method('getBaseCurrencyCode')->willReturn($expected); $oOrder->method('getQuoteCurrencyCode')->willReturn($expected); + $oOrder->method('getStore')->willReturn($this->store); $result = $this->api->getCurrencyFromQuote($oOrder); $this->assertEquals($expected, $result); @@ -353,9 +374,10 @@ public function testGetQuoteAmountBase() $oOrder = $this->getMockBuilder(Quote::class) ->disableOriginalConstructor() - ->setMethods(['getBaseGrandTotal']) + ->setMethods(['getBaseGrandTotal', 'getStore']) ->getMock(); $oOrder->method('getBaseGrandTotal')->willReturn($expected); + $oOrder->method('getStore')->willReturn($this->store); $result = $this->api->getQuoteAmount($oOrder); $this->assertEquals($expected, $result); @@ -368,10 +390,11 @@ public function testGetQuoteAmountDisplay() $oOrder = $this->getMockBuilder(Quote::class) ->disableOriginalConstructor() - ->setMethods(['getBaseGrandTotal', 'getGrandTotal']) + ->setMethods(['getBaseGrandTotal', 'getGrandTotal', 'getStore']) ->getMock(); $oOrder->method('getBaseGrandTotal')->willReturn(200); $oOrder->method('getGrandTotal')->willReturn($expected); + $oOrder->method('getStore')->willReturn($this->store); $result = $this->api->getQuoteAmount($oOrder); $this->assertEquals($expected, $result); From a5eed2f9b9b341e29bd78becc2b4a7a3f9745a68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Fri, 17 Jul 2020 18:25:06 +0200 Subject: [PATCH 4/5] MAG2-146 - Fixed config scope problems --- Model/Api/Invoice.php | 43 ++++++++++++--- Model/Api/Request/Debit.php | 4 +- Model/Methods/Payolution/Invoice.php | 2 +- Model/Methods/Payolution/PayolutionBase.php | 2 +- Model/Methods/PayoneMethod.php | 6 +-- Test/Unit/Model/Api/InvoiceTest.php | 15 +++++- Test/Unit/Model/Api/Request/DebitTest.php | 2 +- Test/Unit/Model/Methods/AmazonPayTest.php | 6 +++ Test/Unit/Model/Methods/BarzahlenTest.php | 5 ++ Test/Unit/Model/Methods/BaseMethodTest.php | 52 +++++++++++++++++-- .../Model/Methods/Payolution/DebitTest.php | 9 ++++ .../Model/Methods/Payolution/InvoiceTest.php | 13 +++++ Test/Unit/Model/Methods/SafeInvoiceTest.php | 9 ++++ 13 files changed, 149 insertions(+), 19 deletions(-) diff --git a/Model/Api/Invoice.php b/Model/Api/Invoice.php index a3d7c150..d3972eae 100644 --- a/Model/Api/Invoice.php +++ b/Model/Api/Invoice.php @@ -76,6 +76,13 @@ class Invoice */ protected $oRequest; + /** + * Current store code + * + * @var string + */ + protected $sStoreCode; + /** * Constructor * @@ -121,6 +128,7 @@ protected function addInvoicePosition($sId, $dPrice, $sItemType, $iAmount, $sDes public function addProductInfo(Base $oRequest, Order $oOrder, $aPositions = false, $blDebit = false) { $this->oRequest = $oRequest; // write request to property for manipulation of the object + $this->setStoreCode($oOrder->getStore()->getCode()); $sInvoiceAppendix = $this->toolkitHelper->getInvoiceAppendix($oOrder); // get invoice appendix if (!empty($sInvoiceAppendix)) {// invoice appendix existing? $this->oRequest->addParameter('invoiceappendix', $sInvoiceAppendix); // add appendix to request @@ -163,7 +171,7 @@ protected function addProductItem($oItem, $aPositions) } $iAmount = $this->convertItemAmount($dItemAmount); $dPrice = $oItem->getBasePriceInclTax(); - if ($this->toolkitHelper->getConfigParam('currency') == 'display') { + if ($this->toolkitHelper->getConfigParam('currency', 'global', 'payone_general', $this->getStoreCode()) == 'display') { $dPrice = $oItem->getPriceInclTax(); } $this->addInvoicePosition($oItem->getSku(), $dPrice, 'goods', $iAmount, $oItem->getName(), $oItem->getTaxPercent()); // add invoice params to request @@ -186,7 +194,7 @@ protected function addShippingItem(Order $oOrder, $aPositions, $blDebit) // shipping costs existing or given for partial captures/debits? if ($oOrder->getBaseShippingInclTax() != 0 && ($aPositions === false || ($blDebit === false || array_key_exists('delcost', $aPositions) !== false))) { $dPrice = $oOrder->getBaseShippingInclTax(); - if ($this->toolkitHelper->getConfigParam('currency') == 'display') { + if ($this->toolkitHelper->getConfigParam('currency', 'global', 'payone_general', $this->getStoreCode()) == 'display') { $dPrice = $oOrder->getShippingInclTax(); } if ($aPositions !== false && array_key_exists('delcost', $aPositions) !== false) { // product existing in single-invoice? @@ -196,7 +204,7 @@ protected function addShippingItem(Order $oOrder, $aPositions, $blDebit) if ($dPrice < 0) { // negative shipping cost $sDelDesc = __('Deduction').' '.__('Shipping Costs'); // change item description to deduction } - $sShippingSku = $this->toolkitHelper->getConfigParam('sku', 'costs', 'payone_misc'); // get configured shipping SKU + $sShippingSku = $this->toolkitHelper->getConfigParam('sku', 'costs', 'payone_misc', $this->getStoreCode()); // get configured shipping SKU $this->addInvoicePosition($sShippingSku, $dPrice, 'shipment', 1, $sDelDesc, $this->dTax); // add invoice params to request } } @@ -213,7 +221,7 @@ protected function addDiscountItem(Order $oOrder, $aPositions, $blDebit) { // discount costs existing or given for partial captures/debit? $dTransmitDiscount = $oOrder->getBaseDiscountAmount(); - if ($this->toolkitHelper->getConfigParam('currency') == 'display') { + if ($this->toolkitHelper->getConfigParam('currency', 'global', 'payone_general', $this->getStoreCode()) == 'display') { $dTransmitDiscount = $oOrder->getDiscountAmount(); } if ($dTransmitDiscount != 0 && ($aPositions === false || ($blDebit === false || array_key_exists('discount', $aPositions) !== false))) { @@ -225,16 +233,16 @@ protected function addDiscountItem(Order $oOrder, $aPositions, $blDebit) // The calculations broken down to single items of Magento2 are unprecise and the Payone API will send an error if // the calculated positions don't match, so we compensate for rounding-problems here $dTotal = $oOrder->getBaseGrandTotal(); - if ($this->toolkitHelper->getConfigParam('currency') == 'display') { + if ($this->toolkitHelper->getConfigParam('currency', 'global', 'payone_general', $this->getStoreCode()) == 'display') { $dTotal = $oOrder->getGrandTotal(); } $dDiff = ($this->dAmount + $dTransmitDiscount - $dTotal); // calc rounding discrepancy $dDiscount -= $dDiff; // subtract difference from discount } - $sDiscountSku = $this->toolkitHelper->getConfigParam('sku', 'discount', 'payone_misc'); // get configured discount SKU + $sDiscountSku = $this->toolkitHelper->getConfigParam('sku', 'discount', 'payone_misc', $this->getStoreCode()); // get configured discount SKU $sDesc = (string)__('Discount'); // default description if ($oOrder->getCouponCode()) {// was a coupon code used? - $sDiscountSku = $this->toolkitHelper->getConfigParam('sku', 'voucher', 'payone_misc'); // get configured voucher SKU + $sDiscountSku = $this->toolkitHelper->getConfigParam('sku', 'voucher', 'payone_misc', $this->getStoreCode()); // get configured voucher SKU $sDesc = (string)__('Coupon').' - '.$oOrder->getCouponCode(); // add counpon code to description } $this->addInvoicePosition($sDiscountSku, $dDiscount, 'voucher', 1, $sDesc, $this->dTax); // add invoice params to request @@ -258,4 +266,25 @@ protected function convertItemAmount($dItemAmount) return intval($dItemAmount); } } + + /** + * Set store code + * + * @param $sStoreCode + * @return void + */ + protected function setStoreCode($sStoreCode) + { + $this->sStoreCode = $sStoreCode; + } + + /** + * Returns store code + * + * @return string + */ + protected function getStoreCode() + { + return $this->sStoreCode; + } } diff --git a/Model/Api/Request/Debit.php b/Model/Api/Request/Debit.php index a2b014cd..52e6ad2e 100644 --- a/Model/Api/Request/Debit.php +++ b/Model/Api/Request/Debit.php @@ -119,13 +119,13 @@ protected function getInvoiceList(Order $oOrder, Creditmemo $oCreditmemo) } if (isset($aCreditmemo['shipping_amount']) && $aCreditmemo['shipping_amount'] != 0) { $aPositions['delcost'] = $oCreditmemo->getBaseShippingInclTax(); - if ($this->shopHelper->getConfigParam('currency') == 'display') { + if ($this->shopHelper->getConfigParam('currency', 'global', 'payone_general', $this->storeCode) == 'display') { $aPositions['delcost'] = $oCreditmemo->getShippingInclTax(); } } if ($blFull !== true && $oCreditmemo->getBaseDiscountAmount() != 0) { $aPositions['discount'] = $oCreditmemo->getBaseDiscountAmount(); - if ($this->shopHelper->getConfigParam('currency') == 'display') { + if ($this->shopHelper->getConfigParam('currency', 'global', 'payone_general', $this->storeCode) == 'display') { $aPositions['discount'] = $oCreditmemo->getDiscountAmount(); } } diff --git a/Model/Methods/Payolution/Invoice.php b/Model/Methods/Payolution/Invoice.php index 8ba736bb..94963ddf 100644 --- a/Model/Methods/Payolution/Invoice.php +++ b/Model/Methods/Payolution/Invoice.php @@ -64,7 +64,7 @@ class Invoice extends PayolutionBase */ public function authorize(InfoInterface $payment, $amount) { - if ($this->shopHelper->getConfigParam('currency') == 'display') { + if ($this->shopHelper->getConfigParam('currency', 'global', 'payone_general', $payment->getOrder()->getStore()->getCode()) == 'display') { $amount = $payment->getOrder()->getTotalDue(); // send display amount instead of base amount } $this->sendPayonePreCheck($amount); diff --git a/Model/Methods/Payolution/PayolutionBase.php b/Model/Methods/Payolution/PayolutionBase.php index 190652fb..3c91e71a 100644 --- a/Model/Methods/Payolution/PayolutionBase.php +++ b/Model/Methods/Payolution/PayolutionBase.php @@ -187,7 +187,7 @@ public function getPaymentSpecificParameters(Order $oOrder) public function sendPayonePreCheck($dAmount) { $oQuote = $this->checkoutSession->getQuote(); - if ($this->shopHelper->getConfigParam('currency') == 'display') { + if ($this->shopHelper->getConfigParam('currency', 'global', 'payone_general', $oQuote->getStore()->getCode()) == 'display') { $dAmount = $oQuote->getGrandTotal(); // send display amount instead of base amount } $aResponse = $this->precheckRequest->sendRequest($this, $oQuote, $dAmount); diff --git a/Model/Methods/PayoneMethod.php b/Model/Methods/PayoneMethod.php index 4916f2db..1defee4b 100644 --- a/Model/Methods/PayoneMethod.php +++ b/Model/Methods/PayoneMethod.php @@ -75,7 +75,7 @@ public function getAuthorizationMode() */ protected function sendPayoneDebit(InfoInterface $payment, $amount) { - if ($this->shopHelper->getConfigParam('currency') == 'display' && $payment->getCreditmemo()) { + if ($this->shopHelper->getConfigParam('currency', 'global', 'payone_general', $payment->getOrder()->getStore()->getCode()) == 'display' && $payment->getCreditmemo()) { $amount = $payment->getCreditmemo()->getGrandTotal(); // send display amount instead of base amount } $aResponse = $this->debitRequest->sendRequest($this, $payment, $amount); @@ -99,7 +99,7 @@ protected function sendPayoneDebit(InfoInterface $payment, $amount) */ protected function sendPayoneCapture(InfoInterface $payment, $amount) { - if ($this->shopHelper->getConfigParam('currency') == 'display' && $payment->getOrder()->hasInvoices()) { + if ($this->shopHelper->getConfigParam('currency', 'global', 'payone_general', $payment->getOrder()->getStore()->getCode()) == 'display' && $payment->getOrder()->hasInvoices()) { $oInvoice = $payment->getOrder()->getInvoiceCollection()->getLastItem(); $amount = $oInvoice->getGrandTotal(); // send display amount instead of base amount } @@ -139,7 +139,7 @@ protected function sendPayoneAuthorization(InfoInterface $payment, $amount) $oOrder = $payment->getOrder(); $oOrder->setCanSendNewEmailFlag(false); // dont send email now, will be sent on appointed - if ($this->shopHelper->getConfigParam('currency') == 'display') { + if ($this->shopHelper->getConfigParam('currency', 'global', 'payone_general', $payment->getOrder()->getStore()->getCode()) == 'display') { $amount = $oOrder->getTotalDue(); // send display amount instead of base amount } diff --git a/Test/Unit/Model/Api/InvoiceTest.php b/Test/Unit/Model/Api/InvoiceTest.php index 53771ff3..76b9c90b 100644 --- a/Test/Unit/Model/Api/InvoiceTest.php +++ b/Test/Unit/Model/Api/InvoiceTest.php @@ -34,6 +34,7 @@ use Magento\Sales\Model\Order\Item; use Payone\Core\Test\Unit\BaseTestCase; use Payone\Core\Test\Unit\PayoneObjectManager; +use Magento\Store\Model\Store; class InvoiceTest extends BaseTestCase { @@ -47,6 +48,11 @@ class InvoiceTest extends BaseTestCase */ private $toolkitHelper; + /** + * @var Store + */ + private $store; + protected function setUp() { $objectManager = $this->getObjectManager(); @@ -64,6 +70,9 @@ protected function setUp() [105, 2, '105.00'], ]); + $this->store = $this->getMockBuilder(Store::class)->disableOriginalConstructor()->getMock(); + $this->store->method('getCode')->willReturn('test'); + $this->classToTest = $objectManager->getObject(ClassToTest::class, [ 'toolkitHelper' => $this->toolkitHelper ]); @@ -98,13 +107,14 @@ public function testAddProductInfo() $items = [$this->getItemMock()]; $expected = 90; - + $order = $this->getMockBuilder(Order::class)->disableOriginalConstructor()->getMock(); $order->method('getAllItems')->willReturn($items); $order->method('getBaseShippingInclTax')->willReturn(-5); $order->method('getBaseDiscountAmount')->willReturn(-5); $order->method('getCouponCode')->willReturn('test'); $order->method('getBaseGrandTotal')->willReturn($expected); + $order->method('getStore')->willReturn($this->store); $result = $this->classToTest->addProductInfo($authorization, $order, false); $this->assertEquals($expected, $result); @@ -129,6 +139,7 @@ public function testAddProductInfoDisplay() $order->method('getCouponCode')->willReturn('test'); $order->method('getBaseGrandTotal')->willReturn($expected); $order->method('getGrandTotal')->willReturn($expected); + $order->method('getStore')->willReturn($this->store); $result = $this->classToTest->addProductInfo($authorization, $order, false); $this->assertEquals($expected, $result); @@ -150,6 +161,7 @@ public function testAddProductInfoSurcharge() $order->method('getBaseDiscountAmount')->willReturn(-5); $order->method('getCouponCode')->willReturn('test'); $order->method('getGrandTotal')->willReturn($expected); + $order->method('getStore')->willReturn($this->store); $positions = ['12345test_123' => '1', 'delcost' => '10', 'discount' => '-10']; @@ -173,6 +185,7 @@ public function testAddProductInfoException() $order->method('getBaseDiscountAmount')->willReturn(-5); $order->method('getCouponCode')->willReturn('test'); $order->method('getGrandTotal')->willReturn($expected); + $order->method('getStore')->willReturn($this->store); $positions = ['12345test_123' => 1.7]; diff --git a/Test/Unit/Model/Api/Request/DebitTest.php b/Test/Unit/Model/Api/Request/DebitTest.php index 6f84c8fc..72fff7d3 100644 --- a/Test/Unit/Model/Api/Request/DebitTest.php +++ b/Test/Unit/Model/Api/Request/DebitTest.php @@ -158,7 +158,7 @@ public function testSendRequestPositions() { $this->shopHelper->method('getConfigParam')->willReturnMap( [ - ['currency', 'global', 'payone_general', null, 'display'], + ['currency', 'global', 'payone_general', 'default', 'display'], ['invoice_appendix_refund', 'invoicing', 'payone_general', 'default', 'test'] ] ); diff --git a/Test/Unit/Model/Methods/AmazonPayTest.php b/Test/Unit/Model/Methods/AmazonPayTest.php index bd33591e..8b339410 100644 --- a/Test/Unit/Model/Methods/AmazonPayTest.php +++ b/Test/Unit/Model/Methods/AmazonPayTest.php @@ -26,6 +26,7 @@ namespace Payone\Core\Test\Unit\Model\Methods; +use Magento\Store\Model\Store; use Payone\Core\Model\Methods\AmazonPay as ClassToTest; use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; use Magento\Sales\Model\Order; @@ -151,7 +152,12 @@ public function testGetPaymentSpecificParametersSynchronous() public function testAuthorize() { $this->checkoutSession->method('getAmazonRetryAsync')->willReturn(true); + + $store = $this->getMockBuilder(Store::class)->disableOriginalConstructor()->getMock(); + $store->method('getCode')->willReturn('test'); + $order = $this->getMockBuilder(Order::class)->disableOriginalConstructor()->getMock(); + $order->method('getStore')->willReturn($store); $paymentInfo = $this->getMockBuilder(Info::class)->disableOriginalConstructor()->setMethods(['getOrder'])->getMock(); $paymentInfo->method('getOrder')->willReturn($order); diff --git a/Test/Unit/Model/Methods/BarzahlenTest.php b/Test/Unit/Model/Methods/BarzahlenTest.php index 2f5dba5e..81e3aac7 100644 --- a/Test/Unit/Model/Methods/BarzahlenTest.php +++ b/Test/Unit/Model/Methods/BarzahlenTest.php @@ -26,6 +26,7 @@ namespace Payone\Core\Test\Unit\Model\Methods; +use Magento\Store\Model\Store; use Payone\Core\Model\Methods\Barzahlen as ClassToTest; use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; use Magento\Sales\Model\Order; @@ -81,7 +82,11 @@ public function testGetPaymentSpecificParameters() public function testAuthorize() { + $store = $this->getMockBuilder(Store::class)->disableOriginalConstructor()->getMock(); + $store->method('getCode')->willReturn('test'); + $order = $this->getMockBuilder(Order::class)->disableOriginalConstructor()->getMock(); + $order->method('getStore')->willReturn($store); $paymentInfo = $this->getMockBuilder(Info::class)->disableOriginalConstructor()->setMethods(['getOrder'])->getMock(); $paymentInfo->method('getOrder')->willReturn($order); diff --git a/Test/Unit/Model/Methods/BaseMethodTest.php b/Test/Unit/Model/Methods/BaseMethodTest.php index 3850be23..faafab19 100644 --- a/Test/Unit/Model/Methods/BaseMethodTest.php +++ b/Test/Unit/Model/Methods/BaseMethodTest.php @@ -29,6 +29,7 @@ use Braintree\PaymentMethod; use Magento\Payment\Model\Method\AbstractMethod; use Magento\Sales\Model\Order; +use Magento\Store\Model\Store; use Payone\Core\Model\Methods\Paydirekt as ClassToTest; use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; use Payone\Core\Helper\Shop; @@ -147,9 +148,13 @@ public function testAuthorize() $payment = $this->getMockBuilder(PaymentMethod::class)->disableOriginalConstructor()->setMethods(['getAdditionalInformation'])->getMock(); $payment->method('getAdditionalInformation')->willReturn([]); + $store = $this->getMockBuilder(Store::class)->disableOriginalConstructor()->getMock(); + $store->method('getCode')->willReturn('test'); + $order = $this->getMockBuilder(Order::class)->disableOriginalConstructor()->getMock(); $order->method('getTotalDue')->willReturn(100); $order->method('getPayment')->willReturn($payment); + $order->method('getStore')->willReturn($store); $paymentInfo = $this->getMockBuilder(Info::class)->disableOriginalConstructor()->setMethods(['getOrder'])->getMock(); $paymentInfo->method('getOrder')->willReturn($order); @@ -166,8 +171,12 @@ public function testAuthorizeError() $payment = $this->getMockBuilder(PaymentMethod::class)->disableOriginalConstructor()->setMethods(['getAdditionalInformation'])->getMock(); $payment->method('getAdditionalInformation')->willReturn([]); + $store = $this->getMockBuilder(Store::class)->disableOriginalConstructor()->getMock(); + $store->method('getCode')->willReturn('test'); + $order = $this->getMockBuilder(Order::class)->disableOriginalConstructor()->getMock(); $order->method('getPayment')->willReturn($payment); + $order->method('getStore')->willReturn($store); $paymentInfo = $this->getMockBuilder(Info::class)->disableOriginalConstructor()->setMethods(['getOrder'])->getMock(); $paymentInfo->method('getOrder')->willReturn($order); @@ -199,11 +208,18 @@ public function testRefund() $creditmemo = $this->getMockBuilder(Creditmemo::class)->disableOriginalConstructor()->getMock(); $creditmemo->method('getGrandTotal')->willReturn(100); + $store = $this->getMockBuilder(Store::class)->disableOriginalConstructor()->getMock(); + $store->method('getCode')->willReturn('test'); + + $order = $this->getMockBuilder(Order::class)->disableOriginalConstructor()->getMock(); + $order->method('getStore')->willReturn($store); + $paymentInfo = $this->getMockBuilder(Info::class) ->disableOriginalConstructor() - ->setMethods(['getCreditmemo']) + ->setMethods(['getCreditmemo', 'getOrder']) ->getMock(); $paymentInfo->method('getCreditmemo')->willReturn($creditmemo); + $paymentInfo->method('getOrder')->willReturn($order); $aResponse = ['status' => 'APPROVED']; $this->debitRequest->method('sendRequest')->willReturn($aResponse); @@ -214,7 +230,14 @@ public function testRefund() public function testRefundError() { - $paymentInfo = $this->getMockBuilder(Info::class)->disableOriginalConstructor()->getMock(); + $store = $this->getMockBuilder(Store::class)->disableOriginalConstructor()->getMock(); + $store->method('getCode')->willReturn('test'); + + $order = $this->getMockBuilder(Order::class)->disableOriginalConstructor()->getMock(); + $order->method('getStore')->willReturn($store); + + $paymentInfo = $this->getMockBuilder(Info::class)->disableOriginalConstructor()->setMethods(['getOrder'])->getMock(); + $paymentInfo->method('getOrder')->willReturn($order); $aResponse = ['status' => 'ERROR', 'errorcode' => '42', 'customermessage' => 'Test error']; $this->debitRequest->method('sendRequest')->willReturn($aResponse); @@ -225,7 +248,14 @@ public function testRefundError() public function testRefundNoResponse() { - $paymentInfo = $this->getMockBuilder(Info::class)->disableOriginalConstructor()->getMock(); + $store = $this->getMockBuilder(Store::class)->disableOriginalConstructor()->getMock(); + $store->method('getCode')->willReturn('test'); + + $order = $this->getMockBuilder(Order::class)->disableOriginalConstructor()->getMock(); + $order->method('getStore')->willReturn($store); + + $paymentInfo = $this->getMockBuilder(Info::class)->disableOriginalConstructor()->setMethods(['getOrder'])->getMock(); + $paymentInfo->method('getOrder')->willReturn($order); $this->debitRequest->method('sendRequest')->willReturn(false); @@ -243,9 +273,13 @@ public function testCapture() $invoiceCollection = $this->getMockBuilder(InvoiceCollection::class)->disableOriginalConstructor()->getMock(); $invoiceCollection->method('getLastItem')->willReturn($invoice); + $store = $this->getMockBuilder(Store::class)->disableOriginalConstructor()->getMock(); + $store->method('getCode')->willReturn('test'); + $order = $this->getMockBuilder(Order::class)->disableOriginalConstructor()->getMock(); $order->method('hasInvoices')->willReturn(true); $order->method('getInvoiceCollection')->willReturn($invoiceCollection); + $order->method('getStore')->willReturn($store); $paymentInfo = $this->getMockBuilder(Info::class) ->disableOriginalConstructor() @@ -263,7 +297,11 @@ public function testCapture() public function testCaptureError() { + $store = $this->getMockBuilder(Store::class)->disableOriginalConstructor()->getMock(); + $store->method('getCode')->willReturn('test'); + $order = $this->getMockBuilder(Order::class)->disableOriginalConstructor()->getMock(); + $order->method('getStore')->willReturn($store); $paymentInfo = $this->getMockBuilder(Info::class) ->disableOriginalConstructor() @@ -281,7 +319,11 @@ public function testCaptureError() public function testCaptureNoResponse() { + $store = $this->getMockBuilder(Store::class)->disableOriginalConstructor()->getMock(); + $store->method('getCode')->willReturn('test'); + $order = $this->getMockBuilder(Order::class)->disableOriginalConstructor()->getMock(); + $order->method('getStore')->willReturn($store); $paymentInfo = $this->getMockBuilder(Info::class) ->disableOriginalConstructor() @@ -301,8 +343,12 @@ public function testCaptureAuth() $payment = $this->getMockBuilder(PaymentMethod::class)->disableOriginalConstructor()->setMethods(['getAdditionalInformation'])->getMock(); $payment->method('getAdditionalInformation')->willReturn([]); + $store = $this->getMockBuilder(Store::class)->disableOriginalConstructor()->getMock(); + $store->method('getCode')->willReturn('test'); + $order = $this->getMockBuilder(Order::class)->disableOriginalConstructor()->getMock(); $order->method('getPayment')->willReturn($payment); + $order->method('getStore')->willReturn($store); $paymentInfo = $this->getMockBuilder(Info::class) ->disableOriginalConstructor() diff --git a/Test/Unit/Model/Methods/Payolution/DebitTest.php b/Test/Unit/Model/Methods/Payolution/DebitTest.php index 24eac92a..d0ceb70b 100644 --- a/Test/Unit/Model/Methods/Payolution/DebitTest.php +++ b/Test/Unit/Model/Methods/Payolution/DebitTest.php @@ -26,6 +26,7 @@ namespace Payone\Core\Test\Unit\Model\Methods\Payolution; +use Magento\Store\Model\Store; use Payone\Core\Helper\Toolkit; use Payone\Core\Model\Methods\Payolution\Debit as ClassToTest; use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; @@ -67,7 +68,11 @@ protected function setUp() $toolkitHelper = $this->getMockBuilder(Toolkit::class)->disableOriginalConstructor()->getMock(); $toolkitHelper->method('getAdditionalDataEntry')->willReturn('value'); + $store = $this->getMockBuilder(Store::class)->disableOriginalConstructor()->getMock(); + $store->method('getCode')->willReturn('test'); + $quote = $this->getMockBuilder(Quote::class)->disableOriginalConstructor()->getMock(); + $quote->method('getStore')->willReturn($store); $checkoutSession = $this->getMockBuilder(Session::class)->disableOriginalConstructor()->getMock(); $checkoutSession->method('getQuote')->willReturn($quote); @@ -96,7 +101,11 @@ public function testAuthorize() $payment->method('getOrder')->willReturn($order); $payment->method('getAdditionalInformation')->willReturn(['iban' => '12345']); + $store = $this->getMockBuilder(Store::class)->disableOriginalConstructor()->getMock(); + $store->method('getCode')->willReturn('test'); + $order->method('getPayment')->willReturn($payment); + $order->method('getStore')->willReturn($store); $result = $this->classToTest->authorize($payment, 100); $this->assertInstanceOf(ClassToTest::class, $result); diff --git a/Test/Unit/Model/Methods/Payolution/InvoiceTest.php b/Test/Unit/Model/Methods/Payolution/InvoiceTest.php index 1d31ef59..25ea8360 100644 --- a/Test/Unit/Model/Methods/Payolution/InvoiceTest.php +++ b/Test/Unit/Model/Methods/Payolution/InvoiceTest.php @@ -26,6 +26,7 @@ namespace Payone\Core\Test\Unit\Model\Methods\Payolution; +use Magento\Store\Model\Store; use Payone\Core\Helper\Shop; use Payone\Core\Helper\Toolkit; use Payone\Core\Model\Methods\Payolution\Invoice as ClassToTest; @@ -69,7 +70,11 @@ protected function setUp() $toolkitHelper = $this->getMockBuilder(Toolkit::class)->disableOriginalConstructor()->getMock(); $toolkitHelper->method('getAdditionalDataEntry')->willReturn('value'); + $store = $this->getMockBuilder(Store::class)->disableOriginalConstructor()->getMock(); + $store->method('getCode')->willReturn('test'); + $quote = $this->getMockBuilder(Quote::class)->disableOriginalConstructor()->getMock(); + $quote->method('getStore')->willReturn($store); $checkoutSession = $this->getMockBuilder(Session::class)->disableOriginalConstructor()->getMock(); $checkoutSession->method('getQuote')->willReturn($quote); @@ -102,7 +107,11 @@ public function testAuthorize() $payment->method('getOrder')->willReturn($order); $payment->method('getAdditionalInformation')->willReturn([]); + $store = $this->getMockBuilder(Store::class)->disableOriginalConstructor()->getMock(); + $store->method('getCode')->willReturn('test'); + $order->method('getPayment')->willReturn($payment); + $order->method('getStore')->willReturn($store); $result = $this->classToTest->authorize($payment, 100); $this->assertInstanceOf(ClassToTest::class, $result); @@ -113,7 +122,11 @@ public function testAuthorizeException() $response = ['status' => 'ERROR', 'errorcode' => '123', 'customermessage' => 'error']; $this->precheckRequest->method('sendRequest')->willReturn($response); + $store = $this->getMockBuilder(Store::class)->disableOriginalConstructor()->getMock(); + $store->method('getCode')->willReturn('test'); + $order = $this->getMockBuilder(Order::class)->disableOriginalConstructor()->getMock(); + $order->method('getStore')->willReturn($store); $payment = $this->getMockBuilder(Info::class)->disableOriginalConstructor()->setMethods(['getOrder'])->getMock(); $payment->method('getOrder')->willReturn($order); diff --git a/Test/Unit/Model/Methods/SafeInvoiceTest.php b/Test/Unit/Model/Methods/SafeInvoiceTest.php index 6b37b22b..1b5c05b5 100644 --- a/Test/Unit/Model/Methods/SafeInvoiceTest.php +++ b/Test/Unit/Model/Methods/SafeInvoiceTest.php @@ -27,6 +27,7 @@ namespace Payone\Core\Test\Unit\Model\Methods; use Magento\Framework\Exception\LocalizedException; +use Magento\Store\Model\Store; use Payone\Core\Model\Methods\SafeInvoice as ClassToTest; use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; use Magento\Sales\Model\Order; @@ -98,8 +99,12 @@ public function testAssignData() public function testAuthorizeRegistered() { + $store = $this->getMockBuilder(Store::class)->disableOriginalConstructor()->getMock(); + $store->method('getCode')->willReturn('test'); + $order = $this->getMockBuilder(Order::class)->disableOriginalConstructor()->getMock(); $order->method('getCustomerId')->willReturn('5'); + $order->method('getStore')->willReturn($store); $paymentInfo = $this->getMockBuilder(Info::class)->disableOriginalConstructor()->setMethods(['getOrder'])->getMock(); $paymentInfo->method('getOrder')->willReturn($order); @@ -113,8 +118,12 @@ public function testAuthorizeRegistered() public function testAuthorizeGuest() { + $store = $this->getMockBuilder(Store::class)->disableOriginalConstructor()->getMock(); + $store->method('getCode')->willReturn('test'); + $order = $this->getMockBuilder(Order::class)->disableOriginalConstructor()->getMock(); $order->method('getCustomerId')->willReturn(null); + $order->method('getStore')->willReturn($store); $paymentInfo = $this->getMockBuilder(Info::class)->disableOriginalConstructor()->setMethods(['getOrder'])->getMock(); $paymentInfo->method('getOrder')->willReturn($order); From 4f384e070d0e99fded0415a9a2b2f4d3a6724c42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Thu, 13 Aug 2020 11:45:40 +0200 Subject: [PATCH 5/5] MAG2-146 - Fixed display of wrong base currency in default store scope --- Model/Source/Currency.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Model/Source/Currency.php b/Model/Source/Currency.php index 77a5e76c..589c421c 100644 --- a/Model/Source/Currency.php +++ b/Model/Source/Currency.php @@ -72,7 +72,7 @@ protected function getBaseCurrencyCode() return $oStoreManager->getStore($aRequestParams['store'])->getBaseCurrencyCode(); } - return $oStoreManager->getStore()->getBaseCurrencyCode(); + return $oStoreManager->getStore(0)->getBaseCurrencyCode(); // storeId 0 = Default Config } /**