Search code examples
magentomagento-soap-api

Pulling Custom Option ID from Magento


We have a SOAP connection to magento that is working great - we're able to pull product info, skus, descriptions, etc. using the magento API. We've been able to successfully add products to the cart programmatically with custom options, and that works great. The problem is this:

When you create a custom option for a product, it is assigned a unique ID that has to be called in order to pass that option value to the cart. For example:

www.mysite.com/magento/checkout/cart/add?product=7&qty=1&options[OPTION ID]=robots

Assuming I have my custom option ID correct, this will add 1 product with the option "robots." Which is nice.

However, we have hundreds of products, and while they all use similar custom options, each option is given a unique ID. That means I need to be able to call the magento API and get custom options details (specifically the option ID) so that we can add them to the cart properly. I have been back and forth with Varien Support (Magento), but they are less than helpful, as usual. Now, I know I can find these options by using firebug in Firefox or Chrome, which I've done to test the "add to cart" script. However, that's not a proper solution. I need to be able to grab this data from magento based on product id.

Can this really be that hard? Shouldn't this be tied to the data for the product somehow? I've done a var_dump on the catalog_product.info and i see where it asks if there are options but doesn't provide any details on them. Thoughts?

Thanks in advance.


Solution

  • Do you need to get all options ids for specific products or just some particular? For the latter you can use this code:

    $productEntity = Mage_Catalog_Model_Product::ENTITY;
    $colorAttribute = Mage::getModel('eav/config')->getAttribute($productEntity, 'color');
    $colorAttribute->getId();
    

    For the first option code in this question might be useful How to get all super attribute options for a configurable item in Magento