How to add not saleable product into product collection

How to add not saleable product into product collection

July 25, 2026 · Illustrated author avatarBy Stefan Bogdanescu
How to add not saleable product into product collection

Retrieving Non-Saleable Products in Magento

In this post, we’ll explore how to retrieve all products from a category collection, including those that are not for sale or have no price assigned. This is particularly useful when you need to display a mix of regular and non-saleable items on your homepage or other custom pages.

Understanding the Challenge

The default Magento behavior is to filter out any product without stock, without a price, or marked as not for sale when creating a category collection. This filters out products like the one shown in the snapshot below:

Category with 2 Products

In this case, I want both these products to appear in my category collection, but currently, only the product with a price is being displayed.

Attempted Solutions

The user has tried creating a custom block and method to modify the product collection. Here’s an overview of their approach:

class Ubt_Featured_Block_Featured extends Mage_Core_Block_Template {

  // Class properties and initialization omitted for brevity

  public function getCollection($collection = 'null') {
    if ($collection != 'null') {
      // Add various filters (price, visibility, status) to the collection
      $collection->addAttributeToFilter('is_saleable', array('like' => '0'));

      return $collection;
    }
  }

}

They’ve tried using ->addAttributeToFilter('is_saleable', array('like' => '0')) to filter out saleable products, but this didn’t work. When they removed this line, the collection displayed one normal product.

The Problem: Incorrect Attribute Filtering

The issue lies in attempting to use the is_saleable attribute for filtering non-saleable products. In Magento 2, is_saleable is a virtual attribute that represents whether a product can be added to the cart based on various factors like stock status and price.

The Solution: Using the Correct Filters

To retrieve non-saleable products, you should use a combination of filters:

class Ubt_Featured_Block_Featured extends Mage_Core_Block_Template {

  // Class properties and initialization omitted for brevity

  public function getCollection($collection = null) {
    if ($collection != null) {
      $collection->addAttributeToFilter('status', array('eq' => '1')) // Enable status
        ->addFieldToFilter('price', array('null' => true))  // Products without price
        ->addFieldToFilter(array(
          array('attribute' => 'visibility', 'eq' => '4'),  // Not visible individually
          array('attribute' => 'status', 'neq' => '2')      // Not disabled
        ), null, true)  // Use OR condition

      return $collection;
    }
  }

}

Why This Works

  1. ->addAttributeToFilter('status', array('eq' => '1')) ensures only enabled products are considered.

  2. ->addFieldToFilter('price', array('null' => true)) includes products with no price set.

  3. The OR filter (->addFieldToFilter(array(...), null, true)) finds products that are either not visible individually or not disabled.

Conclusion

Retrieving non-saleable products from a category collection requires understanding the product status and visibility attributes in Magento 2. By using an appropriate combination of filters, you can successfully include all desired products in your custom collections.

Remember to update your block code accordingly and refresh the cache after making changes. This approach should allow you to display both regular and non-saleable products on any page you choose.

For more advanced customization options in Magento 2, consider exploring the solutions available at Laravel Company. They offer a range of services tailored for e-commerce platforms like Magento.

Catalog Themes Pricing

Our network