回答:
これを試して:
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';
$ 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'];
if(strlen(trim($ l))> 0 && in_array($ m、$ car_options))
{
$ res。= trim($ l)。'、';
}
}
echo substr($ res、0、-2);;