Apply Product Options
Request and response of APPLY_OPTION_SET, which creates an option set (such as Color x Size) on a product or adds values to it.
Data Identifier
{
"dataID": "APPLY_OPTION_SET",
"product_seq": 340,
"option_rev": 0,
"mode": "new",
"label": "Color / Size",
"is_required": 1,
"options": [
{"option_group_seq": 10},
{"name": "Size", "values": ["S", "M", {"label": "L", "price_delta": 2000}]}
]
}
| Key | Description |
|---|---|
| dataID | Data identifier APPLY_OPTION_SET |
| product_seq | Product number |
| option_rev | product.option_rev you loaded. 409 if it changed |
| mode | new (new set) / merge (add values to a set) |
| set_seq | Option set to merge into |
| label | Option set name, e.g. Color / Size |
| is_required | Required 0 / 1 |
| stock_flg | Track stock 0 / 1 |
| options | Options (max 3, rows are combined) |
| options[n].option_group_seq | Use a saved option group |
| options[n].name | Option name when typing values |
| options[n].values | Values. "S" or {label, price_delta} |
HTML
<form id="frm_apply_option_set" method="post">
<input type="hidden" name="product_seq" value="340">
<input type="hidden" name="option_rev" value="0">
<input type="hidden" name="mode" value="new">
<input name="label" value="Color / Size">
<input type="hidden" name="is_required" value="1">
<!-- options: JSON array of {option_group_seq} or {name, values:[label | {label, price_delta}]} (max 3) -->
<input type="hidden" name="options" value="[{"option_group_seq":10},{"name":"Size","values":["S","M",{"label":"L","price_delta":2000}]}]">
<button type="submit" class="btn btn-primary">Apply options</button>
</form>
Response Result
{
"result": true,
"set_seq": 12,
"created_rows": 6,
"option_rev": 1
}
| Key | Description |
|---|---|
| result | Succeeded or not |
| set_seq | Option set created or merged |
| created_rows | Rows created |
| option_rev | New option revision for the next request |
- One row is created per combination, e.g. 2 colors x 3 sizes = 6 rows. A row's price_delta is the sum of the chosen values' price_delta.
- New rows start with 0 stock. Set it with UPDATE_INVENTORY.
- The old SAVE_PRODUCT_OPTIONS API is retired and returns 410. Use APPLY_OPTION_SET described here.
- Error codes — errors also come back as HTTP 200. Check result:false, then error_code (string) and error_message.
- 401 — Sign-in required (Unauthorized).
- 409 — option_rev does not match. Someone saved options first; reload and retry.
- 422 — Invalid input, e.g. more than 3 options, no values, duplicate name, bad mode, merge without set_seq.
- 404 — Product or option set not found.
- 410 — SAVE_PRODUCT_OPTIONS is no longer supported.
<script setup>
import { ref } from 'vue'
// Build a "Color x Size" option set for product #340.
// Use a saved option group (option_group_seq) or type the values (name + values). Up to 3 options.
const optionRev = ref(0) // product.option_rev from GET_PRODUCT
const msg = ref('')
async function apply() {
const { output } = await useNuxtApp().$connector({
dataID: 'APPLY_OPTION_SET', product_seq: 340, option_rev: optionRev.value, mode: 'new',
label: 'Color / Size', is_required: 1,
options: [
{ option_group_seq: 10 },
{ name: 'Size', values: ['S', 'M', { label: 'L', price_delta: 2000 }] }
]
})
if (output.result) {
optionRev.value = output.option_rev
msg.value = `Created ${output.created_rows} rows in set #${output.set_seq}`
} else if (output.error_code === '409') {
msg.value = 'Someone saved the options first. Reload and try again.'
} else {
msg.value = output.error_message
}
}
</script>
<template>
<div class="card shadow-sm p-4">
<p class="mb-2">Color (White, Black) x Size (S, M, L +2,000) = 6 rows</p>
<button class="btn btn-primary" @click="apply">Apply options</button>
<p class="mt-2">{{ msg }}</p>
</div>
</template>
<?php
$requestData = [
'dataID' => 'APPLY_OPTION_SET',
'product_seq' => 340,
'option_rev' => 0, // product.option_rev you loaded; 409 if it changed
'mode' => 'new', // new | merge (merge needs set_seq)
'label' => 'Color / Size',
'is_required' => 1,
'options' => [
['option_group_seq' => 10],
['name' => 'Size', 'values' => ['S', 'M', ['label' => 'L', 'price_delta' => 2000]]],
],
];
$output = $connector->request($requestData);
echo $output['result'] ? "Created {$output['created_rows']} rows (option_rev {$output['option_rev']})" : htmlspecialchars($output['error_message']);
User Discussions
ADD- There are no posts yet.