Posted in:
Magento 2 Tutorials
Magento 2 get all values of dropdown attribute
This post shows how to get all possible values of dropdown attribute in Magento 2. You can use below code to get all options of dropdown attribute in phtml file.
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$productRepository = $objectManager->get('\Magento\Catalog\Model\Product\Attribute\Repository');
$sizes = $productRepository->get('sizes')->getOptions();
foreach ($sizes as $sizesOption) {
if ($sizesOption->getValue() != '') {
$sizesOption->getValue();
$sizesOption->getLabel();
}
}
June 18, 2018
Did you like this post?