Skip to content

Commit f81dfc1

Browse files
committed
ACP2E-862: Cash on Delivery method is visible even if it is not allowed for that particular country
1 parent 28113d8 commit f81dfc1

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

app/code/Magento/Checkout/Model/DefaultConfigProvider.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,7 @@ public function getConfig()
358358
$output['originCountryCode'] = $this->getOriginCountryCode();
359359
$output['paymentMethods'] = $this->getPaymentMethods();
360360
$output['autocomplete'] = $this->isAutocompleteEnabled();
361+
$output['displayBillingOnPaymentMethod'] = $this->checkoutHelper->isDisplayBillingOnPaymentMethodAvailable();
361362
return $this->configPostProcessor->process($output);
362363
}
363364

app/code/Magento/Tax/Model/TaxConfigProvider.php

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Magento\Checkout\Model\ConfigProviderInterface;
99
use Magento\Tax\Helper\Data as TaxHelper;
1010
use Magento\Framework\App\Config\ScopeConfigInterface;
11+
use Magento\Checkout\Model\Session as CheckoutSession;
1112

1213
class TaxConfigProvider implements ConfigProviderInterface
1314
{
@@ -26,23 +27,31 @@ class TaxConfigProvider implements ConfigProviderInterface
2627
*/
2728
protected $scopeConfig;
2829

30+
/**
31+
* @var CheckoutSession
32+
*/
33+
protected $checkoutSession;
34+
2935
/**
3036
* @param TaxHelper $taxHelper
3137
* @param Config $taxConfig
38+
* @param CheckoutSession $checkoutSession
3239
* @param ScopeConfigInterface $scopeConfig
3340
*/
3441
public function __construct(
3542
TaxHelper $taxHelper,
3643
Config $taxConfig,
44+
CheckoutSession $checkoutSession,
3745
ScopeConfigInterface $scopeConfig
3846
) {
3947
$this->taxHelper = $taxHelper;
4048
$this->taxConfig = $taxConfig;
49+
$this->checkoutSession = $checkoutSession;
4150
$this->scopeConfig = $scopeConfig;
4251
}
4352

4453
/**
45-
* @inheritdoc
54+
* {@inheritdoc}
4655
*/
4756
public function getConfig()
4857
{
@@ -63,6 +72,7 @@ public function getConfig()
6372
'includeTaxInGrandTotal' => $this->isTaxDisplayedInGrandTotal(),
6473
'isFullTaxSummaryDisplayed' => $this->isFullTaxSummaryDisplayed(),
6574
'isZeroTaxDisplayed' => $this->taxConfig->displayCartZeroTax(),
75+
'reloadOnBillingAddress' => $this->reloadOnBillingAddress(),
6676
'defaultCountryId' => $this->scopeConfig->getValue(
6777
\Magento\Tax\Model\Config::CONFIG_XML_PATH_DEFAULT_COUNTRY,
6878
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
@@ -162,4 +172,19 @@ public function isTaxDisplayedInGrandTotal()
162172
{
163173
return $this->taxConfig->displayCartTaxWithGrandTotal();
164174
}
175+
176+
/**
177+
* Reload totals(taxes) on billing address update
178+
*
179+
* @return bool
180+
*/
181+
protected function reloadOnBillingAddress()
182+
{
183+
$quote = $this->checkoutSession->getQuote();
184+
$configValue = $this->scopeConfig->getValue(
185+
Config::CONFIG_XML_PATH_BASED_ON,
186+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
187+
);
188+
return 'billing' == $configValue || $quote->isVirtual();
189+
}
165190
}

app/code/Magento/Tax/Test/Unit/Model/TaxConfigProviderTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace Magento\Tax\Test\Unit\Model;
99

10+
use Magento\Checkout\Model\Session;
1011
use Magento\Framework\App\Config\ScopeConfigInterface;
1112
use Magento\Quote\Model\Quote;
1213
use Magento\Store\Model\ScopeInterface;
@@ -28,6 +29,11 @@ class TaxConfigProviderTest extends TestCase
2829
*/
2930
protected $taxConfigMock;
3031

32+
/**
33+
* @var MockObject
34+
*/
35+
protected $checkoutSessionMock;
36+
3137
/**
3238
* @var MockObject
3339
*/
@@ -47,11 +53,14 @@ protected function setUp(): void
4753
{
4854
$this->taxHelperMock = $this->createMock(Data::class);
4955
$this->taxConfigMock = $this->createMock(Config::class);
56+
$this->checkoutSessionMock = $this->createMock(Session::class);
5057
$this->scopeConfigMock = $this->getMockForAbstractClass(ScopeConfigInterface::class);
5158
$this->quoteMock = $this->createMock(Quote::class);
59+
$this->checkoutSessionMock->expects($this->any())->method('getQuote')->willReturn($this->quoteMock);
5260
$this->model = new TaxConfigProvider(
5361
$this->taxHelperMock,
5462
$this->taxConfigMock,
63+
$this->checkoutSessionMock,
5564
$this->scopeConfigMock
5665
);
5766
}
@@ -133,6 +142,7 @@ public function getConfigDataProvider()
133142
'includeTaxInGrandTotal' => 1,
134143
'isFullTaxSummaryDisplayed' => 1,
135144
'isZeroTaxDisplayed' => 1,
145+
'reloadOnBillingAddress' => false,
136146
'defaultCountryId' => 'US',
137147
'defaultRegionId' => 12,
138148
'defaultPostcode' => '*',
@@ -161,6 +171,7 @@ public function getConfigDataProvider()
161171
'includeTaxInGrandTotal' => 1,
162172
'isFullTaxSummaryDisplayed' => 1,
163173
'isZeroTaxDisplayed' => 1,
174+
'reloadOnBillingAddress' => true,
164175
'defaultCountryId' => 'US',
165176
'defaultRegionId' => 12,
166177
'defaultPostcode' => '*',
@@ -189,6 +200,7 @@ public function getConfigDataProvider()
189200
'includeTaxInGrandTotal' => 1,
190201
'isFullTaxSummaryDisplayed' => 1,
191202
'isZeroTaxDisplayed' => 1,
203+
'reloadOnBillingAddress' => true,
192204
'defaultCountryId' => 'US',
193205
'defaultRegionId' => 12,
194206
'defaultPostcode' => '*',
@@ -217,6 +229,7 @@ public function getConfigDataProvider()
217229
'includeTaxInGrandTotal' => 1,
218230
'isFullTaxSummaryDisplayed' => 1,
219231
'isZeroTaxDisplayed' => 1,
232+
'reloadOnBillingAddress' => true,
220233
'defaultCountryId' => 'US',
221234
'defaultRegionId' => 12,
222235
'defaultPostcode' => '*',
@@ -245,6 +258,7 @@ public function getConfigDataProvider()
245258
'includeTaxInGrandTotal' => 1,
246259
'isFullTaxSummaryDisplayed' => 1,
247260
'isZeroTaxDisplayed' => 1,
261+
'reloadOnBillingAddress' => false,
248262
'defaultCountryId' => 'US',
249263
'defaultRegionId' => 12,
250264
'defaultPostcode' => '*',
@@ -273,6 +287,7 @@ public function getConfigDataProvider()
273287
'includeTaxInGrandTotal' => 1,
274288
'isFullTaxSummaryDisplayed' => 1,
275289
'isZeroTaxDisplayed' => 1,
290+
'reloadOnBillingAddress' => false,
276291
'defaultCountryId' => 'US',
277292
'defaultRegionId' => 12,
278293
'defaultPostcode' => '*',
@@ -301,6 +316,7 @@ public function getConfigDataProvider()
301316
'includeTaxInGrandTotal' => 1,
302317
'isFullTaxSummaryDisplayed' => 1,
303318
'isZeroTaxDisplayed' => 1,
319+
'reloadOnBillingAddress' => false,
304320
'defaultCountryId' => 'US',
305321
'defaultRegionId' => null,
306322
'defaultPostcode' => '*',

0 commit comments

Comments
 (0)