문제

I have created a product drop-down attribute and assigned a value to it on the product.

I need them on product detail page.

$_attributeValue = $_product->getResource()->getAttribute('product_type')->setStoreId(0)->getFrontend()->getValue($_product);
echo $_attributeValue;

OR

$_attributeValue = $_product->getResource()->getAttribute('product_type')->getFrontend()->getValue($_product);
echo $_attributeValue;

Output as

NO

On print($_attributeValue) my output

Magento\Framework\Phrase Object ( [text:Magento\Framework\Phrase:private] => No [arguments:Magento\Framework\Phrase:private] => Array ( ) )

But for product text attribute I get the output.

도움이 되었습니까?

해결책

Should just be this

$attribute_code = 'product_type';
echo $_product->getResource()->getAttribute($attribute_code)->getFrontend()->getValue($_product);

or maybe

echo $_product->getAttributeText('product_type');

다른 팁

I tried to get the product from item which dint work for me

$product = $_item->getProduct();
$product->getResource()->getAttribute('product_type')->getFrontend()->getValue($product);

This one works

$objectManager =  \Magento\Framework\App\ObjectManager::getInstance();   
$product = $objectManager->get('Magento\Catalog\Model\Product')->load($_item->getProductId());
$product_type = $product->getResource()->getAttribute('product_type')->getFrontend()->getValue($product);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 magento.stackexchange
scroll top