Product – How to Query if a Product is Set to Be Visible on the Website

product

I have modified the bundled product view template so that the "checkboxed" product options are displayed with links back to their component products using $_product = Mage::getModel, etc.

The problem I'm having is, I need to not show a link if the item is not visible in the website/catalog, and include the link only if the item is visible in the catlog.

Here's a recent version of the code:

<?php $_option = $this->getOption() ?>
<?php $_selections = $_option->getSelections() ?>

....

$_product = Mage::getModel('catalog/product');
$_product->load($_selection->getProductId());

....

<?php if($_selection->getVisibleInSiteVisibilities()) echo '<a href="'.$_selection->getProductUrl().'" target="_blank">'; ?>
<?php echo $this->getSelectionQtyTitlePrice($_selection) ?>
<?php if ($_selection->getVisibleInSiteVisibilities()) echo '</a>'; ?>
</label></span>

I've tried $_selection->getVisibleIn SiteVisibilities() and that provides me with a boolean "false" regardless of how the visibility is set.

I tried $_selection->isVisibleInSiteVisibility() and that returns an array which seems to be the same for all products regardless of how the visibility is set as well.

Is there a simple way to find out if a product is set to be visible (or rather not set to "Not Visible Individually"?)

Best Answer

Have a look at the Mage_Catalog_Helper_Product function canShow. This function is used by the product controller when checking to see if a product can be shown. It uses the functions isVisibleInCatalog and isVisibleInSiteVisibility

public function canShow($product, $where = 'catalog')
{
    if (is_int($product)) {
        $product = Mage::getModel('catalog/product')->load($product);
    }

    /* @var $product Mage_Catalog_Model_Product */

    if (!$product->getId()) {
        return false;
    }

    return $product->isVisibleInCatalog() && $product->isVisibleInSiteVisibility();
}
Related Topic