Skip to content

Commit 1b08a0c

Browse files
author
Prabhu Ram
committed
MC-36897: [GraphQl] Store config and schema modifications for Wishlist
- Added validation for disabled product.
1 parent 73760de commit 1b08a0c

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

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

Lines changed: 4 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;
@@ -116,6 +117,9 @@ private function addItemToWishlist(Wishlist $wishlist, WishlistItem $wishlistIte
116117
if ($wishlistItem->getQuantity() == 0) {
117118
throw new LocalizedException(__("The quantity of a wish list item cannot be 0"));
118119
}
120+
if ($product->getStatus() == Status::STATUS_DISABLED) {
121+
throw new LocalizedException(__("The product is disabled"));
122+
}
119123
$options = $this->buyRequestBuilder->build($wishlistItem, (int) $product->getId());
120124
$result = $wishlist->addNewItem($product, $options);
121125

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

Lines changed: 4 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;
@@ -98,6 +99,9 @@ private function updateItemInWishlist(Wishlist $wishlist, WishlistItemData $wish
9899
if ($wishlistItemData->getQuantity() == 0) {
99100
throw new LocalizedException(__("The quantity of a wish list item cannot be 0"));
100101
}
102+
if ($wishlistItem->getProduct()->getStatus() == Status::STATUS_DISABLED) {
103+
throw new LocalizedException(__("The product is disabled"));
104+
}
101105
$resultItem = $wishlist->updateItem($wishlistItem, $options);
102106

103107
if (is_string($resultItem)) {

0 commit comments

Comments
 (0)