diff --git a/app/code/Magento/Sales/Model/AdminOrder/Create.php b/app/code/Magento/Sales/Model/AdminOrder/Create.php index 3e708d1a0df02..5d621f1632837 100644 --- a/app/code/Magento/Sales/Model/AdminOrder/Create.php +++ b/app/code/Magento/Sales/Model/AdminOrder/Create.php @@ -984,6 +984,7 @@ public function applySidebarData($data) ); if ($item->getId()) { $this->addProduct($item->getProduct(), $item->getBuyRequest()->toArray()); + $this->removeItem($itemId, 'wishlist'); } } } diff --git a/app/code/Magento/Sales/Test/Mftf/Test/CreateOrderFromEditCustomerPageTest.xml b/app/code/Magento/Sales/Test/Mftf/Test/CreateOrderFromEditCustomerPageTest.xml index 367c50359701c..08d5776b79ea0 100644 --- a/app/code/Magento/Sales/Test/Mftf/Test/CreateOrderFromEditCustomerPageTest.xml +++ b/app/code/Magento/Sales/Test/Mftf/Test/CreateOrderFromEditCustomerPageTest.xml @@ -136,14 +136,15 @@ - + + - + @@ -171,9 +172,9 @@ - - - + + + diff --git a/app/code/Magento/Sales/view/adminhtml/web/order/create/scripts.js b/app/code/Magento/Sales/view/adminhtml/web/order/create/scripts.js index ba93f5f88c387..9454fe17fe2d2 100644 --- a/app/code/Magento/Sales/view/adminhtml/web/order/create/scripts.js +++ b/app/code/Magento/Sales/view/adminhtml/web/order/create/scripts.js @@ -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); @@ -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; @@ -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 () { diff --git a/dev/tests/integration/testsuite/Magento/Sales/Controller/Adminhtml/Order/Create/LoadBlockTest.php b/dev/tests/integration/testsuite/Magento/Sales/Controller/Adminhtml/Order/Create/LoadBlockTest.php index b6aa44bac1c4d..529b491269643 100644 --- a/dev/tests/integration/testsuite/Magento/Sales/Controller/Adminhtml/Order/Create/LoadBlockTest.php +++ b/dev/tests/integration/testsuite/Magento/Sales/Controller/Adminhtml/Order/Create/LoadBlockTest.php @@ -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. @@ -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 *