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

Suggested fix to make $quote->getItemById more robust #834

Merged
merged 2 commits into from
Nov 6, 2019

Conversation

seansan
Copy link
Contributor

@seansan seansan commented Oct 14, 2019

Several new quote and order flows do not always trigger and set the quoteid ... the quote is then created with items but has no id yet ... and getItemById () does not work in these case because there is a different key. This happens for instance when orders are created via

        /** @var Mage_Sales_Model_Service_Quote $service */
        $service = Mage::getModel('sales/service_quote', $quote);
        $service->submitAll();

Please review and UPDATE my code suggestion directly. Needs a proper review as it is quite in the core of quotes of M1

Several new quote and order flows do not always trigger and set the quoteid ... the quote is then created with items but has no id yet ...  and getItemById () does not work in these case because there is a different key. This happens for instance when orders are created via

            /** @var Mage_Sales_Model_Service_Quote $service */
            $service = Mage::getModel('sales/service_quote', $quote);
            $service->submitAll();

Please review and UPDATE my code suggestion directly. Needs a proper review as it is quite in the core of quotes of M1
Copy link
Contributor

@Flyingmana Flyingmana left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure if it is the best solution forthe issue, probably not, but I dont see any down sides or possible side effects

@seansan
Copy link
Contributor Author

seansan commented Oct 14, 2019 via email

@Flyingmana Flyingmana merged commit 0205ecb into OpenMage:1.9.4.x Nov 6, 2019
Flyingmana added a commit that referenced this pull request Nov 6, 2019
Flyingmana added a commit that referenced this pull request Nov 6, 2019
for defense, the TravisCI did not run for the PullRequest
@joshua-bn
Copy link
Contributor

Scary that this got committed missing those two giant issues that got fixed in the other two commits

edannenberg pushed a commit to edannenberg/magento-lts that referenced this pull request Aug 20, 2020
Several new quote and order flows do not always trigger and set the quoteid.
The quote is then created with items that have no id yet and getItemById()
does not work in these case because there is a different id.
This happens for instance when orders are created via:

    /** @var Mage_Sales_Model_Service_Quote $service */
    $service = Mage::getModel('sales/service_quote', $quote);
    $service->submitAll();
@sreichel sreichel added the bug label Dec 30, 2020
@henrykbrzoska
Copy link
Contributor

henrykbrzoska commented Feb 9, 2021

if someone have exception like
SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (magento.sales_flat_quote_item_option, CONSTRAINT FK_5F20E478CA64B6891EA8A9D6C2735739 FOREIGN KEY (item_id) REFERENCES sales_flat_quote_item (item_id) ON DELETE CASCADE O)
it's because of this change.
in my example it occurs in IWD order manager when trying to add disabled product to cart(without supermode on quote)

@digitalpianism
Copy link
Contributor

digitalpianism commented Apr 30, 2021

@henrykbrzoska same issue here with the Amasty_Promo module with an "Auto add product to cart" rule. the $itemId being null, the comparator isn't correct so I had to make a fix in the module.

@Flyingmana
Copy link
Contributor

@henrykbrzoska @digitalpianism
Could one of you create an Issue for this and reference it here?

@digitalpianism
Copy link
Contributor

@Flyingmana I'm not entirely sure this is an issue.

Basically the module's code look like this:

$cart->removeItem($item->getId());

On Magento, as the $item does not have an id, it does nothing.

On Openmage, this piece of code here:

foreach ($this->getItemsCollection() as $item) {
                if ($item->getId() == $itemId) {
                    $quoteItem = $item;
                    return $quoteItem;
                } 
            }

the condition is true as there's an item without id and the $itemId is null.

I've just added a condition in the module's code as I assumed it was the module badly written rather than this openmage change.

@digitalpianism
Copy link
Contributor

@Flyingmana I'm not entirely sure why this change was made to start with even though I read @seansan comment.

If the condition I mentionned above, maybe we should add an "isset" or "!is_null" condition. I dont know which one of the two is supposed to be set.

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.

7 participants