1

I have a product attribute, Available Sizes in Magento. The input type is Multiple Select.

The options for the attribute are Small, Medium and Large.

enter image description here

Normally when I call a product attribute on the frontend, I use echo $_product->getAttributeCode();

With this attribute, when I use echo $product->getAvailableSizes(); it is giving me the values for the product like 13 or 14,13 - I assume these are the IDs of the options, rather than the labels.

I want to print out the options as text rather than IDs.

What I want is something like Small or Small,Medium. Can I get the attribute in this format without having to resort to if statements like if value is 13, echo "Small" etc. I want to do something more dynamic than that if possible!

For reference I am working on the catalog/product/view.phtml and catalog/product/list.phtml views.

Many thanks. I'm working with EE 1.14.0.1.

6

Try this:

$product->getAttributeText('available_sizes');
  • 1
    Thanks - this was what I needed. If one of the multiple selects is selected for the product, it gives just the text string. If more than one is selected, it gives an array of the text labels eg. array("Small","Medium","Large"); which you can loop through. – Sarah Sep 8 '14 at 9:17
  • @ParasSood and @Sarah, I am facing same problem, And I user $_product->getAttributeText('has_package'); but no use, I am not able to print multiselect options text, Am missing something? – Charlie Jun 2 '15 at 13:08
  • Does your product have one or more than one of the options selected? If more than one, do something like echo implode(",", $product->getAttributeText); and that will print the values, comma-separated. The other issue you might be having is whether your attribute is available to your current $_product object. Eg. if you are working on a product listing page, check the attribute has the "Visible in Product Listing" option set to Yes. If you are working in the basket or checkout there may be other similar issues. – Sarah Jun 2 '15 at 19:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.