Skip to content

Fix for reverting stock twice for cancelled orders #12668

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 11, 2018
Merged

Fix for reverting stock twice for cancelled orders #12668

merged 1 commit into from
Jan 11, 2018

Conversation

dverkade
Copy link
Member

@dverkade dverkade commented Dec 13, 2017

Description

Fix for reverting stock twice for cancelled orders:

  • Removed cataloginventory event observer restore_quote, that increased the stock when rebuilding a quote. Reverting quote inventory should be responsibility either of sales_model_service_quote_submit_failure or sales_order_item_cancel events;

Fixed Issues

  1. Cancel order and restore quote methods increase stocks twice #9969: Cancel order and restore quote methods increase stocks twice

@magento-engcom-team magento-engcom-team added bugfix Component: Payment Reproduced on 2.1.x The issue has been reproduced on latest 2.1 release Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release labels Dec 13, 2017
@adrian-martinez-interactiv4
Copy link
Contributor

Hi @dverkade , we are discussing internally the best way to solve related issue, I will keep you updated

@adrian-martinez-interactiv4
Copy link
Contributor

Hi again @dverkade , it seems that reverting stock is performed twice due to wrong event legacy observer in Magento/CatalogInventory/etc/events.xml:

<?xml version="1.0"?>
<!--
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    (...)
    <event name="sales_model_service_quote_submit_failure">
        <observer name="inventory" instance="Magento\CatalogInventory\Observer\RevertQuoteInventoryObserver"/>
    </event>
    <event name="restore_quote">
        <observer name="inventory" instance="Magento\CatalogInventory\Observer\RevertQuoteInventoryObserver"/>
    </event>
    <event name="sales_order_item_cancel">
        <observer name="inventory" instance="Magento\CatalogInventory\Observer\CancelOrderItemObserver"/>
    </event>
    (...)
</config>

Reverting quote inventory should be responsibility either of sales_model_service_quote_submit_failure or sales_order_item_cancel events; it seems restore_quote event, using the same observer as sales_model_service_quote_submit_failure, should be removed, as apparently is there as consequence of some refactoring over legacy code and this task is out of its responsibility, for further info see c6856aa#diff-83d4d8c646cab3e9d92bbf93acc36b47L60 :
captura de pantalla 2017-12-13 a las 21 07 55

This should solve the problem without hardcoding and tying order states to available states to revert the stock, as at some point there could be more valid states to revert the stock, and order state does not necessarily defines if a quote item inventory can be reverted or not.

My suggestion is revert the applied changes and remove restore_quote event observer from Magento/CatalogInventory/etc/events.xml.

@dverkade
Copy link
Member Author

dverkade commented Jan 2, 2018

Hi @adrian-martinez-interactiv4,

Thank you for your feedback. I have reverted the commits and took a look at the restore_quote event observer. This event is called when Magento needs to create a new quote with a different quote_id from an order. Nothing happens to the status of the original order, so we should not update the inventory at that moment. So I have removed this event observer from the code. I did not change it to paypal_payment_cancel, since this is event is never dispatched and a paypal event observer should be placed within the paypal module not in the cataloginventory module.

@adrian-martinez-interactiv4
Copy link
Contributor

Hi @dverkade , the paypal_payment_cancel event in the image was only for ilustrating that the change that introduced this observer into cataloginventory module came from legacy code, changes look ok now, as last one thing, could you squash the seven commits into one single clean commit and push force your branch? Thank you in advance.

@magento-team magento-team merged commit 2c1d6a4 into magento:2.2-develop Jan 11, 2018
@magento-engcom-team magento-engcom-team added the Fixed in 2.2.x The issue has been fixed in 2.2 release line label Jan 11, 2018
magento-team pushed a commit that referenced this pull request Jan 11, 2018
…tock twice for cancelled orders #12949

 - Merge Pull Request #12949 from dverkade/magento2:2.3-Fix-for-reverting-stock-twice-for-cancelled-orders
 - Merged commits:
   1. 1055076
magento-team pushed a commit that referenced this pull request Jan 11, 2018
magento-team added a commit that referenced this pull request Jan 11, 2018
Accepted Public Pull Requests:
 - magento-engcom/magento2ce#1195: Ability to switch to default mode[forwardport]. (by @nmalevanec)
 - magento-engcom/magento2ce#1193: Format generated config files using the short array syntax[forwardport]. (by @nmalevanec)
 - #13012: [Port to 2.3-develop] Add trim filter to first, middle and lastname. (by @wardcapp)
 - #12949: [Backport #12668 into 2.3-develop] Fix for reverting stock twice for cancelled orders (by @dverkade)


Fixed GitHub Issues:
 - #4292: Why can't one switch back to default mode ? (reported by @digitalpianism) has been fixed in magento-engcom/magento2ce#1195 by @nmalevanec in 2.3-develop branch
   Related commits:
     1. 3967190

 - #758: Coding standards: arrays (reported by @tzyganu) has been fixed in magento-engcom/magento2ce#1193 by @nmalevanec in 2.3-develop branch
   Related commits:
     1. 6d86db1

 - #10415: Customer First and Last names not being trimmed of leading and trailing spaces on save. (reported by @spyrule) has been fixed in #13012 by @wardcapp in 2.3-develop branch
   Related commits:
     1. e8dad7a
     2. 9a45695
     3. 03f250a

 - #9969: Cancel order and restore quote methods increase stocks twice (reported by @simpleadm) has been fixed in #12949 by @dverkade in 2.3-develop branch
   Related commits:
     1. 1055076
magento-team pushed a commit that referenced this pull request Jan 11, 2018
…tock twice for cancelled orders #12952

 - Merge Pull Request #12952 from dverkade/magento2:2.1-Fix-for-reverting-stock-twice-for-cancelled-orders
 - Merged commits:
   1. bbe2f1a
   2. b5b59be
magento-team pushed a commit that referenced this pull request Jan 11, 2018
magento-team added a commit that referenced this pull request Jan 11, 2018
Accepted Public Pull Requests:
 - #12954: [Backport to 2.1-develop] Fix #2156 Js\Dataprovider uses the RendererInterface. (by @dverkade)
 - #12952: [Backport #12668 into 2.1-develop] Fix for reverting stock twice for cancelled orders (by @dverkade)


Fixed GitHub Issues:
 - #2156: Why does \Magento\Translation\Model\Js\DataProvider use \Magento\Framework\Phrase\Renderer\Translate, not \Magento\Framework\Phrase\Renderer\Composite? (reported by @dmitry-fedyuk) has been fixed in #12954 by @dverkade in 2.1-develop branch
   Related commits:
     1. 65c99b9
     2. f215350
     3. a0b7bc5

 - #9969: Cancel order and restore quote methods increase stocks twice (reported by @simpleadm) has been fixed in #12952 by @dverkade in 2.1-develop branch
   Related commits:
     1. bbe2f1a
     2. b5b59be
@dverkade dverkade deleted the patch-22 branch June 22, 2018 14:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix Community Insider: Cream community-insider-contribution Component: Payment Fixed in 2.2.x The issue has been fixed in 2.2 release line Progress: accept Release Line: 2.2 Reproduced on 2.1.x The issue has been reproduced on latest 2.1 release Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants