#StackBounty: #magento2 #attributes #product-attribute get options value of each options label of an attribute

Bounty: 50

I have an alphabetical sorted list of option label of an attribute, I want to get option value of each option label
this is my code:

<?php
$om = MagentoFrameworkAppObjectManager::getInstance();

/** @var MagentoCatalogApiDataProductAttributeInterface $attribute */
$attribute = $om->get(MagentoCatalogApiProductAttributeRepositoryInterface::class)->get("manufacturer");
$image_source_files = [];
?>

<div id="main_content_wrap" class="outer">
    <section id="main_content" class="inner">

        <ul id="demoOne" class="demo">
<?php foreach ($attribute->getOptions() as $option) {

    $src =  $option->getLabel() ;
    $image_source_files[] = $src;
    
    
}
sort($image_source_files);


foreach ($image_source_files as $value) { 
    $srca = $value ;
    $srcb = $this->getViewFileUrl("images/" . $srca . ".png");
?>  
<li>                


<a href="<?php echo $option->getValue()?>  ">
<p style="display:none;">
<?php echo $srca; ?></p>
<img src="<?php echo $srcb; ?>"  onerror="this.onerror=null; this.remove(); " style="padding: 10px 20px;"  width="200" height="200"/>
</a>
</li>
    <?php

}

?>
</ul>   
</section>
</div>


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.