Manufacturer logo problem on Product page
-
07-10-2020 - |
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') ?> <?php echo $manufacturerName; ?> <?php echo $this->__('press here') ?>" /></a>
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') ?> <?php echo $manufacturerName; ?> <?php echo $this->__('press here') ?>" />
</a>
<?php endif; ?>
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange