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

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

July 30, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento 1 - How to get type of a Magento quote item?

Magento 1 - Determining Simple Products Added Through Grouped Products

In Magento 1, handling grouped products can sometimes require additional logic to differentiate between simple products added directly or via their grouped counterparts. Let’s dive into how you can programmatically determine the origin of a simple product in your cart.

Understanding the Quote Item Structure

The sales_flat_quote_item table stores all quote items, including those from grouped and configurable products. However, the differentiating factor lies in the sales_flat_quote_item_option table when dealing with grouped products.

When you add a simple product through a grouped product’s “Add to Cart” action, Magento populates several additional fields in the sales_flat_quote_item_option table:

  • The option_id field references the simple product.
  • The info_buyRequest field contains an array of information about the product and its options.

Retrieving Quote Items Programmatically

First, let’s fetch all quote items from the current quote. You can use Magento’s API or directly query the database:

// Using Magento API
$quote = Mage::getModel('sales/quote')->loadByIdWithoutStore($quoteId);
$items = $quote->getAllVisibleItems();

// Or, querying the database
$readAdapter = Mage::getSingleton('core/resource')->getConnection('core_read');
$sql = 'SELECT * FROM sales_flat_quote_item WHERE quote_id = ?';
$bindParams = array($quoteId);
$items = $readAdapter->fetchAll($sql, $bindParams);

Distinguishing Grouped Products

To determine if a simple product was added through a grouped product, you need to inspect the sales_flat_quote_item_option table for each item.

foreach ($items as $item) {
    // Check if the item has any options
    if (empty($item['option_id'])) {
        continue;
    }

    $optionId = $item['option_id'];
    $readAdapter = Mage::getSingleton('core/resource')->getConnection('core_read');
    $sql = 'SELECT * FROM sales_flat_quote_item_option WHERE item_id = ?';
    $bindParams = array($item['item_id']);
    $options = $readAdapter->fetchAll($sql, $bindParams);

    // If the option record contains info_buyRequest, it was added via a grouped product
    if (!empty($options)) {
        foreach ($options as $option) {
            $buyRequest = unserialize($option['info_buyRequest']);
            if (isset($buyRequest['super_attribute'])) {
                // The item was added through a grouped or configurable product
                // Perform your logic here
            }
        }
    }
}

Best Practices and Tips

  1. Performance: If you’re dealing with large quotes, consider using Magento’s API instead of directly querying the database for better performance.

  2. Avoiding Deprecated Code: In later versions of Magento 1, some methods may be deprecated or moved around. Always check the official documentation to ensure your code remains compatible and maintainable.

  3. Using Mage::log(): For debugging purposes, use Mage::log() to monitor the items and their options as you process them:

Mage::log($item, null, 'quote_items.log');

Conclusion

Determining if a simple product in your Magento 1 cart was added through a grouped product involves inspecting specific fields in the sales_flat_quote_item_option table. By following the approach outlined above, you can write accurate and efficient logic to handle grouped products within your custom modules.

Remember that using Magento’s official API is generally recommended for better performance and compatibility with future updates. For more advanced customizations and best practices, feel free to explore our comprehensive guides at Laravel Company.

Happy coding!

Magento 1 Checkout Catalog Database

Our network