Magento – show empty grouped products

Joaquín Ruiz - 19th December 2016

Magento – show empty grouped products
  • Date:   19th December 2016
  • Category:

      Magento

  • Comments:

      1

Magento doesn’t show in the catalog view empty grouped products. In other words, Grouped products with no associated products. This is because a grouped product doesn’t have price. And it takes the max and min price for the catalog view from its simple products.

I’m showing on this post a way to show empty grouped products by removing the price index from the catalog query.

The objective

By default Magento performs a query as follow:

SELECT (...) FROM `catalog_product_flat_1` AS `e`
INNER JOIN `catalog_category_product_index` AS `cat_index` ON (...)
INNER JOIN `catalog_product_index_price` AS `price_index` ON (...)
WHERE (...)

Therefore, the items without entries on the catalog_product_index_price won’t appear.

But if we change that query and avoid the price indexes:

SELECT (..) FROM `catalog_product_flat_1` AS `e`
INNER JOIN `catalog_category_product_index` AS `cat_index` ON (...)
WHERE (...)

We can have empty grouped products on our catalog views.

The code

To perform that, we need to rewrite the method of the class Mage_Catalog_Model_Resource_Product_Collection that adds that INNER JOIN to our catalog collection.

The method we need to rewrite is addPriceData, we need to change

$this->_productLimitationFilters['use_price_index'] = true;

to

$this->_productLimitationFilters['use_price_index'] = false;

Remember to rewrite the Model correctly and do not edit the core class.

<models>
    <catalog_resource>
        <rewrite>
            <product_collection>JokiRuiz_Catalog_Model_ 
            Resource_Product_Collection</product_collection>
        </rewrite>
    </catalog_resource>
</models>
class JokiRuiz_Catalog_Model_Resource_Product_Collection
    extends Mage_Catalog_Model_Resource_Product_Collection
{
    public function addPriceData($customerGroupId = null, 
        $websiteId = null)
    {
        $this->_productLimitationFilters['use_price_index'] = 
            false;
        (...)
    }
}

The Author

Joaquín Ruiz (aka Joki)
Joki is a Computer Engineer, Senior Full-Stack Developer and Lead Developer, specialized in web and e-commerce. Joki has also a wide international experience as freelance and working in agencies.