Skip to content

Commit 50209dd

Browse files
authored
Merge pull request #4542 from magento-engcom/graphql-develop-prs
[Magento Community Engineering] Community Contributions - GraphQL
2 parents a9ceb1a + ea1d149 commit 50209dd

File tree

79 files changed

+1539
-431
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+1539
-431
lines changed

app/code/Magento/BundleGraphQl/Model/Resolver/Links/Collection.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@ private function fetch() : array
117117
'price' => $link->getSelectionPriceValue(),
118118
'position' => $link->getPosition(),
119119
'id' => $link->getSelectionId(),
120-
'qty' => (int)$link->getSelectionQty(),
120+
'qty' => (float)$link->getSelectionQty(),
121+
'quantity' => (float)$link->getSelectionQty(),
121122
'is_default' => (bool)$link->getIsDefault(),
122123
'price_type' => $this->enumLookup->getEnumValueFromField(
123124
'PriceTypeEnum',

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ type BundleItem @doc(description: "BundleItem defines an individual item in a bu
1414
type BundleItemOption @doc(description: "BundleItemOption defines characteristics and options for a specific bundle item.") {
1515
id: Int @doc(description: "The ID assigned to the bundled item option.")
1616
label: String @doc(description: "The text that identifies the bundled item option.") @resolver(class: "Magento\\BundleGraphQl\\Model\\Resolver\\Options\\Label")
17-
qty: Float @doc(description: "Indicates the quantity of this specific bundle item.")
17+
qty: Float @deprecated(reason: "The `qty` is deprecated. Use `quantity` instead.") @doc(description: "Indicates the quantity of this specific bundle item.")
18+
quantity: Float @doc(description: "Indicates the quantity of this specific bundle item.")
1819
position: Int @doc(description: "When a bundle item contains multiple options, the relative position of this option compared to the other options.")
1920
is_default: Boolean @doc(description: "Indicates whether this option is the default option.")
2021
price: Float @doc(description: "The price of the selected option.")
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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\ConfigurableProductGraphQl\Model\Cart\BuyRequest;
9+
10+
use Magento\Framework\Stdlib\ArrayManager;
11+
use Magento\QuoteGraphQl\Model\Cart\BuyRequest\BuyRequestDataProviderInterface;
12+
13+
/**
14+
* DataProvider for building super attribute options in buy requests
15+
*/
16+
class SuperAttributeDataProvider implements BuyRequestDataProviderInterface
17+
{
18+
/**
19+
* @var ArrayManager
20+
*/
21+
private $arrayManager;
22+
23+
/**
24+
* @param ArrayManager $arrayManager
25+
*/
26+
public function __construct(
27+
ArrayManager $arrayManager
28+
) {
29+
$this->arrayManager = $arrayManager;
30+
}
31+
32+
/**
33+
* @inheritdoc
34+
*/
35+
public function execute(array $cartItemData): array
36+
{
37+
$superAttributes = $this->arrayManager->get('configurable_attributes', $cartItemData, []);
38+
39+
$superAttributesData = [];
40+
foreach ($superAttributes as $superAttribute) {
41+
$superAttributesData[$superAttribute['id']] = $superAttribute['value'];
42+
}
43+
44+
return ['super_attribute' => $superAttributesData];
45+
}
46+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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\ConfigurableProductGraphQl\Model\Resolver;
9+
10+
use Magento\Framework\GraphQl\Config\Element\Field;
11+
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
12+
use Magento\Framework\GraphQl\Query\ResolverInterface;
13+
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
14+
use Magento\QuoteGraphQl\Model\Cart\AddProductsToCart;
15+
use Magento\QuoteGraphQl\Model\Cart\GetCartForUser;
16+
17+
/**
18+
* Add configurable products to cart GraphQl resolver
19+
* {@inheritdoc}
20+
*/
21+
class AddConfigurableProductsToCart implements ResolverInterface
22+
{
23+
/**
24+
* @var GetCartForUser
25+
*/
26+
private $getCartForUser;
27+
28+
/**
29+
* @var AddProductsToCart
30+
*/
31+
private $addProductsToCart;
32+
33+
/**
34+
* @param GetCartForUser $getCartForUser
35+
* @param AddProductsToCart $addProductsToCart
36+
*/
37+
public function __construct(
38+
GetCartForUser $getCartForUser,
39+
AddProductsToCart $addProductsToCart
40+
) {
41+
$this->getCartForUser = $getCartForUser;
42+
$this->addProductsToCart = $addProductsToCart;
43+
}
44+
45+
/**
46+
* @inheritdoc
47+
*/
48+
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null)
49+
{
50+
if (!isset($args['input']['cart_id']) || empty($args['input']['cart_id'])) {
51+
throw new GraphQlInputException(__('Required parameter "cart_id" is missing'));
52+
}
53+
$maskedCartId = $args['input']['cart_id'];
54+
55+
if (!isset($args['input']['cart_items']) || empty($args['input']['cart_items'])
56+
|| !is_array($args['input']['cart_items'])
57+
) {
58+
throw new GraphQlInputException(__('Required parameter "cart_items" is missing'));
59+
}
60+
$cartItems = $args['input']['cart_items'];
61+
62+
$storeId = (int)$context->getExtensionAttributes()->getStore()->getId();
63+
$cart = $this->getCartForUser->execute($maskedCartId, $context->getUserId(), $storeId);
64+
$this->addProductsToCart->execute($cart, $cartItems);
65+
66+
return [
67+
'cart' => [
68+
'model' => $cart,
69+
],
70+
];
71+
}
72+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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\ConfigurableProductGraphQl\Model\Resolver;
9+
10+
use Magento\Catalog\Helper\Product\Configuration;
11+
use Magento\Framework\Exception\LocalizedException;
12+
use Magento\Framework\GraphQl\Config\Element\Field;
13+
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
14+
use Magento\Framework\GraphQl\Query\ResolverInterface;
15+
use Magento\Quote\Model\Quote\Item;
16+
17+
/**
18+
* @inheritdoc
19+
*/
20+
class ConfigurableCartItemOptions implements ResolverInterface
21+
{
22+
/**
23+
* @var Configuration
24+
*/
25+
private $configurationHelper;
26+
27+
/**
28+
* @param Configuration $configurationHelper
29+
*/
30+
public function __construct(
31+
Configuration $configurationHelper
32+
) {
33+
$this->configurationHelper = $configurationHelper;
34+
}
35+
36+
/**
37+
* Fetch and format configurable variants.
38+
*
39+
* @param Field $field
40+
* @param \Magento\Framework\GraphQl\Query\Resolver\ContextInterface $context
41+
* @param ResolveInfo $info
42+
* @param array|null $value
43+
* @param array|null $args
44+
* @return array|\Magento\Framework\GraphQl\Query\Resolver\Value|mixed
45+
* @throws LocalizedException
46+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
47+
*/
48+
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null)
49+
{
50+
if (!isset($value['model'])) {
51+
throw new LocalizedException(__('"model" value should be specified'));
52+
}
53+
/** @var Item $cartItem */
54+
$cartItem = $value['model'];
55+
56+
$result = [];
57+
foreach ($this->configurationHelper->getOptions($cartItem) as $option) {
58+
$result[] = [
59+
'id' => $option['option_id'],
60+
'option_label' => $option['label'],
61+
'value_id' => $option['option_value'],
62+
'value_label' => $option['value'],
63+
];
64+
}
65+
66+
return $result;
67+
}
68+
}

app/code/Magento/ConfigurableProductGraphQl/composer.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
"magento/module-catalog": "*",
88
"magento/module-configurable-product": "*",
99
"magento/module-catalog-graph-ql": "*",
10+
"magento/module-quote": "*",
11+
"magento/module-quote-graph-ql": "*",
1012
"magento/framework": "*"
1113
},
1214
"license": [

app/code/Magento/ConfigurableProductGraphQl/etc/graphql/di.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,11 @@
2222
</argument>
2323
</arguments>
2424
</type>
25+
<type name="Magento\QuoteGraphQl\Model\Cart\BuyRequest\BuyRequestBuilder">
26+
<arguments>
27+
<argument name="providers" xsi:type="array">
28+
<item name="super_attribute" xsi:type="object">Magento\ConfigurableProductGraphQl\Model\Cart\BuyRequest\SuperAttributeDataProvider</item>
29+
</argument>
30+
</arguments>
31+
</type>
2532
</config>

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright © Magento, Inc. All rights reserved.
22
# See COPYING.txt for license details.
33
type Mutation {
4-
addConfigurableProductsToCart(input: AddConfigurableProductsToCartInput): AddConfigurableProductsToCartOutput @resolver(class: "Magento\\QuoteGraphQl\\Model\\Resolver\\AddSimpleProductsToCart")
4+
addConfigurableProductsToCart(input: AddConfigurableProductsToCartInput): AddConfigurableProductsToCartOutput @resolver(class: "Magento\\ConfigurableProductGraphQl\\Model\\Resolver\\AddConfigurableProductsToCart")
55
}
66

77
type ConfigurableProduct implements ProductInterface, PhysicalProductInterface, CustomizableProductInterface @doc(description: "ConfigurableProduct defines basic features of a configurable product and its simple product variants") {
@@ -50,13 +50,19 @@ type AddConfigurableProductsToCartOutput {
5050

5151
input ConfigurableProductCartItemInput {
5252
data: CartItemInput!
53-
variant_sku: String!
53+
variant_sku: String @deprecated(reason: "Use CartItemInput.sku instead")
54+
configurable_attributes: [ConfigurableCartItemAttributesInput]!
5455
customizable_options:[CustomizableOptionInput!]
5556
}
5657

58+
input ConfigurableCartItemAttributesInput {
59+
id: Int!
60+
value: Int!
61+
}
62+
5763
type ConfigurableCartItem implements CartItemInterface {
5864
customizable_options: [SelectedCustomizableOption]!
59-
configurable_options: [SelectedConfigurableOption!]!
65+
configurable_options: [SelectedConfigurableOption!]! @resolver(class: "Magento\\ConfigurableProductGraphQl\\Model\\Resolver\\ConfigurableCartItemOptions")
6066
}
6167

6268
type SelectedConfigurableOption {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,8 @@ enum CountryCodeEnum @doc(description: "The list of countries codes") {
185185
CC @doc(description: "Cocos (Keeling) Islands")
186186
CO @doc(description: "Colombia")
187187
KM @doc(description: "Comoros")
188-
CG @doc(description: "Congo -Brazzaville")
189-
CD @doc(description: "Congo - Kinshasa")
188+
CG @doc(description: "Congo-Brazzaville")
189+
CD @doc(description: "Congo-Kinshasa")
190190
CK @doc(description: "Cook Islands")
191191
CR @doc(description: "Costa Rica")
192192
CI @doc(description: "Côte d’Ivoire")

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

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,46 @@
11
# Copyright © Magento, Inc. All rights reserved.
22
# See COPYING.txt for license details.
33

4+
directive @doc(description: String="") on QUERY
5+
| MUTATION
6+
| FIELD
7+
| FRAGMENT_DEFINITION
8+
| FRAGMENT_SPREAD
9+
| INLINE_FRAGMENT
10+
| SCHEMA
11+
| SCALAR
12+
| OBJECT
13+
| FIELD_DEFINITION
14+
| ARGUMENT_DEFINITION
15+
| INTERFACE
16+
| UNION
17+
| ENUM
18+
| ENUM_VALUE
19+
| INPUT_OBJECT
20+
| INPUT_FIELD_DEFINITION
21+
22+
directive @resolver(class: String="") on QUERY
23+
| MUTATION
24+
| FIELD
25+
| FRAGMENT_DEFINITION
26+
| FRAGMENT_SPREAD
27+
| INLINE_FRAGMENT
28+
| SCHEMA
29+
| SCALAR
30+
| OBJECT
31+
| FIELD_DEFINITION
32+
| ARGUMENT_DEFINITION
33+
| INTERFACE
34+
| UNION
35+
| ENUM
36+
| ENUM_VALUE
37+
| INPUT_OBJECT
38+
| INPUT_FIELD_DEFINITION
39+
40+
directive @typeResolver(class: String="") on INTERFACE | OBJECT
41+
42+
directive @cache(cacheIdentity: String="" cachable: Boolean=true) on QUERY
43+
444
type Query {
545
}
646

0 commit comments

Comments
 (0)