We sacrifice by not doing any other technology, so that you get the best of Magento.

We sacrifice by not doing any other technology, so that you get the best of Magento.

Sometime we customise code , so we need to get drop-down attribute values in custom file.

So the below code will help to retrieve attribute based on attribute id

$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$attributeId = 101;
$eavModel = $objectManager->create('MagentoCatalogModelResourceModelEavAttribute');
$eavModel->load($attributeId);
$attributeCode = $eavModel->getAttributeCode();
$productAttributeRepository = $objectManager->create('MagentoCatalogModelProductAttributeRepository');
$options = $productAttributeRepository->get($attributeCode)->getOptions();


?>

<div class="field required">
    <label class="label"><?= /* @escapeNotVerified */ __('Colour') ?>:</label>
<div class="control">
<select name="product[color]" id="color" class="required-entry input-text">
<?php
foreach ($options as $option) {
    $value = $option->getValue();  // Value
    $label = $option->getLabel();  // Label              
    ?>
    <option value="<?php echo $value; ?>"><?php echo $label; ?></option>
    <?php 
} ?>
</select>
</div>
</div>

that’s it. Happy coding.

field_5bfb909c5ccae

    Recent Articles
    Get a Free Quote