Skip to content

Commit 20627b0

Browse files
authored
Merge pull request #3829 from magento-engcom/graphql-develop-prs
[EngCom] Public Pull Requests - GraphQL
2 parents 1514eeb + 2d34d77 commit 20627b0

File tree

4 files changed

+160
-4
lines changed

4 files changed

+160
-4
lines changed

app/code/Magento/Elasticsearch/etc/di.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@
417417
<arguments>
418418
<argument name="pageSizeBySearchEngine" xsi:type="array">
419419
<item name="elasticsearch" xsi:type="number">10000</item>
420-
<item name="elasticsearch5" xsi:type="number">2147483647</item>
420+
<item name="elasticsearch5" xsi:type="number">10000</item>
421421
</argument>
422422
</arguments>
423423
</type>

app/code/Magento/QuoteGraphQl/Model/Cart/ExtractDataFromAddress.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public function execute(QuoteAddress $address): array
5555
'code' => $address->getShippingMethod(),
5656
'label' => $address->getShippingDescription(),
5757
'free_shipping' => $address->getFreeShipping(),
58+
'amount' => $address->getShippingAmount()
5859
],
5960
'items_weight' => $address->getWeight(),
6061
'customer_notes' => $address->getCustomerNotes()

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,13 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
6767

6868
$shippingMethod = reset($shippingMethods); // This point can be extended for multishipping
6969

70-
if (!$shippingMethod['cart_address_id']) {
70+
if (!isset($shippingMethod['cart_address_id']) || empty($shippingMethod['cart_address_id'])) {
7171
throw new GraphQlInputException(__('Required parameter "cart_address_id" is missing'));
7272
}
73-
if (!$shippingMethod['carrier_code']) {
73+
if (!isset($shippingMethod['carrier_code']) || empty($shippingMethod['carrier_code'])) {
7474
throw new GraphQlInputException(__('Required parameter "shipping_carrier_code" is missing'));
7575
}
76-
if (!$shippingMethod['method_code']) {
76+
if (!isset($shippingMethod['method_code']) || empty($shippingMethod['method_code'])) {
7777
throw new GraphQlInputException(__('Required parameter "shipping_method_code" is missing'));
7878
}
7979

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
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\Quote;
9+
10+
use Magento\TestFramework\Helper\Bootstrap;
11+
use Magento\TestFramework\TestCase\GraphQlAbstract;
12+
use Magento\Quote\Model\Quote;
13+
use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface;
14+
use Magento\Quote\Model\ResourceModel\Quote as QuoteResource;
15+
16+
class AddConfigurableProductToCartTest extends GraphQlAbstract
17+
{
18+
/**
19+
* @var QuoteResource
20+
*/
21+
private $quoteResource;
22+
23+
/**
24+
* @var Quote
25+
*/
26+
private $quote;
27+
28+
/**
29+
* @var QuoteIdToMaskedQuoteIdInterface
30+
*/
31+
private $quoteIdToMaskedId;
32+
33+
/**
34+
* @inheritdoc
35+
*/
36+
protected function setUp()
37+
{
38+
$objectManager = Bootstrap::getObjectManager();
39+
$this->quoteResource = $objectManager->get(QuoteResource::class);
40+
$this->quote = $objectManager->create(Quote::class);
41+
$this->quoteIdToMaskedId = $objectManager->get(QuoteIdToMaskedQuoteIdInterface::class);
42+
}
43+
44+
/**
45+
* @magentoApiDataFixture Magento/Catalog/_files/multiple_mixed_products.php
46+
* @magentoApiDataFixture Magento/Checkout/_files/active_quote.php
47+
*/
48+
public function testAddConfigurableProductToCart()
49+
{
50+
$variantSku = 'simple_41';
51+
$qty = 2;
52+
53+
$maskedQuoteId = $this->getMaskedQuoteId();
54+
55+
$query = $this->getAddConfigurableProductMutationQuery($maskedQuoteId, $variantSku, $qty);
56+
57+
$response = $this->graphQlQuery($query);
58+
$cartItems = $response['addConfigurableProductsToCart']['cart']['items'];
59+
self::assertEquals($qty, $cartItems[0]['qty']);
60+
self::assertEquals($variantSku, $cartItems[0]['product']['sku']);
61+
}
62+
63+
/**
64+
* @magentoApiDataFixture Magento/Catalog/_files/multiple_mixed_products.php
65+
* @magentoApiDataFixture Magento/Checkout/_files/active_quote.php
66+
* @expectedException \Exception
67+
* @expectedExceptionMessage The requested qty is not available
68+
*/
69+
public function testAddProductIfQuantityIsNotAvailable()
70+
{
71+
$variantSku = 'simple_41';
72+
$qty = 200;
73+
74+
$maskedQuoteId = $this->getMaskedQuoteId();
75+
$query = $this->getAddConfigurableProductMutationQuery($maskedQuoteId, $variantSku, $qty);
76+
77+
$this->graphQlQuery($query);
78+
}
79+
80+
/**
81+
* @magentoApiDataFixture Magento/Framework/Search/_files/product_configurable.php
82+
* @magentoApiDataFixture Magento/Checkout/_files/active_quote.php
83+
* @expectedException \Exception
84+
* @expectedExceptionMessage Product that you are trying to add is not available.
85+
*/
86+
public function testAddOutOfStockProduct()
87+
{
88+
$variantSku = 'simple_1010';
89+
$qty = 1;
90+
$maskedQuoteId = $this->getMaskedQuoteId();
91+
$query = $this->getAddConfigurableProductMutationQuery($maskedQuoteId, $variantSku, $qty);
92+
93+
$this->graphQlQuery($query);
94+
}
95+
96+
/**
97+
* @magentoApiDataFixture Magento/Checkout/_files/active_quote.php
98+
* @return string
99+
* @throws \Magento\Framework\Exception\NoSuchEntityException
100+
*/
101+
private function getMaskedQuoteId()
102+
{
103+
$this->quoteResource->load(
104+
$this->quote,
105+
'test_order_1',
106+
'reserved_order_id'
107+
);
108+
return $this->quoteIdToMaskedId->execute((int)$this->quote->getId());
109+
}
110+
111+
/**
112+
* @param string $maskedQuoteId
113+
* @param string $sku
114+
* @param int $qty
115+
*
116+
* @return string
117+
*/
118+
private function getAddConfigurableProductMutationQuery(string $maskedQuoteId, string $variantSku, int $qty): string
119+
{
120+
return <<<QUERY
121+
mutation {
122+
addConfigurableProductsToCart(
123+
input: {
124+
cart_id: "{$maskedQuoteId}"
125+
cartItems: [
126+
{
127+
variant_sku: "{$variantSku}"
128+
data: {
129+
qty: {$qty}
130+
sku: "{$variantSku}"
131+
}
132+
}
133+
]
134+
}
135+
) {
136+
cart {
137+
items {
138+
id
139+
qty
140+
product {
141+
name
142+
sku
143+
}
144+
... on ConfigurableCartItem {
145+
configurable_options {
146+
option_label
147+
}
148+
}
149+
}
150+
}
151+
}
152+
}
153+
QUERY;
154+
}
155+
}

0 commit comments

Comments
 (0)