How to get the list of option values for particular attribute code in magento 2?
<?php
namespace Sample\Shopbyage\Block;
use \Magento\Eav\Api\Data\AttributeOptionInterfaceFactory;
class Shopbyage extends \Magento\Catalog\Block\Product\AbstractProduct
{
protected $_productCollectionFactory;
protected $catalogProductVisibility;
protected $urlHelper;
protected $sqlBuilder;
protected $imageHelperFactory;
protected $eavEntityFactory;
public function __construct(
\Magento\Catalog\Block\Product\Context $context,
\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory,
\Magento\Catalog\Model\Product\Visibility $catalogProductVisibility,
\Magento\Framework\App\Http\Context $httpContext,
\Magento\Rule\Model\Condition\Sql\Builder $sqlBuilder,
\Magento\Widget\Helper\Conditions $conditionsHelper,
\Magento\Catalog\Helper\ImageFactory $imageHelperFactory,
\Magento\Framework\Url\Helper\Data $urlHelper,
\Magento\Review\Model\ReviewFactory $reviewFactory,
array $data = []
) {
$this->_productCollectionFactory = $productCollectionFactory;
$this->catalogProductVisibility = $catalogProductVisibility;
$this->httpContext = $httpContext;
$this->sqlBuilder = $sqlBuilder;
$this->urlHelper = $urlHelper;
$this->conditionsHelper = $conditionsHelper;
parent::__construct($context, $data);
}
protected function _prepareLayout()
{
}
public function toHtml()
{
return parent::toHtml();
}
public function getShopbyageUrl(){
return $this->getUrl('shopbyage');
}
public function getProductCollection(){
$ageValues = $this->getAge();
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$coll = $objectManager->create('Magento\Catalog\Api\ProductCustomOptionRepositoryInterfaceAttribute $attributeFactory');
/*$coll->optionFactory->create();
$coll->load($ageValues);
$attrAll = $coll->load()->getItems();
foreach($attrAll as $st=>$value){
print_r($value);
}*/
$collection = $this->_productCollectionFactory->create();
$collection->addAttributeToSelect('*');
$collection->addAttributeToFilter('age',array(5,6));
return $collection;
}
}
I have tried above code but not working.