diff --git a/app/code/Magento/Bundle/Model/Product/BundleOptionDataProvider.php b/app/code/Magento/Bundle/Model/Product/BundleOptionDataProvider.php
new file mode 100644
index 0000000000000..f56c4228e49e5
--- /dev/null
+++ b/app/code/Magento/Bundle/Model/Product/BundleOptionDataProvider.php
@@ -0,0 +1,144 @@
+pricingHelper = $pricingHelper;
+ $this->serializer = $serializer;
+ $this->configuration = $configuration;
+ }
+
+ /**
+ * Extract data for a bundled item
+ *
+ * @param ItemInterface $item
+ *
+ * @return array
+ */
+ public function getData(ItemInterface $item): array
+ {
+ $options = [];
+ $product = $item->getProduct();
+ $optionsQuoteItemOption = $item->getOptionByCode('bundle_option_ids');
+ $bundleOptionsIds = $optionsQuoteItemOption
+ ? $this->serializer->unserialize($optionsQuoteItemOption->getValue())
+ : [];
+
+ /** @var Type $typeInstance */
+ $typeInstance = $product->getTypeInstance();
+
+ if ($bundleOptionsIds) {
+ $selectionsQuoteItemOption = $item->getOptionByCode('bundle_selection_ids');
+ $optionsCollection = $typeInstance->getOptionsByIds($bundleOptionsIds, $product);
+ $bundleSelectionIds = $this->serializer->unserialize($selectionsQuoteItemOption->getValue());
+
+ if (!empty($bundleSelectionIds)) {
+ $selectionsCollection = $typeInstance->getSelectionsByIds($bundleSelectionIds, $product);
+ $bundleOptions = $optionsCollection->appendSelections($selectionsCollection, true);
+
+ $options = $this->buildBundleOptions($bundleOptions, $item);
+ }
+ }
+
+ return $options;
+ }
+
+ /**
+ * Build bundle product options based on current selection
+ *
+ * @param Option[] $bundleOptions
+ * @param ItemInterface $item
+ *
+ * @return array
+ */
+ private function buildBundleOptions(array $bundleOptions, ItemInterface $item): array
+ {
+ $options = [];
+ foreach ($bundleOptions as $bundleOption) {
+ if (!$bundleOption->getSelections()) {
+ continue;
+ }
+
+ $options[] = [
+ 'id' => $bundleOption->getId(),
+ 'label' => $bundleOption->getTitle(),
+ 'type' => $bundleOption->getType(),
+ 'values' => $this->buildBundleOptionValues($bundleOption->getSelections(), $item),
+ ];
+ }
+
+ return $options;
+ }
+
+ /**
+ * Build bundle product option values based on current selection
+ *
+ * @param Product[] $selections
+ * @param ItemInterface $item
+ *
+ * @return array
+ */
+ private function buildBundleOptionValues(array $selections, ItemInterface $item): array
+ {
+ $product = $item->getProduct();
+ $values = [];
+
+ foreach ($selections as $selection) {
+ $qty = (float) $this->configuration->getSelectionQty($product, $selection->getSelectionId());
+ if (!$qty) {
+ continue;
+ }
+
+ $selectionPrice = $this->configuration->getSelectionFinalPrice($item, $selection);
+ $values[] = [
+ 'label' => $selection->getName(),
+ 'id' => $selection->getSelectionId(),
+ 'quantity' => $qty,
+ 'price' => $this->pricingHelper->currency($selectionPrice, false, false),
+ ];
+ }
+
+ return $values;
+ }
+}
diff --git a/app/code/Magento/BundleGraphQl/Model/Wishlist/BundleOptions.php b/app/code/Magento/BundleGraphQl/Model/Wishlist/BundleOptions.php
new file mode 100644
index 0000000000000..217f822e771da
--- /dev/null
+++ b/app/code/Magento/BundleGraphQl/Model/Wishlist/BundleOptions.php
@@ -0,0 +1,54 @@
+bundleOptionDataProvider = $bundleOptionDataProvider;
+ }
+
+ /**
+ * @inheritdoc
+ */
+ public function resolve(
+ Field $field,
+ $context,
+ ResolveInfo $info,
+ array $value = null,
+ array $args = null
+ ) {
+ if (!$value['itemModel'] instanceof ItemInterface) {
+ throw new LocalizedException(__('"itemModel" should be a "%instance" instance', [
+ 'instance' => ItemInterface::class
+ ]));
+ }
+
+ return $this->bundleOptionDataProvider->getData($value['itemModel']);
+ }
+}
diff --git a/app/code/Magento/BundleGraphQl/etc/graphql/di.xml b/app/code/Magento/BundleGraphQl/etc/graphql/di.xml
index 863e152fbe177..7fe0b2a53677c 100644
--- a/app/code/Magento/BundleGraphQl/etc/graphql/di.xml
+++ b/app/code/Magento/BundleGraphQl/etc/graphql/di.xml
@@ -100,4 +100,11 @@
+
+
+
+ - BundleWishlistItem
+
+
+
diff --git a/app/code/Magento/BundleGraphQl/etc/schema.graphqls b/app/code/Magento/BundleGraphQl/etc/schema.graphqls
index a66fa397020a7..a2cba24c7c4d4 100644
--- a/app/code/Magento/BundleGraphQl/etc/schema.graphqls
+++ b/app/code/Magento/BundleGraphQl/etc/schema.graphqls
@@ -117,3 +117,7 @@ type ItemSelectedBundleOptionValue @doc(description: "A list of values for the s
quantity: Float! @doc(description: "Indicates how many of this bundle product were ordered")
price: Money! @doc(description: "The price of the child bundle product")
}
+
+type BundleWishlistItem implements WishlistItemInterface {
+ bundle_options: [SelectedBundleOption!] @doc(description: "An array containing information about the selected bundle items") @resolver(class: "\\Magento\\BundleGraphQl\\Model\\Wishlist\\BundleOptions")
+}
diff --git a/app/code/Magento/CatalogGraphQl/etc/graphql/di.xml b/app/code/Magento/CatalogGraphQl/etc/graphql/di.xml
index c4f9bc26ee9f3..9ed36098ab6eb 100644
--- a/app/code/Magento/CatalogGraphQl/etc/graphql/di.xml
+++ b/app/code/Magento/CatalogGraphQl/etc/graphql/di.xml
@@ -180,4 +180,12 @@
Magento\Widget\Model\Template\FilterEmulate
+
+
+
+ - SimpleWishlistItem
+ - VirtualWishlistItem
+
+
+
diff --git a/app/code/Magento/CatalogGraphQl/etc/schema.graphqls b/app/code/Magento/CatalogGraphQl/etc/schema.graphqls
index 35f2c767b3e1e..35067a6cb99af 100644
--- a/app/code/Magento/CatalogGraphQl/etc/schema.graphqls
+++ b/app/code/Magento/CatalogGraphQl/etc/schema.graphqls
@@ -492,3 +492,9 @@ type StoreConfig @doc(description: "The type contains information about a store
catalog_default_sort_by : String @doc(description: "Default Sort By.")
root_category_id: Int @doc(description: "The ID of the root category") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\RootCategoryId")
}
+
+type SimpleWishlistItem implements WishlistItemInterface @doc(description: "A simple product wish list Item") {
+}
+
+type VirtualWishlistItem implements WishlistItemInterface @doc(description: "A virtual product wish list item") {
+}
diff --git a/app/code/Magento/ConfigurableProductGraphQl/Model/Wishlist/ChildSku.php b/app/code/Magento/ConfigurableProductGraphQl/Model/Wishlist/ChildSku.php
new file mode 100644
index 0000000000000..84decab81c96a
--- /dev/null
+++ b/app/code/Magento/ConfigurableProductGraphQl/Model/Wishlist/ChildSku.php
@@ -0,0 +1,43 @@
+ Product::class
+ ]));
+ }
+
+ /** @var Product $product */
+ $product = $value['model'];
+ $optionProduct = $product->getCustomOption('simple_product')->getProduct();
+
+ return $optionProduct->getSku();
+ }
+}
diff --git a/app/code/Magento/ConfigurableProductGraphQl/Model/Wishlist/ConfigurableOptions.php b/app/code/Magento/ConfigurableProductGraphQl/Model/Wishlist/ConfigurableOptions.php
new file mode 100644
index 0000000000000..6fcb3e118e5f1
--- /dev/null
+++ b/app/code/Magento/ConfigurableProductGraphQl/Model/Wishlist/ConfigurableOptions.php
@@ -0,0 +1,67 @@
+configurationHelper = $configurationHelper;
+ }
+
+ /**
+ * @inheritdoc
+ */
+ public function resolve(
+ Field $field,
+ $context,
+ ResolveInfo $info,
+ array $value = null,
+ array $args = null
+ ) {
+ if (!$value['itemModel'] instanceof ItemInterface) {
+ throw new LocalizedException(__('"itemModel" should be a "%instance" instance', [
+ 'instance' => ItemInterface::class
+ ]));
+ }
+
+ /** @var ItemInterface $item */
+ $item = $value['itemModel'];
+ $result = [];
+
+ foreach ($this->configurationHelper->getOptions($item) as $option) {
+ $result[] = [
+ 'id' => $option['option_id'],
+ 'option_label' => $option['label'],
+ 'value_id' => $option['option_value'],
+ 'value_label' => $option['value'],
+ ];
+ }
+
+ return $result;
+ }
+}
diff --git a/app/code/Magento/ConfigurableProductGraphQl/etc/graphql/di.xml b/app/code/Magento/ConfigurableProductGraphQl/etc/graphql/di.xml
index f82bb0dbd4d91..808ca62f7e149 100644
--- a/app/code/Magento/ConfigurableProductGraphQl/etc/graphql/di.xml
+++ b/app/code/Magento/ConfigurableProductGraphQl/etc/graphql/di.xml
@@ -36,4 +36,11 @@
+
+
+
+ - ConfigurableWishlistItem
+
+
+
diff --git a/app/code/Magento/ConfigurableProductGraphQl/etc/schema.graphqls b/app/code/Magento/ConfigurableProductGraphQl/etc/schema.graphqls
index 6e85653380acc..257bca11fb5b7 100644
--- a/app/code/Magento/ConfigurableProductGraphQl/etc/schema.graphqls
+++ b/app/code/Magento/ConfigurableProductGraphQl/etc/schema.graphqls
@@ -68,3 +68,8 @@ type SelectedConfigurableOption {
value_id: Int!
value_label: String!
}
+
+type ConfigurableWishlistItem implements WishlistItemInterface @doc(description: "A configurable product wish list item"){
+ child_sku: String! @doc(description: "The SKU of the simple product corresponding to a set of selected configurable options") @resolver(class: "\\Magento\\ConfigurableProductGraphQl\\Model\\Wishlist\\ChildSku")
+ configurable_options: [SelectedConfigurableOption!] @resolver(class: "\\Magento\\ConfigurableProductGraphQl\\Model\\Wishlist\\ConfigurableOptions") @doc (description: "An array of selected configurable options")
+}
diff --git a/app/code/Magento/DownloadableGraphQl/Model/Wishlist/ItemLinks.php b/app/code/Magento/DownloadableGraphQl/Model/Wishlist/ItemLinks.php
new file mode 100644
index 0000000000000..68223054aa806
--- /dev/null
+++ b/app/code/Magento/DownloadableGraphQl/Model/Wishlist/ItemLinks.php
@@ -0,0 +1,68 @@
+convertLinksToArray = $convertLinksToArray;
+ $this->downloadableConfiguration = $downloadableConfiguration;
+ }
+
+ /**
+ * @inheritdoc
+ */
+ public function resolve(
+ Field $field,
+ $context,
+ ResolveInfo $info,
+ array $value = null,
+ array $args = null
+ ) {
+ if (!$value['itemModel'] instanceof ItemInterface) {
+ throw new LocalizedException(__('"itemModel" should be a "%instance" instance', [
+ 'instance' => ItemInterface::class
+ ]));
+ }
+ /** @var ItemInterface $wishlistItem */
+ $itemItem = $value['itemModel'];
+
+ $links = $this->downloadableConfiguration->getLinks($itemItem);
+ $links = $this->convertLinksToArray->execute($links);
+
+ return $links;
+ }
+}
diff --git a/app/code/Magento/DownloadableGraphQl/etc/graphql/di.xml b/app/code/Magento/DownloadableGraphQl/etc/graphql/di.xml
index c95667de15ac3..51a630d59ca0f 100644
--- a/app/code/Magento/DownloadableGraphQl/etc/graphql/di.xml
+++ b/app/code/Magento/DownloadableGraphQl/etc/graphql/di.xml
@@ -39,4 +39,11 @@
+
+
+
+ - DownloadableWishlistItem
+
+
+
diff --git a/app/code/Magento/DownloadableGraphQl/etc/schema.graphqls b/app/code/Magento/DownloadableGraphQl/etc/schema.graphqls
index 5863e62e81b1b..ba178bb1a427e 100644
--- a/app/code/Magento/DownloadableGraphQl/etc/schema.graphqls
+++ b/app/code/Magento/DownloadableGraphQl/etc/schema.graphqls
@@ -64,3 +64,8 @@ type DownloadableProductSamples @doc(description: "DownloadableProductSamples de
sample_type: DownloadableFileTypeEnum @deprecated(reason: "`sample_url` serves to get the downloadable sample")
sample_file: String @deprecated(reason: "`sample_url` serves to get the downloadable sample")
}
+
+type DownloadableWishlistItem implements WishlistItemInterface @doc(description: "A downloadable product wish list item") {
+ links_v2: [DownloadableProductLinks] @doc(description: "An array containing information about the selected links") @resolver(class: "\\Magento\\DownloadableGraphQl\\Model\\Wishlist\\ItemLinks")
+ samples: [DownloadableProductSamples] @doc(description: "An array containing information about the selected samples") @resolver(class: "Magento\\DownloadableGraphQl\\Resolver\\Product\\Samples")
+}
diff --git a/app/code/Magento/WishlistGraphQl/Model/Resolver/AddProductsToWishlist.php b/app/code/Magento/WishlistGraphQl/Model/Resolver/AddProductsToWishlist.php
index 3489585cd17d7..840c4638614c4 100644
--- a/app/code/Magento/WishlistGraphQl/Model/Resolver/AddProductsToWishlist.php
+++ b/app/code/Magento/WishlistGraphQl/Model/Resolver/AddProductsToWishlist.php
@@ -83,7 +83,7 @@ public function resolve(
array $args = null
) {
if (!$this->wishlistConfig->isEnabled()) {
- throw new GraphQlInputException(__('The wishlist is not currently available.'));
+ throw new GraphQlInputException(__('The wishlist configuration is currently disabled.'));
}
$customerId = $context->getUserId();
diff --git a/app/code/Magento/WishlistGraphQl/Model/Resolver/CustomerWishlistResolver.php b/app/code/Magento/WishlistGraphQl/Model/Resolver/CustomerWishlistResolver.php
index cad574ef56ed2..b73afe27883dd 100644
--- a/app/code/Magento/WishlistGraphQl/Model/Resolver/CustomerWishlistResolver.php
+++ b/app/code/Magento/WishlistGraphQl/Model/Resolver/CustomerWishlistResolver.php
@@ -54,7 +54,7 @@ public function resolve(
array $args = null
) {
if (!$this->wishlistConfig->isEnabled()) {
- throw new GraphQlInputException(__('The wishlist is not currently available.'));
+ throw new GraphQlInputException(__('The wishlist configuration is currently disabled.'));
}
if (false === $context->getExtensionAttributes()->getIsCustomer()) {
diff --git a/app/code/Magento/WishlistGraphQl/Model/Resolver/CustomerWishlists.php b/app/code/Magento/WishlistGraphQl/Model/Resolver/CustomerWishlists.php
new file mode 100644
index 0000000000000..ad0c73691720a
--- /dev/null
+++ b/app/code/Magento/WishlistGraphQl/Model/Resolver/CustomerWishlists.php
@@ -0,0 +1,102 @@
+wishlistDataMapper = $wishlistDataMapper;
+ $this->wishlistConfig = $wishlistConfig;
+ $this->wishlistCollectionFactory = $wishlistCollectionFactory;
+ }
+
+ /**
+ * @inheritdoc
+ */
+ public function resolve(
+ Field $field,
+ $context,
+ ResolveInfo $info,
+ array $value = null,
+ array $args = null
+ ) {
+ if (!$this->wishlistConfig->isEnabled()) {
+ throw new GraphQlInputException(__('The wishlist configuration is currently disabled.'));
+ }
+
+ $customerId = $context->getUserId();
+
+ if (null === $customerId || 0 === $customerId) {
+ throw new GraphQlAuthorizationException(
+ __('The current user cannot perform operations on wishlist')
+ );
+ }
+
+ $currentPage = $args['currentPage'] ?? 1;
+ $pageSize = $args['pageSize'] ?? 20;
+
+ /** @var WishlistCollection $collection */
+ $collection = $this->wishlistCollectionFactory->create();
+ $collection->filterByCustomerId($customerId);
+
+ if ($currentPage > 0) {
+ $collection->setCurPage($currentPage);
+ }
+
+ if ($pageSize > 0) {
+ $collection->setPageSize($pageSize);
+ }
+
+ $wishlists = [];
+
+ /** @var Wishlist $wishList */
+ foreach ($collection->getItems() as $wishList) {
+ array_push($wishlists, $this->wishlistDataMapper->map($wishList));
+ }
+
+ return $wishlists;
+ }
+}
diff --git a/app/code/Magento/WishlistGraphQl/Model/Resolver/ProductResolver.php b/app/code/Magento/WishlistGraphQl/Model/Resolver/ProductResolver.php
index 65c8498fc89ad..31dd33ff2cd79 100644
--- a/app/code/Magento/WishlistGraphQl/Model/Resolver/ProductResolver.php
+++ b/app/code/Magento/WishlistGraphQl/Model/Resolver/ProductResolver.php
@@ -7,12 +7,12 @@
namespace Magento\WishlistGraphQl\Model\Resolver;
+use Magento\Catalog\Model\Product;
use Magento\CatalogGraphQl\Model\ProductDataProvider;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\GraphQl\Config\Element\Field;
use Magento\Framework\GraphQl\Query\ResolverInterface;
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
-use Magento\Wishlist\Model\Item;
/**
* Fetches the Product data according to the GraphQL schema
@@ -45,9 +45,9 @@ public function resolve(
if (!isset($value['model'])) {
throw new LocalizedException(__('Missing key "model" in Wishlist Item value data'));
}
- /** @var Item $wishlistItem */
- $wishlistItem = $value['model'];
+ /** @var Product $product */
+ $product = $value['model'];
- return $this->productDataProvider->getProductDataById((int)$wishlistItem->getProductId());
+ return $this->productDataProvider->getProductDataById((int) $product->getId());
}
}
diff --git a/app/code/Magento/WishlistGraphQl/Model/Resolver/RemoveProductsFromWishlist.php b/app/code/Magento/WishlistGraphQl/Model/Resolver/RemoveProductsFromWishlist.php
index a59c5ccdb0f70..66a6c7b86ea37 100644
--- a/app/code/Magento/WishlistGraphQl/Model/Resolver/RemoveProductsFromWishlist.php
+++ b/app/code/Magento/WishlistGraphQl/Model/Resolver/RemoveProductsFromWishlist.php
@@ -83,7 +83,7 @@ public function resolve(
array $args = null
) {
if (!$this->wishlistConfig->isEnabled()) {
- throw new GraphQlInputException(__('The wishlist is not currently available.'));
+ throw new GraphQlInputException(__('The wishlist configuration is currently disabled.'));
}
$customerId = $context->getUserId();
diff --git a/app/code/Magento/WishlistGraphQl/Model/Resolver/Type/WishlistItemType.php b/app/code/Magento/WishlistGraphQl/Model/Resolver/Type/WishlistItemType.php
new file mode 100644
index 0000000000000..ae4a6ed2b6a64
--- /dev/null
+++ b/app/code/Magento/WishlistGraphQl/Model/Resolver/Type/WishlistItemType.php
@@ -0,0 +1,59 @@
+supportedTypes = $supportedTypes;
+ }
+
+ /**
+ * Resolving wishlist item type
+ *
+ * @param array $data
+ *
+ * @return string
+ *
+ * @throws LocalizedException
+ */
+ public function resolveType(array $data): string
+ {
+ if (!$data['model'] instanceof ProductInterface) {
+ throw new LocalizedException(__('"model" should be a "%instance" instance', [
+ 'instance' => ProductInterface::class
+ ]));
+ }
+
+ $productTypeId = $data['model']->getTypeId();
+
+ if (!isset($this->supportedTypes[$productTypeId])) {
+ throw new LocalizedException(
+ __('Product "%product_type" type is not supported', ['product_type' => $productTypeId])
+ );
+ }
+
+ return $this->supportedTypes[$productTypeId];
+ }
+}
diff --git a/app/code/Magento/WishlistGraphQl/Model/Resolver/UpdateProductsInWishlist.php b/app/code/Magento/WishlistGraphQl/Model/Resolver/UpdateProductsInWishlist.php
index c6ede66fc2b1b..47a408d55555b 100644
--- a/app/code/Magento/WishlistGraphQl/Model/Resolver/UpdateProductsInWishlist.php
+++ b/app/code/Magento/WishlistGraphQl/Model/Resolver/UpdateProductsInWishlist.php
@@ -83,7 +83,7 @@ public function resolve(
array $args = null
) {
if (!$this->wishlistConfig->isEnabled()) {
- throw new GraphQlInputException(__('The wishlist is not currently available.'));
+ throw new GraphQlInputException(__('The wishlist configuration is currently disabled.'));
}
$customerId = $context->getUserId();
diff --git a/app/code/Magento/WishlistGraphQl/Model/Resolver/WishlistById.php b/app/code/Magento/WishlistGraphQl/Model/Resolver/WishlistById.php
new file mode 100644
index 0000000000000..1ddf91637fe90
--- /dev/null
+++ b/app/code/Magento/WishlistGraphQl/Model/Resolver/WishlistById.php
@@ -0,0 +1,115 @@
+wishlistResource = $wishlistResource;
+ $this->wishlistFactory = $wishlistFactory;
+ $this->wishlistDataMapper = $wishlistDataMapper;
+ $this->wishlistConfig = $wishlistConfig;
+ }
+
+ /**
+ * @inheritdoc
+ */
+ public function resolve(
+ Field $field,
+ $context,
+ ResolveInfo $info,
+ array $value = null,
+ array $args = null
+ ) {
+ if (!$this->wishlistConfig->isEnabled()) {
+ throw new GraphQlInputException(__('The wishlist configuration is currently disabled.'));
+ }
+
+ $customerId = $context->getUserId();
+
+ if (null === $customerId || 0 === $customerId) {
+ throw new GraphQlAuthorizationException(
+ __('The current user cannot perform operations on wishlist')
+ );
+ }
+
+ $wishlist = $this->getWishlist((int) $args['id'], $customerId);
+
+ if (null === $wishlist->getId() || (int) $wishlist->getCustomerId() !== $customerId) {
+ return [];
+ }
+
+ return $this->wishlistDataMapper->map($wishlist);
+ }
+
+ /**
+ * Get wishlist
+ *
+ * @param int $wishlistId
+ * @param int $customerId
+ *
+ * @return Wishlist
+ */
+ private function getWishlist(int $wishlistId, int $customerId): Wishlist
+ {
+ $wishlist = $this->wishlistFactory->create();
+
+ if ($wishlistId > 0) {
+ $this->wishlistResource->load($wishlist, $wishlistId);
+ } else {
+ $this->wishlistResource->load($wishlist, $customerId, 'customer_id');
+ }
+
+ return $wishlist;
+ }
+}
diff --git a/app/code/Magento/WishlistGraphQl/Model/Resolver/WishlistItems.php b/app/code/Magento/WishlistGraphQl/Model/Resolver/WishlistItems.php
new file mode 100644
index 0000000000000..77ff483a60bd2
--- /dev/null
+++ b/app/code/Magento/WishlistGraphQl/Model/Resolver/WishlistItems.php
@@ -0,0 +1,98 @@
+wishlistItemCollectionFactory = $wishlistItemCollectionFactory;
+ $this->storeManager = $storeManager;
+ }
+
+ /**
+ * @inheritdoc
+ */
+ public function resolve(
+ Field $field,
+ $context,
+ ResolveInfo $info,
+ array $value = null,
+ array $args = null
+ ) {
+ if (!isset($value['model'])) {
+ throw new LocalizedException(__('Missing key "model" in Wishlist value data'));
+ }
+ /** @var Wishlist $wishlist */
+ $wishlist = $value['model'];
+
+ $wishlistItems = $this->getWishListItems($wishlist);
+
+ $data = [];
+ foreach ($wishlistItems as $wishlistItem) {
+ $data[] = [
+ 'id' => $wishlistItem->getId(),
+ 'quantity' => $wishlistItem->getData('qty'),
+ 'description' => $wishlistItem->getDescription(),
+ 'added_at' => $wishlistItem->getAddedAt(),
+ 'model' => $wishlistItem->getProduct(),
+ 'itemModel' => $wishlistItem,
+ ];
+ }
+ return $data;
+ }
+
+ /**
+ * Get wishlist items
+ *
+ * @param Wishlist $wishlist
+ * @return Item[]
+ */
+ private function getWishListItems(Wishlist $wishlist): array
+ {
+ /** @var WishlistItemCollection $wishlistItemCollection */
+ $wishlistItemCollection = $this->wishlistItemCollectionFactory->create();
+ $wishlistItemCollection
+ ->addWishlistFilter($wishlist)
+ ->addStoreFilter(array_map(function (StoreInterface $store) {
+ return $store->getId();
+ }, $this->storeManager->getStores()))
+ ->setVisibilityFilter();
+ return $wishlistItemCollection->getItems();
+ }
+}
diff --git a/app/code/Magento/WishlistGraphQl/Model/Resolver/WishlistItemsResolver.php b/app/code/Magento/WishlistGraphQl/Model/Resolver/WishlistItemsResolver.php
index dfbbf6543f66f..36a03da2b79a9 100644
--- a/app/code/Magento/WishlistGraphQl/Model/Resolver/WishlistItemsResolver.php
+++ b/app/code/Magento/WishlistGraphQl/Model/Resolver/WishlistItemsResolver.php
@@ -70,7 +70,7 @@ public function resolve(
'qty' => $wishlistItem->getData('qty'),
'description' => $wishlistItem->getDescription(),
'added_at' => $wishlistItem->getAddedAt(),
- 'model' => $wishlistItem,
+ 'model' => $wishlistItem->getProduct(),
];
}
return $data;
diff --git a/app/code/Magento/WishlistGraphQl/Model/Resolver/WishlistResolver.php b/app/code/Magento/WishlistGraphQl/Model/Resolver/WishlistResolver.php
index 09c0a8a935a6c..f31b403a514fb 100644
--- a/app/code/Magento/WishlistGraphQl/Model/Resolver/WishlistResolver.php
+++ b/app/code/Magento/WishlistGraphQl/Model/Resolver/WishlistResolver.php
@@ -63,7 +63,7 @@ public function resolve(
array $args = null
) {
if (!$this->wishlistConfig->isEnabled()) {
- throw new GraphQlInputException(__('The wishlist is not currently available.'));
+ throw new GraphQlInputException(__('The wishlist configuration is currently disabled.'));
}
$customerId = $context->getUserId();
diff --git a/app/code/Magento/WishlistGraphQl/composer.json b/app/code/Magento/WishlistGraphQl/composer.json
index 7a3fca599a4b3..58bc738bd24d6 100644
--- a/app/code/Magento/WishlistGraphQl/composer.json
+++ b/app/code/Magento/WishlistGraphQl/composer.json
@@ -5,6 +5,7 @@
"require": {
"php": "~7.3.0||~7.4.0",
"magento/framework": "*",
+ "magento/module-catalog": "*",
"magento/module-catalog-graph-ql": "*",
"magento/module-wishlist": "*",
"magento/module-store": "*"
diff --git a/app/code/Magento/WishlistGraphQl/etc/schema.graphqls b/app/code/Magento/WishlistGraphQl/etc/schema.graphqls
index 430e77cc45e96..69bc45462d4c8 100644
--- a/app/code/Magento/WishlistGraphQl/etc/schema.graphqls
+++ b/app/code/Magento/WishlistGraphQl/etc/schema.graphqls
@@ -6,7 +6,12 @@ type Query {
}
type Customer {
- wishlist: Wishlist! @resolver(class:"\\Magento\\WishlistGraphQl\\Model\\Resolver\\CustomerWishlistResolver") @doc(description: "Contains the contents of a customer's wish lists") @cache(cacheable: false)
+ wishlists(
+ pageSize: Int = 20 @doc(description: "Specifies the maximum number of results to return at once. This attribute is optional."),
+ currentPage: Int = 1 @doc(description: "Specifies which page of results to return. The default value is 1.")
+ ): [Wishlist!]! @doc(description: "An array of wishlists. In Magento Open Source, customers are limited to one wish list. The number of wish lists is configurable for Magento Commerce") @resolver(class:"\\Magento\\WishlistGraphQl\\Model\\Resolver\\CustomerWishlists")
+ wishlist: Wishlist! @deprecated(reason: "Use `Customer.wishlists` or `Customer.wishlist_v2`") @resolver(class:"\\Magento\\WishlistGraphQl\\Model\\Resolver\\CustomerWishlistResolver") @doc(description: "Contains a customer's wish lists") @cache(cacheable: false)
+ wishlist_v2(id: ID!): Wishlist @doc(description: "Retrieve the specified wish list") @resolver(class: "\\Magento\\WishlistGraphQl\\Model\\Resolver\\WishlistById")
}
type WishlistOutput @doc(description: "Deprecated: `Wishlist` type should be used instead") {
@@ -19,12 +24,22 @@ type WishlistOutput @doc(description: "Deprecated: `Wishlist` type should be use
type Wishlist {
id: ID @doc(description: "Wishlist unique identifier")
- items: [WishlistItem] @resolver(class: "\\Magento\\WishlistGraphQl\\Model\\Resolver\\WishlistItemsResolver") @doc(description: "An array of items in the customer's wish list"),
- items_count: Int @doc(description: "The number of items in the wish list"),
- sharing_code: String @doc(description: "An encrypted code that Magento uses to link to the wish list"),
+ items: [WishlistItem] @resolver(class: "\\Magento\\WishlistGraphQl\\Model\\Resolver\\WishlistItemsResolver") @deprecated(reason: "Use field `items_v2` from type `Wishlist` instead")
+ items_v2: [WishlistItemInterface] @resolver(class: "\\Magento\\WishlistGraphQl\\Model\\Resolver\\WishlistItems") @doc(description: "An array of items in the customer's wish list")
+ items_count: Int @doc(description: "The number of items in the wish list")
+ sharing_code: String @doc(description: "An encrypted code that Magento uses to link to the wish list")
updated_at: String @doc(description: "The time of the last modification to the wish list")
}
+interface WishlistItemInterface @typeResolver(class: "Magento\\WishlistGraphQl\\Model\\Resolver\\Type\\WishlistItemType") {
+ id: ID! @doc(description: "The ID of the wish list item")
+ quantity: Float! @doc(description: "The quantity of this wish list item")
+ description: String @doc(description: "The description of the item")
+ added_at: String! @doc(description: "The date and time the item was added to the wish list")
+ product: ProductInterface @doc(description: "Product details of the wish list item") @resolver(class: "\\Magento\\WishlistGraphQl\\Model\\Resolver\\ProductResolver")
+ customizable_options: [SelectedCustomizableOption] @doc(description: "Custom options selected for the wish list item")
+}
+
type WishlistItem {
id: Int @doc(description: "The wish list item ID")
qty: Float @doc(description: "The quantity of this wish list item"),
diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Wishlist/AddBundleProductToWishlistTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Wishlist/AddBundleProductToWishlistTest.php
index a81ec701b22a8..b97cd379e4384 100644
--- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Wishlist/AddBundleProductToWishlistTest.php
+++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Wishlist/AddBundleProductToWishlistTest.php
@@ -16,6 +16,7 @@
use Magento\Integration\Api\CustomerTokenServiceInterface;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\TestFramework\TestCase\GraphQlAbstract;
+use Magento\Ui\Component\Form\Element\Select;
use Magento\Wishlist\Model\Item;
use Magento\Wishlist\Model\WishlistFactory;
@@ -74,7 +75,7 @@ public function testAddBundleProductWithOptions(): void
$selection = $typeInstance->getSelectionsCollection([$option->getId()], $product)->getFirstItem();
$optionId = $option->getId();
$selectionId = $selection->getSelectionId();
- $bundleOptions = $this->generateBundleOptionIdV2((int) $optionId, (int) $selectionId, $optionQty);
+ $bundleOptions = $this->generateBundleOptionUid((int) $optionId, (int) $selectionId, $optionQty);
$query = $this->getQuery($sku, $qty, $bundleOptions);
$response = $this->graphQlMutation($query, [], '', $this->getHeaderMap());
@@ -88,9 +89,13 @@ public function testAddBundleProductWithOptions(): void
$this->assertEquals($wishlist->getItemsCount(), $response['items_count']);
$this->assertEquals($wishlist->getSharingCode(), $response['sharing_code']);
$this->assertEquals($wishlist->getUpdatedAt(), $response['updated_at']);
- $this->assertEquals($item->getData('qty'), $response['items'][0]['qty']);
- $this->assertEquals($item->getDescription(), $response['items'][0]['description']);
- $this->assertEquals($item->getAddedAt(), $response['items'][0]['added_at']);
+ $this->assertEquals($item->getData('qty'), $response['items_v2'][0]['quantity']);
+ $this->assertEquals($item->getDescription(), $response['items_v2'][0]['description']);
+ $this->assertEquals($item->getAddedAt(), $response['items_v2'][0]['added_at']);
+ $this->assertNotEmpty($response['items_v2'][0]['bundle_options']);
+ $bundleOptions = $response['items_v2'][0]['bundle_options'];
+ $this->assertEquals('Bundle Product Items', $bundleOptions[0]['label']);
+ $this->assertEquals(Select::NAME, $bundleOptions[0]['type']);
}
/**
@@ -149,11 +154,24 @@ private function getQuery(
sharing_code
items_count
updated_at
- items {
+ items_v2 {
id
description
- qty
+ quantity
added_at
+ ... on BundleWishlistItem {
+ bundle_options {
+ id
+ label
+ type
+ values {
+ id
+ label
+ quantity
+ price
+ }
+ }
+ }
}
}
}
@@ -169,7 +187,7 @@ private function getQuery(
*
* @return string
*/
- private function generateBundleOptionIdV2(int $optionId, int $selectionId, int $quantity): string
+ private function generateBundleOptionUid(int $optionId, int $selectionId, int $quantity): string
{
return base64_encode("bundle/$optionId/$selectionId/$quantity");
}
diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Wishlist/AddConfigurableProductToWishlistTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Wishlist/AddConfigurableProductToWishlistTest.php
index d8d44541f899d..cffc5eb6f93c1 100644
--- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Wishlist/AddConfigurableProductToWishlistTest.php
+++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Wishlist/AddConfigurableProductToWishlistTest.php
@@ -48,7 +48,7 @@ protected function setUp(): void
*
* @throws Exception
*/
- public function testAddDownloadableProductWithOptions(): void
+ public function testAddConfigurableProductWithOptions(): void
{
$product = $this->getConfigurableProductInfo();
$customerId = 1;
@@ -57,7 +57,7 @@ public function testAddDownloadableProductWithOptions(): void
$valueIndex = $product['configurable_options'][0]['values'][0]['value_index'];
$childSku = $product['variants'][0]['product']['sku'];
$parentSku = $product['sku'];
- $selectedConfigurableOptionsQuery = $this->generateSuperAttributesIdV2Query($attributeId, $valueIndex);
+ $selectedConfigurableOptionsQuery = $this->generateSuperAttributesUidQuery($attributeId, $valueIndex);
$query = $this->getQuery($parentSku, $childSku, $qty, $selectedConfigurableOptionsQuery);
@@ -66,16 +66,19 @@ public function testAddDownloadableProductWithOptions(): void
/** @var Item $wishlistItem */
$wishlistItem = $wishlist->getItemCollection()->getFirstItem();
- self::assertArrayHasKey('addProductsToWishlist', $response);
- self::assertArrayHasKey('wishlist', $response['addProductsToWishlist']);
+ $this->assertArrayHasKey('addProductsToWishlist', $response);
+ $this->assertArrayHasKey('wishlist', $response['addProductsToWishlist']);
$wishlistResponse = $response['addProductsToWishlist']['wishlist'];
- self::assertEquals($wishlist->getItemsCount(), $wishlistResponse['items_count']);
- self::assertEquals($wishlist->getSharingCode(), $wishlistResponse['sharing_code']);
- self::assertEquals($wishlist->getUpdatedAt(), $wishlistResponse['updated_at']);
- self::assertEquals($wishlistItem->getId(), $wishlistResponse['items'][0]['id']);
- self::assertEquals($wishlistItem->getData('qty'), $wishlistResponse['items'][0]['qty']);
- self::assertEquals($wishlistItem->getDescription(), $wishlistResponse['items'][0]['description']);
- self::assertEquals($wishlistItem->getAddedAt(), $wishlistResponse['items'][0]['added_at']);
+ $this->assertEquals($wishlist->getItemsCount(), $wishlistResponse['items_count']);
+ $this->assertEquals($wishlist->getSharingCode(), $wishlistResponse['sharing_code']);
+ $this->assertEquals($wishlist->getUpdatedAt(), $wishlistResponse['updated_at']);
+ $this->assertEquals($wishlistItem->getId(), $wishlistResponse['items_v2'][0]['id']);
+ $this->assertEquals($wishlistItem->getData('qty'), $wishlistResponse['items_v2'][0]['quantity']);
+ $this->assertEquals($wishlistItem->getDescription(), $wishlistResponse['items_v2'][0]['description']);
+ $this->assertEquals($wishlistItem->getAddedAt(), $wishlistResponse['items_v2'][0]['added_at']);
+ $this->assertNotEmpty($wishlistResponse['items_v2'][0]['configurable_options']);
+ $configurableOptions = $wishlistResponse['items_v2'][0]['configurable_options'];
+ $this->assertEquals('Test Configurable', $configurableOptions[0]['option_label']);
}
/**
@@ -135,11 +138,20 @@ private function getQuery(
sharing_code
items_count
updated_at
- items {
+ items_v2 {
id
description
- qty
+ quantity
added_at
+ ... on ConfigurableWishlistItem {
+ child_sku
+ configurable_options {
+ id
+ option_label
+ value_id
+ value_label
+ }
+ }
}
}
}
@@ -148,14 +160,14 @@ private function getQuery(
}
/**
- * Generates Id_v2 for super configurable product super attributes
+ * Generates uid for super configurable product super attributes
*
* @param int $attributeId
* @param int $valueIndex
*
* @return string
*/
- private function generateSuperAttributesIdV2Query(int $attributeId, int $valueIndex): string
+ private function generateSuperAttributesUidQuery(int $attributeId, int $valueIndex): string
{
return 'selected_options: ["' . base64_encode("configurable/$attributeId/$valueIndex") . '"]';
}
diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Wishlist/AddDownloadableProductToWishlistTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Wishlist/AddDownloadableProductToWishlistTest.php
index 489a960056f1b..0de45fb21b20b 100644
--- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Wishlist/AddDownloadableProductToWishlistTest.php
+++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Wishlist/AddDownloadableProductToWishlistTest.php
@@ -37,9 +37,9 @@ class AddDownloadableProductToWishlistTest extends GraphQlAbstract
private $wishlistFactory;
/**
- * @var GetCustomOptionsWithIDV2ForQueryBySku
+ * @var GetCustomOptionsWithUidForQueryBySku
*/
- private $getCustomOptionsWithIDV2ForQueryBySku;
+ private $getCustomOptionsWithUidForQueryBySku;
/**
* Set Up
@@ -49,69 +49,75 @@ protected function setUp(): void
$this->objectManager = Bootstrap::getObjectManager();
$this->customerTokenService = $this->objectManager->get(CustomerTokenServiceInterface::class);
$this->wishlistFactory = $this->objectManager->get(WishlistFactory::class);
- $this->getCustomOptionsWithIDV2ForQueryBySku =
- $this->objectManager->get(GetCustomOptionsWithIDV2ForQueryBySku::class);
+ $this->getCustomOptionsWithUidForQueryBySku =
+ $this->objectManager->get(GetCustomOptionsWithUidForQueryBySku::class);
}
/**
- * @magentoConfigFixture default_store wishlist/general/active 1
+ * @magentoConfigFixture default_store wishlist/general/active 0
* @magentoApiDataFixture Magento/Customer/_files/customer.php
* @magentoApiDataFixture Magento/Downloadable/_files/product_downloadable_with_custom_options.php
*/
- public function testAddDownloadableProductWithOptions(): void
+ public function testAddDownloadableProductOnDisabledWishlist(): void
{
- $customerId = 1;
- $sku = 'downloadable-product-with-purchased-separately-links';
$qty = 2;
+ $sku = 'downloadable-product-with-purchased-separately-links';
$links = $this->getProductsLinks($sku);
$linkId = key($links);
- $itemOptions = $this->getCustomOptionsWithIDV2ForQueryBySku->execute($sku);
+ $itemOptions = $this->getCustomOptionsWithUidForQueryBySku->execute($sku);
$itemOptions['selected_options'][] = $this->generateProductLinkSelectedOptions($linkId);
- $productOptionsQuery = preg_replace(
+ $productOptionsQuery = trim(preg_replace(
'/"([^"]+)"\s*:\s*/',
'$1:',
json_encode($itemOptions)
- );
- $query = $this->getQuery($qty, $sku, trim($productOptionsQuery, '{}'));
- $response = $this->graphQlMutation($query, [], '', $this->getHeaderMap());
- $wishlist = $this->wishlistFactory->create();
- $wishlist->loadByCustomerId($customerId, true);
- /** @var Item $wishlistItem */
- $wishlistItem = $wishlist->getItemCollection()->getFirstItem();
-
- self::assertArrayHasKey('addProductsToWishlist', $response);
- self::assertArrayHasKey('wishlist', $response['addProductsToWishlist']);
- $wishlistResponse = $response['addProductsToWishlist']['wishlist'];
- self::assertEquals($wishlist->getItemsCount(), $wishlistResponse['items_count']);
- self::assertEquals($wishlist->getSharingCode(), $wishlistResponse['sharing_code']);
- self::assertEquals($wishlist->getUpdatedAt(), $wishlistResponse['updated_at']);
- self::assertEquals($wishlistItem->getId(), $wishlistResponse['items'][0]['id']);
- self::assertEquals($wishlistItem->getData('qty'), $wishlistResponse['items'][0]['qty']);
- self::assertEquals($wishlistItem->getDescription(), $wishlistResponse['items'][0]['description']);
- self::assertEquals($wishlistItem->getAddedAt(), $wishlistResponse['items'][0]['added_at']);
+ ), '{}');
+ $query = $this->getQuery($qty, $sku, $productOptionsQuery);
+ $this->expectExceptionMessage('The wishlist configuration is currently disabled.');
+ $this->graphQlMutation($query, [], '', $this->getHeaderMap());
}
/**
- * @magentoConfigFixture default_store wishlist/general/active 0
+ * @magentoConfigFixture default_store wishlist/general/active 1
* @magentoApiDataFixture Magento/Customer/_files/customer.php
* @magentoApiDataFixture Magento/Downloadable/_files/product_downloadable_with_custom_options.php
*/
- public function testAddDownloadableProductOnDisabledWishlist(): void
+ public function testAddDownloadableProductWithOptions(): void
{
- $qty = 2;
+ $customerId = 1;
$sku = 'downloadable-product-with-purchased-separately-links';
+ $qty = 2;
$links = $this->getProductsLinks($sku);
$linkId = key($links);
- $itemOptions = $this->getCustomOptionsWithIDV2ForQueryBySku->execute($sku);
+ $itemOptions = $this->getCustomOptionsWithUidForQueryBySku->execute($sku);
$itemOptions['selected_options'][] = $this->generateProductLinkSelectedOptions($linkId);
- $productOptionsQuery = trim(preg_replace(
+ $productOptionsQuery = preg_replace(
'/"([^"]+)"\s*:\s*/',
'$1:',
json_encode($itemOptions)
- ), '{}');
- $query = $this->getQuery($qty, $sku, $productOptionsQuery);
- $this->expectExceptionMessage('The wishlist is not currently available.');
- $this->graphQlMutation($query, [], '', $this->getHeaderMap());
+ );
+ $query = $this->getQuery($qty, $sku, trim($productOptionsQuery, '{}'));
+ $response = $this->graphQlMutation($query, [], '', $this->getHeaderMap());
+ $wishlist = $this->wishlistFactory->create();
+ $wishlist->loadByCustomerId($customerId, true);
+ /** @var Item $wishlistItem */
+ $wishlistItem = $wishlist->getItemCollection()->getFirstItem();
+
+ $this->assertArrayHasKey('addProductsToWishlist', $response);
+ $this->assertArrayHasKey('wishlist', $response['addProductsToWishlist']);
+ $wishlistResponse = $response['addProductsToWishlist']['wishlist'];
+ $this->assertEquals($wishlist->getItemsCount(), $wishlistResponse['items_count']);
+ $this->assertEquals($wishlist->getSharingCode(), $wishlistResponse['sharing_code']);
+ $this->assertEquals($wishlist->getUpdatedAt(), $wishlistResponse['updated_at']);
+ $this->assertEquals($wishlistItem->getId(), $wishlistResponse['items_v2'][0]['id']);
+ $this->assertEquals($wishlistItem->getData('qty'), $wishlistResponse['items_v2'][0]['quantity']);
+ $this->assertEquals($wishlistItem->getDescription(), $wishlistResponse['items_v2'][0]['description']);
+ $this->assertEquals($wishlistItem->getAddedAt(), $wishlistResponse['items_v2'][0]['added_at']);
+ $this->assertNotEmpty($wishlistResponse['items_v2'][0]['links_v2']);
+ $wishlistItemLinks = $wishlistResponse['items_v2'][0]['links_v2'];
+ $this->assertEquals('Downloadable Product Link 1', $wishlistItemLinks[0]['title']);
+ $this->assertNotEmpty($wishlistResponse['items_v2'][0]['samples']);
+ $wishlistItemSamples = $wishlistResponse['items_v2'][0]['samples'];
+ $this->assertEquals('Downloadable Product Sample', $wishlistItemSamples[0]['title']);
}
/**
@@ -190,11 +196,23 @@ private function getQuery(
sharing_code
items_count
updated_at
- items {
+ items_v2 {
id
description
- qty
+ quantity
added_at
+ ... on DownloadableWishlistItem {
+ links_v2 {
+ id
+ title
+ sample_url
+ }
+ samples {
+ id
+ title
+ sample_url
+ }
+ }
}
}
}
@@ -203,7 +221,7 @@ private function getQuery(
}
/**
- * Generates Id_v2 for downloadable links
+ * Generates uid for downloadable links
*
* @param int $linkId
*
diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Wishlist/CustomerWishlistTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Wishlist/CustomerWishlistTest.php
index 0a8e1757a2ce2..04095c1679d2f 100644
--- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Wishlist/CustomerWishlistTest.php
+++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Wishlist/CustomerWishlistTest.php
@@ -131,7 +131,7 @@ public function testGuestCannotGetWishlist()
public function testCustomerCannotGetWishlistWhenDisabled()
{
$this->expectException(\Exception::class);
- $this->expectExceptionMessage('The wishlist is not currently available.');
+ $this->expectExceptionMessage('The wishlist configuration is currently disabled.');
$query =
<<customerTokenService = Bootstrap::getObjectManager()->get(CustomerTokenServiceInterface::class);
+ $this->wishlistCollectionFactory = Bootstrap::getObjectManager()->get(CollectionFactory::class);
+ }
+
+ /**
+ * Test fetching customer wishlist
+ *
+ * @magentoConfigFixture default_store wishlist/general/active 1
+ * @magentoApiDataFixture Magento/Wishlist/_files/wishlist.php
+ */
+ public function testCustomerWishlist(): void
+ {
+ $customerId = 1;
+ /** @var Wishlist $wishlist */
+ $collection = $this->wishlistCollectionFactory->create()->filterByCustomerId($customerId);
+ /** @var Item $wishlistItem */
+ $wishlistItem = $collection->getFirstItem();
+ $response = $this->graphQlQuery(
+ $this->getQuery(),
+ [],
+ '',
+ $this->getCustomerAuthHeaders('customer@example.com', 'password')
+ );
+ $this->assertArrayHasKey('wishlists', $response['customer']);
+ $wishlist = $response['customer']['wishlists'][0];
+ $this->assertEquals($wishlistItem->getItemsCount(), $wishlist['items_count']);
+ $this->assertEquals($wishlistItem->getSharingCode(), $wishlist['sharing_code']);
+ $this->assertEquals($wishlistItem->getUpdatedAt(), $wishlist['updated_at']);
+ $wishlistItemResponse = $wishlist['items_v2'][0];
+ $this->assertEquals('simple', $wishlistItemResponse['product']['sku']);
+ }
+
+ /**
+ * Testing fetching the wishlist when wishlist is disabled
+ *
+ * @magentoConfigFixture default_store wishlist/general/active 0
+ * @magentoApiDataFixture Magento/Customer/_files/customer.php
+ */
+ public function testCustomerCannotGetWishlistWhenDisabled(): void
+ {
+ $this->expectException(Exception::class);
+ $this->expectExceptionMessage('The wishlist configuration is currently disabled.');
+ $this->graphQlQuery(
+ $this->getQuery(),
+ [],
+ '',
+ $this->getCustomerAuthHeaders('customer@example.com', 'password')
+ );
+ }
+
+ /**
+ * Test wishlist fetching for a guest customer
+ *
+ * @magentoConfigFixture default_store wishlist/general/active 1
+ */
+ public function testGuestCannotGetWishlist(): void
+ {
+ $this->expectException(Exception::class);
+ $this->expectExceptionMessage('The current customer isn\'t authorized.');
+ $this->graphQlQuery($this->getQuery());
+ }
+
+ /**
+ * Returns GraphQl query string
+ *
+ * @return string
+ */
+ private function getQuery(): string
+ {
+ return <<customerTokenService->createCustomerAccessToken($email, $password);
+
+ return ['Authorization' => 'Bearer ' . $customerToken];
+ }
+}
diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Wishlist/DeleteProductsFromWishlistTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Wishlist/DeleteProductsFromWishlistTest.php
index ebe99289b8934..13aaecbc7b733 100644
--- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Wishlist/DeleteProductsFromWishlistTest.php
+++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Wishlist/DeleteProductsFromWishlistTest.php
@@ -42,17 +42,17 @@ public function testDeleteWishlistItemFromWishlist(): void
$wishlist = $this->getWishlist();
$wishlistId = $wishlist['customer']['wishlist']['id'];
$wishlist = $wishlist['customer']['wishlist'];
- $wishlistItems = $wishlist['items'];
- self::assertEquals(1, $wishlist['items_count']);
+ $wishlistItems = $wishlist['items_v2'];
+ $this->assertEquals(1, $wishlist['items_count']);
$query = $this->getQuery((int) $wishlistId, (int) $wishlistItems[0]['id']);
$response = $this->graphQlMutation($query, [], '', $this->getHeaderMap());
- self::assertArrayHasKey('removeProductsFromWishlist', $response);
- self::assertArrayHasKey('wishlist', $response['removeProductsFromWishlist']);
+ $this->assertArrayHasKey('removeProductsFromWishlist', $response);
+ $this->assertArrayHasKey('wishlist', $response['removeProductsFromWishlist']);
$wishlistResponse = $response['removeProductsFromWishlist']['wishlist'];
- self::assertEquals(0, $wishlistResponse['items_count']);
- self::assertEmpty($wishlistResponse['items']);
+ $this->assertEquals(0, $wishlistResponse['items_count']);
+ $this->assertEmpty($wishlistResponse['items_v2']);
}
/**
@@ -98,10 +98,10 @@ private function getQuery(
id
sharing_code
items_count
- items {
+ items_v2 {
id
description
- qty
+ quantity
}
}
}
@@ -134,9 +134,9 @@ private function getCustomerWishlistQuery(): string
wishlist {
id
items_count
- items {
+ items_v2 {
id
- qty
+ quantity
description
}
}
diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Wishlist/GetCustomOptionsWithIDV2ForQueryBySku.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Wishlist/GetCustomOptionsWithUidForQueryBySku.php
similarity index 94%
rename from dev/tests/api-functional/testsuite/Magento/GraphQl/Wishlist/GetCustomOptionsWithIDV2ForQueryBySku.php
rename to dev/tests/api-functional/testsuite/Magento/GraphQl/Wishlist/GetCustomOptionsWithUidForQueryBySku.php
index fcba7458f317a..4bd0c135f039a 100644
--- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Wishlist/GetCustomOptionsWithIDV2ForQueryBySku.php
+++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Wishlist/GetCustomOptionsWithUidForQueryBySku.php
@@ -10,9 +10,9 @@
use Magento\Catalog\Api\ProductCustomOptionRepositoryInterface;
/**
- * Generate an array with test values for customizable options with encoded id_v2 value
+ * Generate an array with test values for customizable options with encoded uid value
*/
-class GetCustomOptionsWithIDV2ForQueryBySku
+class GetCustomOptionsWithUidForQueryBySku
{
/**
* @var ProductCustomOptionRepositoryInterface
@@ -71,7 +71,7 @@ public function execute(string $sku): array
}
/**
- * Returns id_v2 of the selected custom option
+ * Returns uid of the selected custom option
*
* @param int $optionId
* @param int $optionValueId
@@ -84,7 +84,7 @@ private function encodeSelectedOption(int $optionId, int $optionValueId): string
}
/**
- * Returns id_v2 of the entered custom option
+ * Returns uid of the entered custom option
*
* @param int $optionId
*
diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Wishlist/UpdateProductsFromWishlistTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Wishlist/UpdateProductsFromWishlistTest.php
index 9a9cd424e54ca..08273e7936640 100644
--- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Wishlist/UpdateProductsFromWishlistTest.php
+++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Wishlist/UpdateProductsFromWishlistTest.php
@@ -43,18 +43,18 @@ public function testUpdateSimpleProductFromWishlist(): void
$qty = 5;
$description = 'New Description';
$wishlistId = $wishlist['customer']['wishlist']['id'];
- $wishlistItem = $wishlist['customer']['wishlist']['items'][0];
- self::assertNotEquals($description, $wishlistItem['description']);
- self::assertNotEquals($qty, $wishlistItem['qty']);
+ $wishlistItem = $wishlist['customer']['wishlist']['items_v2'][0];
+ $this->assertNotEquals($description, $wishlistItem['description']);
+ $this->assertNotEquals($qty, $wishlistItem['quantity']);
$query = $this->getQuery((int) $wishlistId, (int) $wishlistItem['id'], $qty, $description);
$response = $this->graphQlMutation($query, [], '', $this->getHeaderMap());
- self::assertArrayHasKey('updateProductsInWishlist', $response);
- self::assertArrayHasKey('wishlist', $response['updateProductsInWishlist']);
+ $this->assertArrayHasKey('updateProductsInWishlist', $response);
+ $this->assertArrayHasKey('wishlist', $response['updateProductsInWishlist']);
$wishlistResponse = $response['updateProductsInWishlist']['wishlist'];
- self::assertEquals($qty, $wishlistResponse['items'][0]['qty']);
- self::assertEquals($description, $wishlistResponse['items'][0]['description']);
+ $this->assertEquals($qty, $wishlistResponse['items_v2'][0]['quantity']);
+ $this->assertEquals($description, $wishlistResponse['items_v2'][0]['description']);
}
/**
@@ -110,10 +110,10 @@ private function getQuery(
id
sharing_code
items_count
- items {
+ items_v2 {
id
description
- qty
+ quantity
}
}
}
@@ -146,9 +146,9 @@ private function getCustomerWishlistQuery(): string
wishlist {
id
items_count
- items {
+ items_v2 {
id
- qty
+ quantity
description
}
}