Skip to content

Commit 959d466

Browse files
authored
LYNX-412: Fix post code not being removed in estimateTotals
1 parent ee2ffab commit 959d466

File tree

2 files changed

+122
-9
lines changed

2 files changed

+122
-9
lines changed

app/code/Magento/QuoteGraphQl/Model/Resolver/EstimateTotals.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Magento\Quote\Api\CartRepositoryInterface;
1919
use Magento\Quote\Api\Data\AddressInterface;
2020
use Magento\Quote\Model\MaskedQuoteIdToQuoteIdInterface;
21+
use Magento\Quote\Model\Quote\Address;
2122
use Magento\Quote\Model\Quote\AddressFactory;
2223

2324
/**
@@ -69,7 +70,8 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
6970
throw new GraphQlInputException(__('Required parameter "country_code" is missing'));
7071
}
7172

72-
$this->totalsInformationManagement->calculate($cartId, $this->getTotalsInformation($args['input']));
73+
$data = $this->getTotalsInformation($args['input']);
74+
$this->totalsInformationManagement->calculate($cartId, $data);
7375

7476
return [
7577
'cart' => [
@@ -106,14 +108,14 @@ private function getTotalsInformation(array $input): TotalsInformationInterface
106108
*/
107109
private function getAddress(array $data): AddressInterface
108110
{
109-
$data = [
110-
AddressInterface::KEY_COUNTRY_ID => $data['country_code'],
111-
AddressInterface::KEY_REGION => $data['region'][AddressInterface::KEY_REGION] ?? null,
112-
AddressInterface::KEY_REGION_ID => $data['region'][AddressInterface::KEY_REGION_ID] ?? null,
113-
AddressInterface::KEY_REGION_CODE => $data['region'][AddressInterface::KEY_REGION_CODE] ?? null,
114-
AddressInterface::KEY_POSTCODE => $data[AddressInterface::KEY_POSTCODE] ?? null,
115-
];
111+
/** @var Address $address */
112+
$address = $this->addressFactory->create();
113+
$address->setCountryId($data['country_code']);
114+
$address->setRegion($data['region'][AddressInterface::KEY_REGION] ?? null);
115+
$address->setRegionId($data['region'][AddressInterface::KEY_REGION_ID] ?? null);
116+
$address->setRegionCode($data['region'][AddressInterface::KEY_REGION_CODE] ?? null);
117+
$address->setPostcode($data[AddressInterface::KEY_POSTCODE] ?? null);
116118

117-
return $this->addressFactory->create(['data' => array_filter($data)]);
119+
return $address;
118120
}
119121
}

dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/EstimateTotalsTest.php

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,117 @@ public function testEstimateTotals(string $countryCode, string $shipping, array
117117
);
118118
}
119119

120+
/**
121+
* @return void
122+
* @throws LocalizedException
123+
*/
124+
#[
125+
DataFixture(
126+
ProductTaxClass::class,
127+
as: 'product_tax_class'
128+
),
129+
DataFixture(
130+
TaxRateFixture::class,
131+
[
132+
'tax_country_id' => 'ES',
133+
'tax_postcode' => '08005',
134+
],
135+
'rate'
136+
),
137+
DataFixture(
138+
TaxRuleFixture::class,
139+
[
140+
'customer_tax_class_ids' => [3],
141+
'product_tax_class_ids' => ['$product_tax_class.classId$'],
142+
'tax_rate_ids' => ['$rate.id$']
143+
],
144+
'rule'
145+
),
146+
DataFixture(
147+
ProductFixture::class,
148+
[
149+
'custom_attributes' => [
150+
'tax_class_id' => '$product_tax_class.classId$'
151+
],
152+
],
153+
'product'
154+
),
155+
DataFixture(GuestCart::class, ['currency' => 'USD'], 'cart'),
156+
DataFixture(QuoteIdMask::class, ['cart_id' => '$cart.id$'], 'quoteIdMask'),
157+
DataFixture(AddProductToCart::class, [
158+
'cart_id' => '$cart.id$',
159+
'product_id' => '$product.id$',
160+
'qty' => 1
161+
])
162+
]
163+
public function testEstimateTotalsCleanPostCode(): void
164+
{
165+
$maskedQuoteId = DataFixtureStorageManager::getStorage()->get('quoteIdMask')->getMaskedId();
166+
167+
$query = <<<QUERY
168+
mutation {
169+
estimateTotals(input: {
170+
cart_id: "{$maskedQuoteId}",
171+
address: {
172+
country_code: ES
173+
postcode: "%s"
174+
},
175+
shipping_method: {
176+
carrier_code: "flatrate",
177+
method_code: "flatrate"
178+
}
179+
}) {
180+
cart {
181+
prices {
182+
applied_taxes {
183+
amount {
184+
value
185+
currency
186+
}
187+
}
188+
}
189+
}
190+
}
191+
}
192+
QUERY;
193+
$response = $this->graphQlMutation(sprintf($query, '08005'));
194+
195+
self::assertEquals(
196+
[
197+
'estimateTotals' => [
198+
'cart' => [
199+
'prices' => [
200+
'applied_taxes' => [
201+
[
202+
'amount' => [
203+
'value' => 1,
204+
'currency' => 'USD'
205+
]
206+
]
207+
]
208+
]
209+
]
210+
]
211+
],
212+
$response
213+
);
214+
215+
$response = $this->graphQlMutation(sprintf($query, ''));
216+
217+
self::assertEquals(
218+
[
219+
'estimateTotals' => [
220+
'cart' => [
221+
'prices' => [
222+
'applied_taxes' => []
223+
]
224+
]
225+
]
226+
],
227+
$response
228+
);
229+
}
230+
120231
public function estimationsProvider(): array
121232
{
122233
return [

0 commit comments

Comments
 (0)