Skip to main content Link Menu Expand (external link) Document Search Copy Copied

Module: Complex Product API

Resource: product_custom_option

Method:
  • product_custom_option.add (SOAP V1)
  • catalogProductCustomOptionAdd (SOAP V2)

Allows you to add a new custom option for a product.

Arguments:

TypeNameDescription
stringsessionIdSession ID
stringproductIdProduct ID
arraydataArray of catalogProductCustomOptionToAdd
stringstoreStore view ID or code (optional)

Return:

TypeDescription
booleanTrue if the custom option is added

The catalogProductCustomOptionToAdd content is as follows:

TypeNameDescription
stringtitleOption title
stringtypeOption type
stringsort_orderOption sort order
intis_requireDefines whether the option is required
arrayadditional_fieldsArray of catalogProductCustomOptionAdditionalFields

The catalogProductCustomOptionAdditionalFieldsEntity content is as follows:

TypeNameDescription
stringtitleCustom option title
stringpriceCustom option price
stringprice_typePrice type. Possible values are as follows: “fixed” or “percent”
stringskuCustom option SKU
stringmax_charactersMaximum number of characters for the customer input on the frontend (optional)
stringsort_orderCustom option sort order
stringfile_extensionList of file extensions allowed to upload by the user on the frontend (optional)
stringimage_size_xWidth limit for uploaded images (optional)
stringimage_size_yHeight limit for uploaded images (optional)
stringvalue_idValue ID

Faults:

Fault CodeFault Message
101Product with requested id does not exist.
102Provided data is invalid.
103Error while saving an option. Details are in the error message.
104Store with requested code/id does not exist.
106Invalid option type provided. Call ‘types’ to get list of allowed option types.

Examples

Request Example SOAP V1
$proxy = new SoapClient('http://magentohost/api/soap/?wsdl');
$sessionId = $proxy->login('apiUser', 'apiKey');
$productId = 1;// Existing product ID

// Add custom option of Text Field type
$customTextFieldOption = array(
    "title" => "Custom Text Field Option Title",
    "type" => "field",
    "is_require" => 1,
    "sort_order" => 0,
    "additional_fields" => array(
        array(
            "price" => 10.00,
            "price_type" => "fixed",
            "sku" => "custom_text_option_sku",
            "max_characters" => 255
        )
    )
);
$resultCustomTextFieldOptionAdd = $proxy->call(
    $sessionId,
    "product_custom_option.add",
    array(
        $productId,
        $customTextFieldOption
    )
);

// Add custom option of File type
$customFileOption = array(
    "title" => "Custom File Option Title",
    "type" => "file",
    "is_require" => 1,
    "sort_order" => 5,
    "additional_fields" => array(
        array(
            "price" => 10.00,
            "price_type" => "fixed",
            "sku" => "custom_file_option_sku",
            "file_extension" => "jpg",
            "image_size_x" => 800,
            "image_size_y" => 600
        )
    )
);
$resultCustomFileOptionAdd = $proxy->call(
    $sessionId,
    "product_custom_option.add",
    array(
        $productId,
        $customFileOption
    )
);

// Add custom option of Dropdown type
$customDropdownOption = array(
    "title" => "Custom Dropdown Option Title",
    "type" => "drop_down",
    "is_require" => 1,
    "sort_order" => 10,
    "additional_fields" => array(
        array(
            "title" => "Dropdown row #1",
            "price" => 10.00,
            "price_type" => "fixed",
            "sku" => "custom_select_option_sku_1",
            "sort_order" => 0
        ),
        array(
            "title" => "Dropdown row #2",
            "price" => 10.00,
            "price_type" => "fixed",
            "sku" => "custom_select_option_sku_2",
            "sort_order" => 5
        )
    )
);
$resultCustomDropdownOptionAdd = $proxy->call(
    $sessionId,
    "product_custom_option.add",
    array(
        $productId,
        $customDropdownOption
    )
);
Request Example SOAP V2
$proxy = new SoapClient('http://magentohost/api/v2_soap/?wsdl');

$sessionId = $proxy->login('apiUser', 'apiKey');

$result = $proxy->catalogProductCustomOptionAdd($sessionId, '1', array('title' => 'title',
'type' => 'field',
'sort_order' => '1',
'is_require' => 1,
'additional_fields' => array(array(
'price' => '15',
'price_type' => 'fixed',
'sku' => 'sku',
'max_characters' => '100'
))));
var_dump($result);
Request Example SOAP V2 (WS-I Compliance Example)
$proxy = new SoapClient('http://magentohost/api/v2_soap/?wsdl');

$sessionId = $proxy->login((object)array('username' => 'apiUser', 'apiKey' => 'apiKey'));

$result = $proxy->catalogProductCustomOptionAdd((object)array('sessionId' => $sessionId->result, 'productId' => '1', 'store' => '1', 'data' => ((object)array(
'title' => 'title',
'type' => 'field',
'sort_order' => '1',
'is_require' => 1,
'additional_fields' => array(array(
'price' => '15',
'price_type' => 'fixed',
'sku' => 'sku',
'max_characters' => '100'
))))));
var_dump($result->result);