Save Option Group
This page describes the request data identifiers and response structure required to create or update an option group and its values.
Data Identifier
{
"dataID": "SAVE_OPTION_GROUP",
"seq": 10,
"code": "COLOR",
"name": "Color",
"status": "ACTIVE",
"stock_flg": 1,
"option_values": [
{"seq": 111, "code": "WHT", "label": "White", "sort_order": 0, "status": "ACTIVE", "price_delta": 0},
{"seq": 112, "code": "BLK", "label": "Black", "sort_order": 1, "status": "ACTIVE", "price_delta": 1000},
{"code": "NVY", "label": "Navy", "sort_order": 2, "status": "ACTIVE", "price_delta": 1000}
],
"return_url": "/commerce/option-group/list"
}
| Key | Description |
|---|---|
| dataID | Data identifier SAVE_OPTION_GROUP |
| seq | Group to update. Empty creates a new one. |
| code | Group code (1062 if duplicated) |
| name | Group name |
| status | ACTIVE / INACTIVE |
| stock_flg | Track stock 0 / 1. Anything else is 422 |
| option_values | Full value list. Values left out are removed. |
| option_values[n].seq | Existing value number. Omit for a new value |
| option_values[n].code | Value code |
| option_values[n].label | Display label |
| option_values[n].price_delta | Default extra amount |
| option_values[n].sort_order | Sort order |
| option_values[n].status | ACTIVE / INACTIVE |
| delete | 1 deletes group seq (404 if not found) |
| return_url | Where to go after saving |
HTML
<form id="frm_save_option_group" method="post">
<input type="hidden" name="seq" value="10">
<input name="code" value="COLOR">
<input name="name" value="Color">
<select name="stock_flg"><option value="1" selected="">Track stock</option><option value="0">No stock</option></select>
<!-- option_values: JSON array of {seq?, code, label, sort_order, status, price_delta} -->
<input type="hidden" name="option_values" value="[{"seq":111,"code":"WHT","label":"White","sort_order":0,"status":"ACTIVE","price_delta":0},{"seq":112,"code":"BLK","label":"Black","sort_order":1,"status":"ACTIVE","price_delta":1000}]">
<input type="hidden" name="return_url" value="/commerce/option-group/list">
<button type="submit" class="btn btn-primary">Save group</button>
</form>
Response Result
{
"result": true,
"result_code": 200,
"seq": 10,
"option_group_seq": 10,
"return_url": "/commerce/option-group/list"
}
| Key | Description |
|---|---|
| result | Saved or not (true / false) |
| result_code | 200 saved, 1062 duplicate code |
| seq | Saved group number. 0 on failure |
| option_group_seq | Same as seq (explicit key) |
| return_url | The return_url you sent |
- Editing a group does not change options already applied to products; product options are copies made at apply time.
- Error codes — errors also come back as HTTP 200. Check result:false, then error_code (string) and error_message.
- 401 — Sign-in required (Unauthorized).
- 1062 — The code already exists. This one comes as result:false, result_code:1062, seq:0 with no error_code.
- 422 — Invalid input. errors holds the reason per field, e.g. errors.stock_flg
- 404 — The group to delete was not found.
<script setup>
import { ref } from 'vue'
const group = ref({ seq: 10, code: 'COLOR', name: 'Color', status: 'ACTIVE', stock_flg: 1 })
const values = ref([
{ seq: 111, code: 'WHT', label: 'White', sort_order: 0, status: 'ACTIVE', price_delta: 0 },
{ seq: 112, code: 'BLK', label: 'Black', sort_order: 1, status: 'ACTIVE', price_delta: 1000 }
])
const msg = ref('')
const addValue = () => values.value.push({ code: '', label: '', sort_order: values.value.length, status: 'ACTIVE', price_delta: 0 })
async function save() {
const { output } = await useNuxtApp().$connector({
dataID: 'SAVE_OPTION_GROUP', ...group.value, option_values: values.value, return_url: '/commerce/option-group/list'
})
if (output.result) msg.value = `Saved group #${output.option_group_seq}`
else if (output.result_code === 1062) msg.value = 'This code is already in use.'
else msg.value = output.error_message // e.g. 422 stock_flg
}
</script>
<template>
<form class="card shadow-sm p-4" @submit.prevent="save">
<div class="row g-3">
<div class="col-md-4"><label class="form-label">Code</label><input class="form-control" v-model="group.code"></div>
<div class="col-md-5"><label class="form-label">Name</label><input class="form-control" v-model="group.name"></div>
<div class="col-md-3"><label class="form-label">Track stock</label>
<select class="form-select" v-model.number="group.stock_flg"><option :value="1">Yes</option><option :value="0">No</option></select></div>
</div>
<table class="table table-sm align-middle mt-3">
<thead><tr><th>Code</th><th>Label</th><th>+Price</th></tr></thead>
<tbody>
<tr v-for="(v, i) in values" :key="i">
<td><input class="form-control form-control-sm" v-model="v.code"></td>
<td><input class="form-control form-control-sm" v-model="v.label"></td>
<td><input type="number" class="form-control form-control-sm" v-model.number="v.price_delta"></td>
</tr>
</tbody>
</table>
<button type="button" class="btn btn-sm btn-outline-secondary" @click="addValue">Add value</button>
<div><button class="btn btn-primary mt-3">Save group</button></div>
<p class="mt-2">{{ msg }}</p>
</form>
</template>
<?php
$requestData = [
'dataID' => 'SAVE_OPTION_GROUP',
'seq' => 10, // omit to create
'code' => 'COLOR',
'name' => 'Color',
'status' => 'ACTIVE',
'stock_flg' => 1, // 0 | 1 (anything else: 422)
'option_values' => [ // full value set; values not listed are removed
['seq' => 111, 'code' => 'WHT', 'label' => 'White', 'sort_order' => 0, 'status' => 'ACTIVE', 'price_delta' => 0],
['seq' => 112, 'code' => 'BLK', 'label' => 'Black', 'sort_order' => 1, 'status' => 'ACTIVE', 'price_delta' => 1000],
],
'return_url' => '/commerce/option-group/list',
];
$output = $connector->request($requestData);
echo $output['result'] ? 'Saved #' . $output['option_group_seq'] : 'Failed (' . ($output['error_code'] ?? $output['result_code']) . ')';
Related Links
User Discussions
ADD- There are no posts yet.