In some cases if a product has moved to is_in_stock=0 and a refund is issued and returns the stock, the is_in_stock=1 flag is not being set so the product remains unsaleable.
The only change from #92 that was necessary for me to get working tests was b1a1c7b3a21d782b8cae4ed4fbf7c8d917ecb6d5 so that's what has been committed into this branch.
Before code fix
2.4.3 fails like
There was 1 failure:
1) Ampersand\DisableStockReservation\Test\Integration\Refund\ProductGoesBackInStockWhenRefundedTest::testProductBackInStockHandling with data set "back_to_stock=true returns items" ('1', array(true, 5))
is_in_stock does not match expected
Failed asserting that false matches expected true.
2.4.5 and higher fails like
1) CheckoutCest: Product goes back in stock when order is refunded
Test tests/acceptance/CheckoutCest.php:productGoesBackInStockWhenOrderIsRefunded
Step Assert equals 1,0,"Product did not go to is_in_stock=1 after a refund"
Fail Product did not go to is_in_stock=1 after a refund
Failed asserting that 0 matches expected 1.
Rest API testing
See the code for the details, but we could reproduce this issue using the rest api and it went away after cherry picking in the fix.
I cover two flows
creditmemo without back_to_stock
creditmemo with back_to_stock
Adminhtml Controller testing
See the code for the details, but we could reproduce this issue using the adminhtml controller and it went away after cherry picking in the fix.
A bit of work was needed to identify which caches need cleared during the execution, this is not needed for the rest api test because it actually spins up a new request with no object cache storage to cause problems.
I cover two flows
creditmemo without return_to_stock_items
creditmemo with return_to_stock_items
Manual Testing
I have also tested this on the frontend manually
On vanilla install of magento 2.4.3
require this module at this branch
Create a simple product
Place order for simple product taking its full stock using checkmo
Product goes is_in_stock=0
Invoice the order
Ship the order
Before this fix
Create a credit memo for the order, return items to stock, see that is_in_stock=0 goes back. ⚠️
After this fix
Create a credit memo for the order, return items to stock, see that is_in_stock=1 goes back. ✅
Checklist
[x] Pull request has a meaningful description of its purpose, include affected Magento versions if it is a bug.
[x] All commits are accompanied by meaningful commit messages
[x] Tests have been ran / updated (see ./dev/README.md for how to run tests)
In some cases if a product has moved to
is_in_stock=0
and a refund is issued and returns the stock, theis_in_stock=1
flag is not being set so the product remains unsaleable.This is detailed in https://github.com/AmpersandHQ/magento2-disable-stock-reservation/pull/92
The only change from #92 that was necessary for me to get working tests was b1a1c7b3a21d782b8cae4ed4fbf7c8d917ecb6d5 so that's what has been committed into this branch.
Before code fix
2.4.3 fails like
2.4.5 and higher fails like
Rest API testing
See the code for the details, but we could reproduce this issue using the rest api and it went away after cherry picking in the fix.
I cover two flows
back_to_stock
back_to_stock
Adminhtml Controller testing
See the code for the details, but we could reproduce this issue using the adminhtml controller and it went away after cherry picking in the fix.
A bit of work was needed to identify which caches need cleared during the execution, this is not needed for the rest api test because it actually spins up a new request with no object cache storage to cause problems.
I cover two flows
return_to_stock_items
return_to_stock_items
Manual Testing
I have also tested this on the frontend manually
checkmo
is_in_stock=0
Before this fix
is_in_stock=0
goes back. ⚠️After this fix
is_in_stock=1
goes back. ✅Checklist
./dev/README.md
for how to run tests)