Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MC-36779: Product still present in the Wish List after added to order #31110

Merged
merged 6 commits into from
Dec 12, 2020
Merged
1 change: 1 addition & 0 deletions app/code/Magento/Sales/Model/AdminOrder/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -984,6 +984,7 @@ public function applySidebarData($data)
);
if ($item->getId()) {
$this->addProduct($item->getProduct(), $item->getBuyRequest()->toArray());
$this->removeItem($itemId, 'wishlist');
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,15 @@
<see selector="{{AdminCreateOrderWishListSection.wishListBlock}}" userInput="$$simpleProduct.name$$" stepKey="seeSimpleProductInWishList"/>
<see selector="{{AdminCreateOrderWishListSection.wishListBlock}}" userInput="$$createConfigProduct.name$$" stepKey="seeConfigurableProductInWishList"/>

<!-- Add products to order from Wish List -->
<!-- Move products to order from Wish List -->
<waitForElementVisible selector="{{AdminCreateOrderWishListSection.addProductToOrderCheckBox($$simpleProduct.name$$)}}" stepKey="waitForCheckBoxToVisible"/>
<click selector="{{AdminCreateOrderWishListSection.addProductToOrderCheckBox($$simpleProduct.name$$)}}" stepKey="selectProductToAddToOrder"/>
<click selector="{{AdminCustomerCreateNewOrderSection.updateChangesBtn}}" stepKey="clickUpdateChangesButton"/>
<click selector="{{AdminCreateOrderWishListSection.addConfigProductToOrder($$createConfigProduct.name$$)}}" stepKey="AddConfigurableProductToOrder"/>
<waitForElementVisible selector="{{AdminOrderFormConfigureProductSection.optionSelect($$createConfigProductAttribute.default_frontend_label$$)}}" stepKey="waitForConfigurablePopover"/>
<selectOption selector="{{AdminOrderFormConfigureProductSection.optionSelect($$createConfigProductAttribute.default_frontend_label$$)}}" userInput="$$getConfigAttributeOption1.label$$" stepKey="selectConfigurableOption"/>
<click selector="{{AdminOrderFormConfigureProductSection.ok}}" stepKey="clickOkButton"/>
<click selector="{{AdminCustomerCreateNewOrderSection.updateChangesBtn}}" stepKey="clickOnUpdateButton"/>
<comment userInput="Action should be removed but replaced with comment due to backward compatibility" stepKey="clickOnUpdateButton"/>
<waitForPageLoad stepKey="waitForAdminOrderItemsOrderedSectionPageLoad1"/>

<!-- Assert Products in Order item section -->
Expand Down Expand Up @@ -171,9 +172,9 @@
<dontSee selector="{{AdminCreateOrderShoppingCartSection.shoppingCartBlock}}" userInput="$$simpleProduct.name$$" stepKey="donSeeProductInShoppingCart"/>
<dontSee selector="{{AdminCreateOrderShoppingCartSection.shoppingCartBlock}}" userInput="$$simpleProduct1.name$$" stepKey="dontSeeSecondProductInShoppingCart"/>

<!-- After move, assert products are present in Wish List section -->
<see selector="{{AdminCreateOrderWishListSection.wishListBlock}}" userInput="$$simpleProduct.name$$" stepKey="seeSimpleProductInWishList1"/>
<see selector="{{AdminCreateOrderWishListSection.wishListBlock}}" userInput="$$createConfigProduct.name$$" stepKey="seeConfigurableProductInWishList1"/>
<!-- After move, assert products are not present in Wish List section -->
<dontSee selector="{{AdminCreateOrderWishListSection.wishListBlock}}" userInput="$$simpleProduct.name$$" stepKey="seeSimpleProductInWishList1"/>
<dontSee selector="{{AdminCreateOrderWishListSection.wishListBlock}}" userInput="$$createConfigProduct.name$$" stepKey="seeConfigurableProductInWishList1"/>

<!-- After move, assert products are present in order items section -->
<see selector="{{AdminOrderItemsOrderedSection.productName}}" userInput="$$simpleProduct.name$$" stepKey="seeSimpleProductInOrderItemGrid1"/>
Expand Down
18 changes: 15 additions & 3 deletions app/code/Magento/Sales/view/adminhtml/web/order/create/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -942,7 +942,8 @@ define([
*/
sidebarConfigureProduct: function (listType, productId, itemId) {
// create additional fields
var params = {};
var params = {},
isWishlist = !!itemId;
params.reset_shipping = true;
params.add_product = productId;
this.prepareParams(params);
Expand All @@ -963,10 +964,18 @@ define([
}.bind(this));
// response handler
productConfigure.setOnLoadIFrameCallback(listType, function (response) {
var areas = ['items', 'shipping_method', 'billing_method', 'totals', 'giftmessage'];

if (!response.ok) {
return;
}
this.loadArea(['items', 'shipping_method', 'billing_method', 'totals', 'giftmessage'], true);
if (isWishlist) {
this.removeSidebarItem(itemId, 'wishlist').done(function () {
this.loadArea(areas, true);
}.bind(this));
} else {
this.loadArea(areas, true);
}
}.bind(this));
// show item configuration
itemId = itemId ? itemId : productId;
Expand All @@ -975,7 +984,10 @@ define([
},

removeSidebarItem: function (id, from) {
this.loadArea(['sidebar_' + from], 'sidebar_data_' + from, {remove_item: id, from: from});
return this.loadArea(['sidebar_' + from], 'sidebar_data_' + from, {
remove_item: id,
from: from
});
},

itemsUpdate: function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Magento\Store\Model\StoreManagerInterface;
use Magento\TestFramework\Quote\Model\GetQuoteByReservedOrderId;
use Magento\TestFramework\TestCase\AbstractBackendController;
use Magento\Wishlist\Model\Wishlist;

/**
* Class checks create order load block controller.
Expand Down Expand Up @@ -201,6 +202,35 @@ public function testMoveFromOrderToShoppingCart(): void
$this->quoteIdsToRemove[] = $customerCart->getId();
}

/**
* Check that Wishlist item is deleted after it has been added to Order.
*
* @return void
* @magentoDataFixture Magento/Wishlist/_files/wishlist_with_simple_product.php
*/
public function testAddProductToOrderFromWishList(): void
{
/** @var Wishlist $wishlist */
$wishlist = $this->_objectManager->create(Wishlist::class);
$wishlistItems = $wishlist->loadByCustomerId(1)->getItemCollection();
$this->assertCount(1, $wishlistItems);

$post = $this->hydratePost([
'sidebar' => [
'add_wishlist_item' => [
$wishlistItems->getFirstItem()->getId() => 1,
],
],
]);
$params = $this->hydrateParams();
$this->dispatchWitParams($params, $post);

$wishlistItems->clear()->load();
$this->assertEmpty($wishlistItems);
$quoteItems = $this->session->getQuote()->getItemsCollection();
$this->assertCount(1, $quoteItems);
}

/**
* Check customer quotes
*
Expand Down