Skip to content
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

PayPal checkout fails if twice the required stock is not available #10511

Closed
wants to merge 1 commit into from

Conversation

driskell
Copy link
Contributor

@driskell driskell commented Aug 12, 2017

Description

When checking out using PayPal payment method in checkout, you will be thrown back to the "Review" screen with "We can't place the order" message if one or more items in the cart are ordering half of the available stock. For example, "RED BOOT" is in the cart with quantity 1, and there is only 2 left in stock.

#10512 is a continuation of this as there is another section of code that triggers same error with slightly different conditions - when ordering the last item in stock. #10511 and #10512 together have resolved and stabilised all of our PayPal transactions to date.

Fixed Issues (if relevant)

Part of #9116
Possibly #10142

Manual testing scenarios

  1. Create configurable product with variations RED and BLUE color
  2. Set RED variation to stock level 2
  3. Add RED to cart and proceed to checkout and then at payment method stage select PayPal and proceed to pay.

Expected

  1. Successful checkout
  2. Stock of RED becomes 1

Actual

  1. We can't place the order - PayPal review step shown
  2. Order is actually recorded unbeknownst to the user
  3. Stock of RED becomes 3

Rationale

The quote object is saved via repository TWICE during PayPal checkout.
Saving a quote via repository triggers CartItemPersister of all items.
In the first save, the product options of the items are not present since no changes were made to the items. Thus the CartItemOptionsProcessor returns just the quantity and no buyRequestData. (This could be an issue itself but it seems to work OK.) During this first save the CartItemPersister at the end, however, then adds the product options to the item. As with any quote save, the stock is also validated.
Then, during the second save via repository, because product options now exist, updateItems is called for every configurable product in the cart.
Because the buyRequestData passed to updateItem does not contain the ID of the item like it would if it was triggered from a cart edit, it results in the reset quantity flag being ignored, thus, the quantity of the item within the cart is increased to 2 and a stock check for 2 is performed.
PayPal checkout has a quote save early on and then it has one in Quote->submit AFTER order placement. So at this point, the RED stock is now 1, but then a stock check is performed for 2 items, and throws an exception post order placement, causing the redirect to the review screen with error message. In fact, this then triggers a return to stock of the items in the quote for some reason, resulting in 3 RED items now in stock...

Contribution checklist

[x] Pull request has a meaningful description of its purpose
[x] All commits are accompanied by meaningful commit messages
[ ] All new or changed code is covered with unit/integration tests (if applicable)
[ ] All automated tests passed successfully (all builds on Travis CI are green)

…out) the checkout fails if twice the required stock is not available

Furthermore, after the failure, twice the stock is returned, resulting in an increase in stock.
@YevSent
Copy link
Contributor

YevSent commented Aug 14, 2017

Hi, @driskell. We are already working on the fix related to issue with PayPal Express Checkout and configurable products. As I see, proposed changes do not solve the problem with out of stock products on payment review page (our fix wider). Did you test proposed changes on the place order flow with a bundle and configurable products?

@driskell
Copy link
Contributor Author

We tested thoroughly this in combination with #10512 with configurable products only.

Together they solved the error for ordering down to the last item in stock. We did not test ordering out of stock item.

@driskell
Copy link
Contributor Author

@joni-jones Is your wider fix visible in the repository? I'd be super happy to test it and compare it with our discoveries. It'll also help us keep in-line with upstream.

@YevSent
Copy link
Contributor

YevSent commented Aug 16, 2017

@driskell, now our fix only in the internal repository. We are preparing PR to deliver it.

@ishakhsuvarov
Copy link
Contributor

Hi @driskell
Did you have a change to check the fix provided by @magento-team ?

@ishakhsuvarov
Copy link
Contributor

@driskell Closing this PR for now. Please reopen if issue is not fixed with the solution proposed in 2.2.0-preview.
Thank you for collaboration.

@ebaschiera
Copy link

Hi @ishakhsuvarov ,
what are the fixes proposed in 2.2.0-preview? Can you provide a link to a commit please?
This issue feels like a dead end to me.

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants