Sort grouped products in Magento by “in stock” status

Posted on March 14th, 2015 | Posted by admin

Many of the products in our Magento catalog are grouped products. We’ve noticed that unless they’re looking for a specific variation of a specific product, they tend to just order the first of the grouped products listed on the product details page. We want to avoid customers moving on to other products (or *gasp* other web sites) to order, so we want any out of stock products moved to the bottom of the grouped products table.

Getting Ready to Modify

First of all, this modification was done while running Magento It may work on others, but no promises.

The collection of grouped products that gets displayed on the product details page is assembled in this file:


Before we do anything else, let’s make sure we make our changes in a way that won’t get erased next
time we update Magento. Copy everything inside the file I just referenced, and paste it inside this brand new one.
If this new file already exists, skip this step. We don’t want to undo any modifications you have
already made to this file:


Magento will read this new file any time it wants to do anything that would have used the old file. When we update Magento, the old file will get overwritten, but our new file will stay in place with all its customizations.

Down to Business

In the new file we just created (or opened up because it was already there), find the method named getAssociatedProducts.

This is where we’ll do all our work.

On about the 8th line of that method, the $collection variable is created, and the next few lines define what goes in the collection. This is how it looks by default:

$collection = $this->getAssociatedProductCollection($product)
	->addAttributeToFilter('status', array('in' => $this->getStatusFilters($product)));

We’re going to add two lines before the addAttributeToSelect method is called.
The first line declares a join between the database table with product information and
the database table with stock information. It lets us use stock information as an attribute of product information.

->joinField('inventory_in_stock', 'cataloginventory_stock_item', 'is_in_stock',
'product_id=entity_id','is_in_stock>=0', 'left')

The second line tells Magento that we want to sort by the is_in_stock flag. That groups together items that in stock so we can display them all together.


Here’s what it looks like all together:

$collection = $this->getAssociatedProductCollection($product)
	->joinField('inventory_in_stock', 'cataloginventory_stock_item', 'is_in_stock',
'product_id=entity_id','is_in_stock>=0', 'left')
	->addAttributeToFilter('status', array('in' => $this->getStatusFilters($product)));

That should do it. Give the file a save, refresh your cache (if it’s on, which it is by default)
and check the details page of a grouped product.

how to create bundle products in Magento

Posted on March 2nd, 2013 | Posted by admin

Magento allows store owners to sell customizable products (eg. Product with more options to select from).
In this tutorial, we will show you how to:

  • Creae a new computer bundle, composed of the following user-selectable options: System Color, Operating System and Monitors.
  • Selections (eg. Pure White, Plum Purple) within each Option (eg. System Color) are composed from Simple Products. This means that you have to create your simple products first.
  • Pricing is dynamically calculated based on the user selected Option(s), using the Simple Products pricin

Magento performance: Optimization of Magento configurable products

Posted on October 24th, 2012 | Posted by admin

If you use configurable products in your Magento store and your super attribute have a lot of options (thousands of options), you can experience the following performance issues:

  • Loading time of a configurable product page is more than other pages (especially when Magento cache is disabled)
  • When you add a configurable product to store cart, cart page become slow
  • When configurable product is added to store cart, all store pages become slow

In this article I will show how to debug such issues and how to fix the speed issue I described above.

Note: Pages load time depends on your server configuration and number of attribute options in your Magento store.

Product view loading time optimization

I started investigation of this issue on product view page. I found “TTT4″ point in the Magento profiler, which take a lot of loading time (in our case 10-15 seconds).
This is a call of _loadPrices() method in the Mage_Catalog_Model_Resource_Product_Type_Configurable_Attribute_Collection class.

Magento: Get Bestselling products by category and date time

Posted on October 9th, 2012 | Posted by admin

Magento: Get Bestselling products by category and date time

This article will show you how to get best selling products. You will see how to get overall best selling products as well as best selling products by category and by date time range.

Here is the code:-

Get overall Bestselling products

public function getBestsellingProducts()
	// number of products to display
	$productCount = 5; 

	// store ID
	$storeId    = Mage::app()->getStore()->getId();       

	// get most viewed products for current category
	$products = Mage::getResourceModel('reports/product_collection')

How to sort products Magento

Posted on February 4th, 2012 | Posted by admin

How to change the product position in the category product listing.

Sounds simple but most of people don’t know how to do it.

Magento allows you to order your products by name or by price when you’re surfing a category.

It also allows you to change the position when you’re sorting by default.

Page 1 of 612345»...Last »