Skip to content

Commit 8b38d52

Browse files
[Magento Community Engineering] Community Contributions - 2.3-develop
- merged latest code from mainline branch
2 parents 186e96f + b5a38dc commit 8b38d52

23 files changed

+820
-183
lines changed

app/code/Magento/QuoteGraphQl/Model/Resolver/ShippingAddress/AvailableShippingMethods.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
7575
);
7676
$methods[] = $this->processMoneyTypeData(
7777
$methodData,
78-
$cart->getQuoteCurrencyCode(),
79-
$context->getExtensionAttributes()->getStore()
78+
$cart->getQuoteCurrencyCode()
8079
);
8180
}
8281
}
@@ -88,21 +87,17 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
8887
*
8988
* @param array $data
9089
* @param string $quoteCurrencyCode
91-
* @param StoreInterface $store
9290
* @return array
9391
* @throws NoSuchEntityException
9492
*/
95-
private function processMoneyTypeData(array $data, string $quoteCurrencyCode, StoreInterface $store): array
93+
private function processMoneyTypeData(array $data, string $quoteCurrencyCode): array
9694
{
9795
if (isset($data['amount'])) {
9896
$data['amount'] = ['value' => $data['amount'], 'currency' => $quoteCurrencyCode];
9997
}
10098

101-
if (isset($data['base_amount'])) {
102-
/** @var Currency $currency */
103-
$currency = $store->getBaseCurrency();
104-
$data['base_amount'] = ['value' => $data['base_amount'], 'currency' => $currency->getCode()];
105-
}
99+
/** @deprecated The field should not be used on the storefront */
100+
$data['base_amount'] = null;
106101

107102
if (isset($data['price_excl_tax'])) {
108103
$data['price_excl_tax'] = ['value' => $data['price_excl_tax'], 'currency' => $quoteCurrencyCode];

app/code/Magento/QuoteGraphQl/Model/Resolver/ShippingAddress/SelectedShippingMethod.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,6 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
4646
}
4747
}
4848

49-
/** @var Currency $currency */
50-
$currency = $context->getExtensionAttributes()->getStore()->getBaseCurrency();
51-
5249
$data = [
5350
'carrier_code' => $carrierCode,
5451
'method_code' => $methodCode,
@@ -58,10 +55,8 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
5855
'value' => $address->getShippingAmount(),
5956
'currency' => $address->getQuote()->getQuoteCurrencyCode(),
6057
],
61-
'base_amount' => [
62-
'value' => $address->getBaseShippingAmount(),
63-
'currency' => $currency->getCode(),
64-
],
58+
/** @deprecated The field should not be used on the storefront */
59+
'base_amount' => null,
6560
];
6661
} else {
6762
$data = [
@@ -70,6 +65,7 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
7065
'carrier_title' => $carrierTitle,
7166
'method_title' => $methodTitle,
7267
'amount' => null,
68+
/** @deprecated The field should not be used on the storefront */
7369
'base_amount' => null,
7470
];
7571
}

app/code/Magento/QuoteGraphQl/etc/schema.graphqls

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ type SelectedShippingMethod {
244244
carrier_title: String
245245
method_title: String
246246
amount: Money
247-
base_amount: Money
247+
base_amount: Money @deprecated(reason: "The field should not be used on the storefront")
248248
}
249249

250250
type AvailableShippingMethod {
@@ -254,7 +254,7 @@ type AvailableShippingMethod {
254254
method_title: String @doc(description: "Could be null if method is not available")
255255
error_message: String
256256
amount: Money!
257-
base_amount: Money @doc(description: "Could be null if method is not available")
257+
base_amount: Money @deprecated(reason: "The field should not be used on the storefront")
258258
price_excl_tax: Money!
259259
price_incl_tax: Money!
260260
available: Boolean!

dev/tests/api-functional/testsuite/Magento/GraphQl/ConfigurableProduct/AddConfigurableProductToCartTest.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,56 @@ public function testAddProductIfQuantityIsNotAvailable()
164164
$this->graphQlMutation($query);
165165
}
166166

167+
/**
168+
* @magentoApiDataFixture Magento/ConfigurableProduct/_files/product_configurable_sku.php
169+
* @magentoApiDataFixture Magento/Checkout/_files/active_quote.php
170+
* @expectedException \Exception
171+
* @expectedExceptionMessage Could not find a product with SKU "configurable_no_exist"
172+
*/
173+
public function testAddNonExistentConfigurableProductParentToCart()
174+
{
175+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_1');
176+
$parentSku = 'configurable_no_exist';
177+
$sku = 'simple_20';
178+
179+
$query = $this->getQuery(
180+
$maskedQuoteId,
181+
$parentSku,
182+
$sku,
183+
2000
184+
);
185+
186+
$this->graphQlMutation($query);
187+
}
188+
189+
/**
190+
* @magentoApiDataFixture Magento/ConfigurableProduct/_files/product_configurable_sku.php
191+
* @magentoApiDataFixture Magento/Checkout/_files/active_quote.php
192+
*/
193+
public function testAddNonExistentConfigurableProductVariationToCart()
194+
{
195+
$searchResponse = $this->graphQlQuery($this->getFetchProductQuery('configurable'));
196+
$product = current($searchResponse['products']['items']);
197+
198+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_1');
199+
$parentSku = $product['sku'];
200+
$sku = 'simple_no_exist';
201+
202+
$query = $this->getQuery(
203+
$maskedQuoteId,
204+
$parentSku,
205+
$sku,
206+
2000
207+
);
208+
209+
$this->expectException(\Exception::class);
210+
$this->expectExceptionMessage(
211+
'Could not add the product with SKU configurable to the shopping cart: Could not find specified product.'
212+
);
213+
214+
$this->graphQlMutation($query);
215+
}
216+
167217
/**
168218
* @param string $maskedQuoteId
169219
* @param string $parentSku
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\GraphQl\ConfigurableProduct;
9+
10+
use Magento\Catalog\Api\ProductRepositoryInterface;
11+
use Magento\GraphQl\Quote\GetMaskedQuoteIdByReservedOrderId;
12+
use Magento\Quote\Model\Quote\Item;
13+
use Magento\Quote\Model\QuoteFactory;
14+
use Magento\Quote\Model\ResourceModel\Quote as QuoteResource;
15+
use Magento\TestFramework\Helper\Bootstrap;
16+
use Magento\TestFramework\TestCase\GraphQlAbstract;
17+
18+
/**
19+
* Remove configurable product from cart testcases
20+
*/
21+
class RemoveConfigurableProductFromCartTest extends GraphQlAbstract
22+
{
23+
/**
24+
* @var GetMaskedQuoteIdByReservedOrderId
25+
*/
26+
private $getMaskedQuoteIdByReservedOrderId;
27+
28+
/**
29+
* @var ProductRepositoryInterface
30+
*/
31+
private $productRepository;
32+
33+
/**
34+
* @var QuoteFactory
35+
*/
36+
private $quoteFactory;
37+
38+
/**
39+
* @var QuoteResource
40+
*/
41+
private $quoteResource;
42+
43+
/**
44+
* @inheritdoc
45+
*/
46+
protected function setUp()
47+
{
48+
$objectManager = Bootstrap::getObjectManager();
49+
$this->getMaskedQuoteIdByReservedOrderId = $objectManager->get(GetMaskedQuoteIdByReservedOrderId::class);
50+
$this->quoteFactory = $objectManager->get(QuoteFactory::class);
51+
$this->quoteResource = $objectManager->get(QuoteResource::class);
52+
$this->productRepository = $objectManager->get(ProductRepositoryInterface::class);
53+
}
54+
55+
/**
56+
* @magentoApiDataFixture Magento/ConfigurableProduct/_files/quote_with_configurable_product.php
57+
*/
58+
public function testRemoveConfigurableProductFromCart()
59+
{
60+
$configurableOptionSku = 'simple_10';
61+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_cart_with_configurable');
62+
$quoteItemId = $this->getQuoteItemIdBySku($configurableOptionSku);
63+
$query = $this->getQuery($maskedQuoteId, $quoteItemId);
64+
$response = $this->graphQlMutation($query);
65+
66+
$this->assertArrayHasKey('cart', $response['removeItemFromCart']);
67+
$this->assertArrayHasKey('items', $response['removeItemFromCart']['cart']);
68+
$this->assertEquals(0, count($response['removeItemFromCart']['cart']['items']));
69+
}
70+
71+
/**
72+
* @param string $maskedQuoteId
73+
* @param int $itemId
74+
* @return string
75+
*/
76+
private function getQuery(string $maskedQuoteId, int $itemId): string
77+
{
78+
return <<<QUERY
79+
mutation {
80+
removeItemFromCart(
81+
input: {
82+
cart_id: "{$maskedQuoteId}"
83+
cart_item_id: {$itemId}
84+
}
85+
) {
86+
cart {
87+
items {
88+
quantity
89+
}
90+
}
91+
}
92+
}
93+
QUERY;
94+
}
95+
96+
/**
97+
* Returns quote item ID by product's SKU
98+
*
99+
* @param string $sku
100+
* @return int
101+
*/
102+
private function getQuoteItemIdBySku(string $sku): int
103+
{
104+
$quote = $this->quoteFactory->create();
105+
$this->quoteResource->load($quote, 'test_cart_with_configurable', 'reserved_order_id');
106+
/** @var Item $quoteItem */
107+
$quoteItemsCollection = $quote->getItemsCollection();
108+
foreach ($quoteItemsCollection->getItems() as $item) {
109+
if ($item->getSku() == $sku) {
110+
return (int)$item->getId();
111+
}
112+
}
113+
}
114+
}

0 commit comments

Comments
 (0)