Skip to content

Instantly share code, notes, and snippets.

@enis-ismail
Last active September 10, 2020 11:36
Show Gist options
  • Save enis-ismail/7786211 to your computer and use it in GitHub Desktop.
Save enis-ismail/7786211 to your computer and use it in GitHub Desktop.
Magento: Get attribute option's label by ID and vice versa
<?php
$productModel = Mage::getModel('catalog/product');
$attr = $productModel->getResource()->getAttribute("color");
if ($attr->usesSource()) {
echo $color_id = $attr->getSource()->getOptionId("Red");
echo $color_label = $attr->getSource()->getOptionText("8");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment