Skip to content

Commit f842f8d

Browse files
authored
Merge pull request #6054 from magento-honey-badgers/MC-36897
[honey] MC-36897: [GraphQl] Store config and schema modifications for Wishlist
2 parents b5088b7 + 15e7367 commit f842f8d

File tree

15 files changed

+523
-13
lines changed

15 files changed

+523
-13
lines changed

app/code/Magento/ConfigurableProductGraphQl/Model/Resolver/ConfigurableCartItemOptions.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
5555

5656
$result = [];
5757
foreach ($this->configurationHelper->getOptions($cartItem) as $option) {
58+
if (isset($option['option_type'])) {
59+
//Don't return customizable options in this resolver
60+
continue;
61+
}
5862
$result[] = [
5963
'id' => $option['option_id'],
6064
'option_label' => $option['label'],

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ input ConfigurableProductCartItemInput {
5858
}
5959

6060
type ConfigurableCartItem implements CartItemInterface {
61-
customizable_options: [SelectedCustomizableOption]!
61+
customizable_options: [SelectedCustomizableOption] @resolver(class: "Magento\\QuoteGraphQl\\Model\\Resolver\\CustomizableOptions")
6262
configurable_options: [SelectedConfigurableOption!]! @resolver(class: "Magento\\ConfigurableProductGraphQl\\Model\\Resolver\\ConfigurableCartItemOptions")
6363
}
6464

app/code/Magento/QuoteGraphQl/Model/Cart/SetShippingAddressesOnCart.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77

88
namespace Magento\QuoteGraphQl\Model\Cart;
99

10+
use Magento\Framework\App\ObjectManager;
1011
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
1112
use Magento\GraphQl\Model\Query\ContextInterface;
1213
use Magento\Quote\Api\Data\CartInterface;
14+
use Magento\Quote\Model\QuoteRepository;
1315

1416
/**
1517
* Set single shipping address for a specified shopping cart
@@ -26,16 +28,25 @@ class SetShippingAddressesOnCart implements SetShippingAddressesOnCartInterface
2628
*/
2729
private $getShippingAddress;
2830

31+
/**
32+
* @var QuoteRepository
33+
*/
34+
private $quoteRepository;
35+
2936
/**
3037
* @param AssignShippingAddressToCart $assignShippingAddressToCart
3138
* @param GetShippingAddress $getShippingAddress
39+
* @param QuoteRepository|null $quoteRepository
3240
*/
3341
public function __construct(
3442
AssignShippingAddressToCart $assignShippingAddressToCart,
35-
GetShippingAddress $getShippingAddress
43+
GetShippingAddress $getShippingAddress,
44+
QuoteRepository $quoteRepository = null
3645
) {
3746
$this->assignShippingAddressToCart = $assignShippingAddressToCart;
3847
$this->getShippingAddress = $getShippingAddress;
48+
$this->quoteRepository = $quoteRepository
49+
?? ObjectManager::getInstance()->get(QuoteRepository::class);
3950
}
4051

4152
/**
@@ -70,5 +81,7 @@ public function execute(ContextInterface $context, CartInterface $cart, array $s
7081
throw $e;
7182
}
7283
$this->assignShippingAddressToCart->execute($cart, $shippingAddress);
84+
// trigger quote re-evaluation after address change
85+
$this->quoteRepository->save($cart);
7386
}
7487
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
9+
<type name="Magento\StoreGraphQl\Model\Resolver\Store\StoreConfigDataProvider">
10+
<arguments>
11+
<argument name="extendedConfigData" xsi:type="array">
12+
<item name="product_reviews_enabled" xsi:type="string">catalog/review/active</item>
13+
<item name="allow_guests_to_write_product_reviews" xsi:type="string">catalog/review/allow_guest</item>
14+
</argument>
15+
</arguments>
16+
</type>
17+
</config>

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ type ProductReviewRatingsMetadata {
3939
}
4040

4141
type ProductReviewRatingMetadata {
42-
id: String! @doc(description: "Base64 encoded rating ID.")
42+
id: String! @doc(description: "An encoded rating ID.")
4343
name: String! @doc(description: "The label assigned to an aspect of a product that is being rated, such as quality or price")
4444
values: [ProductReviewRatingValueMetadata!]! @doc(description: "List of product review ratings sorted by position.") @resolver(class: "Magento\\ReviewGraphQl\\Model\\Resolver\\ProductReviewRatingValueMetadata")
4545
}
4646

4747
type ProductReviewRatingValueMetadata {
48-
value_id: String! @doc(description: "Base 64 encoded rating value id.")
49-
value: String! @doc(description: "e.g Good, Perfect, 3, 4, 5")
48+
value_id: String! @doc(description: "An encoded rating value id.")
49+
value: String! @doc(description: "A ratings scale, such as the number of stars awarded")
5050
}
5151

5252
type Customer {
@@ -73,6 +73,11 @@ input CreateProductReviewInput {
7373
}
7474

7575
input ProductReviewRatingInput {
76-
id: String! @doc(description: "Base64 encoded rating ID.")
77-
value_id: String! @doc(description: "Base 64 encoded rating value id.")
76+
id: String! @doc(description: "An encoded rating ID.")
77+
value_id: String! @doc(description: "An encoded rating value id.")
78+
}
79+
80+
type StoreConfig @doc(description: "The type contains information about a store config") {
81+
product_reviews_enabled : String @doc(description: "Indicates whether product reviews are enabled. Possible values: 1 (Yes) and 0 (No)")
82+
allow_guests_to_write_product_reviews : String @doc(description: "Indicates whether guest users can write product reviews. Possible values: 1 (Yes) and 0 (No)")
7883
}

app/code/Magento/Wishlist/Model/Wishlist/AddProductsToWishlist.php

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

1010
use Magento\Catalog\Api\ProductRepositoryInterface;
11+
use Magento\Catalog\Model\Product\Attribute\Source\Status;
1112
use Magento\Framework\Exception\AlreadyExistsException;
1213
use Magento\Framework\Exception\LocalizedException;
1314
use Magento\Framework\Exception\NoSuchEntityException;
@@ -113,6 +114,12 @@ private function addItemToWishlist(Wishlist $wishlist, WishlistItem $wishlistIte
113114
}
114115

115116
try {
117+
if ((int)$wishlistItem->getQuantity() === 0) {
118+
throw new LocalizedException(__("The quantity of a wish list item cannot be 0"));
119+
}
120+
if ($product->getStatus() == Status::STATUS_DISABLED) {
121+
throw new LocalizedException(__("The product is disabled"));
122+
}
116123
$options = $this->buyRequestBuilder->build($wishlistItem, (int) $product->getId());
117124
$result = $wishlist->addNewItem($product, $options);
118125

app/code/Magento/Wishlist/Model/Wishlist/UpdateProductsInWishlist.php

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

88
namespace Magento\Wishlist\Model\Wishlist;
99

10+
use Magento\Catalog\Model\Product\Attribute\Source\Status;
1011
use Magento\Framework\Exception\LocalizedException;
1112
use Magento\Wishlist\Model\Item as WishlistItem;
1213
use Magento\Wishlist\Model\ItemFactory as WishlistItemFactory;
@@ -95,6 +96,12 @@ private function updateItemInWishlist(Wishlist $wishlist, WishlistItemData $wish
9596
$wishlistItem = $this->wishlistItemFactory->create();
9697
$this->wishlistItemResource->load($wishlistItem, $wishlistItemData->getId());
9798
$wishlistItem->setDescription($wishlistItemData->getDescription());
99+
if ((int)$wishlistItemData->getQuantity() === 0) {
100+
throw new LocalizedException(__("The quantity of a wish list item cannot be 0"));
101+
}
102+
if ($wishlistItem->getProduct()->getStatus() == Status::STATUS_DISABLED) {
103+
throw new LocalizedException(__("The product is disabled"));
104+
}
98105
$resultItem = $wishlist->updateItem($wishlistItem, $options);
99106

100107
if (is_string($resultItem)) {

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public function resolve(
101101
}
102102

103103
$wishlistItems = $args['wishlistItems'];
104-
$wishlistItems = $this->getWishlistItems($wishlistItems);
104+
$wishlistItems = $this->getWishlistItems($wishlistItems, $wishlist);
105105
$wishlistOutput = $this->updateProductsInWishlist->execute($wishlist, $wishlistItems);
106106

107107
if (count($wishlistOutput->getErrors()) !== count($wishlistItems)) {
@@ -126,14 +126,27 @@ function (Error $error) {
126126
* Get DTO wishlist items
127127
*
128128
* @param array $wishlistItemsData
129+
* @param Wishlist $wishlist
129130
*
130131
* @return array
131132
*/
132-
private function getWishlistItems(array $wishlistItemsData): array
133+
private function getWishlistItems(array $wishlistItemsData, Wishlist $wishlist): array
133134
{
134135
$wishlistItems = [];
135136

136137
foreach ($wishlistItemsData as $wishlistItemData) {
138+
if (!isset($wishlistItemData['quantity'])) {
139+
$wishlistItem = $wishlist->getItem($wishlistItemData['wishlist_item_id']);
140+
if ($wishlistItem !== null) {
141+
$wishlistItemData['quantity'] = (float) $wishlistItem->getQty();
142+
}
143+
}
144+
if (!isset($wishlistItemData['description'])) {
145+
$wishlistItem = $wishlist->getItem($wishlistItemData['wishlist_item_id']);
146+
if ($wishlistItem !== null) {
147+
$wishlistItemData['description'] = $wishlistItem->getDescription();
148+
}
149+
}
137150
$wishlistItems[] = (new WishlistItemFactory())->create($wishlistItemData);
138151
}
139152

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
10+
<type name="Magento\StoreGraphQl\Model\Resolver\Store\StoreConfigDataProvider">
11+
<arguments>
12+
<argument name="extendedConfigData" xsi:type="array">
13+
<item name="magento_wishlist_general_is_enabled" xsi:type="string">wishlist/general/active</item>
14+
</argument>
15+
</arguments>
16+
</type>
17+
</config>

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ type Mutation {
4040
}
4141

4242
input WishlistItemInput @doc(description: "Defines the items to add to a wish list") {
43-
sku: String @doc(description: "The SKU of the product to add. For complex product types, specify the child product SKU")
44-
quantity: Float @doc(description: "The amount or number of items to add")
43+
sku: String! @doc(description: "The SKU of the product to add. For complex product types, specify the child product SKU")
44+
quantity: Float! @doc(description: "The amount or number of items to add")
4545
parent_sku: String @doc(description: "For complex product types, the SKU of the parent product")
4646
selected_options: [ID!] @doc(description: "An array of strings corresponding to options the customer selected")
4747
entered_options: [EnteredOptionInput!] @doc(description: "An array of options that the customer entered")
@@ -58,9 +58,9 @@ type RemoveProductsFromWishlistOutput @doc(description: "Contains the customer's
5858
}
5959

6060
input WishlistItemUpdateInput @doc(description: "Defines updates to items in a wish list") {
61-
wishlist_item_id: ID @doc(description: "The ID of the wishlist item to update")
61+
wishlist_item_id: ID! @doc(description: "The ID of the wishlist item to update")
6262
quantity: Float @doc(description: "The new amount or number of this item")
63-
description: String @doc(description: "Describes the update")
63+
description: String @doc(description: "Customer-entered comments about the item")
6464
selected_options: [ID!] @doc(description: "An array of strings corresponding to options the customer selected")
6565
entered_options: [EnteredOptionInput!] @doc(description: "An array of options that the customer entered")
6666
}
@@ -79,3 +79,7 @@ enum WishListUserInputErrorType {
7979
PRODUCT_NOT_FOUND
8080
UNDEFINED
8181
}
82+
83+
type StoreConfig {
84+
magento_wishlist_general_is_enabled: String @doc(description: "Indicates whether wishlists are enabled (1) or disabled (0)")
85+
}

0 commit comments

Comments
 (0)