我通过使用此Magento扩展名添加了制造商品牌徽标。但是,由于在制造商中的下拉输入,我只能添加一个徽标。如何在产品页面中添加两个制造商品牌徽标。
<?php/***********Display Brand Attribute************/?>
<?php
$om = MagentoFrameworkAppObjectManager::getInstance();
$category = $om->get('MagentoFrameworkRegistry')->registry('current_category');//get current category
$om = MagentoFrameworkAppObjectManager::getInstance();
$categoryFactory = $om->get('MagentoCatalogModelCategoryFactory');
$categoryHelper = $om->get('MagentoCatalogHelperCategory');
$categoryRepository = $om->get('MagentoCatalogModelCategoryRepository');
$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 = MagentoFrameworkAppObjectManager::getInstance();
$swatchHelper=$om->get("MagentoSwatchesHelperMedia");
$swatchCollection = $om->create('MagentoSwatchesModelResourceModelSwatchCollection');
$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>
此代码添加到产品视图模板路径:
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();