diff --git a/app/code/Magento/Sales/Block/Adminhtml/Order/Create/AbstractCreate.php b/app/code/Magento/Sales/Block/Adminhtml/Order/Create/AbstractCreate.php index 85b0ed891b64f..f335705e3deee 100644 --- a/app/code/Magento/Sales/Block/Adminhtml/Order/Create/AbstractCreate.php +++ b/app/code/Magento/Sales/Block/Adminhtml/Order/Create/AbstractCreate.php @@ -160,4 +160,22 @@ public function convertPrice($value, $format = true) ) : $this->priceCurrency->convert($value, $this->getStore()); } + + /** + * If item is quote or wishlist we need to get product from it. + * + * @param $item + * + * @return Product + */ + public function getProduct($item) + { + if ($item instanceof Product) { + $product = $item; + } else { + $product = $item->getProduct(); + } + + return $product; + } } diff --git a/app/code/Magento/Sales/Test/Unit/Block/Adminhtml/Order/Create/AbstractCreateTest.php b/app/code/Magento/Sales/Test/Unit/Block/Adminhtml/Order/Create/AbstractCreateTest.php index 447fd7791ecbd..e010674ca354e 100644 --- a/app/code/Magento/Sales/Test/Unit/Block/Adminhtml/Order/Create/AbstractCreateTest.php +++ b/app/code/Magento/Sales/Test/Unit/Block/Adminhtml/Order/Create/AbstractCreateTest.php @@ -3,8 +3,10 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ + namespace Magento\Sales\Test\Unit\Block\Adminhtml\Order\Create; +use Magento\Catalog\Model\Product; use Magento\Catalog\Pricing\Price\FinalPrice; class AbstractCreateTest extends \PHPUnit\Framework\TestCase @@ -67,4 +69,34 @@ public function testGetItemPrice() ->willReturn($resultPrice); $this->assertEquals($resultPrice, $this->model->getItemPrice($this->productMock)); } + + /** + * @param $item + * + * @dataProvider getProductDataProvider + */ + public function testGetProduct($item) + { + $product = $this->model->getProduct($item); + + self::assertInstanceOf(Product::class, $product); + } + + /** + * DataProvider for testGetProduct. + * + * @return array + */ + public function getProductDataProvider() + { + $productMock = $this->createMock(Product::class); + + $itemMock = $this->createMock(\Magento\Wishlist\Model\Item::class); + $itemMock->expects($this->once())->method('getProduct')->willReturn($productMock); + + return [ + [$productMock], + [$itemMock], + ]; + } } diff --git a/app/code/Magento/Sales/view/adminhtml/templates/order/create/sidebar/items.phtml b/app/code/Magento/Sales/view/adminhtml/templates/order/create/sidebar/items.phtml index 2ca2420934519..2dbf717f73439 100644 --- a/app/code/Magento/Sales/view/adminhtml/templates/order/create/sidebar/items.phtml +++ b/app/code/Magento/Sales/view/adminhtml/templates/order/create/sidebar/items.phtml @@ -67,11 +67,7 @@ canDisplayPrice()): ?> - getDataId() == 'cart'): ?> - getItemPrice($_item->getProduct()) ?> - - getItemPrice($_item) ?> - + getItemPrice($block->getProduct($_item)) ?>