fxchain
Total Posts: 40
Joined: 2009-03-01
Hello,
I am trying to create a product feed. When I load the product collection, any filter I try to not include disabled product do not work.
Code:
<?php require_once \ 'app/Mage.php\' ; umask ( 0 ); Mage :: app ( \ 'default\' ); $products = Mage :: getModel ( \ 'catalog/product\' )-> getCollection (); $products -> addAttributeToSelect ( \ '*\' ); //$products->addAttributeToFilter(\'status\', array(\'value\'=>1)); //$products->addAttributeToFilter(\'status\', array(\'eq\'=>\'1\')); //$products->addAttributeToFilter(\'status\', 1); //Mage::getSingleton(\'catalog/product_status\')->addVisibleFilterToCollection($products); $products -> load (); foreach( $products as $product ) { echo $product -> getData ( \ 'name\' ). \ "<br />\" ; //var_dump($product->getStatus()); } ?>
As you can see I try to filter them different ways (they are now commented out, but I tried them one by one):
$products->addAttributeToFilter(\’status\’, array(\’value\’=>1));
$products->addAttributeToFilter(\’status\’, array(\’eq\’=>\’1\’));
$products->addAttributeToFilter(\’status\’, 1);
Mage::getSingleton(\’catalog/product_status\’)->addVisibleFilterToCollection($products);
Also, $product->getStatus() always returns 1, even if the product is disabled
o_0
Please help! (looks like it adds \ to all single and double quote on this forum)
Posted: April 30 2010
| top
The Sunday Paper
Total Posts: 202
Joined: 2008-08-06
Mage::getSingleton(’catalog/product_status’)->addVisibleFilterToCollection($collection);
Mage::getSingleton(’catalog/product_visibility’)->addVisibleInCatalogFilterToCollection($collection);
Posted: July 21 2010
| top
| # 1
fxchain
Total Posts: 40
Joined: 2009-03-01
Thank, that worked!!!
Posted: August 12 2010
| top
| # 2
Sana-Sbiha
Total Posts: 61
Joined: 2009-10-13
Hello all,
I m trying to filter product by status. I used this code:
$product=Mage::getRessourcesModel(\’catalog/product_collection\’)
->addAttributeToSelect(\’*\’)
->addAttributeToFilter(\’status\’,1)
But i have all product affiched even wich have status disable. And when i do echo for the sattus i have always 1.
How did you resolve the problème?
Thks a lot
Posted: November 30 2010
| top
| # 3
tzyganu
Total Posts: 2181
Joined: 2009-11-18
Bucharest, Romania
Read the thread more carefully.
See what ‘The Sunday Paper’ suggested.
instead of
->addAttributeToFilter(\’status\’,1)
use
Mage::getSingleton(’catalog/product_status’)->addVisibleFilterToCollection($collection);
Signature
http://marius-strajeru.blogspot.com/
Check out the Ultimate Module Creator:
on magento connect
on github
Posted: November 30 2010
| top
| # 4
Devz
Total Posts: 7
Joined: 2010-12-06
Is there any new non-depreciated method for doing this?
Im trying to export my product list, but status=1 regardless of if the product is enabled or not.
Posted: March 3 2011
| top
| # 6
dam358
Total Posts: 6
Joined: 2010-03-29
+1
I’m interested to filter by status
Posted: April 13 2011
| top
| # 7
anoopnath
Total Posts: 14
Joined: 2010-08-27
Hello
Please tell me at which level status filter is done for Catalog/product collection.
is it at the level of Varien classes?..
as in the Product status class the function is deprecated.
Thanks in advance
Anoop
Posted: August 19 2011
| top
| # 8
miked2004
Total Posts: 214
Joined: 2007-12-13
Atlanta, Georgia
Just an update:
This will do nothing in new releases
Mage :: getSingleton ( 'catalog/product_status' )-> addVisibleFilterToCollection ( $collection );
This will filter the collection by visibility status:
Mage :: getSingleton ( 'catalog/product_visibility' )-> addVisibleInCatalogFilterToCollection ( $collection );
Both of the above are deprecated but the second one will filter the collection. You can also do things like the following to filter based on different combinations of the products visibility setting.
$collection -> setVisibility ( Mage :: getSingleton ( 'catalog/product_visibility' )-> getVisibleInCatalogIds ()); //OR $collection -> setVisibility ( Mage :: getSingleton ( 'catalog/product_visibility' )-> getVisibleInSiteIds ());
Signature
~ Mike D
http://www.sharpdotinc.com
http://www.sharpdotinc.com/mdost
Posted: September 30 2011
| top
| # 10
Clay S
Total Posts: 15
Joined: 2009-10-02
I achieved this like so:
$products = Mage :: getModel ( 'catalog/product' )-> getCollection () -> addAttributeToSelect ( '*' ) -> addFieldToFilter ( 'status' , Mage_Catalog_Model_Product_Status :: STATUS_ENABLED )
Posted: November 16 2011
| top
| # 11
MattStephens
Total Posts: 152
Joined: 2011-07-12
United Kingdom
Hello. Just an update on this…
As miked2004 has suggested, these methods are now depreciated.
Product Status
Instead of:
Mage :: getSingleton ( 'catalog/product_status' )-> addVisibleFilterToCollection ( $collection );
You can use:
$collection -> addFieldToFilter ( 'status' , Mage_Catalog_Model_Product_Status :: STATUS_ENABLED )
Other options avaliable are:
STATUS_ENABLED
STATUS_DISABLED
Product Visibility
Instead of:
Mage :: getSingleton ( 'catalog/product_visibility' )-> addVisibleInCatalogFilterToCollection ( $collection );
You can use:
$collection -> addFieldToFilter ( 'visibility' , Mage_Catalog_Model_Product_Visibility :: VISIBILITY_BOTH );
Other options avaliable are:
VISIBILITY_NOT_VISIBLE
VISIBILITY_IN_CATALOG
VISIBILITY_IN_SEARCH
VISIBILITY_BOTH
For more information have a look at:
/core/Mage/Catalog/Products/Visibility.php
/core/Mage/Catalog/Products/Status.php
You will find the contstants defined at the top of each of these.
Other filtering
For that matter, you can also filter this way for the product type (simple, configurable etc.). Take a peak at /core/Mage/Catalog/Products/Type.php
Cheers
Matt
MattStephens
Total Posts: 152
Joined: 2011-07-12
United Kingdom
Hello JRosell
You’re correct, the addInStockFilterToCollection() method is still accessible against the Catalog Inventory Stock singleton.
The methods described as depreciated in the post mainly concern product visibility rather than stock, therefore the method you\’ve chosen still remains an acceptable way to check a product is in stock or not.
Cheers
Posted: October 29 2012
| top
| # 14