Magento – show empty grouped products

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;
        (...)
    }
}
0 0 votes
Article Rating
Subscribe
Notify of
guest
1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
alex
alex
6 years ago

Hi,
great solution!

But there’s a bug… or i got one! 😉
When you are in a category page, and sort by price the products, something goes wrong.
Also if you add “price” to the layered navigation the page shit off.

Any ideas?

1
0
Would love your thoughts, please comment.x
()
x