You can try something like this
$products ->getResource()->getAttribute('status')->getFrontend()->getValue($products );
this is for status attribute.
Question
How can I get the friendly text for a products status and visibility options. for example, 'Enabled' or 'Disabled' rather the 1 or 2, and similarly for visibility 'Not Visible Individually', 'Catalog, Search' etc rather than 1,2,3 or 4?
I'm guessing there is a function somewhere that can take $product->getStatus
and return the text value? and a similar one for visibility?
I'm just playing about getting used to magento trying to build a simple list:
$products = Mage::getModel('catalog/product')
->getCollection();
foreach ( $products as $product ) {
echo $product->getSku();
echo $product->getStatus();
echo $product->getVisibility();
}
but would like status and visibility to appear as they do in the admin pages rather than the numeric values.
EDIT: With the help of Mufaddal's answer, my final solution was;
$products = Mage::getModel('catalog/product')
->getCollection()
->addAttributeToSelect('sku')
->addAttributeToSelect('status')
->addAttributeToSelect('visibility')
->addAttributeToSort('sku', 'asc');
foreach( $products as $product ){
echo 'SKU: ' .$product->getSku() . '<br/>';
echo 'Visibility: ' . $product->getResource()->getAttribute('visibility')->getFrontend()->getValue($product); . '<br/>';
echo 'Status: ' . $product->getResource()->getAttribute('status')->getFrontend()->getValue($product); . '<br/>';
}
I needed to either ->addAttributeToSelect('*')
or specify each attribute in the select before the getResource calls would work e.g. $product->getResource()->getAttribute('status')->getFrontend()->getValue($product);
.
Solution 2
You can try something like this
$products ->getResource()->getAttribute('status')->getFrontend()->getValue($products );
this is for status attribute.
OTHER TIPS
You can also try:
$product->getAttributeText('status')
Which will work in some cases and not in others, but where it does work it is shorter and simpler than going through the resource.