Stumped on getOptions method for Select Attribute when used as Product Option

Permalink
I've been getting along pretty well with attributes lately but this one has got me stumped. I'm working with Core Commerce Products and getting the Configurable Attributes (Customer Choices). But when I try to get the actual options for a select attribute, I can't find any way to make it work. Here's an abridged version of what I'm trying to do:

$attribs = $product->getProductConfigurableAttributes();
foreach ($attribs as $att) {
   switch ($att->atHandle) {
      case 'select':
         $options = $att->getOptions();
         // do something with $options ...         
         break;
      // other cases ...
   }
}


The problem is with the getOptions() method.

$att->getOptions();  // undefined method CoreCommerceProductOptionAttributeKey::getOptions()

$att->getAttributeType()->getOptions();  // undefined method AttributeType::getOptions()

$at = $att->getAttributeType();
$cnt = $at->getController();
$options = $cnt->getOptions();  // This one at least isn't undefined, but gives:
Fatal error: Call to a member function getAttributeKeyID() on a non-object in /home/duckandd/public_html/concrete/core/models/attribute/types/select.php on line 449


(Line 449 in the Select Controller is where it calls $this->attributeKey->getAttributeKeyID() and for some reason the key is not an object.)

Meanwhile, this works just fine:

$att->render('form');


...and the 'form' view that is being rendered calls $this->controller->getOptions(), of course.

I just can't seem to get into the right context to be able to use the getOptions method on a select attribute from the Product Options starting point. The getOptions method sits in the SelectAttributeTypeController -- it would seem I could get at it by going through the Attribute Type, as I tried above, but without luck.

If anyone has bushwhacked through this conundrum before and has a suggestion, please don't hesitate to speak up. Any feedback appreciated!

Benji
View Replies:
vectorsevenmedia replied on at Permalink Reply
vectorsevenmedia
Did you ever figure this out? I am having the exact same issue and cannot find any answers anywhere.
Benji replied on at Permalink Reply
Benji
Yeah, I did, but apparently was going too fast to come back here and post the solution. It's this:

$attribs = $product->getProductConfigurableAttributes();
foreach ($attribs as $att) {
   switch ($att->atHandle) {
      case 'select':
         $cnt = $att->getAttributeType()->getController();
         $cnt->setAttributeKey($att);
         $options = $cnt->getOptions();
      // etc.


The missing part was the $cnt->setAttributeKey($att) line. It wasn't easy to discover that -- there's no documentation or forum posts, and the controller didn't lend itself easily to that conclusion either. But once you set the attribute key, you're off and running.

Enjoy!