Question

I have the code below to the view.phtml file and shows the manufacturer logo under the price. The problem is that if I have no manufacturer it shows me the symbol that there is no image (only in Chrome) How can I fix that?

<?php $_product = $this->getProduct();
$manufacturerName = $_product->getAttributeText('manufacturer');
$manufacturerId = $_product->getManufacturer();
echo '<a href="/catalogsearch/advanced/result/?manufacturer='.$manufacturerId.'&q='.$manufacturerName.'">' ?> 
<img src="/media/catalog/brand/<?php echo str_replace(' ', '_',$manufacturerId); ?>.jpg" alt="<?php echo $manufacturerName; ?>" title="<?php echo $this->__('For more of') ?>&nbsp;<?php echo $manufacturerName; ?>&nbsp;<?php echo $this->__('press here') ?>" /></a>

enter image description here

Was it helpful?

Solution

You need to add an if statement around your output to check your manufacturer attribute:

<?php
$_product = $this->getProduct();
$manufacturerName = $_product->getAttributeText('manufacturer');
$manufacturerId = $_product->getManufacturer();
?> 
<?php if ($manufacturerId) : ?>
<a href="/catalogsearch/advanced/result/?manufacturer=<?php echo $manufacturerId; ?>&q=<?php echo $manufacturerName; ?>">
<img src="/media/catalog/brand/<?php echo str_replace(' ', '_',$manufacturerId); ?>.jpg" alt="<?php echo $manufacturerName; ?>" title="<?php echo $this->__('For more of') ?>&nbsp;<?php echo $manufacturerName; ?>&nbsp;<?php echo $this->__('press here') ?>" />
</a>
<?php endif; ?>
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top