Skip to content

Commit 694f967

Browse files
committed
ACP2E-267: GraphQl - Issues with add Configurable product to Wishlist
1 parent 5c88424 commit 694f967

File tree

6 files changed

+45
-29
lines changed

6 files changed

+45
-29
lines changed

app/code/Magento/ConfigurableProductGraphQl/Model/Wishlist/SelectedVariantSku.php renamed to app/code/Magento/ConfigurableProductGraphQl/Model/Wishlist/ConfiguredVariant.php

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,30 @@
88
namespace Magento\ConfigurableProductGraphQl\Model\Wishlist;
99

1010
use Magento\Catalog\Model\Product\Configuration\Item\ItemInterface;
11+
use Magento\CatalogGraphQl\Model\ProductDataProvider;
1112
use Magento\Framework\Exception\LocalizedException;
1213
use Magento\Framework\GraphQl\Config\Element\Field;
1314
use Magento\Framework\GraphQl\Query\ResolverInterface;
1415
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
1516

1617
/**
17-
* Fetches the selected variant SKU of configurable product
18+
* Fetches the data of selected variant of configurable product
1819
*/
19-
class SelectedVariantSku implements ResolverInterface
20+
class ConfiguredVariant implements ResolverInterface
2021
{
22+
/**
23+
* @var ProductDataProvider
24+
*/
25+
private $productDataProvider;
26+
27+
/**
28+
* @param ProductDataProvider $productDataProvider
29+
*/
30+
public function __construct(ProductDataProvider $productDataProvider)
31+
{
32+
$this->productDataProvider = $productDataProvider;
33+
}
34+
2135
/**
2236
* @inheritdoc
2337
*/
@@ -38,6 +52,8 @@ public function resolve(
3852
$product = $item->getProduct();
3953
$option = $product->getCustomOption('simple_product');
4054

41-
return $option && $option->getProduct() ? $option->getProduct()->getSku() : null;
55+
return $option && $option->getProduct()
56+
? $this->productDataProvider->getProductDataById((int) $option->getProduct()->getId())
57+
: null;
4258
}
4359
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ type SelectedConfigurableOption @doc(description: "Contains details about a sele
7777
}
7878

7979
type ConfigurableWishlistItem implements WishlistItemInterface @doc(description: "A configurable product wish list item."){
80-
child_sku: String! @deprecated(reason: "Use `ConfigurableWishlistItem.selected_variant_sku` instead.") @doc(description: "The SKU of the simple product corresponding to a set of selected configurable options.") @resolver(class: "\\Magento\\ConfigurableProductGraphQl\\Model\\Wishlist\\ChildSku")
81-
selected_variant_sku: String @doc(description: "The SKU of the simple product corresponding to a set of selected configurable options.") @resolver(class: "\\Magento\\ConfigurableProductGraphQl\\Model\\Wishlist\\SelectedVariantSku")
80+
child_sku: String! @deprecated(reason: "Use `ConfigurableWishlistItem.configured_variant.sku` instead.") @doc(description: "The SKU of the simple product corresponding to a set of selected configurable options.") @resolver(class: "\\Magento\\ConfigurableProductGraphQl\\Model\\Wishlist\\ChildSku")
8281
configurable_options: [SelectedConfigurableOption!] @resolver(class: "\\Magento\\ConfigurableProductGraphQl\\Model\\Wishlist\\ConfigurableOptions") @doc(description: "An array of selected configurable options.")
82+
configured_variant: ProductInterface @doc(description: "Product details of the selected variant. The value is null if some options are not configured.") @resolver(class: "\\Magento\\ConfigurableProductGraphQl\\Model\\Wishlist\\ConfiguredVariant")
8383
}
8484

8585
type ConfigurableProductOptionsSelection @doc(description: "Contains metadata corresponding to the selected configurable options.") {

app/code/Magento/WishlistGraphQl/Model/WishlistItem/DataProvider/CustomizableOption.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
namespace Magento\WishlistGraphQl\Model\WishlistItem\DataProvider;
99

10-
use Magento\Framework\App\ObjectManager;
1110
use Magento\Framework\Exception\LocalizedException;
1211
use Magento\Framework\GraphQl\Query\Uid;
1312
use Magento\Wishlist\Model\Item as WishlistItem;
@@ -27,20 +26,21 @@ class CustomizableOption
2726
*/
2827
private $customizableOptionValue;
2928

30-
/** @var Uid */
29+
/**
30+
* @var Uid
31+
*/
3132
private $uidEncoder;
3233

3334
/**
3435
* @param CustomizableOptionValueInterface $customOptionValueDataProvider
35-
* @param Uid|null $uidEncoder
36+
* @param Uid $uidEncoder
3637
*/
3738
public function __construct(
3839
CustomizableOptionValueInterface $customOptionValueDataProvider,
39-
Uid $uidEncoder = null
40+
Uid $uidEncoder
4041
) {
4142
$this->customizableOptionValue = $customOptionValueDataProvider;
42-
$this->uidEncoder = $uidEncoder ?: ObjectManager::getInstance()
43-
->get(Uid::class);
43+
$this->uidEncoder = $uidEncoder;
4444
}
4545

4646
/**

app/code/Magento/WishlistGraphQl/Model/WishlistItem/DataProvider/CustomizableOptionValue/Dropdown.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
use Magento\Catalog\Model\Product\Option;
1111
use Magento\Catalog\Model\Product\Option\Type\Select as SelectOptionType;
12-
use Magento\Framework\App\ObjectManager;
1312
use Magento\Framework\GraphQl\Query\Uid;
1413
use Magento\Wishlist\Model\Item as WishlistItem;
1514
use Magento\Wishlist\Model\Item\Option as SelectedOption;
@@ -30,20 +29,21 @@ class Dropdown implements CustomizableOptionValueInterface
3029
*/
3130
private $priceUnitLabel;
3231

33-
/** @var Uid */
32+
/**
33+
* @var Uid
34+
*/
3435
private $uidEncoder;
3536

3637
/**
3738
* @param PriceUnitLabel $priceUnitLabel
38-
* @param Uid|null $uidEncoder
39+
* @param Uid $uidEncoder
3940
*/
4041
public function __construct(
4142
PriceUnitLabel $priceUnitLabel,
42-
Uid $uidEncoder = null
43+
Uid $uidEncoder
4344
) {
4445
$this->priceUnitLabel = $priceUnitLabel;
45-
$this->uidEncoder = $uidEncoder ?: ObjectManager::getInstance()
46-
->get(Uid::class);
46+
$this->uidEncoder = $uidEncoder;
4747
}
4848

4949
/**

app/code/Magento/WishlistGraphQl/Model/WishlistItem/DataProvider/CustomizableOptionValue/Multiple.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
namespace Magento\WishlistGraphQl\Model\WishlistItem\DataProvider\CustomizableOptionValue;
99

1010
use Magento\Catalog\Model\Product\Option;
11-
use Magento\Framework\App\ObjectManager;
1211
use Magento\Framework\GraphQl\Query\Uid;
1312
use Magento\Wishlist\Model\Item as WishlistItem;
1413
use Magento\Wishlist\Model\Item\Option as SelectedOption;
@@ -29,20 +28,21 @@ class Multiple implements CustomizableOptionValueInterface
2928
*/
3029
private $priceUnitLabel;
3130

32-
/** @var Uid */
31+
/**
32+
* @var Uid
33+
*/
3334
private $uidEncoder;
3435

3536
/**
3637
* @param PriceUnitLabel $priceUnitLabel
37-
* @param Uid|null $uidEncoder
38+
* @param Uid $uidEncoder
3839
*/
3940
public function __construct(
4041
PriceUnitLabel $priceUnitLabel,
41-
Uid $uidEncoder = null
42+
Uid $uidEncoder
4243
) {
4344
$this->priceUnitLabel = $priceUnitLabel;
44-
$this->uidEncoder = $uidEncoder ?: ObjectManager::getInstance()
45-
->get(Uid::class);
45+
$this->uidEncoder = $uidEncoder;
4646
}
4747

4848
/**

app/code/Magento/WishlistGraphQl/Model/WishlistItem/DataProvider/CustomizableOptionValue/Text.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
use Magento\Catalog\Model\Product\Option;
1111
use Magento\Catalog\Model\Product\Option\Type\Text as TextOptionType;
12-
use Magento\Framework\App\ObjectManager;
1312
use Magento\Framework\GraphQl\Query\Uid;
1413
use Magento\Wishlist\Model\Item as WishlistItem;
1514
use Magento\Wishlist\Model\Item\Option as SelectedOption;
@@ -30,20 +29,21 @@ class Text implements CustomizableOptionValueInterface
3029
*/
3130
private $priceUnitLabel;
3231

33-
/** @var Uid */
32+
/**
33+
* @var Uid
34+
*/
3435
private $uidEncoder;
3536

3637
/**
3738
* @param PriceUnitLabel $priceUnitLabel
38-
* @param Uid|null $uidEncoder
39+
* @param Uid $uidEncoder
3940
*/
4041
public function __construct(
4142
PriceUnitLabel $priceUnitLabel,
42-
Uid $uidEncoder = null
43+
Uid $uidEncoder
4344
) {
4445
$this->priceUnitLabel = $priceUnitLabel;
45-
$this->uidEncoder = $uidEncoder ?: ObjectManager::getInstance()
46-
->get(Uid::class);
46+
$this->uidEncoder = $uidEncoder;
4747
}
4848

4949
/**

0 commit comments

Comments
 (0)