Skip to content

Commit c26eb79

Browse files
committed
Merge remote-tracking branch 'origin/MC-40417' into 2.4-develop-pr131
2 parents 45f27d6 + 3a3c70f commit c26eb79

File tree

4 files changed

+139
-15
lines changed

4 files changed

+139
-15
lines changed

app/code/Magento/Catalog/view/frontend/templates/product/view/options/type/file.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
id="<?= /* @noEscape */ $_fileName ?>"
5252
class="product-custom-option<?= $_option->getIsRequire() ? ' required' : '' ?>"
5353
<?= $_fileExists ? 'disabled="disabled"' : '' ?> />
54-
<input type="hidden" name="<?= /* @noEscape */ $_fieldNameAction ?>"
54+
<input type="hidden" class="product-custom-option" name="<?= /* @noEscape */ $_fieldNameAction ?>"
5555
value="<?= /* @noEscape */ $_fieldValueAction ?>" />
5656
<?php if ($_option->getFileExtension()):?>
5757
<p class="note">

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

Lines changed: 47 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +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;
18+
use Magento\Framework\App\ObjectManager;
19+
use Magento\Framework\UrlInterface;
20+
use Magento\Framework\App\Response\RedirectInterface;
21+
use Magento\Framework\Controller\ResultInterface;
22+
use Magento\Wishlist\Controller\WishlistProviderInterface;
1523

1624
/**
1725
* Wish list Add controller
@@ -21,12 +29,12 @@
2129
class Add extends \Magento\Wishlist\Controller\AbstractIndex implements HttpPostActionInterface
2230
{
2331
/**
24-
* @var \Magento\Wishlist\Controller\WishlistProviderInterface
32+
* @var WishlistProviderInterface
2533
*/
2634
protected $wishlistProvider;
2735

2836
/**
29-
* @var \Magento\Customer\Model\Session
37+
* @var Session
3038
*/
3139
protected $_customerSession;
3240

@@ -41,38 +49,54 @@ class Add extends \Magento\Wishlist\Controller\AbstractIndex implements HttpPost
4149
protected $formKeyValidator;
4250

4351
/**
44-
* @param Action\Context $context
45-
* @param \Magento\Customer\Model\Session $customerSession
46-
* @param \Magento\Wishlist\Controller\WishlistProviderInterface $wishlistProvider
52+
* @var RedirectInterface
53+
*/
54+
private $redirect;
55+
56+
/**
57+
* @var UrlInterface
58+
*/
59+
private $urlBuilder;
60+
61+
/**
62+
* @param Context $context
63+
* @param Session $customerSession
64+
* @param WishlistProviderInterface $wishlistProvider
4765
* @param ProductRepositoryInterface $productRepository
4866
* @param Validator $formKeyValidator
67+
* @param RedirectInterface|null $redirect
68+
* @param UrlInterface|null $urlBuilder
4969
*/
5070
public function __construct(
51-
Action\Context $context,
52-
\Magento\Customer\Model\Session $customerSession,
53-
\Magento\Wishlist\Controller\WishlistProviderInterface $wishlistProvider,
71+
Context $context,
72+
Session $customerSession,
73+
WishlistProviderInterface $wishlistProvider,
5474
ProductRepositoryInterface $productRepository,
55-
Validator $formKeyValidator
75+
Validator $formKeyValidator,
76+
RedirectInterface $redirect = null,
77+
UrlInterface $urlBuilder = null
5678
) {
5779
$this->_customerSession = $customerSession;
5880
$this->wishlistProvider = $wishlistProvider;
5981
$this->productRepository = $productRepository;
6082
$this->formKeyValidator = $formKeyValidator;
83+
$this->redirect = $redirect ?: ObjectManager::getInstance()->get(RedirectInterface::class);
84+
$this->urlBuilder = $urlBuilder ?: ObjectManager::getInstance()->get(UrlInterface::class);
6185
parent::__construct($context);
6286
}
6387

6488
/**
6589
* Adding new item
6690
*
67-
* @return \Magento\Framework\Controller\Result\Redirect
91+
* @return ResultInterface
6892
* @throws NotFoundException
6993
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
7094
* @SuppressWarnings(PHPMD.NPathComplexity)
7195
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
7296
*/
7397
public function execute()
7498
{
75-
/** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
99+
/** @var Redirect $resultRedirect */
76100
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
77101
if (!$this->formKeyValidator->validate($this->getRequest())) {
78102
return $resultRedirect->setPath('*/');
@@ -115,7 +139,7 @@ public function execute()
115139

116140
$result = $wishlist->addNewItem($product, $buyRequest);
117141
if (is_string($result)) {
118-
throw new \Magento\Framework\Exception\LocalizedException(__($result));
142+
throw new LocalizedException(__($result));
119143
}
120144
if ($wishlist->isObjectNew()) {
121145
$wishlist->save();
@@ -142,7 +166,7 @@ public function execute()
142166
]
143167
);
144168
// phpcs:disable Magento2.Exceptions.ThrowCatch
145-
} catch (\Magento\Framework\Exception\LocalizedException $e) {
169+
} catch (LocalizedException $e) {
146170
$this->messageManager->addErrorMessage(
147171
__('We can\'t add the item to Wish List right now: %1.', $e->getMessage())
148172
);
@@ -153,7 +177,16 @@ public function execute()
153177
);
154178
}
155179

180+
if ($this->getRequest()->isAjax()) {
181+
$url = $this->urlBuilder->getUrl('*', $this->redirect->updatePathParams(['wishlist_id' => $wishlist->getId()]));
182+
/** @var Json $resultJson */
183+
$resultJson = $this->resultFactory->create(ResultFactory::TYPE_JSON);
184+
$resultJson->setData(['backUrl' => $url]);
185+
186+
return $resultJson;
187+
}
156188
$resultRedirect->setPath('*', ['wishlist_id' => $wishlist->getId()]);
189+
157190
return $resultRedirect;
158191
}
159192
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
11+
<actionGroup name="StorefrontCustomerUpdateProductInWishlistActionGroup" extends="StorefrontCustomerAddProductToWishlistActionGroup">
12+
<annotations>
13+
<description>Updates the provided Product to the Wish List from the Storefront Product page. Validates that the Success Message is present and correct.</description>
14+
</annotations>
15+
<see selector="{{StorefrontCustomerWishlistSection.successMsg}}" userInput="{{productVar.name}} has been updated in your Wish List." stepKey="addProductToWishlistSeeProductNameAddedToWishlist"/>
16+
</actionGroup>
17+
</actionGroups>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
11+
<test name="StorefrontAddSimpleProductWithCustomizableFileOptionToWishlistTest">
12+
<annotations>
13+
<features value="Wishlist"/>
14+
<stories value="Add product to wishlist"/>
15+
<title value="Add simple product with customizable file option to wishlist"/>
16+
<description value="Add simple Product with customizable file option to Wishlist and verify customizable options are preserved"/>
17+
<severity value="CRITICAL"/>
18+
<testCaseId value="MC-41040"/>
19+
<useCaseId value="MC-40417"/>
20+
<group value="wishlist"/>
21+
</annotations>
22+
<before>
23+
<createData entity="Simple_US_Customer" stepKey="createCustomer"/>
24+
<createData entity="SimpleProduct2" stepKey="createProduct">
25+
<field key="price">100.00</field>
26+
</createData>
27+
<updateData entity="productWithFileOption" createDataKey="createProduct" stepKey="updateProductWithOptions">
28+
<requiredEntity createDataKey="createProduct"/>
29+
</updateData>
30+
</before>
31+
<after>
32+
<actionGroup ref="AdminLogoutActionGroup" stepKey="logout"/>
33+
<deleteData createDataKey="createCustomer" stepKey="deleteCustomer"/>
34+
<deleteData createDataKey="createProduct" stepKey="deleteProduct1"/>
35+
</after>
36+
37+
<!-- Login as a customer -->
38+
<actionGroup ref="LoginToStorefrontActionGroup" stepKey="loginToStorefrontAccount">
39+
<argument name="Customer" value="$createCustomer$"/>
40+
</actionGroup>
41+
42+
<!-- Open Product page -->
43+
<actionGroup ref="StorefrontOpenProductPageActionGroup" stepKey="openProductPage">
44+
<argument name="productUrl" value="$createProduct.custom_attributes[url_key]$"/>
45+
</actionGroup>
46+
<attachFile userInput="adobe-base.jpg" selector="{{StorefrontProductInfoMainSection.addLinkFileUploadFile(ProductOptionFile.title)}}" stepKey="fillUploadFile"/>
47+
48+
<!-- Add product to the wishlist -->
49+
<actionGroup ref="StorefrontCustomerAddProductToWishlistActionGroup" stepKey="addProductWithOptionToWishlist">
50+
<argument name="productVar" value="$createProduct$"/>
51+
</actionGroup>
52+
53+
<!-- Assert product is present in wishlist -->
54+
<actionGroup ref="AssertProductIsPresentInWishListActionGroup" stepKey="assertProductPresent">
55+
<argument name="productName" value="$createProduct.name$"/>
56+
<argument name="productPrice" value="$109.99"/>
57+
</actionGroup>
58+
59+
<!-- Edit wishlist product -->
60+
<actionGroup ref="StorefrontCustomerUpdateWishlistItemActionGroup" stepKey="clickEditWishlistItem">
61+
<argument name="productName" value="$createProduct.name$"/>
62+
</actionGroup>
63+
64+
<!-- Update product in wishlist from product page -->
65+
<actionGroup ref="StorefrontCustomerUpdateProductInWishlistActionGroup" stepKey="updateProductWithOptionInWishlist">
66+
<argument name="productVar" value="$createProduct$"/>
67+
</actionGroup>
68+
69+
<actionGroup ref="AssertProductIsPresentInWishListActionGroup" stepKey="assertProductPresent2">
70+
<argument name="productName" value="$createProduct.name$"/>
71+
<argument name="productPrice" value="$109.99"/>
72+
</actionGroup>
73+
</test>
74+
</tests>

0 commit comments

Comments
 (0)