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

Issue Preventing Checkout with Configurable Products in Low Stock #59

Open
mbernabeu opened this issue Oct 2, 2024 · 2 comments
Open
Assignees

Comments

@mbernabeu
Copy link
Collaborator

Describe the bug
Bug When One Product in Stock. No order can be placed. After investigating the issue, it's observed that no problems occur with MSI + Adyen or with Hyva theme + MSI. However, the issue arises when the compatibility module is involved. Specifically, when attempting to add a configurable product with limited stock (e.g., 2 items), the shipping methods do not appear on the checkout page. Interestingly, if the pre-selected shipping method is not changed, the issue does not occur.
In the code, two calls are made to CartItemPersister to collect BuyRequestData using the line:
$buyRequestData = $this->cartItemOptionProcessor->getBuyRequest($productType, $item);
This BuyRequestData can either be a float value or an object. In the first request, it's a float, so no exception is thrown. However, in the second request, it becomes an object. When the system proceeds to update the quote item with the following logic:
if (is_object($buyRequestData)) { /** Update item product options */ if ($quote->getIsActive()) { $item = $quote->updateItem($itemId, $buyRequestData); } }
While updating the quote item, the logic in Quote.php tries to add more products to the quote, same amount as already added to the cart. Since there are no additional items available in stock, this triggers an exception.
$resultItem = $this->addProduct($product, $buyRequest);
My observation is that since the configuration is only needed to populate data in the payment block, it may be sufficient to fetch only the specific configurations required for those blocks, rather than retrieving all configurations.

To Reproduce
Steps to reproduce the behavior:

  1. Make sure MSI is enabled and set up correctly
  2. Make sure you have a configurable product with at least one option that has 1 in stock (note: it will also happen with a larger stock, but 1 might be easier to test)
  3. Add the configurable option to your cart and make sure you add all items in stock to the cart
  4. Go to the checkout
  5. Fill in the form and change the country
  6. If you keep the country as it is, the same issue will happen when selecting a (different) shipping method

Expected behavior

  • It's possible to change the country
  • It's possible to select a shipping method

Actual behavior

  • When changing the country or selecting a shipping method, an error is shown that the requested quantity is not available
  • No shipping methods are available anymore and it's impossible for customers to place an order

Magento version
2.4.7

Plugin version
1.1.0

Additional context

  • This issue doesn't happen for simple products
  • This issue doesn't happen if Adyen is removed (disabling through the admin doesn't solve it)
  • I've done quite some research and debugging here and noticed that the issue comes from the Adyen module fetching all the configuration for the checkout in the payment block's constructor (\Adyen\Hyva\Block\PaymentMethod). This results in the additional options being loaded in \Magento\Checkout\Model\DefaultConfigProvider::getQuoteItemData(), which on itself results in the buy request being an object in \Magento\Quote\Model\Quote\Item\CartItemPersister::save() on line 75. Because this is an object, it will update the order item and not just set the new quantity. Through some more steps we will get to \Magento\Quote\Model\Quote\Item::addQy() where the current item quantity is increased with the given quantity (which is also the current quantity).
  • Since the configuration is only needed for filling the data in the payment block, it might be enough to just fetch the specific configuration that is needed in these blocks and not fetch all the configurations.
@pmarjan-onestic
Copy link
Collaborator

hi @mbernabeu thanks for the comment and the nice details that give a good head start.

Also thank you for this suggestions "Since the configuration is only needed for filling the data in the payment block, it might be enough to just fetch the specific configuration that is needed in these blocks and not fetch all the configurations."

I am thinking though that this configuration is needed in a situation when we have a one step hyva checkout enabled, in which case it is possible to select a payment method before anything else is done with the checkout including selecting the shipping method. This is probably the reason behind the current implementation.

I have a feeling that the important thing to clarify is why would the $cartItem have product options attached in the faulty case, and not in other cases.

Magento\ConfigurableProduct\Model\Quote\Item\CartItemProcessor::convertToBuyRequest(CartItemInterface $cartItem)

Of course, I will add posts with any updates that I might run into.

pmarjan-onestic added a commit that referenced this issue Oct 7, 2024
@pmarjan-onestic
Copy link
Collaborator

Draft solution is added.
Not completely tested due do lack of access to the adyen customer console.

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

No branches or pull requests

2 participants