Magento 1 - How to get type of a Magento quote item?

6.4k views Asked by At

Grouped products are grouping simple products, everyone knows. In somewhere of my custom module, I need to know if there's a simple product in my cart (quote) "added by grouped product" or by "itself"?

I know there's a table sales_flat_quote_item_option. Item records doesn't differ in sales_flat_quote_item but in that option table there's some difference. When you add your simple product with "grouped product add action", it creates a row including info_buyRequest in sales_flat_quote_item_option table.

I want to determine that record programatically.

Thanks for any help/directive.

2

There are 2 answers

1
muhammedv On BEST ANSWER

I found a solution. Its enough simple to embarrass me;

$_item->getProductType()

returns "grouped" when that simple item came with a grouped product's add action. Altough, there's a logical mistake, because that product's type is actually "simple" not "grouped".

1
Vishal Thakur On

If you do not want to loop through all the products in the cart items what you could do would be to get the quote id and load the items directly from the database, including the product type filter.

/** @var Mage_Sales_Model_Quote $quote */
$quoteId = Mage::getModel('checkout/cart')->getQuote()->getId();
/** @var Mage_Sales_Model_Resource_Quote_Item_Collection $quoteItems */
$quoteItems = Mage::getModel('sales/quote_item')->getCollection();
$quoteItems->addFieldToFilter('quote_id', $quoteId);
$quoteItems->addFieldToFilter('product_type', 'bundle');

if ($quoteItems->getSize() >= 1) {
    echo 'We have bundle products in the cart';
}