1

My question is in two parts.

  1. When you call $product->getOptions(), does this mean Options is an attribute? For example, when you are trying to get the name or a custom attribute "custom_attribute" of a product, you will use:

    $product->getName();
    $product->getCustomAttribute()
    

    Is this the same for options?? Are product options held in the options attribute? Is there even an options attribute??

  2. What is the fastest way to get the options only? I need to parse through the options to see if an options exists and then print it out. This takes way to much time to load since I have to do this in a product list view. For example, when you only need a products name and image you can use collections to grab only the attributes you need using:

    $collection->addAttributeToSelect('name');
    $collection->addAttributeToSelect('small_image');
    

    Can you do this with options?? As of right now I have to get the product id and then load the product to get the product options. This takes waaaayyyy too much time @_@. Urks my soul.

2

So to answer you first question. Technically the options are set against the product like another attribute but then are not standard Magento product attributes. They are set on the function Mage_Catalog_Model_Product::_afterLoad. What this function does is load each product option from a collection and then attach it to the current model.

protected function _afterLoad()
{
    parent::_afterLoad();
    /**
     * Load product options
     */
    if ($this->getHasOptions()) {
        foreach ($this->getProductOptionsCollection() as $option) {
            $option->setProduct($this);
            $this->addOption($option);
        }
    }
    return $this;
}

So you can simply access them like a normal attribute even though they are "special" in that case.

For you second question what you can do is to simply use the options model Mage::getSingleton('catalog/product_option') and then then get the product option collection by filtering by product.

You can do this via a call to getProductOptionCollection this takes in a product object as a parameter which I think you already have and then builds a collection of all the options.

There may be a better option to add options to the product list collection but I am not sure about that.

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.