当制造商属性设置为空时,magento不显示标题和徽标

时间:2016-01-26 20:25:10

标签: php magento

我在产品页面view.phtml中使用以下Magento代码。

 <div class="manufacturer">                                                             
    <?php if ($_product->getAttributeText('manufacturer') == "Bellazza" || "Della" || "Pet Zone" || "Spyder Auto" ):?> 
        <div class="dealer">
            <p>Authorized Dealer:</p>
        </div>
        <div class="logoImg">
            <?php echo $this->getLayout()->createBlock('manufacturer/manufacturer')->setProduct($_product)->setTemplate('manufacturer/product_manufacturer.phtml')->toHtml();?>
        </div>
    <?php elseif ?>

    <?php endif;?>

</div>  

因此,我创建div.manufacturer以显示由“授权经销商”标题开始的关联品牌徽标图像。有用。但并非所有产品都有品牌,因此当我将制造商属性设置为空时(参见下图)我不再需要标题“授权经销商”。接近elseif的最佳做法是什么?谢谢

enter image description here

制造商/ manufacturer.phtml

<?php
$maufacturers = Mage::getModel('manufacturer/manufacturer')->getCollection()->addFieldToFilter('status',Array('eq'=>1));    
$_columnCount=4;
$i=0;
?>
<div class="manufacturer-list">
<?php foreach($maufacturers as $manufacturer): ?>
<?php if(Mage::getModel('eav/entity_attribute_source_table')->setAttribute(Mage::getModel('eav/entity_attribute')->load(Mage::getModel('eav/entity_attribute')->getIdByCode('catalog_product',"manufacturer")))->getOptionText($manufacturer->getMenufecturerName())): ?>
<?php if ($i++%$_columnCount==0): ?>
<ul>
<?php endif; ?>
    <li>
        <a href="<?php echo $this->getBaseUrl()."catalogsearch/advanced/result/?manufacturer[]=".$manufacturer->getMenufecturerName() ?>">
            <?php echo $this->getLayout()->createBlock('core/template')->setmanufacturerimage($manufacturer->getFilename())->setlegend($manufacturer->getLegend())->setListPageFlag(1)->setTemplate('manufacturer/manufacturer_resize.phtml')->toHtml(); ?>
        </a>
        <div class="manufacturer-name">
            <?php echo Mage::getModel('eav/entity_attribute_source_table')->setAttribute(Mage::getModel('eav/entity_attribute')->load(Mage::getModel('eav/entity_attribute')->getIdByCode('catalog_product',"manufacturer")))->getOptionText($manufacturer->getMenufecturerName()) ?>
        </div>
    </li>
<?php if ($i%$_columnCount==0 && $i!=count($maufacturers)): ?>
</ul>
<?php endif; ?>
<?php endif; ?>
<?php endforeach; ?>
</div>

product_manufacturer

<?php     
$product=$this->getProduct();
if(Mage::getModel('eav/entity_attribute_source_table')->setAttribute(Mage::getModel('eav/entity_attribute')->load(Mage::getModel('eav/entity_attribute')->getIdByCode('catalog_product',"manufacturer")))->getOptionText($product->getData('manufacturer'))):
    $manufacturers=Mage::getModel('manufacturer/manufacturer')->getCollection()->addFieldToFilter('menufecturer_name',$product->getData('manufacturer'));
    foreach($manufacturers as $manufacturer){
        $status=$manufacturer->getStatus();    
        if($status==1){
?>
        <div class="manufacturer-img-box">
        <a href="<?php echo $this->getBaseUrl()."catalogsearch/advanced/result/?manufacturer[]=".$manufacturer->getMenufecturerName() ?>">
        <?php echo $this->getLayout()->createBlock('core/template')->setmanufacturerimage($manufacturer->getFilename())->setlegend($manufacturer->getLegend())->setTemplate('manufacturer/manufacturer_resize.phtml')->toHtml(); ?>
        </a>
        </div>
<?php } 
} 
endif;
?>

1 个答案:

答案 0 :(得分:0)

您需要重构代码

install.packages("png", "/home/user/anaconda3/lib/R/library")

并检查变量

 <div class="manufacturer">                                                          
        <div class="logoImg">
            <?php echo $this->getLayout()->createBlock('manufacturer/manufacturer')->setProduct($_product)->setTemplate('manufacturer/product_manufacturer.phtml')->toHtml();?>
        </div>
</div> 

您需要重构代码。因为我在你的模板中浪费了太多的代码。你需要在你的块中获取数据,在phtml中你需要通过API块来渲染这些数据。 getImageSrc(); getManufactures()以及获取处理信息的方法。