Skip to content

Commit 560c59f

Browse files
committed
Refactoring the code in separate modules
1 parent c6bd685 commit 560c59f

File tree

14 files changed

+70
-63
lines changed

14 files changed

+70
-63
lines changed

app/code/Magento/Wishlist/Model/Product/BundleOptionDataProvider.php renamed to app/code/Magento/Bundle/Model/Product/BundleOptionDataProvider.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@
55
*/
66
declare(strict_types=1);
77

8-
namespace Magento\Wishlist\Model\Product;
8+
namespace Magento\Bundle\Model\Product;
99

1010
use Magento\Bundle\Helper\Catalog\Product\Configuration;
1111
use Magento\Bundle\Model\Option;
12-
use Magento\Bundle\Model\Product\Type;
1312
use Magento\Catalog\Model\Product;
1413
use Magento\Framework\Exception\LocalizedException;
1514
use Magento\Framework\Pricing\Helper\Data;

app/code/Magento/WishlistGraphQl/Model/Resolver/Type/Bundle/BundleOptions.php renamed to app/code/Magento/BundleGraphQl/Model/Wishlist/BundleOptions.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
*/
66
declare(strict_types=1);
77

8-
namespace Magento\WishlistGraphQl\Model\Resolver\Type\Bundle;
8+
namespace Magento\BundleGraphQl\Model\Wishlist;
99

10-
use Magento\Wishlist\Model\Product\BundleOptionDataProvider;
10+
use Magento\Bundle\Model\Product\BundleOptionDataProvider;
11+
use Magento\Catalog\Model\Product\Configuration\Item\ItemInterface;
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;
15-
use Magento\Wishlist\Model\Item;
1616

1717
/**
1818
* Fetches the selected bundle options
@@ -43,9 +43,9 @@ public function resolve(
4343
array $value = null,
4444
array $args = null
4545
) {
46-
if (!$value['itemModel'] instanceof Item) {
46+
if (!$value['itemModel'] instanceof ItemInterface) {
4747
throw new LocalizedException(__('"itemModel" should be a "%instance" instance', [
48-
'instance' => Item::class
48+
'instance' => ItemInterface::class
4949
]));
5050
}
5151

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,11 @@
100100
</argument>
101101
</arguments>
102102
</type>
103+
<type name="Magento\WishlistGraphQl\Model\Resolver\Type\WishlistItemType">
104+
<arguments>
105+
<argument name="supportedTypes" xsi:type="array">
106+
<item name="bundle" xsi:type="string">BundleWishlistItem</item>
107+
</argument>
108+
</arguments>
109+
</type>
103110
</config>

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,7 @@ type ItemSelectedBundleOptionValue @doc(description: "A list of values for the s
117117
quantity: Float! @doc(description: "Indicates how many of this bundle product were ordered")
118118
price: Money! @doc(description: "The price of the child bundle product")
119119
}
120+
121+
type BundleWishlistItem implements WishlistItemInterface {
122+
bundle_options: [SelectedBundleOption!] @doc(description: "An array containing information about the selected bundled items") @resolver(class: "\\Magento\\BundleGraphQl\\Model\\Wishlist\\BundleOptions")
123+
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,4 +180,12 @@
180180
<argument name="templateFilterModel" xsi:type="string">Magento\Widget\Model\Template\FilterEmulate</argument>
181181
</arguments>
182182
</type>
183+
<type name="Magento\WishlistGraphQl\Model\Resolver\Type\WishlistItemType">
184+
<arguments>
185+
<argument name="supportedTypes" xsi:type="array">
186+
<item name="simple" xsi:type="string">SimpleWishlistItem</item>
187+
<item name="virtual" xsi:type="string">VirtualWishlistItem</item>
188+
</argument>
189+
</arguments>
190+
</type>
183191
</config>

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,3 +492,9 @@ type StoreConfig @doc(description: "The type contains information about a store
492492
catalog_default_sort_by : String @doc(description: "Default Sort By.")
493493
root_category_id: Int @doc(description: "The ID of the root category") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\RootCategoryId")
494494
}
495+
496+
type SimpleWishlistItem implements WishlistItemInterface @doc(description: "Simple Wishlist Item") {
497+
}
498+
499+
type VirtualWishlistItem implements WishlistItemInterface @doc(description: "Virtual Wishlist Item") {
500+
}

app/code/Magento/WishlistGraphQl/Model/Resolver/Type/Configurable/ChildSku.php renamed to app/code/Magento/ConfigurableProductGraphQl/Model/Wishlist/ChildSku.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
*/
66
declare(strict_types=1);
77

8-
namespace Magento\WishlistGraphQl\Model\Resolver\Type\Configurable;
8+
namespace Magento\ConfigurableProductGraphQl\Model\Wishlist;
99

10+
use Magento\Catalog\Model\Product;
1011
use Magento\Framework\Exception\LocalizedException;
1112
use Magento\Framework\GraphQl\Config\Element\Field;
1213
use Magento\Framework\GraphQl\Query\ResolverInterface;
1314
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
14-
use Magento\Wishlist\Model\Item;
1515

1616
/**
1717
* Fetches the simple child sku of configurable product
@@ -28,15 +28,15 @@ public function resolve(
2828
array $value = null,
2929
array $args = null
3030
) {
31-
if (!$value['itemModel'] instanceof Item) {
31+
if (!$value['model'] instanceof Product) {
3232
throw new LocalizedException(__('"itemModel" should be a "%instance" instance', [
33-
'instance' => Item::class
33+
'instance' => Product::class
3434
]));
3535
}
3636

37-
/** @var Item $wishlistItem */
38-
$wishlistItem = $value['itemModel'];
39-
$optionProduct = $wishlistItem->getProduct()->getCustomOption('simple_product')->getProduct();
37+
/** @var Product $product */
38+
$product = $value['model'];
39+
$optionProduct = $product->getCustomOption('simple_product')->getProduct();
4040

4141
return $optionProduct->getSku();
4242
}

app/code/Magento/WishlistGraphQl/Model/Resolver/Type/Configurable/ConfigurableOptions.php renamed to app/code/Magento/ConfigurableProductGraphQl/Model/Wishlist/ConfigurableOptions.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
*/
66
declare(strict_types=1);
77

8-
namespace Magento\WishlistGraphQl\Model\Resolver\Type\Configurable;
8+
namespace Magento\ConfigurableProductGraphQl\Model\Wishlist;
99

1010
use Magento\Catalog\Helper\Product\Configuration;
11+
use Magento\Catalog\Model\Product\Configuration\Item\ItemInterface;
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;
15-
use Magento\Wishlist\Model\Item;
1616

1717
/**
1818
* Fetches the selected configurable options
@@ -43,17 +43,17 @@ public function resolve(
4343
array $value = null,
4444
array $args = null
4545
) {
46-
if (!$value['itemModel'] instanceof Item) {
46+
if (!$value['itemModel'] instanceof ItemInterface) {
4747
throw new LocalizedException(__('"itemModel" should be a "%instance" instance', [
48-
'instance' => Item::class
48+
'instance' => ItemInterface::class
4949
]));
5050
}
5151

52-
/** @var Item $wishlistItem */
53-
$wishlistItem = $value['itemModel'];
52+
/** @var ItemInterface $item */
53+
$item = $value['itemModel'];
5454
$result = [];
5555

56-
foreach ($this->configurationHelper->getOptions($wishlistItem) as $option) {
56+
foreach ($this->configurationHelper->getOptions($item) as $option) {
5757
$result[] = [
5858
'id' => $option['option_id'],
5959
'option_label' => $option['label'],

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,11 @@
3636
</argument>
3737
</arguments>
3838
</type>
39+
<type name="Magento\WishlistGraphQl\Model\Resolver\Type\WishlistItemType">
40+
<arguments>
41+
<argument name="supportedTypes" xsi:type="array">
42+
<item name="configurable" xsi:type="string">ConfigurableWishlistItem</item>
43+
</argument>
44+
</arguments>
45+
</type>
3946
</config>

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,8 @@ type SelectedConfigurableOption {
6868
value_id: Int!
6969
value_label: String!
7070
}
71+
72+
type ConfigurableWishlistItem implements WishlistItemInterface {
73+
child_sku: String! @doc(description: "SKU of the simple product corresponding to a set of selected configurable options.") @resolver(class: "\\Magento\\ConfigurableProductGraphQl\\Model\\Wishlist\\ChildSku")
74+
configurable_options: [SelectedConfigurableOption!] @resolver(class: "\\Magento\\ConfigurableProductGraphQl\\Model\\Wishlist\\ConfigurableOptions")
75+
}

0 commit comments

Comments
 (0)