I want to write a controller that finds the different options for a given product (eg. Large, Medium, Small, Red, Blue etc...).
Can anyone show me the code I would write into my controller?
Additional details
I'm getting closer, but I still can't figure it out. Here's the code I wrote in my controller
$db = Mage::getModel('catalog/product')->load($productId);
print_r($db->getOptions()); // returns an empty array
echo $db->getHasOptions(); // echos 1
But when I do the print_r() on the second line, the getOptions returns an empty array. The third line echo's the value 1, which means there SHOULD BE options.
Additional Details
I tried clockworkgeek's solution of $db->getProductOptions()
, that returned nothing. I tried $db->getProductOptionsCollection()
, and got this output
Array
(
[totalRecords] => 0
[items] => Array
(
)
)
What's wrong with my code such that it is not returning the allowable product options?
Instead of
getOptions()
please trygetCustomOptions()
orgetProductOptionsCollection()
orgetProductOptionsCollection()->load()
.Edit
I tried this on a product I knew had options.
And got something like this:
However,
getOptions()
also worked for me so I don't know what's going on.Post-edit
The confusion was one of semantics. A simple product can have "custom options", they allow creation of a few form fields which are recorded as part of the order. A configurable product uses "associated products" to create a form with conditional fields.
For example you might be selling socks that are large-green, small-green or large-blue - but no small-blue ones. With a simple product you would have a field for large/small and a field for blue/green - which allows the customer to select small-blue and that is wrong.
So to find the component parts of a configurable you might do something like this:
To find the equivalent of
getOptions()
you need this:Mage_Catalog_Model_Product_Type_Configurable_Attribute
doesn't have much to reveal about itself.The above solution is perfect and I solved my problem using it. I was trying to display the colors on the list. Here is my solution