Save Category

This page describes the request data identifiers and response structure required to create or update a category.

Data Identifier

{
  "dataID": "SAVE_CATEGORY",
  "seq": 2,
  "parent_seq": 1,
  "code": "TSHIRTS",
  "name": "T-Shirts",
  "sort_order": 1,
  "status": "ACTIVE",
  "return_url": "/commerce/category/list"
}
KeyDescription
dataIDData identifier SAVE_CATEGORY
seqCategory to update. Empty or 0 creates a new one.
parent_seqParent category. Empty = root. depth is calculated by the server.
codeCategory code (letters and digits recommended)
nameCategory name
sort_orderOrder among siblings
statusACTIVE / INACTIVE
return_urlWhere to go after saving. Echoed back in the response.

HTML

<form id="frm_save_category">
  <input type="hidden" name="seq" value="2">
  <select name="parent_seq">
    <option value="">(root)</option>
    <option value="1">Apparel</option>
  </select>
  <input name="code" value="TSHIRTS">
  <input name="name" value="T-Shirts">
  <input type="number" name="sort_order" value="1">
  <select name="status"><option>ACTIVE</option><option>INACTIVE</option></select>
  <input type="hidden" name="return_url" value="/commerce/category/list">
  <button type="submit" class="btn btn-primary">Save</button>
</form>

Response Result

{
  "result": true,
  "seq": 2,
  "result_code": 200,
  "return_url": "/commerce/category/list"
}
KeyDescription
resultSaved or not (true / false)
seqSaved category number (number)
result_code200 saved, 500 save failed
return_urlThe return_url you sent
  • Screen example: build the parent picker with GET_CATEGORY_LIST tree=Y plus the seq being edited, and disable every category listed in exclude_parent_seq.
  • Error codes — errors also come back as HTTP 200. Check result:false, then error_code (string) and error_message.
  • 401 — Sign-in required (Unauthorized).
  • 400 — A category cannot be moved under itself or one of its descendants.

Example

Category
<script setup>
import { ref } from 'vue'
const form = ref({ seq: 2, parent_seq: 1, code: 'TSHIRTS', name: 'T-Shirts', sort_order: 1, status: 'ACTIVE' })
const message = ref('')
async function save() {
  const { output } = await useNuxtApp().$connector({ dataID: 'SAVE_CATEGORY', ...form.value, return_url: '/commerce/category/list' })
  message.value = output.result ? `Saved (seq ${output.seq})` : 'Save failed'
}
</script>

<template>
  <form class="card shadow-sm p-4" @submit.prevent="save">
    <h5 class="mb-3">Category</h5>
    <div class="mb-3">
      <label class="form-label">Parent</label>
      <select class="form-select" v-model="form.parent_seq">
        <option :value="null">(root)</option>
        <option :value="1">Apparel</option>
      </select>
    </div>
    <div class="row g-3">
      <div class="col-md-4"><label class="form-label">Code</label><input class="form-control" v-model="form.code"></div>
      <div class="col-md-5"><label class="form-label">Name</label><input class="form-control" v-model="form.name"></div>
      <div class="col-md-3"><label class="form-label">Sort</label><input type="number" class="form-control" v-model="form.sort_order"></div>
    </div>
    <div class="mb-3 mt-3">
      <label class="form-label">Status</label>
      <select class="form-select" v-model="form.status"><option>ACTIVE</option><option>INACTIVE</option></select>
    </div>
    <button class="btn btn-primary">Save</button>
    <p class="mt-2 text-success">{{ message }}</p>
  </form>
</template>
<?php
$requestData = [
    'dataID'     => 'SAVE_CATEGORY',
    'seq'        => 2,          // omit / 0 to insert a new category
    'parent_seq' => 1,          // NULL for a root category
    'code'       => 'TSHIRTS',
    'name'       => 'T-Shirts',
    'sort_order' => 1,
    'status'     => 'ACTIVE',
    'return_url' => '/commerce/category/list',
];
$output = $connector->request($requestData);

if ($output['result']) {
    header('Location: ' . $output['return_url']);   // saved -> seq = $output['seq']
    exit;
}
echo 'Save failed (code ' . $output['result_code'] . ')';