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}]}
  ]
}
KeyDescription
dataIDData identifier APPLY_OPTION_SET
product_seqProduct number
option_revproduct.option_rev you loaded. 409 if it changed
modenew (new set) / merge (add values to a set)
set_seqOption set to merge into
labelOption set name, e.g. Color / Size
is_requiredRequired 0 / 1
stock_flgTrack stock 0 / 1
optionsOptions (max 3, rows are combined)
options[n].option_group_seqUse a saved option group
options[n].nameOption name when typing values
options[n].valuesValues. "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="[{&quot;option_group_seq&quot;:10},{&quot;name&quot;:&quot;Size&quot;,&quot;values&quot;:[&quot;S&quot;,&quot;M&quot;,{&quot;label&quot;:&quot;L&quot;,&quot;price_delta&quot;: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
}
KeyDescription
resultSucceeded or not
set_seqOption set created or merged
created_rowsRows created
option_revNew 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.

Example

Color (White, Black) x Size (S, M, L +2,000) = 6 rows

Created 6 rows in set #12

<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']);