-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4542 from magento-engcom/graphql-develop-prs
[Magento Community Engineering] Community Contributions - GraphQL
- 2.4.8-beta1
- 2.4.7
- 2.4.7-p3
- 2.4.7-p2
- 2.4.7-p1
- 2.4.7-beta3
- 2.4.7-beta2
- 2.4.7-beta1
- 2.4.6
- 2.4.6-p8
- 2.4.6-p7
- 2.4.6-p6
- 2.4.6-p5
- 2.4.6-p4
- 2.4.6-p3
- 2.4.6-p2
- 2.4.6-p1
- 2.4.5
- 2.4.5-p10
- 2.4.5-p9
- 2.4.5-p8
- 2.4.5-p7
- 2.4.5-p6
- 2.4.5-p5
- 2.4.5-p4
- 2.4.5-p3
- 2.4.5-p2
- 2.4.5-p1
- 2.4.4
- 2.4.4-p11
- 2.4.4-p10
- 2.4.4-p9
- 2.4.4-p8
- 2.4.4-p7
- 2.4.4-p6
- 2.4.4-p5
- 2.4.4-p4
- 2.4.4-p3
- 2.4.4-p2
- 2.4.4-p1
- 2.4.3
- 2.4.3-p3
- 2.4.3-p2
- 2.4.3-p1
- 2.4.2
- 2.4.2-p2
- 2.4.2-p1
- 2.4.1
- 2.4.1-p1
- 2.4.0
- 2.4.0-p1
- 2.3.7
- 2.3.7-p4
- 2.3.7-p3
- 2.3.7-p2
- 2.3.7-p1
- 2.3.6
- 2.3.6-p1
- 2.3.5
- 2.3.5-p2
- 2.3.5-p1
- 2.3.4
- 2.3.4-p2
- 2.3.3
- 2.3.3-p1
Showing
79 changed files
with
1,539 additions
and
431 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
...e/Magento/ConfigurableProductGraphQl/Model/Cart/BuyRequest/SuperAttributeDataProvider.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
app/code/Magento/ConfigurableProductGraphQl/Model/Resolver/AddConfigurableProductsToCart.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
], | ||
]; | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
app/code/Magento/ConfigurableProductGraphQl/Model/Resolver/ConfigurableCartItemOptions.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.