I have json array for attribute options which is showing below:
"options":[
{
"label":"string",
"value":"string",
"sort_order":0,
"is_default":true,
"store_labels":[
{
"store_id":0,
"label":"string"
}
]
}
],
So I need that types of data by the magento 2 collection for particular attribute id or code.
I need to add/edit attribute options data using rest api in magento 2
Please provide me collection, thanks in advance.
Best Answer
First of all, we need take a look: Log in Magento Admin > Choose a product > ADVANCED SETTINGS > Custom Options:
We can see some fields, we need to fill in these input fields.
Second, we have the APIs for updating the custom options: http://devdocs.magento.com/swagger/#resource_catalogProductCustomOptionRepositoryV1
POST: /V1/products/options
PUT: /V1/products/options/{optionId}
For example:
product_sku
: Product SKUoption_id
: We can get by /V1/products/{sku}/optionstitle
: Title of the custom option.type
: Input Type: Text, File, Dropdown, Radio, etcsort_order
: Set the order of custom attributeis_require
: Required or notprice
: Price for the custom optionprice_type
: Fixed or Percentsku
: (updated later)file_extension
: can be empty, allowed file types: pdf, jpg, ...max_characters
: can be empty, used for Input type: Field, Area.image_size_x
andimage_size_y
: blank if it is not an image.values
: can be empty, used for Select Type: Dropdown, Radio Buttons, Checkbox, Multiple Select. We need to set the title, price type, Sortorder, etc.