Skip to content

Commit 7ca4158

Browse files
committed
#28573:ConfigurableCartItem added to Cart returns wrong thumbnail
Added configured_variant field to the ConfigurableCartItem
1 parent aa272e6 commit 7ca4158

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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\Exception\LocalizedException;
11+
use Magento\Framework\GraphQl\Config\Element\Field;
12+
use Magento\Framework\GraphQl\Query\ResolverInterface;
13+
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
14+
use Magento\Catalog\Api\ProductRepositoryInterface;
15+
16+
/**
17+
* Fetches the Product data according to the GraphQL schema
18+
*/
19+
class ProductResolver implements ResolverInterface
20+
{
21+
/**
22+
* @var ProductRepositoryInterface
23+
*/
24+
private $productRepository;
25+
26+
/**
27+
* @param ProductRepositoryInterface $productRepository
28+
*/
29+
public function __construct(ProductRepositoryInterface $productRepository)
30+
{
31+
$this->productRepository = $productRepository;
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+
$cartItem = $value['model'];
49+
$product = $this->productRepository->get($cartItem->getSku());
50+
$productData = $product->toArray();
51+
$productData['model'] = $product;
52+
return $productData;
53+
}
54+
}

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

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

6667
type SelectedConfigurableOption {

0 commit comments

Comments
 (0)