문제

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

도움이 되었습니까?

해결책

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; ?>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 magento.stackexchange
scroll top