Skip to content

Commit 63222cf

Browse files
author
Yu Tang
committed
Merge remote-tracking branch 'origin/FearlessKiwis-MAGETWO-44614-Incorrect-Default-Address-For-Guest-Tax' into FearlessKiwis-develop-no-refactoring
2 parents 0f050dc + b9e33ab commit 63222cf

File tree

4 files changed

+86
-16
lines changed

4 files changed

+86
-16
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,6 @@ public function getConfig()
278278
);
279279
$output['postCodes'] = $this->postCodesConfig->getPostCodes();
280280
$output['imageData'] = $this->imageProvider->getImages($quoteId);
281-
$output['defaultCountryId'] = $this->directoryHelper->getDefaultCountry();
282281
$output['totalsData'] = $this->getTotalsData();
283282
$output['shippingPolicy'] = [
284283
'isEnabled' => $this->scopeConfig->isSetFlag(

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: 65 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace Magento\Tax\Test\Unit\Model;
77

8+
use \Magento\Tax\Model\Config;
9+
810
class TaxConfigProviderTest extends \PHPUnit_Framework_TestCase
911
{
1012
/**
@@ -79,8 +81,8 @@ public function testGetConfig(
7981
$cartPriceExclTax,
8082
$cartSubTotalBoth,
8183
$cartSubTotalExclTax,
82-
$calculationType,
83-
$isQuoteVirtual
84+
$isQuoteVirtual,
85+
$config
8486
) {
8587
$this->taxConfigMock->expects($this->any())->method('displayCartShippingBoth')
8688
->will($this->returnValue($cartShippingBoth));
@@ -107,10 +109,14 @@ public function testGetConfig(
107109
->will($this->returnValue(1));
108110
$this->taxConfigMock->expects(($this->any()))->method('displayCartZeroTax')
109111
->will($this->returnValue(1));
110-
$this->scopeConfigMock->expects($this->once())
112+
113+
$valueMap = [];
114+
foreach ($config as $key => $value) {
115+
$valueMap[] = [$key, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, null, $value];
116+
}
117+
$this->scopeConfigMock->expects($this->atLeastOnce())
111118
->method('getValue')
112-
->with(\Magento\Tax\Model\Config::CONFIG_XML_PATH_BASED_ON)
113-
->willReturn($calculationType);
119+
->willReturnMap($valueMap);
114120
$this->quoteMock->expects($this->any())->method('isVirtual')->willReturn($isQuoteVirtual);
115121
$this->assertEquals($expectedResult, $this->model->getConfig());
116122
}
@@ -133,15 +139,23 @@ public function getConfigDataProvider()
133139
'isFullTaxSummaryDisplayed' => 1,
134140
'isZeroTaxDisplayed' => 1,
135141
'reloadOnBillingAddress' => false,
142+
'defaultCountryId' => 'US',
143+
'defaultRegionId' => 12,
144+
'defaultPostcode' => '*',
136145
],
137146
'cartShippingBoth' => 1,
138147
'cartShippingExclTax' => 1,
139148
'cartBothPrices' => 1,
140149
'cartPriceExclTax' => 1,
141150
'cartSubTotalBoth' => 1,
142151
'cartSubTotalExclTax' => 1,
143-
'calculationType' => 'shipping',
144152
'isQuoteVirtual' => false,
153+
'config' => [
154+
Config::CONFIG_XML_PATH_BASED_ON => 'shipping',
155+
Config::CONFIG_XML_PATH_DEFAULT_COUNTRY => 'US',
156+
Config::CONFIG_XML_PATH_DEFAULT_REGION => 12,
157+
Config::CONFIG_XML_PATH_DEFAULT_POSTCODE => '*',
158+
],
145159
],
146160
[
147161
'expectedResult' => [
@@ -154,15 +168,23 @@ public function getConfigDataProvider()
154168
'isFullTaxSummaryDisplayed' => 1,
155169
'isZeroTaxDisplayed' => 1,
156170
'reloadOnBillingAddress' => true,
171+
'defaultCountryId' => 'US',
172+
'defaultRegionId' => 12,
173+
'defaultPostcode' => '*',
157174
],
158175
'cartShippingBoth' => 0,
159176
'cartShippingExclTax' => 1,
160177
'cartBothPrices' => 0,
161178
'cartPriceExclTax' => 1,
162179
'cartSubTotalBoth' => 0,
163180
'cartSubTotalExclTax' => 1,
164-
'calculationType' => 'billing',
165181
'isQuoteVirtual' => false,
182+
'config' => [
183+
Config::CONFIG_XML_PATH_BASED_ON => 'billing',
184+
Config::CONFIG_XML_PATH_DEFAULT_COUNTRY => 'US',
185+
Config::CONFIG_XML_PATH_DEFAULT_REGION => 12,
186+
Config::CONFIG_XML_PATH_DEFAULT_POSTCODE => '*',
187+
],
166188
],
167189
[
168190
'expectedResult' => [
@@ -175,15 +197,23 @@ public function getConfigDataProvider()
175197
'isFullTaxSummaryDisplayed' => 1,
176198
'isZeroTaxDisplayed' => 1,
177199
'reloadOnBillingAddress' => true,
200+
'defaultCountryId' => 'US',
201+
'defaultRegionId' => 12,
202+
'defaultPostcode' => '*',
178203
],
179204
'cartShippingBoth' => 0,
180205
'cartShippingExclTax' => 0,
181206
'cartBothPrices' => 0,
182207
'cartPriceExclTax' => 0,
183208
'cartSubTotalBoth' => 0,
184209
'cartSubTotalExclTax' => 0,
185-
'calculationType' => 'shipping',
186210
'isQuoteVirtual' => true,
211+
'config' => [
212+
Config::CONFIG_XML_PATH_BASED_ON => 'shipping',
213+
Config::CONFIG_XML_PATH_DEFAULT_COUNTRY => 'US',
214+
Config::CONFIG_XML_PATH_DEFAULT_REGION => 12,
215+
Config::CONFIG_XML_PATH_DEFAULT_POSTCODE => '*',
216+
],
187217
],
188218
[
189219
'expectedResult' => [
@@ -196,15 +226,23 @@ public function getConfigDataProvider()
196226
'isFullTaxSummaryDisplayed' => 1,
197227
'isZeroTaxDisplayed' => 1,
198228
'reloadOnBillingAddress' => true,
229+
'defaultCountryId' => 'US',
230+
'defaultRegionId' => 12,
231+
'defaultPostcode' => '*',
199232
],
200233
'cartShippingBoth' => 0,
201234
'cartShippingExclTax' => 0,
202235
'cartBothPrices' => 0,
203236
'cartPriceExclTax' => 0,
204237
'cartSubTotalBoth' => 0,
205238
'cartSubTotalExclTax' => 0,
206-
'calculationType' => 'billing',
207239
'isQuoteVirtual' => true,
240+
'config' => [
241+
Config::CONFIG_XML_PATH_BASED_ON => 'billing',
242+
Config::CONFIG_XML_PATH_DEFAULT_COUNTRY => 'US',
243+
Config::CONFIG_XML_PATH_DEFAULT_REGION => 12,
244+
Config::CONFIG_XML_PATH_DEFAULT_POSTCODE => '*',
245+
],
208246
],
209247
[
210248
'expectedResult' => [
@@ -217,15 +255,23 @@ public function getConfigDataProvider()
217255
'isFullTaxSummaryDisplayed' => 1,
218256
'isZeroTaxDisplayed' => 1,
219257
'reloadOnBillingAddress' => false,
258+
'defaultCountryId' => 'US',
259+
'defaultRegionId' => 12,
260+
'defaultPostcode' => '*',
220261
],
221262
'cartShippingBoth' => 1,
222263
'cartShippingExclTax' => 0,
223264
'cartBothPrices' => 1,
224265
'cartPriceExclTax' => 0,
225266
'cartSubTotalBoth' => 1,
226267
'cartSubTotalExclTax' => 0,
227-
'calculationType' => 'shipping',
228268
'isQuoteVirtual' => false,
269+
'config' => [
270+
Config::CONFIG_XML_PATH_BASED_ON => 'shipping',
271+
Config::CONFIG_XML_PATH_DEFAULT_COUNTRY => 'US',
272+
Config::CONFIG_XML_PATH_DEFAULT_REGION => 12,
273+
Config::CONFIG_XML_PATH_DEFAULT_POSTCODE => '*',
274+
],
229275
],
230276
[
231277
'expectedResult' => [
@@ -238,15 +284,23 @@ public function getConfigDataProvider()
238284
'isFullTaxSummaryDisplayed' => 1,
239285
'isZeroTaxDisplayed' => 1,
240286
'reloadOnBillingAddress' => false,
287+
'defaultCountryId' => 'US',
288+
'defaultRegionId' => 12,
289+
'defaultPostcode' => '*',
241290
],
242291
'cartShippingBoth' => 0,
243292
'cartShippingExclTax' => 1,
244293
'cartBothPrices' => 0,
245294
'cartPriceExclTax' => 0,
246295
'cartSubTotalBoth' => 1,
247296
'cartSubTotalExclTax' => 0,
248-
'calculationType' => 'shipping',
249297
'isQuoteVirtual' => false,
298+
'config' => [
299+
Config::CONFIG_XML_PATH_BASED_ON => 'shipping',
300+
Config::CONFIG_XML_PATH_DEFAULT_COUNTRY => 'US',
301+
Config::CONFIG_XML_PATH_DEFAULT_REGION => 12,
302+
Config::CONFIG_XML_PATH_DEFAULT_POSTCODE => '*',
303+
],
250304
],
251305
];
252306
}

0 commit comments

Comments
 (0)