Skip to content

Commit e1d32cf

Browse files
author
Yu Tang
committed
MAGETWO-44614: Incorrect behaviour of estimate shipping and taxes for guest user based on default tax destination
- Set default addresses from TaxConfigProvider
1 parent 46851c6 commit e1d32cf

File tree

5 files changed

+90
-18
lines changed

5 files changed

+90
-18
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,6 @@ public function getConfig()
286286
);
287287
$output['postCodes'] = $this->postCodesConfig->getPostCodes();
288288
$output['imageData'] = $this->imageProvider->getImages($quoteId);
289-
$output['defaultCountryId'] = $this->directoryHelper->getDefaultCountry();
290289
$output['totalsData'] = $this->getTotalsData();
291290
$output['shippingPolicy'] = [
292291
'isEnabled' => $this->scopeConfig->isSetFlag(

app/code/Magento/Checkout/view/frontend/web/js/model/checkout-data-resolver.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,16 @@ define([
4141
if (checkoutData.getShippingAddressFromData()) {
4242
var address = addressConverter.formAddressDataToQuoteAddress(checkoutData.getShippingAddressFromData());
4343
selectShippingAddress(address);
44+
} else {
45+
this.resolveShippingAddress();
4446
}
45-
4647
if (quote.isVirtual()) {
4748
if (checkoutData.getBillingAddressFromData()) {
4849
address = addressConverter.formAddressDataToQuoteAddress(checkoutData.getBillingAddressFromData());
4950
selectBillingAddress(address);
50-
}
51+
} else {
52+
this.resolveBillingAddress();
53+
}
5154
}
5255

5356
},

app/code/Magento/Checkout/view/frontend/web/js/model/new-customer-address.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,17 @@ define([], function() {
1414
return {
1515
email: addressData.email,
1616
countryId: (addressData.country_id) ? addressData.country_id : window.checkoutConfig.defaultCountryId,
17-
regionId: (addressData.region) ? addressData.region.region_id : null,
17+
regionId: (addressData.region && addressData.region.region_id)
18+
? addressData.region.region_id
19+
: window.checkoutConfig.defaultRegionId,
1820
regionCode: (addressData.region) ? addressData.region.region_code : null,
1921
region: (addressData.region) ? addressData.region.region : null,
2022
customerId: addressData.customer_id,
2123
street: addressData.street,
2224
company: addressData.company,
2325
telephone: addressData.telephone,
2426
fax: addressData.fax,
25-
postcode: addressData.postcode,
27+
postcode: addressData.postcode ? addressData.postcode : window.checkoutConfig.defaultPostcode,
2628
city: addressData.city,
2729
firstname: addressData.firstname,
2830
lastname: addressData.lastname,

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,18 @@ public function getConfig()
6565
'isFullTaxSummaryDisplayed' => $this->isFullTaxSummaryDisplayed(),
6666
'isZeroTaxDisplayed' => $this->taxConfig->displayCartZeroTax(),
6767
'reloadOnBillingAddress' => $this->reloadOnBillingAddress(),
68+
'defaultCountryId' => $this->scopeConfig->getValue(
69+
\Magento\Tax\Model\Config::CONFIG_XML_PATH_DEFAULT_COUNTRY,
70+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
71+
),
72+
'defaultRegionId' => $this->scopeConfig->getValue(
73+
\Magento\Tax\Model\Config::CONFIG_XML_PATH_DEFAULT_REGION,
74+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
75+
),
76+
'defaultPostcode' => $this->scopeConfig->getValue(
77+
\Magento\Tax\Model\Config::CONFIG_XML_PATH_DEFAULT_POSTCODE,
78+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
79+
),
6880
];
6981
}
7082

@@ -164,7 +176,10 @@ public function isTaxDisplayedInGrandTotal()
164176
protected function reloadOnBillingAddress()
165177
{
166178
$quote = $this->checkoutSession->getQuote();
167-
return 'billing' == $this->scopeConfig->getValue(Config::CONFIG_XML_PATH_BASED_ON)
168-
|| $quote->isVirtual();
179+
$configValue = $this->scopeConfig->getValue(
180+
Config::CONFIG_XML_PATH_BASED_ON,
181+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
182+
);
183+
return 'billing' == $configValue || $quote->isVirtual();
169184
}
170185
}

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

Lines changed: 64 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace Magento\Tax\Test\Unit\Model;
77

8+
use \Magento\Tax\Model\Config;
89
class TaxConfigProviderTest extends \PHPUnit_Framework_TestCase
910
{
1011
/**
@@ -79,8 +80,8 @@ public function testGetConfig(
7980
$cartPriceExclTax,
8081
$cartSubTotalBoth,
8182
$cartSubTotalExclTax,
82-
$calculationType,
83-
$isQuoteVirtual
83+
$isQuoteVirtual,
84+
$config
8485
) {
8586
$this->taxConfigMock->expects($this->any())->method('displayCartShippingBoth')
8687
->will($this->returnValue($cartShippingBoth));
@@ -107,10 +108,14 @@ public function testGetConfig(
107108
->will($this->returnValue(1));
108109
$this->taxConfigMock->expects(($this->any()))->method('displayCartZeroTax')
109110
->will($this->returnValue(1));
110-
$this->scopeConfigMock->expects($this->once())
111+
112+
$valueMap = [];
113+
foreach ($config as $key => $value) {
114+
$valueMap[] = [$key, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, null, $value];
115+
}
116+
$this->scopeConfigMock->expects($this->atLeastOnce())
111117
->method('getValue')
112-
->with(\Magento\Tax\Model\Config::CONFIG_XML_PATH_BASED_ON)
113-
->willReturn($calculationType);
118+
->willReturnMap($valueMap);
114119
$this->quoteMock->expects($this->any())->method('isVirtual')->willReturn($isQuoteVirtual);
115120
$this->assertEquals($expectedResult, $this->model->getConfig());
116121
}
@@ -133,15 +138,23 @@ public function getConfigDataProvider()
133138
'isFullTaxSummaryDisplayed' => 1,
134139
'isZeroTaxDisplayed' => 1,
135140
'reloadOnBillingAddress' => false,
141+
'defaultCountryId' => 'US',
142+
'defaultRegionId' => 12,
143+
'defaultPostcode' => '*',
136144
],
137145
'cartShippingBoth' => 1,
138146
'cartShippingExclTax' => 1,
139147
'cartBothPrices' => 1,
140148
'cartPriceExclTax' => 1,
141149
'cartSubTotalBoth' => 1,
142150
'cartSubTotalExclTax' => 1,
143-
'calculationType' => 'shipping',
144151
'isQuoteVirtual' => false,
152+
'config' => [
153+
Config::CONFIG_XML_PATH_BASED_ON => 'shipping',
154+
Config::CONFIG_XML_PATH_DEFAULT_COUNTRY => 'US',
155+
Config::CONFIG_XML_PATH_DEFAULT_REGION => 12,
156+
Config::CONFIG_XML_PATH_DEFAULT_POSTCODE => '*',
157+
],
145158
],
146159
[
147160
'expectedResult' => [
@@ -154,15 +167,23 @@ public function getConfigDataProvider()
154167
'isFullTaxSummaryDisplayed' => 1,
155168
'isZeroTaxDisplayed' => 1,
156169
'reloadOnBillingAddress' => true,
170+
'defaultCountryId' => 'US',
171+
'defaultRegionId' => 12,
172+
'defaultPostcode' => '*',
157173
],
158174
'cartShippingBoth' => 0,
159175
'cartShippingExclTax' => 1,
160176
'cartBothPrices' => 0,
161177
'cartPriceExclTax' => 1,
162178
'cartSubTotalBoth' => 0,
163179
'cartSubTotalExclTax' => 1,
164-
'calculationType' => 'billing',
165180
'isQuoteVirtual' => false,
181+
'config' => [
182+
Config::CONFIG_XML_PATH_BASED_ON => 'billing',
183+
Config::CONFIG_XML_PATH_DEFAULT_COUNTRY => 'US',
184+
Config::CONFIG_XML_PATH_DEFAULT_REGION => 12,
185+
Config::CONFIG_XML_PATH_DEFAULT_POSTCODE => '*',
186+
],
166187
],
167188
[
168189
'expectedResult' => [
@@ -175,15 +196,23 @@ public function getConfigDataProvider()
175196
'isFullTaxSummaryDisplayed' => 1,
176197
'isZeroTaxDisplayed' => 1,
177198
'reloadOnBillingAddress' => true,
199+
'defaultCountryId' => 'US',
200+
'defaultRegionId' => 12,
201+
'defaultPostcode' => '*',
178202
],
179203
'cartShippingBoth' => 0,
180204
'cartShippingExclTax' => 0,
181205
'cartBothPrices' => 0,
182206
'cartPriceExclTax' => 0,
183207
'cartSubTotalBoth' => 0,
184208
'cartSubTotalExclTax' => 0,
185-
'calculationType' => 'shipping',
186209
'isQuoteVirtual' => true,
210+
'config' => [
211+
Config::CONFIG_XML_PATH_BASED_ON => 'shipping',
212+
Config::CONFIG_XML_PATH_DEFAULT_COUNTRY => 'US',
213+
Config::CONFIG_XML_PATH_DEFAULT_REGION => 12,
214+
Config::CONFIG_XML_PATH_DEFAULT_POSTCODE => '*',
215+
],
187216
],
188217
[
189218
'expectedResult' => [
@@ -196,15 +225,23 @@ public function getConfigDataProvider()
196225
'isFullTaxSummaryDisplayed' => 1,
197226
'isZeroTaxDisplayed' => 1,
198227
'reloadOnBillingAddress' => true,
228+
'defaultCountryId' => 'US',
229+
'defaultRegionId' => 12,
230+
'defaultPostcode' => '*',
199231
],
200232
'cartShippingBoth' => 0,
201233
'cartShippingExclTax' => 0,
202234
'cartBothPrices' => 0,
203235
'cartPriceExclTax' => 0,
204236
'cartSubTotalBoth' => 0,
205237
'cartSubTotalExclTax' => 0,
206-
'calculationType' => 'billing',
207238
'isQuoteVirtual' => true,
239+
'config' => [
240+
Config::CONFIG_XML_PATH_BASED_ON => 'billing',
241+
Config::CONFIG_XML_PATH_DEFAULT_COUNTRY => 'US',
242+
Config::CONFIG_XML_PATH_DEFAULT_REGION => 12,
243+
Config::CONFIG_XML_PATH_DEFAULT_POSTCODE => '*',
244+
],
208245
],
209246
[
210247
'expectedResult' => [
@@ -217,15 +254,23 @@ public function getConfigDataProvider()
217254
'isFullTaxSummaryDisplayed' => 1,
218255
'isZeroTaxDisplayed' => 1,
219256
'reloadOnBillingAddress' => false,
257+
'defaultCountryId' => 'US',
258+
'defaultRegionId' => 12,
259+
'defaultPostcode' => '*',
220260
],
221261
'cartShippingBoth' => 1,
222262
'cartShippingExclTax' => 0,
223263
'cartBothPrices' => 1,
224264
'cartPriceExclTax' => 0,
225265
'cartSubTotalBoth' => 1,
226266
'cartSubTotalExclTax' => 0,
227-
'calculationType' => 'shipping',
228267
'isQuoteVirtual' => false,
268+
'config' => [
269+
Config::CONFIG_XML_PATH_BASED_ON => 'shipping',
270+
Config::CONFIG_XML_PATH_DEFAULT_COUNTRY => 'US',
271+
Config::CONFIG_XML_PATH_DEFAULT_REGION => 12,
272+
Config::CONFIG_XML_PATH_DEFAULT_POSTCODE => '*',
273+
],
229274
],
230275
[
231276
'expectedResult' => [
@@ -238,15 +283,23 @@ public function getConfigDataProvider()
238283
'isFullTaxSummaryDisplayed' => 1,
239284
'isZeroTaxDisplayed' => 1,
240285
'reloadOnBillingAddress' => false,
286+
'defaultCountryId' => 'US',
287+
'defaultRegionId' => 12,
288+
'defaultPostcode' => '*',
241289
],
242290
'cartShippingBoth' => 0,
243291
'cartShippingExclTax' => 1,
244292
'cartBothPrices' => 0,
245293
'cartPriceExclTax' => 0,
246294
'cartSubTotalBoth' => 1,
247295
'cartSubTotalExclTax' => 0,
248-
'calculationType' => 'shipping',
249296
'isQuoteVirtual' => false,
297+
'config' => [
298+
Config::CONFIG_XML_PATH_BASED_ON => 'shipping',
299+
Config::CONFIG_XML_PATH_DEFAULT_COUNTRY => 'US',
300+
Config::CONFIG_XML_PATH_DEFAULT_REGION => 12,
301+
Config::CONFIG_XML_PATH_DEFAULT_POSTCODE => '*',
302+
],
250303
],
251304
];
252305
}

0 commit comments

Comments
 (0)