Magento check bundled product visibility


I’ve created a custom module that adds a hyperlink to bundled products on the product view page, however it needs to consider the product’s visibility since Magento will return an error page when visiting a product that is hidden in the catalog. Apparently calling $_product->getVisibility() would return the integer 1-4 we’re looking for on Magento version 1.5, but not so on 1.8. The way I was able to accomplish this with Magento 1.8 is by loading the product and then checking isVisibleInSiteVisibility() like this:

//load full product for bundled selection so we can check visibility		
$selectionProduct = Mage::getModel('catalog/product')->load($_selection->getId());
 
if ($selectionProduct->isVisibleInSiteVisibility()) {
	$priceTitle .= '<a href="' . $_selection->getProductUrl() . '">';
}
$priceTitle .= $this->escapeHtml($_selection->getName());
if ($selectionProduct->isVisibleInSiteVisibility()) {
	$priceTitle .= '</a>';
}

This is applied to the four files at Yourmodule/Bundle/Block/Catalog/Product/View/Type/Bundle/Option/ . The full code for Yourmodule/Bundle/Block/Catalog/Product/View/Type/Bundle/Option/Select.php is

<?php
class Yourmodule_Bundle_Block_Catalog_Product_View_Type_Bundle_Option_Select
	extends Mage_Bundle_Block_Catalog_Product_View_Type_Bundle_Option_Select 
{
 
	public function getSelectionTitlePrice($_selection, $includeContainer = true)
	{
		$price = $this->getProduct()->getPriceModel()->getSelectionPreFinalPrice($this->getProduct(), $_selection, 1);
		$tierPrice = $_selection->getTierPrice();
		if (!empty($tierPrice)) {
			$qty = $_selection->getSelectionQty();
			$price = $qty * (float) $_selection->getPriceModel()->getTierPrice($qty, $_selection);
		}
		$this->setFormatProduct($_selection);
 
		$priceTitle = '';
 
		//load full product for bundled selection so we can check visibility		
		$selectionProduct = Mage::getModel('catalog/product')->load($_selection->getId());
 
		if ($selectionProduct->isVisibleInSiteVisibility()) {
			$priceTitle .= '<a href="' . $_selection->getProductUrl() . '">';
		}
		$priceTitle .= $this->escapeHtml($_selection->getName());
		if ($selectionProduct->isVisibleInSiteVisibility()) {
			$priceTitle .= '</a>';
		}
 
		$priceTitle .= ' &nbsp; ' . ($includeContainer ? '<span class="price-notice">' : '')
		. '+' . $this->formatPriceString($price, $includeContainer)
		. ($includeContainer ? '</span>' : '');
		return $priceTitle;
	}
 
}

Leave a comment

Your email address will not be published. Required fields are marked *