Get attribute value label by code


protected $eavConfig;

public function __construct(
Context $context,
\Magento\Eav\Model\Config $eavConfig
) {
$this->_eavConfig = $eavConfig;
parent::__construct($context);
}
$attributeCode = "attribute_code";
$attribute = $this->_eavConfig->getAttribute('catalog_product', $attributeCode);
$options = $attribute->getSource()->getAllOptions();
$arr = [];
foreach ($options as $option) {
if ($option['value'] > 0) {
$arr[] = $option;
}
}

---
$_product->getResource()->getAttribute('design_color')->getFrontend()->getValue($_product);
$_product->getAttributeText('farben');

$optionId = 27;
$attribute = $_product->getResource()->getAttribute('design_color');
if ($attribute->usesSource()) {
$optionText = $attribute->getSource()->getOptionText($optionId);
}
$optionLabel = "blue";
$attribute = $_product->getResource()->getAttribute('design_color');
if ($attribute->usesSource()) {
$option_id = $attribute->getSource()->getOptionId($optionLabel);
}

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *