如何在我的magento产品页面中添加多个制造商品牌徽标

时间:2014-01-21 09:04:44

标签: magento

我已使用此magento extension添加了制造商品牌徽标。但我可以只添加一个徽标,因为在制造商中有下拉输入。如何在产品页面中添加两个制造商品牌徽标。

2 个答案:

答案 0 :(得分:0)

此代码添加到产品视图模板路径:

template/catalog/product/view.phtml

此品牌名称代码:

<?php getAttributeText('manufacturer') ?>
This Code for Manufacture Logo :

echo $this->getLayout()->createBlock('manufacturer/manufacturer')->setProduct($_product)->setTemplate('manufacturer/product_manufacturer.phtml')->toHtml();

答案 1 :(得分:0)

<?php/***********Display Brand Attribute************/?>
<?php

$om = \Magento\Framework\App\ObjectManager::getInstance();
$category = $om->get('Magento\Framework\Registry')->registry('current_category');//get current category

$om = \Magento\Framework\App\ObjectManager::getInstance();
$categoryFactory = $om->get('\Magento\Catalog\Model\CategoryFactory');
$categoryHelper = $om->get('\Magento\Catalog\Helper\Category');
$categoryRepository = $om->get('\Magento\Catalog\Model\CategoryRepository');
$category = $categoryFactory->create()->load($catId);
$categoryProducts = $category->getProductCollection()
                             ->addAttributeToSelect('*');
?>
<div class="main_brand_bg">
    <ul>
    <?php  
    $brandIds = [];                        
    foreach ($categoryProducts as $_product) {
        if($_product->getManufacturer()){

            $brandValue = $_product->getResource()->getAttribute('manufacturer')->getFrontend()->getValue($_product);
            $brandId = $_product->getManufacturer();
            $curnt_cat_url = $category->getUrl();
            $brandLink = '?manufacturer='.$brandId;

            $om = \Magento\Framework\App\ObjectManager::getInstance();
            $swatchHelper=$om->get("Magento\Swatches\Helper\Media");
            $swatchCollection = $om->create('Magento\Swatches\Model\ResourceModel\Swatch\Collection');
            $swatchCollection->addFieldtoFilter('option_id',$brandId);
            $item = $swatchCollection->getFirstItem();
            $thumbImage =  $swatchHelper->getSwatchAttributeImage('swatch_thumb', $item->getValue());
            $SwatchImage = $swatchHelper->getSwatchAttributeImage('swatch_image', $item->getValue());

            if (!in_array($brandId,$brandIds )){
                $brandIds[] = $brandId;
            ?>
                <div class="brand_bg">
                    <li class="brand_img_bg"> 
                        <a href="<?php echo $curnt_cat_url.$brandLink; ?>" title="<?php echo $brandValue; ?>" ><img src="<?php echo $thumbImage; ?>"></a>
                    </li>
                </div>

            <?php } ?>

        <?php } ?>
    <?php } ?>
    </ul>
</div>