BE SMART, hand over your headache to Rootways and FOCUS ON YOUR BUSINESS.

Magento 2 get all values of dropdown attribute

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?
0
0