Skip to content

Commit ba849cc

Browse files
committed
MC-40417: Unexpected behavior when updating a Product with a Customizable Option (File) in the Wish List
1 parent f067066 commit ba849cc

File tree

2 files changed

+30
-16
lines changed

2 files changed

+30
-16
lines changed

app/code/Magento/Wishlist/Controller/Index/Add.php

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,20 @@
66
namespace Magento\Wishlist\Controller\Index;
77

88
use Magento\Catalog\Api\ProductRepositoryInterface;
9-
use Magento\Framework\App\Action;
9+
use Magento\Customer\Model\Session;
10+
use Magento\Framework\App\Action\Context;
1011
use Magento\Framework\App\Action\HttpPostActionInterface;
12+
use Magento\Framework\Controller\Result\Redirect;
1113
use Magento\Framework\Data\Form\FormKey\Validator;
14+
use Magento\Framework\Exception\LocalizedException;
1215
use Magento\Framework\Exception\NotFoundException;
1316
use Magento\Framework\Exception\NoSuchEntityException;
1417
use Magento\Framework\Controller\ResultFactory;
1518
use Magento\Framework\App\ObjectManager;
1619
use Magento\Framework\UrlInterface;
1720
use Magento\Framework\App\Response\RedirectInterface;
21+
use Magento\Framework\Controller\ResultInterface;
22+
use Magento\Wishlist\Controller\WishlistProviderInterface;
1823

1924
/**
2025
* Wish list Add controller
@@ -24,12 +29,12 @@
2429
class Add extends \Magento\Wishlist\Controller\AbstractIndex implements HttpPostActionInterface
2530
{
2631
/**
27-
* @var \Magento\Wishlist\Controller\WishlistProviderInterface
32+
* @var WishlistProviderInterface
2833
*/
2934
protected $wishlistProvider;
3035

3136
/**
32-
* @var \Magento\Customer\Model\Session
37+
* @var Session
3338
*/
3439
protected $_customerSession;
3540

@@ -43,23 +48,29 @@ class Add extends \Magento\Wishlist\Controller\AbstractIndex implements HttpPost
4348
*/
4449
protected $formKeyValidator;
4550

51+
/**
52+
* @var RedirectInterface
53+
*/
4654
private $redirect;
4755

56+
/**
57+
* @var mixed UrlInterface
58+
*/
4859
private $urlBuilder;
4960

5061
/**
51-
* @param Action\Context $context
52-
* @param \Magento\Customer\Model\Session $customerSession
53-
* @param \Magento\Wishlist\Controller\WishlistProviderInterface $wishlistProvider
62+
* @param Context $context
63+
* @param Session $customerSession
64+
* @param WishlistProviderInterface $wishlistProvider
5465
* @param ProductRepositoryInterface $productRepository
5566
* @param Validator $formKeyValidator
56-
* @param RedirectInterface $redirect
57-
* @param UrlInterface $urlBuilder
67+
* @param RedirectInterface|null $redirect
68+
* @param UrlInterface|null $urlBuilder
5869
*/
5970
public function __construct(
60-
Action\Context $context,
61-
\Magento\Customer\Model\Session $customerSession,
62-
\Magento\Wishlist\Controller\WishlistProviderInterface $wishlistProvider,
71+
Context $context,
72+
Session $customerSession,
73+
WishlistProviderInterface $wishlistProvider,
6374
ProductRepositoryInterface $productRepository,
6475
Validator $formKeyValidator,
6576
RedirectInterface $redirect = null,
@@ -75,15 +86,17 @@ public function __construct(
7586
}
7687

7788
/**
78-
* @return \Magento\Framework\Controller\Result\Redirect|\Magento\Framework\Controller\ResultInterface
89+
* Adding new item
90+
*
91+
* @return ResultInterface
7992
* @throws NotFoundException
8093
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
8194
* @SuppressWarnings(PHPMD.NPathComplexity)
8295
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
8396
*/
8497
public function execute()
8598
{
86-
/** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
99+
/** @var Redirect $resultRedirect */
87100
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
88101
if (!$this->formKeyValidator->validate($this->getRequest())) {
89102
return $resultRedirect->setPath('*/');
@@ -126,7 +139,7 @@ public function execute()
126139

127140
$result = $wishlist->addNewItem($product, $buyRequest);
128141
if (is_string($result)) {
129-
throw new \Magento\Framework\Exception\LocalizedException(__($result));
142+
throw new LocalizedException(__($result));
130143
}
131144
if ($wishlist->isObjectNew()) {
132145
$wishlist->save();
@@ -153,7 +166,7 @@ public function execute()
153166
]
154167
);
155168
// phpcs:disable Magento2.Exceptions.ThrowCatch
156-
} catch (\Magento\Framework\Exception\LocalizedException $e) {
169+
} catch (LocalizedException $e) {
157170
$this->messageManager->addErrorMessage(
158171
__('We can\'t add the item to Wish List right now: %1.', $e->getMessage())
159172
);

app/code/Magento/Wishlist/Test/Mftf/Test/StorefrontAddSimpleProductWithCustomizableFileOptionToWishlistTest.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
1111
<test name="StorefrontAddSimpleProductWithCustomizableFileOptionToWishlistTest">
1212
<annotations>
13-
<stories value="Wishlist"/>
13+
<features value="Wishlist"/>
14+
<stories value="Add product to wishlist"/>
1415
<title value="Add simple product with customizable file option to wishlist"/>
1516
<description value="Add simple Product with customizable file option to Wishlist and verify customizable options are preserved"/>
1617
<severity value="CRITICAL"/>

0 commit comments

Comments
 (0)