Categories


Archives


Recent Posts


Categories


Deleting Bundled Product Items from a Quote

astorm

Frustrated by Magento? Then you’ll love Commerce Bug, the must have debugging extension for anyone using Magento. Whether you’re just starting out or you’re a seasoned pro, Commerce Bug will save you and your team hours everyday. Grab a copy and start working with Magento instead of against it.

Updated for Magento 2! No Frills Magento Layout is the only Magento front end book you'll ever need. Get your copy today!

Here’s another caution sign if you’re using the sales/quote object’s deleteItem or removeItem method. If you look at the code that marks an item for deletion

$item->isDeleted(true);
if ($item->getHasChildren()) {
    foreach ($item->getChildren() as $child) {
        $child->isDeleted(true);
    }
}

$parent = $item->getParentItem();
if ($parent) {
    $parent->isDeleted(true);
}

In addition to removing the item you asked about, Magento will remove any child items (members of a bundled product) or any parent items (the bundled parent if you remove a specific child item of the bundled product). Likely the right behavior (although I could argue for an exception being thrown if you try to remove a child item), but one that leads to confusing results if you’re foreaching over a quotes items collection and removing items based on criteria.

Copyright © Alana Storm 1975 – 2023 All Rights Reserved

Originally Posted: 13th October 2015

email hidden; JavaScript is required