3

I am getting sales quote collection with this reference,,but it throws below error.

MyCode

Mage::log($item_ids);
$collection=Mage::getSingleton('sales/quote_item')->getCollection()->addFieldToFilter('item_id',array('in'=>$item_ids));
foreach($collection as $item)
    {
        Mage::log($item);
    }

Log

2014-12-10T13:13:46+00:00 DEBUG (7): Array
(
    [0] => 3030
    [1] => 3032
    [2] => 3056
    [3] => 3057
    [4] => 3070
)

Error showing on frontend white screen with this message.

Fatal error: Call to a member function getStoreId() on a non-object in /var/www/beta/app/code/core/Mage/Sales/Model/Resource/Quote/Item/Collection.php on line 67

What is wrong in my code? .

  • You are getting this error because you have the quote item isolated. It does not have a quote associated to it. This may work in some cases but in others (like yours) it doesn't. Can you post the code you are using on frontend? – Marius Dec 10 '14 at 13:38
  • @Marius Which code you are asking? – Manikandan Arunachalam Dec 10 '14 at 13:40
  • The error appears when you run the code you posted in the question? Or is there something else? – Marius Dec 10 '14 at 13:48
  • @Marius I tried in Collection.php's getStoredId() Mage::log($this->_quote); this returns empty, so this error occurs. – Manikandan Arunachalam Dec 10 '14 at 13:57
5

Apparently this is a bug.
You cannot use the Mage_Sales_Model_Resource_Quote_Item_Collection without linking it to a quote.
Because of this:
When the collection is loaded the method _assignProducts from the same class is called.
this method dispatches an event

    Mage::dispatchEvent('prepare_catalog_product_collection_prices', array(
        'collection'            => $productCollection,
        'store_id'              => $this->getStoreId(),
    ));

This event requires a store id that is retrieved like this:

public function getStoreId()
{
    return (int)$this->_quote->getStoreId();
}

When using the collection directly the _quote member is empty.

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.