-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Open
Labels
Area: OrderComponent: AdminIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedPriority: P2A defect with this priority could have functionality issues which are not to expectations.A defect with this priority could have functionality issues which are not to expectations.Reported on 2.4.7Indicates original Magento version for the Issue report.Indicates original Magento version for the Issue report.Reproduced on 2.4.xThe issue has been reproduced on latest 2.4-develop branchThe issue has been reproduced on latest 2.4-develop branch
Description
Preconditions and environment
- Magento version: 2.4.7-p6, 2.4.8-p1, 2.4-develop (tried with commit b209408) (for what it's worth, this bug didn't happen on Magento 2.3.6-p1)
Steps to reproduce
Everything happens in the backoffice:
- Create a simple product, nothing special
- Create a second simple product, but this time with 2 custom options, of which one is a file upload (see screenshot)

- Reindex
- Still in backoffice, go to Sales > Orders > Create New Order
- Click 'Create new Customer' button
- Click 'Add Products' button
- Add the simple product with custom options, just select one of the 2 radio buttons, and pick qty: 10, nothing else
- Click 'Add Selected Product(s) to Order' button
- Click 'Add Products' button again
- Now select the other simple product, the one without custom options, qty: 1
- Click 'Add Selected Product(s) to Order' again
Expected result
We expect 2 item rows in the order:
- simple product with custom options - qty 10
- simple product - qty 1
Actual result
We see 3 item rows in the order:
- simple product with custom options - qty 10
- simple product with custom options - qty 1 - and some errors about missing required options
- simple product - qty 1

Additional information
This happens because with the second product you add, a POST request goes to the url /sales/order_create/loadBlock/key/{redacted}/block/search,items,shipping_method,totals,giftmessage,billing_method?isAjax=true
and contains the following in the payload:
item[2][options][files_prefix] => item_2_
item[1][qty] => 1
customer_id =>
store_id => 1
currency_id =>
form_key => {redacted}
payment[method] => checkmo
reset_shipping => 1
json => 1
as_js_varname => iFrameResponse
form_key => {redacted}
The first line is the one that causes problems and causes the unwanted product to be added to the cart
Temporary workaround
I have figured out this very ugly workaround that prevents this, but I'm very sure that this isn't the best solution. But no idea what the best solution would be ... (probably to fix the JS to not send data for product items you didn't add?)
diff --git a/app/code/Magento/Sales/Model/AdminOrder/Create.php b/app/code/Magento/Sales/Model/AdminOrder/Create.php
index 4b1868e6852..68ed656d8e3 100644
--- a/app/code/Magento/Sales/Model/AdminOrder/Create.php
+++ b/app/code/Magento/Sales/Model/AdminOrder/Create.php
@@ -1142,6 +1142,20 @@ class Create extends \Magento\Framework\DataObject implements \Magento\Checkout\
public function addProducts(array $products)
{
foreach ($products as $productId => $config) {
+ // VERY DIRTY HACK TO PREVENT ADDING UNWANTED PRODUCTS TO ORDER, WHEN CREATING ORDER IN ADMIN
+ $configToIgnore = [
+ 'options' => [
+ 'files_prefix' => sprintf('item_%d_', (int) $productId),
+ ],
+ ];
+ $strippedConfigToCompare = $config;
+ unset($strippedConfigToCompare['_processing_params']);
+
+ if ($strippedConfigToCompare === $configToIgnore) {
+ continue;
+ }
+ // END VERY DIRTY HACK
+
$config['qty'] = isset($config['qty']) ? (double)$config['qty'] : 1;
try {
$this->addProduct($productId, $config);
Release note
No response
Triage and priority
- Severity: S0 - Affects critical data or functionality and leaves users without workaround.
- Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
- Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
- Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
- Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.
Metadata
Metadata
Assignees
Labels
Area: OrderComponent: AdminIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedPriority: P2A defect with this priority could have functionality issues which are not to expectations.A defect with this priority could have functionality issues which are not to expectations.Reported on 2.4.7Indicates original Magento version for the Issue report.Indicates original Magento version for the Issue report.Reproduced on 2.4.xThe issue has been reproduced on latest 2.4-develop branchThe issue has been reproduced on latest 2.4-develop branch
Type
Projects
Status
Ready for Development