Skip to content

Commit dc7a107

Browse files
Merge branch '2.4-develop' into MC-40859
2 parents 15d59a3 + 800acfa commit dc7a107

File tree

26 files changed

+1538
-11
lines changed

26 files changed

+1538
-11
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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\CatalogGraphQl\Model\Resolver\Product;
9+
10+
use Magento\Framework\GraphQl\Config\Element\Field;
11+
use Magento\Framework\GraphQl\Query\Resolver\ContextInterface;
12+
use Magento\Framework\GraphQl\Query\ResolverInterface;
13+
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
14+
15+
/**
16+
* Format the option type value.
17+
*/
18+
class CustomizableDateTypeOptionValue implements ResolverInterface
19+
{
20+
/**
21+
* Resolver option code.
22+
*/
23+
private const OPTION_CODE = 'type';
24+
25+
/**
26+
* Resolver enum type options to up case format.
27+
*
28+
* @param Field $field
29+
* @param ContextInterface $context
30+
* @param ResolveInfo $info
31+
* @param array|null $value
32+
* @param array|null $args
33+
*
34+
* @return string
35+
*/
36+
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null): string
37+
{
38+
$dteType = $value[self::OPTION_CODE] ?? '';
39+
40+
return strtoupper($dteType);
41+
}
42+
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ enum PriceTypeEnum @doc(description: "This enumeration the price type.") {
4949
DYNAMIC
5050
}
5151

52+
enum CustomizableDateTypeEnum @doc(description: "This enumeration customizable date type.") {
53+
DATE
54+
DATE_TIME
55+
TIME
56+
}
57+
5258
type ProductPrices @doc(description: "ProductPrices is deprecated, replaced by PriceRange. The ProductPrices object contains the regular price of an item, as well as its minimum and maximum prices. Only composite products, which include bundle, configurable, and grouped products, can contain a minimum and maximum price.") {
5359
minimalPrice: Price @deprecated(reason: "Use PriceRange.minimum_price.") @doc(description: "The lowest possible final price for all the options defined within a composite product. If you are specifying a price range, this would be the from value.")
5460
maximalPrice: Price @deprecated(reason: "Use PriceRange.maximum_price.") @doc(description: "The highest possible final price for all the options defined within a composite product. If you are specifying a price range, this would be the to value.")
@@ -154,6 +160,7 @@ type CustomizableDateOption implements CustomizableOptionInterface @doc(descript
154160
type CustomizableDateValue @doc(description: "CustomizableDateValue defines the price and sku of a product whose page contains a customized date picker.") {
155161
price: Float @doc(description: "The price assigned to this option.")
156162
price_type: PriceTypeEnum @doc(description: "FIXED, PERCENT, or DYNAMIC.")
163+
type: CustomizableDateTypeEnum @doc(description: "DATE, DATE_TIME or TIME") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\CustomizableDateTypeOptionValue")
157164
sku: String @doc(description: "The Stock Keeping Unit for this option.")
158165
uid: ID! @doc(description: "The unique ID for a `CustomizableDateValue` object.") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\CustomizableEnteredOptionValueUid")
159166
}

app/code/Magento/ConfigurableProductGraphQl/Model/Cart/BuyRequest/SuperAttributeDataProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public function execute(array $cartItemData): array
9393
throw new GraphQlNoSuchEntityException(__('Could not find specified product.'));
9494
}
9595

96-
$this->checkProductStock($sku, (float) $qty, (int) $cart->getStoreId());
96+
$this->checkProductStock($sku, (float) $qty, (int) $cart->getStore()->getWebsite()->getId());
9797

9898
$configurableProductLinks = $parentProduct->getExtensionAttributes()->getConfigurableProductLinks();
9999
if (!in_array($product->getId(), $configurableProductLinks)) {
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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\Model\Product\Configuration\Item\ItemResolverInterface;
11+
use Magento\Framework\Exception\LocalizedException;
12+
use Magento\Framework\GraphQl\Config\Element\Field;
13+
use Magento\Framework\GraphQl\Query\ResolverInterface;
14+
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
15+
16+
/**
17+
* Fetches the Product data according to the GraphQL schema
18+
*/
19+
class ProductResolver implements ResolverInterface
20+
{
21+
/**
22+
* @var ItemResolverInterface
23+
*/
24+
private $configurableItemResolver;
25+
26+
/**
27+
* @param ItemResolverInterface $configurableItemResolver
28+
*/
29+
public function __construct(ItemResolverInterface $configurableItemResolver)
30+
{
31+
$this->configurableItemResolver = $configurableItemResolver;
32+
}
33+
34+
/**
35+
* @inheritdoc
36+
*/
37+
public function resolve(
38+
Field $field,
39+
$context,
40+
ResolveInfo $info,
41+
array $value = null,
42+
array $args = null
43+
) {
44+
if (!isset($value['model'])) {
45+
throw new LocalizedException(__('"model" value should be specified'));
46+
}
47+
48+
$product = $this->configurableItemResolver->getFinalProduct($value['model']);
49+
$productData = $product->toArray();
50+
$productData['model'] = $product;
51+
return $productData;
52+
}
53+
}

app/code/Magento/ConfigurableProductGraphQl/Model/Resolver/SelectionMediaGallery.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\ConfigurableProductGraphQl\Model\Resolver;
79

810
use Magento\Framework\GraphQl\Config\Element\Field;
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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\Plugin\Product\Configuration\Item;
9+
10+
use Magento\Catalog\Api\Data\ProductInterface;
11+
use Magento\Catalog\Model\Product\Configuration\Item\ItemInterface;
12+
use Magento\ConfigurableProduct\Model\Product\Configuration\Item\ItemProductResolver;
13+
use Magento\ConfigurableProduct\Model\Product\Type\Configurable;
14+
15+
/**
16+
* Plugin for item resolver
17+
*/
18+
class ItemResolver
19+
{
20+
/**
21+
* After plugin for final product
22+
*
23+
* @param ItemProductResolver $subject
24+
* @param $result
25+
* @param ItemInterface $item
26+
* @return ProductInterface
27+
*/
28+
public function afterGetFinalProduct(ItemProductResolver $subject, $result, ItemInterface $item): ProductInterface
29+
{
30+
if ($result->getTypeId() === Configurable::TYPE_CODE) {
31+
$option = $item->getOptionByCode('simple_product');
32+
$result = $option ? $option->getProduct() : $item->getProduct();
33+
}
34+
35+
return $result;
36+
}
37+
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,8 @@
5959
</argument>
6060
</arguments>
6161
</type>
62+
63+
<type name="Magento\ConfigurableProduct\Model\Product\Configuration\Item\ItemProductResolver">
64+
<plugin name="configured_variant" type="Magento\ConfigurableProductGraphQl\Plugin\Product\Configuration\Item\ItemResolver"/>
65+
</type>
6266
</config>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ input ConfigurableProductCartItemInput {
6464
type ConfigurableCartItem implements CartItemInterface {
6565
customizable_options: [SelectedCustomizableOption] @resolver(class: "Magento\\QuoteGraphQl\\Model\\Resolver\\CustomizableOptions")
6666
configurable_options: [SelectedConfigurableOption!]! @resolver(class: "Magento\\ConfigurableProductGraphQl\\Model\\Resolver\\ConfigurableCartItemOptions")
67+
configured_variant: ProductInterface! @doc(description: "Product details of the cart item") @resolver(class: "\\Magento\\ConfigurableProductGraphQl\\Model\\Resolver\\ProductResolver")
6768
}
6869

6970
type SelectedConfigurableOption {

app/code/Magento/WishlistGraphQl/Mapper/WishlistDataMapper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,4 @@ private function getMappedVisibility(int $visibility): ?string
6666

6767
return isset($visibilityEnums[$visibility]) ? strtoupper($visibilityEnums[$visibility]) : null;
6868
}
69-
}
69+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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\WishlistGraphQl\Model\CartItems;
9+
10+
use Magento\Wishlist\Model\Item;
11+
use Magento\Framework\GraphQl\Query\Uid;
12+
13+
/**
14+
* Data provider for bundlue product cart item request
15+
*/
16+
class BundleDataProvider implements CartItemsRequestDataProviderInterface
17+
{
18+
/**
19+
* @var Uid
20+
*/
21+
private $uidEncoder;
22+
23+
/**
24+
* @param Uid $uidEncoder
25+
*/
26+
public function __construct(
27+
Uid $uidEncoder
28+
) {
29+
$this->uidEncoder = $uidEncoder;
30+
}
31+
32+
/**
33+
* @inheritdoc
34+
*/
35+
public function execute(Item $wishlistItem, ?string $sku): array
36+
{
37+
$buyRequest = $wishlistItem->getBuyRequest();
38+
$selected_options = [];
39+
if (isset($buyRequest['bundle_option'])) {
40+
$bundleOptions = $buyRequest['bundle_option'];
41+
$bundleOptionQty = $buyRequest['bundle_option_qty'];
42+
foreach ($bundleOptions as $option => $value) {
43+
$qty = $bundleOptionQty[$option];
44+
$selected_options[] = $this->uidEncoder->encode("bundle/$option/$value/$qty");
45+
}
46+
}
47+
48+
$cartItems['selected_options'] = $selected_options;
49+
return $cartItems;
50+
}
51+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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\WishlistGraphQl\Model\CartItems;
9+
10+
use Magento\Catalog\Api\ProductRepositoryInterface;
11+
use Magento\Wishlist\Model\Item;
12+
13+
/**
14+
* Building cart items request for add to cart form wishlist buy request
15+
*/
16+
class CartItemsRequestBuilder
17+
{
18+
/**
19+
* @var CartItemsRequestDataProviderInterface[]
20+
*/
21+
private $providers;
22+
23+
/**
24+
* @var ProductRepositoryInterface
25+
*/
26+
private $productRepository;
27+
28+
/**
29+
* @param ProductRepositoryInterface $productRepository
30+
* @param array $providers
31+
*/
32+
public function __construct(
33+
ProductRepositoryInterface $productRepository,
34+
array $providers = []
35+
) {
36+
$this->productRepository = $productRepository;
37+
$this->providers = $providers;
38+
}
39+
40+
/**
41+
* Build wishlist cart item request for adding to cart
42+
*
43+
* @param Item $wishlistItem
44+
* @return array
45+
*/
46+
public function build(Item $wishlistItem): array
47+
{
48+
$product = $this->productRepository->getById($wishlistItem->getProductId());
49+
$parentsku = $product->getSku();
50+
$cartItems['quantity'] = floatval($wishlistItem->getQty());
51+
$cartItems['sku'] = $parentsku;
52+
53+
foreach ($this->providers as $provider) {
54+
$cartItems = array_merge_recursive($cartItems, $provider->execute($wishlistItem, $parentsku));
55+
}
56+
return $cartItems;
57+
}
58+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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\WishlistGraphQl\Model\CartItems;
9+
10+
use Magento\Wishlist\Model\Item;
11+
12+
/**
13+
* Build cart item request for adding products to cart
14+
*/
15+
interface CartItemsRequestDataProviderInterface
16+
{
17+
/**
18+
* Provide cart item request from buy request to add wishlist items to cart
19+
*
20+
* @param Item $wishlistItem
21+
* @param string $sku
22+
*
23+
* @return array
24+
*/
25+
public function execute(Item $wishlistItem, ?string $sku): array;
26+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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\WishlistGraphQl\Model\CartItems;
9+
10+
use Magento\Wishlist\Model\Item;
11+
use Magento\Framework\GraphQl\Query\Uid;
12+
13+
/**
14+
* Data provider for configurable product cart item request
15+
*/
16+
class ConfigurableDataProvider implements CartItemsRequestDataProviderInterface
17+
{
18+
/**
19+
* @var Uid
20+
*/
21+
private $uidEncoder;
22+
23+
/**
24+
* @param Uid $uidEncoder
25+
*/
26+
public function __construct(
27+
Uid $uidEncoder
28+
) {
29+
$this->uidEncoder = $uidEncoder;
30+
}
31+
32+
/**
33+
* @inheritdoc
34+
*/
35+
public function execute(Item $wishlistItem, ?string $sku): array
36+
{
37+
$buyRequest = $wishlistItem->getBuyRequest();
38+
$selected_options = [];
39+
if (isset($buyRequest['super_attribute'])) {
40+
$superAttributes = $buyRequest['super_attribute'];
41+
foreach ($superAttributes as $attributeId => $value) {
42+
$selected_options[] = $this->uidEncoder->encode("configurable/$attributeId/$value");
43+
}
44+
}
45+
$cartItems['selected_options'] = $selected_options;
46+
return $cartItems;
47+
}
48+
}

0 commit comments

Comments
 (0)