1

I want to get all product_ids of quote_items without for loop.
I don't use $cart = Mage::getModel('checkout/cart')->getQuote()->getAllVisibleItems();

I want to use below code
Below code not work and it throws error.Error is Fatal error: Call to a member function getStoreId() on a non-object


Why below code not work for getColumnValues('product_id') ? Any idea ?

$quote_id = Mage::getModel('checkout/cart')->getQuote()->getData('entity_id');
            $collection = Mage::getModel('sales/quote_item')->getCollection()
                    ->addFieldToSelect('*')
                    ->addFieldToFilter('quote_id',$quote_id);
            print_r($collection->getColumnValues('product_id'));

2 Answers 2

1

Because getAllVisibleItems() returns an array instead of a collection. Use Mage::getModel('checkout/cart')->getQuote()->getItemsCollection() instead and apply filters as needed.

See https://magento.stackexchange.com/a/78325/243 for more information about the different methods to retrieve quote items.

7
  • I override getItemsCollection(Mage/sales/Model/Quote.php) method Dec 28, 2015 at 12:14
  • And now it does not return the item collection anymore? Dec 28, 2015 at 12:15
  • I am developing Split cart functionality so I override itemscollection method and filter by vendor so Dec 28, 2015 at 12:24
  • Then you need to replicate the code from the original method. Dec 28, 2015 at 12:24
  • sorry I do not understand what you say.Could you elaborate more ? I override getItemsCollection method and filter by vendor id . After successfully place vendor1 product I am adding rest of vendor product in cart programmatically Dec 28, 2015 at 12:31
0

I found a solution by setQuote() function

    $quote = Mage::getModel('checkout/cart')->getQuote();
        $collection = Mage::getModel('sales/quote_item')->getCollection()
                ->setQuote($quote);
        print_r($collection->getColumnValues('product_id'));
2
  • In which context are you doing that? I mean if you are doing that around an active session, you should load the quote data from the session or singleton instead to reload the entire model. Dec 28, 2015 at 7:23
  • Because I am developing split cart functionality Dec 28, 2015 at 12:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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