Skip to content

API Products

Module Products cung cấp các phương thức để quản lý sản phẩm và danh mục sản phẩm trong hệ thống Pancake POS.

Khởi Tạo

typescript
import { PancakeClient } from 'pancake-client-sdk';

const client = new PancakeClient('your-api-key', 'your-shop-id');
const productsApi = client.products;

Quản Lý Sản Phẩm

Lấy Danh Sách Sản Phẩm

typescript
const { data: products } = await client.products.list({
  page_size: 20,
  page_number: 1,
  search: 'áo thun',
  category_id: [1, 2],
  is_published: true,
  has_variations: true,
  in_stock: true
});

Tham Số

TênKiểuBắt buộcMô tả
page_sizenumberkhôngSố sản phẩm trên một trang
page_numbernumberkhôngSố trang
searchstringkhôngTìm kiếm theo tên sản phẩm
category_idnumber[]khôngLọc theo danh mục
is_publishedbooleankhôngLọc sản phẩm đã xuất bản
has_variationsbooleankhôngLọc sản phẩm có biến thể
in_stockbooleankhôngLọc sản phẩm còn hàng

Lấy Chi Tiết Sản Phẩm

typescript
const product = await client.products.getById('product-id');

Tạo Sản Phẩm Mới

typescript
const newProduct = await client.products.create({
  name: 'Áo thun nam',
  category_ids: [1], // Danh mục quần áo nam
  weight: 200, // gram
  is_published: true,
  variations: [
    {
      fields: [
        { name: 'Size', value: 'M' },
        { name: 'Màu', value: 'Đen' }
      ],
      retail_price: 199000,
      weight: 200,
      stock: 100,
      sku: 'AT-NAM-M-DEN'
    }
  ],
  description: 'Áo thun nam chất liệu cotton',
  images: ['https://example.com/image1.jpg'],
  tags: ['áo thun', 'nam'],
  measure_unit: 'cái',
  specifications: [
    { name: 'Chất liệu', value: '100% cotton' },
    { name: 'Xuất xứ', value: 'Việt Nam' }
  ]
});

Model CreateProductRequest

TênKiểuBắt buộcMô tả
namestringTên sản phẩm
category_idsnumber[]khôngID các danh mục
note_productstringkhôngGhi chú nội bộ
weightnumberKhối lượng (gram)
custom_idstringkhôngMã tự định nghĩa
is_publishedbooleankhôngTrạng thái xuất bản
variationsProductVariation[]Danh sách biến thể
descriptionstringkhôngMô tả sản phẩm
imagesstring[]khôngURL hình ảnh
tagsstring[]khôngThẻ/nhãn
measure_unitstringkhôngĐơn vị tính
specificationsProductSpecification[]khôngThông số kỹ thuật

Cập Nhật Sản Phẩm

typescript
const updatedProduct = await client.products.update('product-id', {
  name: 'Áo thun nam (Cập nhật)',
  description: 'Mô tả mới'
});

Cập Nhật Tồn Kho

Cập nhật tồn kho một biến thể

typescript
await client.products.updateStock('product-id', {
  warehouse_id: 'warehouse-1',
  variation_id: 'variation-1',
  stock: 100
});

Cập nhật tồn kho nhiều biến thể

typescript
await client.products.updateBulkStock('product-id', [
  {
    warehouse_id: 'warehouse-1',
    variation_id: 'variation-1',
    stock: 100
  },
  {
    warehouse_id: 'warehouse-1',
    variation_id: 'variation-2',
    stock: 150
  }
]);

Quản Lý Danh Mục

Lấy Danh Sách Danh Mục

typescript
const { data: categories } = await client.products.listCategories();

Tạo Danh Mục Mới

typescript
const newCategory = await client.products.createCategory({
  name: 'Quần áo nam',
  parent_id: 1, // Danh mục cha
  image_url: 'https://example.com/category.jpg',
  is_visible: true
});

Cập Nhật Danh Mục

typescript
const updatedCategory = await client.products.updateCategory(1, {
  name: 'Quần áo nam (Cập nhật)',
  is_visible: false
});

Xóa Danh Mục

typescript
await client.products.deleteCategory(1);

Lịch Sử Tồn Kho

typescript
const history = await client.products.getInventoryHistory('product-id', {
  from_date: '2025-01-01',
  to_date: '2025-12-31',
  page_size: 20,
  page_number: 1
});

Models

Product

typescript
interface Product {
    id: string;
    name: string;
    category_ids: number[];
    note_product?: string;
    weight: number;
    custom_id?: string;
    is_published: boolean;
    variations: ProductVariation[];
    stock?: number;
    description?: string;
    images?: string[];
    tags?: string[];
    measure_unit?: string;
    wholesale_price?: number;
    retail_price: number;
    warranty_info?: string;
    specifications?: ProductSpecification[];
}

ProductVariation

typescript
interface ProductVariation {
    id?: string;
    fields?: ProductField[];
    images?: string[];
    last_imported_price?: number;
    retail_price: number;
    price_at_counter?: number;
    weight: number;
    barcode?: string;
    custom_id?: string;
    is_hidden?: boolean;
    stock?: number;
    sku?: string;
    wholesale_price?: number;
}

ProductCategory

typescript
interface ProductCategory {
    id: number;
    name: string;
    parent_id?: number;
    image_url?: string;
    is_visible: boolean;
    children?: ProductCategory[];
}