magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.48k stars 9.29k forks source link

Shipping Label is created although shipment creation fails due to items being out of stock #31555

Open HenKun opened 3 years ago

HenKun commented 3 years ago

Preconditions (*)

Magento 2.4.1 Netresearch DHL Shipping Module (dhl/shipping-m2) v1.3.0 (but it will happen with any other carrier that is able to print shipping labels)

Steps to reproduce (*)

Expected result (*)

  1. Message is shown: "Not all of your products are available in the requested quantity."
  2. Shipping Label is not created, since shipment creation failed

Actual result (*)

  1. Message is shown: "Not all of your products are available in the requested quantity." image

  2. Shipping Label is created in background without any immediate notice and without any comment on the order that a label was created although shipment failed.

Reason

The creation of the label takes place in Magento\Shipping\Controller\Adminhtml\Order\Shipment\Save::execute on line 153. The check for out of stock items takes place in Magento\Shipping\Controller\Adminhtml\Order\Shipment\Save::execute on line 157 (i.e. somewhere in _saveShipment), so after the labels was already created successfully. By saying that, all errors that might occur in Magento\Shipping\Controller\Adminhtml\Order\Shipment\Save::_saveShipment result in a failed shipment but in a successfully created shipping label in the background.

Proposed solutions

  1. Defer creation of shipping label to after shipment was created successfully or
  2. Cancel shipping label if shipment failed.

Please provide Severity assessment for the Issue as Reporter. This information will help during Confirmation and Issue triage processes.

m2-assistant[bot] commented 3 years ago

Hi @HenKun. Thank you for your report. To help us process this issue please make sure that you provided the following information:

Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:

@magento give me 2.4-develop instance - upcoming 2.4.x release

For more details, please, review the Magento Contributor Assistant documentation.

Please, add a comment to assign the issue: @magento I am working on this


:clock10: You can find the schedule on the Magento Community Calendar page.

:telephone_receiver: The triage of issues happens in the queue order. If you want to speed up the delivery of your contribution, please join the Community Contributions Triage session to discuss the appropriate ticket.

:movie_camera: You can find the recording of the previous Community Contributions Triage on the Magento Youtube Channel

:pencil2: Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel

m2-assistant[bot] commented 3 years ago

Hi @engcom-Alfa. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

engcom-Alfa commented 3 years ago

Hi @HenKun . Thank you for your report!

Unfortunately, we are not able to reproduce the issue on а clean 2.4-develop. Everything works as expected.

Precondition: Configure DHL shipping method;

Manual testing scenario:

  1. Create an order with an in stock product and shipping method of carrier that is able to print shipping labels Screenshot from 2021-02-17 13-00-43
  2. Set the quantity of product to 0;
  3. Go to order and click "Ship"
  4. Check the checkbox "Create Shipping Label"

Actual Result: Shipping Label was successfully created

Screenshot from 2021-02-17 13-14-14

@HenKun Maybe we missed something? Could you take a look? Thanks!

HenKun commented 3 years ago

@engcom-Alfa

The steps seem correct, however I am wondering why your shipment could be created successfully if the product is not in stock (after setting stock to 0 manually).

Normal behavior:

The case on hand:

So maybe these config settings were not correct:

So the issue on hand will occur, if the shipment fails, i.e. shipment cannot be created if the qty of the product is already 0.

You can even simulate the problem by throwing an arbitrary exception in Magento\Shipping\Controller\Adminhtml\Order\Shipment\Save::_saveShipment. And indeed, the shipment can fail on whatever failure happens in _saveShipment.

HenKun commented 3 years ago

Any more updates needed for this issue?

m2-assistant[bot] commented 3 years ago

Hi @engcom-November. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

engcom-November commented 3 years ago

Verified the issue on Magento 2.4-develop branch and the issue is reproducible: Steps to reproduce:

  1. Create an order with an in stock product and shipping method of carrier that is able to print shipping labels (Ex: use DHL Shipping Method while placing order)
  2. Set quantity of same product to 0 from Admin - Catalog - Edit Product - Update Quantity to 0 and save
  3. Reindex and clear cache
  4. Go to Admin - Sales - Orders - View order and click "Ship"
  5. Check checkbox "Create Shipping Label"
  6. Click "Submit Shipment" - Add Products to Package - Select Product - Add selected
  7. Click on Save button - No issue: "Not all of your products are available in the requested quantity." error message is displayed to the user
  8. Verify shipping.log file Issue: Shipping Label number is getting created even though Shipment creation failed. image

image

github-jira-sync-bot commented 3 years ago

:white_check_mark: Jira issue https://jira.corp.magento.com/browse/AC-938 is successfully created for this GitHub issue.

m2-assistant[bot] commented 3 years ago

:white_check_mark: Confirmed by @engcom-November. Thank you for verifying the issue.
Issue Available: @engcom-November, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.

engcom-November commented 3 years ago

Verified the scenario again by putting back the same Product quantity to Stock and created Shipment again for the same order with Shipping Label - Shipment is created with new Shipping Label and DB tables are updated as expected - No issue. Issue observed only when product Quantity is 0 while creating Shipment with Shipping Label - Shipment is failing but Shipping Label is getting created. Steps to reproduce:

  1. Create an order with an in stock product and shipping method of carrier that is able to print shipping labels (Ex: use DHL Shipping Method while placing order)
  2. Set quantity of same product to 0 from Admin - Catalog - Edit Product - Update Quantity to 0 and save
  3. Reindex and clear cache
  4. Go to Admin - Sales - Orders - View order and click "Ship"
  5. Check checkbox "Create Shipping Label"
  6. Click "Submit Shipment" - Add Products to Package - Select Product - Add select
  7. Click on Save button - No issue: "Not all of your products are available in the requested quantity." error message is displayed to the user
  8. Verify shipping.log file Issue: Shipping Label number is getting created even though Shipment creation failed.
  9. Put back the Product Quantity to >1 or in stock and save
  10. Reindex and clear cache
  11. Admin - Sales - Open same Order - Ship - Check with Shipping Label - Submit shipment - Shipment is created with new Shipping Label.
HenKun commented 1 year ago

Amy progress on that?

HenKun commented 1 year ago

Any news on that?