Skip to content

Commit c5ff367

Browse files
committed
AC-15286::Order creation in backoffice with multiple products of which at least one contains custom options, leads to unwanted extra products to get added to the order
1 parent 7ef67e6 commit c5ff367

File tree

1 file changed

+12
-5
lines changed
  • app/code/Magento/Sales/Controller/Adminhtml/Order

1 file changed

+12
-5
lines changed

app/code/Magento/Sales/Controller/Adminhtml/Order/Create.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88
namespace Magento\Sales\Controller\Adminhtml\Order;
99

1010
use Magento\Backend\App\Action;
11+
use Magento\Catalog\Model\Product;
1112
use Magento\Framework\App\ObjectManager;
1213
use Magento\Framework\View\Result\PageFactory;
1314
use Magento\Backend\Model\View\Result\ForwardFactory;
1415
use Magento\Sales\Model\Order\Create\ValidateCoupon;
16+
use Magento\Catalog\Api\ProductRepositoryInterface;
1517

1618
/**
1719
* Adminhtml sales orders creation process controller
@@ -54,6 +56,11 @@ abstract class Create extends \Magento\Backend\App\Action
5456
*/
5557
private $validateCoupon;
5658

59+
/**
60+
* @var ProductRepositoryInterface
61+
*/
62+
private ProductRepositoryInterface $productRepository;
63+
5764
/**
5865
* @param Action\Context $context
5966
* @param \Magento\Catalog\Helper\Product $productHelper
@@ -68,13 +75,16 @@ public function __construct(
6875
\Magento\Framework\Escaper $escaper,
6976
PageFactory $resultPageFactory,
7077
ForwardFactory $resultForwardFactory,
78+
?ProductRepositoryInterface $productRepository = null,
7179
?ValidateCoupon $validateCoupon = null
7280
) {
7381
parent::__construct($context);
7482
$productHelper->setSkipSaleableCheck(true);
7583
$this->escaper = $escaper;
7684
$this->resultPageFactory = $resultPageFactory;
7785
$this->resultForwardFactory = $resultForwardFactory;
86+
$this->productRepository = $productRepository ?: ObjectManager::getInstance()
87+
->get(ProductRepositoryInterface::class);
7888
$this->validateCoupon = $validateCoupon ?: ObjectManager::getInstance()->get(ValidateCoupon::class);
7989
}
8090

@@ -281,11 +291,8 @@ function ($v) {
281291
}
282292
if ($this->_getQuote()->hasProductId((int)$productId) && !$hasOptionsInConfig) {
283293
try {
284-
/** @var \Magento\Catalog\Model\Product $product */
285-
$product = $this
286-
->_objectManager
287-
->create(\Magento\Catalog\Model\Product::class)
288-
->load($productId);
294+
/** @var Product $product */
295+
$product = $this->productRepository->getById($productId);
289296
if ($product->getId() && $product->getHasOptions()) {
290297
$hasRequired = false;
291298
foreach ($product->getOptions() as $option) {

0 commit comments

Comments
 (0)