Magento Version: 1.5.0.1
Let’s say you have a product object
$p = Mage::getProduct('catalog/product')->load(3425);
You can get the value of the product’s status with the magic getter method or the getData
method.
$p->getStatus()
$p->getData('status');
However, the return value of this method is not a boolean. The value of a product object’s status (Enabled, Disable by default) is the numerical value of the select in the admin. A false status means a status value isn’t set. It doesn’t mean that the status is disabled
if(!$p->getStatus())
{
echo "No Status Set";
}
else if($p->getStatus() == 1)
{
echo "Status: Enabled";
}
else if($p->getStatus() == 2)
{
echo "Status: Disabled";
}
Not rocket science, but one of those little gotchas that can easily trip you up.
Update: Fabian over on the twitters points out that there’s class constants for the various status values.
Mage_Catalog_Model_Product_Status::STATUS_ENABLED
Shame on me