Skip to content

Commit c6bd685

Browse files
committed
Refactoring the downloadable product logic
1 parent e0b482c commit c6bd685

File tree

11 files changed

+25
-26
lines changed

11 files changed

+25
-26
lines changed

app/code/Magento/WishlistGraphQl/Model/Resolver/Type/Downloadable/Links.php renamed to app/code/Magento/DownloadableGraphQl/Model/Wishlist/ItemLinks.php

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

8-
namespace Magento\WishlistGraphQl\Model\Resolver\Type\Downloadable;
8+
namespace Magento\DownloadableGraphQl\Model\Wishlist;
99

10+
use Magento\Catalog\Model\Product\Configuration\Item\ItemInterface;
1011
use Magento\Downloadable\Helper\Catalog\Product\Configuration;
1112
use Magento\DownloadableGraphQl\Model\ConvertLinksToArray;
1213
use Magento\Framework\Exception\LocalizedException;
1314
use Magento\Framework\GraphQl\Config\Element\Field;
1415
use Magento\Framework\GraphQl\Query\ResolverInterface;
1516
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
16-
use Magento\Wishlist\Model\Item;
1717

1818
/**
19-
* Fetches the selected downloadable links
19+
* Fetches the selected item downloadable links
2020
*/
21-
class Links implements ResolverInterface
21+
class ItemLinks implements ResolverInterface
2222
{
2323
/**
2424
* @var ConvertLinksToArray
@@ -52,13 +52,15 @@ public function resolve(
5252
array $value = null,
5353
array $args = null
5454
) {
55-
if (!isset($value['wishlistItemModel'])) {
56-
throw new LocalizedException(__('Missing key "wishlistItemModel" in Wishlist Item value data'));
55+
if (!$value['itemModel'] instanceof ItemInterface) {
56+
throw new LocalizedException(__('"itemModel" should be a "%instance" instance', [
57+
'instance' => ItemInterface::class
58+
]));
5759
}
58-
/** @var Item $wishlistItem */
59-
$wishlistItem = $value['wishlistItemModel'];
60+
/** @var ItemInterface $wishlistItem */
61+
$itemItem = $value['itemModel'];
6062

61-
$links = $this->downloadableConfiguration->getLinks($wishlistItem);
63+
$links = $this->downloadableConfiguration->getLinks($itemItem);
6264
$links = $this->convertLinksToArray->execute($links);
6365

6466
return $links;

app/code/Magento/WishlistGraphQl/Model/Resolver/ProductResolver.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
use Magento\Framework\GraphQl\Config\Element\Field;
1414
use Magento\Framework\GraphQl\Query\ResolverInterface;
1515
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
16-
use Magento\Wishlist\Model\Item;
1716

1817
/**
1918
* Fetches the Product data according to the GraphQL schema

app/code/Magento/WishlistGraphQl/Model/Resolver/Type/Bundle/BundleOptions.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ public function resolve(
4343
array $value = null,
4444
array $args = null
4545
) {
46-
if (!$value['wishlistItemModel'] instanceof Item) {
47-
throw new LocalizedException(__('"wishlistItemModel" should be a "%instance" instance', [
46+
if (!$value['itemModel'] instanceof Item) {
47+
throw new LocalizedException(__('"itemModel" should be a "%instance" instance', [
4848
'instance' => Item::class
4949
]));
5050
}
5151

52-
return $this->bundleOptionDataProvider->getData($value['wishlistItemModel']);
52+
return $this->bundleOptionDataProvider->getData($value['itemModel']);
5353
}
5454
}

app/code/Magento/WishlistGraphQl/Model/Resolver/Type/Configurable/ChildSku.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ public function resolve(
2828
array $value = null,
2929
array $args = null
3030
) {
31-
if (!$value['wishlistItemModel'] instanceof Item) {
32-
throw new LocalizedException(__('"wishlistItemModel" should be a "%instance" instance', [
31+
if (!$value['itemModel'] instanceof Item) {
32+
throw new LocalizedException(__('"itemModel" should be a "%instance" instance', [
3333
'instance' => Item::class
3434
]));
3535
}
3636

3737
/** @var Item $wishlistItem */
38-
$wishlistItem = $value['wishlistItemModel'];
38+
$wishlistItem = $value['itemModel'];
3939
$optionProduct = $wishlistItem->getProduct()->getCustomOption('simple_product')->getProduct();
4040

4141
return $optionProduct->getSku();

app/code/Magento/WishlistGraphQl/Model/Resolver/Type/Configurable/ConfigurableOptions.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ public function resolve(
4343
array $value = null,
4444
array $args = null
4545
) {
46-
if (!$value['wishlistItemModel'] instanceof Item) {
47-
throw new LocalizedException(__('"wishlistItemModel" should be a "%instance" instance', [
46+
if (!$value['itemModel'] instanceof Item) {
47+
throw new LocalizedException(__('"itemModel" should be a "%instance" instance', [
4848
'instance' => Item::class
4949
]));
5050
}
5151

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

5656
foreach ($this->configurationHelper->getOptions($wishlistItem) as $option) {

app/code/Magento/WishlistGraphQl/Model/Resolver/WishlistItems.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function resolve(
7171
'description' => $wishlistItem->getDescription(),
7272
'added_at' => $wishlistItem->getAddedAt(),
7373
'model' => $wishlistItem->getProduct(),
74-
'wishlistItemModel' => $wishlistItem,
74+
'itemModel' => $wishlistItem,
7575
];
7676
}
7777
return $data;

app/code/Magento/WishlistGraphQl/composer.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
"magento/framework": "*",
88
"magento/module-catalog": "*",
99
"magento/module-catalog-graph-ql": "*",
10-
"magento/module-downloadable": "*",
11-
"magento/module-downloadable-graphql": "*",
1210
"magento/module-wishlist": "*",
1311
"magento/module-store": "*"
1412
},

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ type ConfigurableWishlistItem implements WishlistItemInterface {
5252
}
5353

5454
type DownloadableWishlistItem implements WishlistItemInterface @doc(description: "Downloadable Wishlist Item") {
55-
links_v2: [DownloadableProductLinks] @doc(description: "An array containing information about the selected links") @resolver(class: "\\Magento\\WishlistGraphQl\\Model\\Resolver\\Type\\Downloadable\\Links")
55+
links_v2: [DownloadableProductLinks] @doc(description: "An array containing information about the selected links") @resolver(class: "\\Magento\\DownloadableGraphQl\\Model\\Wishlist\\ItemLinks")
5656
samples: [DownloadableProductSamples] @doc(description: "DownloadableProductSamples defines characteristics of a downloadable product") @resolver(class: "Magento\\DownloadableGraphQl\\Resolver\\Product\\Samples")
5757
}
5858

dev/tests/api-functional/testsuite/Magento/GraphQl/Wishlist/AddConfigurableProductToWishlistTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ private function getQuery(
160160
}
161161

162162
/**
163-
* Generates Id_v2 for super configurable product super attributes
163+
* Generates uid for super configurable product super attributes
164164
*
165165
* @param int $attributeId
166166
* @param int $valueIndex

dev/tests/api-functional/testsuite/Magento/GraphQl/Wishlist/AddDownloadableProductToWishlistTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ private function getQuery(
221221
}
222222

223223
/**
224-
* Generates Id_v2 for downloadable links
224+
* Generates uid for downloadable links
225225
*
226226
* @param int $linkId
227227
*

0 commit comments

Comments
 (0)