tags:

views:

2434

answers:

3

How do I add custom options to a product like you can in the backend, using the API.

Im using C# but if you know how do to this in Php, that would be helpful too.

I noticed that product has this:

var product = new catalogProductCreateEntity();
product.options_container = "blah";

And there is this:

catalogAttributeOptionEntity optionEntity = new catalogAttributeOptionEntity();
            optionEntity.value = "sds";
            optionEntity.label = "ere";

But I cant see a way of utilizing them, im not sure how to make a container, and the catalogAttributeOptionEntity does not have all the properties needed to make a custom option.

A: 

In the end I decided it cant be done via the API and went to the database directly.

Dan
It can be done using the API, however, I do not have any proof to show you. It may be that many of us don't know the proper way of adding products using API, for which I will suggest that you should be trying in every possible way to find out the details of the API.
Knowledge Craving
+1  A: 

Look at the admin product controller. Yes it is possible.

/**
         * Initialize data for configurable product
         */
        if (($data = $this->getRequest()->getPost('configurable_products_data')) && !$product->getConfigurableReadonly()) {
            $product->setConfigurableProductsData(Zend_Json::decode($data));
        }
        if (($data = $this->getRequest()->getPost('configurable_attributes_data')) && !$product->getConfigurableReadonly()) {
            $product->setConfigurableAttributesData(Zend_Json::decode($data));
        }

        $product->setCanSaveConfigurableAttributes((bool)$this->getRequest()->getPost('affect_configurable_product_attributes') && !$product->getConfigurableReadonly());

        /**
         * Initialize product options
         */
        if (isset($productData['options']) && !$product->getOptionsReadonly()) {
            $product->setProductOptions($productData['options']);
        }
Josh Ribakoff
A: 

Nice tutorial here

http://subesh.com.np/2009/12/adding-custom-options-product-magento/

subesh