Is there anyway i can hide a product that doesn't have a price or 0 for its price?

We use stock import tools (Magmi Data Importer) and so some products imported don't have a price. How can i check each product has a price and disable it if it doesn't.

I've tried overriding the getStatus() method from Mage Core but this seems to disable the whole product and not just a product which is part of a group.


Run this after the import:

$zeroPriceProducts = Mage::getModel('catalog/product')->getCollection()
             array('attribute'=>'price', 'eq'=>'0'),
             array('attribute'=>'price', 'isnull'=>true),
$ids = $zeroPriceProducts->getAllIds();
    array('status' => 2).

This should identify the products with price zero and disable them.

  • Hi Marius. This doesn't seem to find 0 priced and instead is printing out every product in the DB. It seems that the attribute to select doesn't do anything? – Marc Nov 5 '14 at 12:10
  • @Marc Sorry I should be addAttributeToFilter instead of addAttributeToSelect. I fixed it. – Marius Nov 5 '14 at 12:14
  • Hi Marius, Yep i swapped this just after posting and also added '' around the 0? It seems to work now – Marc Nov 5 '14 at 12:15
  • If this answer or any other one solved your problem, mark it as accepted. Let's keep a clean website. – Marius Nov 5 '14 at 12:16
  • Just marked it solved as a quick one to check for NULL can i just add ->addAttributeToFilter('price', array('eq'=> NULL)); that way if the price doesn't exist also (which is mainly the case) it would also get disabled? – Marc Nov 5 '14 at 12:18

I would create a backend script to fix this issue

require_once('app/Mage.php'); //Path to Magento
$Products = Mage::getModel('catalog/product')
                        ->addAttributeToFilter('price', array('lt' => '0.01') // you can change this accordingly
                        ->addFieldToFilter('status', array('eq' => '1');

foreach($Products as $product){

Remember to backup your db before run this script

  • Good answer except one thing. You should not use save in a loop. It's time and resource consuming. You don't need it if you are going to change one single attribute for all the products. – Marius Nov 5 '14 at 11:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.