Bypass custom options checks for bundled child items #3995
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description (*)
We came across an alarming issue when dealing with bundled products. Seemingly randomly, some orders were getting double the child items shipped even though there was only a single parent item in the cart. After digging in, I noticed an issue inside
Mage_Sales_Model_Quote_Item::representProduct
. If a customer has a bundled product in their cart, then a child item's price is updated before checkout and the user adds the bundled item to their cart again, this method returnsfalse
in thecompareOptions
checks due to non-matching option values insales_flat_quote_item_option
. This then causes the_addCatalogProduct
method to trigger adding a new quote item (per the$newItem
) flag. The result is a duplicated simple product quote item entry, which is then propagated into an order and shipped unknowingly.This isn't a frequent case, but depending on the product types and costs can be disastrous as we are effectively shipping free product without any intention or visibility.
Manual testing scenarios (*)
I made sure to replicate this on a fresh OM install to confirm this wasn't a bug in our module code. The steps are as follows:
You should be able to see an additional quote item in
sales_flat_quote_item
after adding the product again. This however does not show up on the frontend, but will be submitted to the order quantities. You may also observesales_flat_quote_item_option
, particularly thebundle_selection_attributes
code, to see the differences in values which causecompareOptions
to fail.Questions or comments
I found a comment of a similar, unaddressed issue in the M2 repo here.
It is worth noting that the
bundle_selection_attributes
serialized array is also used for some backend displays in admin. This particular fix implies that the prices will not be updated in these options, so when viewing an order under this scenario the user will still see item priced at the previous value before their update.Another solution I was playing around with was, instead of simply returning
true
here, to instead call$this->setOptions($product->getCustomOptions());
. This method actually does update the quote item options to the latest price, keeping consistent with the UI and the final amount charged to the customer. Although I did not find any regressions in tested with this solution, I figured it would be safer to not clobber existing options data at the expense of a UI inconvenience. If someone could confirm this is safe, it would be the more complete way to handle this bug. It appears for fixed priced bundled items,price
is not populated in the quote_item table, so this may be a better long term fix for reporting, etc.Contribution checklist (*)