Description
Preconditions
- Magento 2.1.0 under nginx, php7 and mysql5.7
- Paypal Express enabled with sandbox account
- Configurable products set up with inventory enabled
Steps to reproduce
- Add configurable product to basket more with qty for more than 1/2 remaining stock of that option (e.g. 3 left for option, so add qty of 2)
- Checkout normally (do not use PayPal express from cart)
- Select PayPal express from payment methods, enter details and submit back to site
Expected result
- Success page
Actual result
- Sent to review page with error message "We can't place the order."
Purchasing for an amount less than half works. Also, going to paypal express directly from the cart works. This is just for the checkout payment method.
From stepping through the code, it seems that after placing the order the quote is saved. On this save, all products are re-added to the cart. As the qty has already been removed from stock, this fails and an exception is thrown that there is not enough of the product. Although this isn't logged anywhere, on \Magento\Quote\Model\Quote line 1628 the exception is thrown along the lines of "Not enough stock for product blah". Thus, any qty that is more than 1/2 the remaining stock fails.
It then returns twice the stock back, so that the stock ends up too high. In some ways this is even more of a problem than PayPal failing, as we have a client that now has to do a whole new stock take!
I'm struggling to follow the code that is being run here. Why are all the products added to the quote again? Why are the buyRequests objects rather than the bare qtys that seem to exist when run at other times? Why is reset_count set on the request when the condition on \Magento\Quote\Model\Quote\Item\Processor::process never seems to fire?