Skip to content

Commit

Permalink
Merge pull request #4542 from magento-engcom/graphql-develop-prs
Browse files Browse the repository at this point in the history
[Magento Community Engineering] Community Contributions - GraphQL
naydav authored Jul 30, 2019

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
2 parents a9ceb1a + ea1d149 commit 50209dd
Showing 79 changed files with 1,539 additions and 431 deletions.
Original file line number Diff line number Diff line change
@@ -117,7 +117,8 @@ private function fetch() : array
'price' => $link->getSelectionPriceValue(),
'position' => $link->getPosition(),
'id' => $link->getSelectionId(),
'qty' => (int)$link->getSelectionQty(),
'qty' => (float)$link->getSelectionQty(),
'quantity' => (float)$link->getSelectionQty(),
'is_default' => (bool)$link->getIsDefault(),
'price_type' => $this->enumLookup->getEnumValueFromField(
'PriceTypeEnum',
3 changes: 2 additions & 1 deletion app/code/Magento/BundleGraphQl/etc/schema.graphqls
Original file line number Diff line number Diff line change
@@ -14,7 +14,8 @@ type BundleItem @doc(description: "BundleItem defines an individual item in a bu
type BundleItemOption @doc(description: "BundleItemOption defines characteristics and options for a specific bundle item.") {
id: Int @doc(description: "The ID assigned to the bundled item option.")
label: String @doc(description: "The text that identifies the bundled item option.") @resolver(class: "Magento\\BundleGraphQl\\Model\\Resolver\\Options\\Label")
qty: Float @doc(description: "Indicates the quantity of this specific bundle item.")
qty: Float @deprecated(reason: "The `qty` is deprecated. Use `quantity` instead.") @doc(description: "Indicates the quantity of this specific bundle item.")
quantity: Float @doc(description: "Indicates the quantity of this specific bundle item.")
position: Int @doc(description: "When a bundle item contains multiple options, the relative position of this option compared to the other options.")
is_default: Boolean @doc(description: "Indicates whether this option is the default option.")
price: Float @doc(description: "The price of the selected option.")
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\ConfigurableProductGraphQl\Model\Cart\BuyRequest;

use Magento\Framework\Stdlib\ArrayManager;
use Magento\QuoteGraphQl\Model\Cart\BuyRequest\BuyRequestDataProviderInterface;

/**
* DataProvider for building super attribute options in buy requests
*/
class SuperAttributeDataProvider implements BuyRequestDataProviderInterface
{
/**
* @var ArrayManager
*/
private $arrayManager;

/**
* @param ArrayManager $arrayManager
*/
public function __construct(
ArrayManager $arrayManager
) {
$this->arrayManager = $arrayManager;
}

/**
* @inheritdoc
*/
public function execute(array $cartItemData): array
{
$superAttributes = $this->arrayManager->get('configurable_attributes', $cartItemData, []);

$superAttributesData = [];
foreach ($superAttributes as $superAttribute) {
$superAttributesData[$superAttribute['id']] = $superAttribute['value'];
}

return ['super_attribute' => $superAttributesData];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\ConfigurableProductGraphQl\Model\Resolver;

use Magento\Framework\GraphQl\Config\Element\Field;
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
use Magento\Framework\GraphQl\Query\ResolverInterface;
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
use Magento\QuoteGraphQl\Model\Cart\AddProductsToCart;
use Magento\QuoteGraphQl\Model\Cart\GetCartForUser;

/**
* Add configurable products to cart GraphQl resolver
* {@inheritdoc}
*/
class AddConfigurableProductsToCart implements ResolverInterface
{
/**
* @var GetCartForUser
*/
private $getCartForUser;

/**
* @var AddProductsToCart
*/
private $addProductsToCart;

/**
* @param GetCartForUser $getCartForUser
* @param AddProductsToCart $addProductsToCart
*/
public function __construct(
GetCartForUser $getCartForUser,
AddProductsToCart $addProductsToCart
) {
$this->getCartForUser = $getCartForUser;
$this->addProductsToCart = $addProductsToCart;
}

/**
* @inheritdoc
*/
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null)
{
if (!isset($args['input']['cart_id']) || empty($args['input']['cart_id'])) {
throw new GraphQlInputException(__('Required parameter "cart_id" is missing'));
}
$maskedCartId = $args['input']['cart_id'];

if (!isset($args['input']['cart_items']) || empty($args['input']['cart_items'])
|| !is_array($args['input']['cart_items'])
) {
throw new GraphQlInputException(__('Required parameter "cart_items" is missing'));
}
$cartItems = $args['input']['cart_items'];

$storeId = (int)$context->getExtensionAttributes()->getStore()->getId();
$cart = $this->getCartForUser->execute($maskedCartId, $context->getUserId(), $storeId);
$this->addProductsToCart->execute($cart, $cartItems);

return [
'cart' => [
'model' => $cart,
],
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\ConfigurableProductGraphQl\Model\Resolver;

use Magento\Catalog\Helper\Product\Configuration;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\GraphQl\Config\Element\Field;
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
use Magento\Framework\GraphQl\Query\ResolverInterface;
use Magento\Quote\Model\Quote\Item;

/**
* @inheritdoc
*/
class ConfigurableCartItemOptions implements ResolverInterface
{
/**
* @var Configuration
*/
private $configurationHelper;

/**
* @param Configuration $configurationHelper
*/
public function __construct(
Configuration $configurationHelper
) {
$this->configurationHelper = $configurationHelper;
}

/**
* Fetch and format configurable variants.
*
* @param Field $field
* @param \Magento\Framework\GraphQl\Query\Resolver\ContextInterface $context
* @param ResolveInfo $info
* @param array|null $value
* @param array|null $args
* @return array|\Magento\Framework\GraphQl\Query\Resolver\Value|mixed
* @throws LocalizedException
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null)
{
if (!isset($value['model'])) {
throw new LocalizedException(__('"model" value should be specified'));
}
/** @var Item $cartItem */
$cartItem = $value['model'];

$result = [];
foreach ($this->configurationHelper->getOptions($cartItem) as $option) {
$result[] = [
'id' => $option['option_id'],
'option_label' => $option['label'],
'value_id' => $option['option_value'],
'value_label' => $option['value'],
];
}

return $result;
}
}
2 changes: 2 additions & 0 deletions app/code/Magento/ConfigurableProductGraphQl/composer.json
Original file line number Diff line number Diff line change
@@ -7,6 +7,8 @@
"magento/module-catalog": "*",
"magento/module-configurable-product": "*",
"magento/module-catalog-graph-ql": "*",
"magento/module-quote": "*",
"magento/module-quote-graph-ql": "*",
"magento/framework": "*"
},
"license": [
Original file line number Diff line number Diff line change
@@ -22,4 +22,11 @@
</argument>
</arguments>
</type>
<type name="Magento\QuoteGraphQl\Model\Cart\BuyRequest\BuyRequestBuilder">
<arguments>
<argument name="providers" xsi:type="array">
<item name="super_attribute" xsi:type="object">Magento\ConfigurableProductGraphQl\Model\Cart\BuyRequest\SuperAttributeDataProvider</item>
</argument>
</arguments>
</type>
</config>
12 changes: 9 additions & 3 deletions app/code/Magento/ConfigurableProductGraphQl/etc/schema.graphqls
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright © Magento, Inc. All rights reserved.
# See COPYING.txt for license details.
type Mutation {
addConfigurableProductsToCart(input: AddConfigurableProductsToCartInput): AddConfigurableProductsToCartOutput @resolver(class: "Magento\\QuoteGraphQl\\Model\\Resolver\\AddSimpleProductsToCart")
addConfigurableProductsToCart(input: AddConfigurableProductsToCartInput): AddConfigurableProductsToCartOutput @resolver(class: "Magento\\ConfigurableProductGraphQl\\Model\\Resolver\\AddConfigurableProductsToCart")
}

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 {

input ConfigurableProductCartItemInput {
data: CartItemInput!
variant_sku: String!
variant_sku: String @deprecated(reason: "Use CartItemInput.sku instead")
configurable_attributes: [ConfigurableCartItemAttributesInput]!
customizable_options:[CustomizableOptionInput!]
}

input ConfigurableCartItemAttributesInput {
id: Int!
value: Int!
}

type ConfigurableCartItem implements CartItemInterface {
customizable_options: [SelectedCustomizableOption]!
configurable_options: [SelectedConfigurableOption!]!
configurable_options: [SelectedConfigurableOption!]! @resolver(class: "Magento\\ConfigurableProductGraphQl\\Model\\Resolver\\ConfigurableCartItemOptions")
}

type SelectedConfigurableOption {
4 changes: 2 additions & 2 deletions app/code/Magento/CustomerGraphQl/etc/schema.graphqls
Original file line number Diff line number Diff line change
@@ -185,8 +185,8 @@ enum CountryCodeEnum @doc(description: "The list of countries codes") {
CC @doc(description: "Cocos (Keeling) Islands")
CO @doc(description: "Colombia")
KM @doc(description: "Comoros")
CG @doc(description: "Congo -Brazzaville")
CD @doc(description: "Congo - Kinshasa")
CG @doc(description: "Congo-Brazzaville")
CD @doc(description: "Congo-Kinshasa")
CK @doc(description: "Cook Islands")
CR @doc(description: "Costa Rica")
CI @doc(description: "Côte d’Ivoire")
40 changes: 40 additions & 0 deletions app/code/Magento/GraphQl/etc/schema.graphqls
Original file line number Diff line number Diff line change
@@ -1,6 +1,46 @@
# Copyright © Magento, Inc. All rights reserved.
# See COPYING.txt for license details.

directive @doc(description: String="") on QUERY
| MUTATION
| FIELD
| FRAGMENT_DEFINITION
| FRAGMENT_SPREAD
| INLINE_FRAGMENT
| SCHEMA
| SCALAR
| OBJECT
| FIELD_DEFINITION
| ARGUMENT_DEFINITION
| INTERFACE
| UNION
| ENUM
| ENUM_VALUE
| INPUT_OBJECT
| INPUT_FIELD_DEFINITION

directive @resolver(class: String="") on QUERY
| MUTATION
| FIELD
| FRAGMENT_DEFINITION
| FRAGMENT_SPREAD
| INLINE_FRAGMENT
| SCHEMA
| SCALAR
| OBJECT
| FIELD_DEFINITION
| ARGUMENT_DEFINITION
| INTERFACE
| UNION
| ENUM
| ENUM_VALUE
| INPUT_OBJECT
| INPUT_FIELD_DEFINITION

directive @typeResolver(class: String="") on INTERFACE | OBJECT

directive @cache(cacheIdentity: String="" cachable: Boolean=true) on QUERY

type Query {
}

Loading

0 comments on commit 50209dd

Please sign in to comment.