回答:
magento 1と同じようにできます。
詳細、訪問、構成可能な製品からのオプションIDおよびラベルの取得の詳細
//製品オブジェクトからオプションIDに基づいてオプションラベルを取得します
$optionId = 10;
$attr = $_product->getResource()->getAttribute('color');
 if ($attr->usesSource()) {
       $optionText = $attr->getSource()->getOptionText($optionId);
 }
//get option text ex. Red//オプションラベルに基づいてオプションIDを取得
$attr = $_product->getResource()->getAttribute('color');
 if ($attr->usesSource()) {
       $option_id = $attr->getSource()->getOptionId("Red");
 }
//get option id ex. 10magentoのベストプラクティスは、xmlを使用して行うことです。
たとえばbrand、次のような標準的な属性を取得するには、次のようにcatalog_product_view.xmlします。
<referenceBlock name="product.info.main">
    <block class="Magento\Catalog\Block\Product\View\Description" name="product.info.brand" template="product/view/attribute.phtml" before="-">
        <arguments>
            <argument name="at_call" xsi:type="string">getBrand</argument>
            <argument name="at_code" xsi:type="string">brand</argument>
            <argument name="css_class" xsi:type="string">brand</argument>
            <argument name="at_label" xsi:type="string">none</argument>
            <argument name="add_attribute" xsi:type="string">itemprop="brand"</argument>
        </arguments>
    </block>
</referenceBlock>これにより、入力属性またはテキストエリアの値が取得されます。ドロップダウンがある場合は、テキストタイプを使用する必要があります。そのため、引数のリストに次の行を追加します。
<argument name="at_type" xsi:type="string">text</argument>属性を取得するためにファイルを作成したり、PHPコードを記述する必要はありません。これにより、一貫性が保たれ、すべての属性に同じattribute.phtmlファイルが使用されます。何かを変更する場合は、1か所でのみ変更する必要があります。
私のために働いた
$_product->getResource()->getAttribute('your_attribute_code')->getFrontend()->getValue($_product);ファクトリーメソッドを使用
   protected $_attributeLoading;
   public function __construct( 
        .....
          \Magento\Catalog\Model\ResourceModel\ProductFactory   $attributeLoading,  
          ....
                                ) {
            parent::__construct($context);
            ....
            $this->_attributeLoading = $attributeLoading;
            ....
    }
   public function getAttributeOptionId($attribute,$label)
    {
        $poductReource=$this->_attributeLoading->create();
        $attr = $poductReource->getAttribute($attribute);
         if ($attr->usesSource()) {
                return  $option_id = $attr->getSource()->getOptionId($label);
         }
    }
   public function getAttributeOptionText($attribute,$label)
    {
        $poductReource=$this->_attributeLoading->create();
        $attr = $poductReource->getAttribute($attribute);
         if ($attr->usesSource()) {
                return  $option_Text = $attr->getSource()->getOptionText($label);
         }
    }phtmlファイル内
  $this->getAttributeOptionId('color','//optionLabel');
  $this->getAttributeOptionText('color','//optionId');$product->getResource()少なくともv2.2.2で非推奨になったことに関するDocBlockのメモがあるので、私はそれを使用してコーディングをためらっていました。代わりに、このページに既にあるものに触発されて、このソリューションを見つけました。
$optionId = $product->getDataByKey('attribute_code');
$optionText = null;
$attributes = $product->getAttributes();
if ($optionId && array_key_exists('attribute_code', $attributes)) {
    $attr = $attributes['attribute_code'];
    if ($attr->usesSource()) {
        $optionText = $attr->getSource()->getOptionText($optionId);
    }
}
if ($optionText) {
    //do something with $optionText
}参考のために、これはAbstractModel.phpのメソッドです
/**
 * Retrieve model resource
 *
 * @return \Magento\Framework\Model\ResourceModel\Db\AbstractDb
 * @deprecated 101.0.0 because resource models should be used directly
 */
public function getResource()
{
    return $this->_getResource();
}getResource()。このモデル内のメソッドgithub.com/magento/magento2/blob/2.3-develop/app/code/Magento/...
                    getResource()以前に存在した方法でした。私が述べたように、v2.2.2では、すでに廃止予定でした。2.3-developブランチでは、完成したと思われます。したがって、その機能を必要としない私の例。
                    皆のためにここに来ます。
製品エンティティがない場合は、この手順でオプション値を取得できます。
\Magento\Eav\Api\AttributeRepositoryInterfaceクラスに注入する
public function __construct(
    ...
    \Magento\Eav\Api\AttributeRepositoryInterface $attributeRepository,
    ...
) {
    ...
    $this->attributeRepository = $attributeRepository;
    ...
}リポジトリを使用して属性インスタンスを取得します
// 4 is the default entity_type_id for product
$attribute = $this->attributeRepository->get('4', '[attribute_code]');$attributeオプション値からオプションIDを取得するために使用します
$optionId = $attribute->getSource()->getOptionId('[option_value]');属性ラベルを取得するために使用できます
$product->getResource()->getAttribute($key)->getFrontend()->getLabel($product);あなたはオブジェクトマネージャを使用することができます:
$pid = 1;
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$pdata = $objectManager->create('Magento\Catalog\Model\Product')->load($pid);
$getlable = $pdata->getResource()->getAttribute($key)->getFrontend()->getLabel($pdata);このコードを試してください
ステップ1)最初に製品をロードする必要があります
$_productCollection = $block->getLoadedProductCollection();ステップ2)製品リストページには、このような製品をリストするためのforeachループがあります。
foreach ($_productCollection as $_product)Step3)コードはこのループ内にあります。属性ラベルを表示したい場所に以下のコードを配置します。
$_product->getResource()->getAttribute('your_attribute_code')->getFrontend()->getValue($_product);your_attribute_codeを属性の名前に置き換えてください。