Answers:
尝试这个:
echo $_product->getResource()->getAttribute('car_options')->getFrontend()->getValue($_product);
var_dump($_product->getData('car_options');检查输出。它应该是一个逗号分隔的字符串,如果不是,那么我只能想象一个第三方模块正在干扰。
$_product->getData('car_options')返回NULL,则表示未将其添加到您的产品集中。我们将需要了解有关您尝试在何处访问此属性的更多信息
$ objectManager = \ Magento \ Framework \ App \ ObjectManager :: getInstance(); $ product = $ objectManager-> get('Magento \ Catalog \ Model \ Product')-> load($ product_id); $ attributevalues = $ product-> getResource()-> getAttributeRawValue($ product_id,'my_custom_attribute_code',$ storeid);
它有效..希望它对您有帮助..
以下代码
$ _attribute_code ='汽车选项';
$ car_options_csv = Mage :: getResourceModel('catalog / product')-> getAttributeRawValue($ productId,$ _attribute_code,$ storeId); //返回值:123,124
$ car_options = explode(',',$ car_options_csv);
$ attributeId = Mage :: getResourceModel('eav / entity_attribute')-> getIdByCode('catalog_product',$ _ attribute_code);
$ attribute = Mage :: getModel('catalog / resource_eav_attribute')-> load($ attributeId);
$ attributeOptions = $ attribute-> getSource()-> getAllOptions();
$ res ='';
foreach($ attributeOptions as $ a)
{
$ l = $ a ['label'];
$ m = $ a ['value'];
如果(strlen(trim($ l))> 0 && in_array($ m,$ car_options))
{
$ res。= trim($ l)。',';
}
}
echo substr($ res,0,-2);;