2018-09-26 00:47
浏览 28

Magento 2 - 产品中默认没有制造商或品牌属性

I need to use for my extension either a brand attribute or a manufacturer attribute in the products. Nevertheless, I cannot find any attribute that corresponds to that case.

For example, doing something like these returns nothing:

$this->_logger->debug(' Manufacturer ' . $product->getAttributeText('manufacturer'));

And something like these:

$this->_logger->debug('Manufacturer ' .$product->getManufacturer());

raises an exception.

Am I missing something or it doesn't exist by default?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongpin2969 2018-09-26 06:56
    • Make sure that you have assigned "manufacture" or "brand" attribute
      to appropriate product Attribute Set.
    • Make sure you have enter values manufacture or brand for the product as well.

    You can get attribute text by using below code.

    echo $_product->getAttributeText('manufacturer');
    echo $_product->getAttributeText('brand');

    if $_product doesn't work for you then try below code to get product data.

    $_product = $this->getProduct();


    $_product = $block->getProduct();

    Accept if this answer is helpful to you.

    Source link answered here as well

    解决 无用
    打赏 举报

相关推荐 更多相似问题