Magento code adding custom options in product


Which was used in one of my projects to import product data including custom options. Another solution would be writing a script which could dynamically add custom options to a set of existing products. In this post I will show you how to create such script.

The available properties are as follows:

  • title – the option’s label;
  • type – option type, possible values:
    • field – simple input text,
    • area – multiline text area,
    • file – file with an upload form in the front-end,
    • drop_down – drop-down list with predefined values,
    • radio – a set of radio buttons,
    • checkbox – multiple selectable checkbox options,
    • multiselect – list of multiple selectable options,
    • date – date input field,
    • date_time – date and time combined,
    • time – time only;
  • is_require – a flag indicating if the option is required, 1 or 0;
  • price – price surcharge for the option;
  • price_type – type of the option surcharge, fixed or percent (of the product’s price);
  • sku – SKU for the option.

Some of the properties are type-dependent, e.g., a “file” option also has:

  • file_extension – a string of comma-separated file extensions that are accepted by the option; if empty any extension except “exe” and “php” is allowed;
  • image_size_x and image_size_y – image dimension limits in pixels;

An option of type “field” can have the following property:

  • max_characters – maximum allowed number of characters.

I will demo a example.
I have a json string as below:



Magento code adding custom options in product

Thanks for watching!.

About Author

Là một developer rất ham chơi nhưng không ham hố, không ham chơi nhưng rất thích cầm đầu...

Comments are closed.

%d bloggers like this: