1

I'm spliting the magento order separately like different vendors, I'm fallowing the Vinai Answer from previous post. But it's returning an error.

Error: Invalid method Mage_Sales_Model_Quote::removeItemByKey()

Mage_Sales_Model_Quote this class have this method but it's returning error WHY?

my code is

<?php

class Easylife_SplitOrder_Model_Type_Onepage extends Mage_Checkout_Model_Type_Onepage
{

    public function saveOrder()
    {
        $quote = $this->getQuote();

        // First build an array with the items split by vendor
        $sortedItems = array();
        foreach ($quote->getAllItems() as $item) {
            //$vendor = $item->getProduct()->getVendor(); // <- whatever you need
            $product = Mage::getModel('catalog/product')->load($item->getProductId());
            //Mage::log($product->getVendor());
            $vendor = $product->getVendor();
            if($vendor != 0){
                if (! isset($sortedItems[$vendor])) {
                    $sortedItems[$vendor] = $item;
                    //Mage::log('vendor');
                }
            }
            //Mage::log('$vendor');
        }

        Mage::log('One');
        foreach ($sortedItems as $vendor => $items) {
            // Empty quote
            foreach ($quote->getAllItems() as $item) {
                $quote->removeItemByKey($item->getId());
            }
            foreach ($items as $item) {
                $quote->addItem($item);
            }
            // Update totals for vendor
            $quote->setTotalsCollectedFlag(false)->collectTotals();

            // Delegate to parent method to place an order for each vendor
            parent::saveOrder();
        }
        Mage::log('2');
        return $this;
    }

}

How can I solve this?

Thanks in advance..

1
Mage_Sales_Model_Quote::removeItemByKey()

This method doesn't quite exist in Mage_Sales_Model_Quote in Magento and this is why you are getting this error.

0

The function removeItemByKey can be found on the class Varien_Data_Collection. This means that is is a core function for collection objects. The class Mage_Sales_Model_Quote is not a collection object and so does not have this class.

I think what you want is removeItem this will take the id of the item you wish to remove and removes the item.

$quote->removeItem($item->getId());
0

What Vinai wrote is:

$quote->getItemsCollection()->removeItemByKey($item->getId());

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.