Tổng đài hỗ trợ - 
1900 6750
( 7:00 - 22:00 )

Product Variant

Một Product Variant là một phiên bản khác của Product, ví dụ như kích cỡ hay màu sắc khác.

Nếu không có Product Variant, bạn sẽ phải coi áo sơ mi với 3 kích cỡ nhỏ, vừa, lớn như 3 sản phẩm riêng biệt. Product Variant cho phép bạn coi các áo sơ mi cỡ nhỏ, vừa, lớn như 3 biến thể của cùng một sản phẩm là áo sơ mi.

Mỗi một sản phẩm có tối đa 100 biến thể.

Bạn có thể làm gì với Product Variant?

Sapo API cho phép bạn thực hiện các thao tác sau với tài nguyên Product Variant. Các phiên bản chi tiết hơn của những thao tác này có thể có:

Các thuộc tính của Product Variant

barcode
{ "barcode" : "1234_pink" }

Barcode, UPC hoặc số ISBN của Product.

compare_at_price
{ "compare_at_price" : "null" }

Giá so sách với sản phẩm tương tự.

created_on
{ "created_on" : "2012-08-24T14:01:47Z" }

Thời gian Product Variant được tạo. API trả về kết quả theo định dạng chuẩn ISO 8601.

grams
{ "grams" : 200 }

Khối lượng của Product Variant được tính theo đơn vị gram.

id
{ "id" : 808950810 }

Số duy nhất định danh Product Variant.

inventory_management
{ "inventory_management" : "bizweb" }

Xác định xem Sapo có quản lý số lượng Product Variant trong kho hay không. Các giá trị hợp lệ là:

  • "": Sapo không quản lý số lượng Product Variant còn trong kho.
  • bizweb: Sapo quản lý số lượng Product Variant còn trong kho.
inventory_policy
{ "inventory_policy" : "continue" }

Xác định khách hàng có được phép đặt hàng khi đã hết hàng trong kho hay không. Các giá trị hợp lệ:

  • deny (mặc định): Khách hàng không được phép đặt hàng khi sản phẩm đã hết hàng.
  • continue: Khách hàng được phép đặt hàng cả khi sản phẩm đã hết hàng.
inventory_quantity
{ "inventory_quantity" : 10 }

Số lượng Product Variant còn trong kho.

inventory_quantity_adjustment
{ "inventory_quantity_adjustment" : 5 }

Giá trị điều chỉnh số lượng trong kho.

metafield
{ "key" : "new" }
{ "value" : "newvalue" }
{ "value_type" : "string" }
{ "namespace" : "global" }

Các thông tin thêm đính kèm với tài nguyên của Shop.

  • key (bắt buộc): Định danh cho metafield (tối đa 30 ký tự).
  • namespace (bắt buộc): Chứa tập hợp metadata. Namespace giúp phân biệt các metadata được tạo từ các nguồn khác nhau (tối đa 20 ký tự).
  • value (bắt buộc): Thông tin được lưu trữ dưới dạng metadata.
  • value_type (bắt buộc): Quy định dữ liệu lưu trữ trong trường value là kiểu 'string' hay 'integer'
  • description (tùy chọn): Thông tin thêm về metafield.
option
{ "option1" : "Pink" }

Các thuộc tính tùy chỉnh mà chủ shop dùng để định nghĩa Product Variant. Có thể có nhiều option: option1, option2, option3...

position
{ "position" : 1 }

Thứ tự của Product Variant. 1 là vị trí đầu tiên.

price
{ "price" : "199.00" }

Giá của Product Variant.

product_id
{ "product_id" : 632910392 }

Số duy nhất định danh Product.

requires_shipping
{ "requires_shipping" : true }

Quy định khách hàng có cần cung cấp thông tin giao hàng khi đặt hàng không. Các giá trị hợp lệ:

  • true: Khách hàng cần cung cấp địa chỉ giao hàng.
  • false: Khách hàng không cần cung cấp địa chỉ giao hàng.
sku
{ "sku" : "IPOD2008PINK" }

Định danh duy nhất cho Product trong Shop.

title
{ "title" : "Pink" }

Tiêu đề của Product Variant.

modified_on
{ "modified_on" : "2012-08-24T14:01:47Z" }

Thời gian Product Variant được cập nhật lần cuối. API trả về kết quả theo định dạng chuẩn ISO 8601.

weight
{ "weight" : 100 }

Khối lượng của Product Variant tính theo đơn vị được xác định bởi trường weight_unit.

weight_unit
{ "weight_unit" : "oz" }

Đơn vị dùng để đo khối lượng của Product Variant. Ví dụ: "g", "kg, "oz" hoặc "lb"

image_id
{ "image_id" : 434522 }

Số duy nhất định danh ảnh của Product.

Endpoints

GET/admin/products/632910392/variants.json

Lấy danh sách Product Variant

limit

Số lượng kết quả

(mặc định: 50) (tối đa: 250)
page

Trang

(mặc định: 1)
since_id

Giới hạn kết quả trả về sau một ID xác định

fields

Danh sách các trường trong kết quả trả về, cách nhau bởi dấu phẩy

Lấy tất cả Variant của Product

GET /admin/products/#{id}/variants.json
Xem kết quả
HTTP/1.1 200 OK
{
  "variants": [
    {
      "id": 808950810,
      "product_id": 632910392,
      "title": "Pink",
      "price": "199.00",
      "sku": "IPOD2008PINK",
      "position": 1,
      "grams": 200,
      "inventory_policy": "continue",
      "compare_at_price": null,
      
      "inventory_management": "bizweb",
      "option1": "Pink",
      "option2": null,
      "option3": null,
      "created_on": "2015-12-08T11:40:19Z",
      "modified_on": "2015-12-08T11:40:19Z",
      "requires_shipping": true,
      
      "barcode": "1234_pink",
      "inventory_quantity": 10,
      
      "image_id": 562641783,
      "weight": 0.2,
      "weight_unit": "kg"
    },
    {
      "id": 49148385,
      "product_id": 632910392,
      "title": "Red",
      "price": "199.00",
      "sku": "IPOD2008RED",
      "position": 2,
      "grams": 200,
      "inventory_policy": "continue",
      "compare_at_price": null,
      
      "inventory_management": "bizweb",
      "option1": "Red",
      "option2": null,
      "option3": null,
      "created_on": "2015-12-08T11:40:19Z",
      "modified_on": "2015-12-08T11:40:19Z",
      "requires_shipping": true,
      
      "barcode": "1234_red",
      "inventory_quantity": 20,
      
      "image_id": null,
      "weight": 0.2,
      "weight_unit": "kg"
    },
    {
      "id": 39072856,
      "product_id": 632910392,
      "title": "Green",
      "price": "199.00",
      "sku": "IPOD2008GREEN",
      "position": 3,
      "grams": 200,
      "inventory_policy": "continue",
      "compare_at_price": null,
      
      "inventory_management": "bizweb",
      "option1": "Green",
      "option2": null,
      "option3": null,
      "created_on": "2015-12-08T11:40:19Z",
      "modified_on": "2015-12-08T11:40:19Z",
      "requires_shipping": true,
      
      "barcode": "1234_green",
      "inventory_quantity": 30,
      
      "image_id": null,
      "weight": 0.2,
      "weight_unit": "kg"
    },
    {
      "id": 457924702,
      "product_id": 632910392,
      "title": "Black",
      "price": "199.00",
      "sku": "IPOD2008BLACK",
      "position": 4,
      "grams": 200,
      "inventory_policy": "continue",
      "compare_at_price": null,
      
      "inventory_management": "bizweb",
      "option1": "Black",
      "option2": null,
      "option3": null,
      "created_on": "2015-12-08T11:40:19Z",
      "modified_on": "2015-12-08T11:40:19Z",
      "requires_shipping": true,
      
      "barcode": "1234_black",
      "inventory_quantity": 40,
      
      "image_id": null,
      "weight": 0.2,
      "weight_unit": "kg"
    }
  ]
}

Lấy tất cả Variant của Product sau một ID xác định

GET /admin/products/#{id}/variants.json?since_id=49148385
Xem kết quả
HTTP/1.1 200 OK
{
  "variants": [
    {
      "id": 457924702,
      "product_id": 632910392,
      "title": "Black",
      "price": "199.00",
      "sku": "IPOD2008BLACK",
      "position": 4,
      "grams": 200,
      "inventory_policy": "continue",
      "compare_at_price": null,
      
      "inventory_management": "bizweb",
      "option1": "Black",
      "option2": null,
      "option3": null,
      "created_on": "2015-12-08T11:40:19Z",
      "modified_on": "2015-12-08T11:40:19Z",
      "requires_shipping": true,
      
      "barcode": "1234_black",
      "inventory_quantity": 40,
      
      "image_id": null,
      "weight": 0.2,
      "weight_unit": "kg"
    },
    {
      "id": 808950810,
      "product_id": 632910392,
      "title": "Pink",
      "price": "199.00",
      "sku": "IPOD2008PINK",
      "position": 1,
      "grams": 200,
      "inventory_policy": "continue",
      "compare_at_price": null,
      
      "inventory_management": "bizweb",
      "option1": "Pink",
      "option2": null,
      "option3": null,
      "created_on": "2015-12-08T11:40:19Z",
      "modified_on": "2015-12-08T11:40:19Z",
      "requires_shipping": true,
      
      "barcode": "1234_pink",
      "inventory_quantity": 10,
      
      "image_id": 562641783,
      "weight": 0.2,
      "weight_unit": "kg"
    }
  ]
}
GET/admin/products/632910392/variants/count.json

Lấy tổng số Product Variant

Tổng số Variant của Product

GET /admin/products/#{id}/variants/count.json
Xem kết quả
HTTP/1.1 200 OK
{
  "count": 4
}
GET/admin/variants/808950810.json

Lấy một Product Variant bằng Id

fields

Danh sách các trường trong kết quả trả về, cách nhau bởi dấu phẩy

Lấy một Product Variant bằng Id

GET /admin/variants/#{id}.json
Xem kết quả
HTTP/1.1 200 OK
{
  "variant": {
    "id": 808950810,
    "product_id": 632910392,
    "title": "Pink",
    "price": "199.00",
    "sku": "IPOD2008PINK",
    "position": 1,
    "grams": 200,
    "inventory_policy": "continue",
    "compare_at_price": null,
    
    "inventory_management": "bizweb",
    "option1": "Pink",
    "option2": null,
    "option3": null,
    "created_on": "2015-12-08T11:40:19Z",
    "modified_on": "2015-12-08T11:40:19Z",
    "requires_shipping": true,
    
    "barcode": "1234_pink",
    "inventory_quantity": 10,
    
    "image_id": 562641783,
    "weight": 0.2,
    "weight_unit": "kg"
  }
}
POST/admin/products/632910392/variants.json

Tạo mới một Product Variant

Tạo mới một Product Varian với metafield

POST /admin/products/#{id}/variants.json
{
  "variant": {
    "option1":"Back",
    "metafields": [
      {
        "key": "new",
        "value": "newvalue",
        "value_type": "string",
        "namespace": "global"
      }
    ]
  }
}
Xem kết quả
HTTP/1.1 201 Created
{
  "variant": {
    "id": 1070325035,
    "product_id": 632910392,
    "title": "Default Title",
    "price": "0.00",
    "sku": "",
    "position": 5,
    "grams": 0,
    "inventory_policy": "deny",
    "compare_at_price": null,
    
    "inventory_management": null,
    "option1": "Black",
    "option2": null,
    "option3": null,
    "created_on": "2015-12-08T11:41:21Z",
    "modified_on": "2015-12-08T11:41:21Z",
    "requires_shipping": true,
    
    "barcode": null,
    "inventory_quantity": 1,
    
    "image_id": null,
    "weight": 0.0,
    "weight_unit": "kg"
  }
}

Tạo mới một Product Variant với ảnh

POST /admin/products/#{id}/variants.json
{
  "variant": {
    "option1": "Default Title",
    "image_id": 850703190
  }
}
Xem kết quả
HTTP/1.1 201 Created
{
  "variant": {
    "id": 1070325036,
    "product_id": 632910392,
    "title": "Default Title",
    "price": "0.00",
    "sku": "",
    "position": 5,
    "grams": 0,
    "inventory_policy": "deny",
    "compare_at_price": null,
    
    "inventory_management": null,
    "option1": "Default Title",
    "option2": null,
    "option3": null,
    "created_on": "2015-12-08T11:41:21Z",
    "modified_on": "2015-12-08T11:41:21Z",
    "requires_shipping": true,
    
    "barcode": null,
    "inventory_quantity": 1,
    
    "image_id": 850703190,
    "weight": 0.0,
    "weight_unit": "kg"
  }
}

Tạo mới một Product Variant

POST /admin/products/#{id}/variants.json
{
  "variant": {
    "option1": "Default Title",
    "price": "1.00"
  }
}
Xem kết quả
HTTP/1.1 201 Created
{
  "variant": {
    "id": 1070325037,
    "product_id": 632910392,
    "title": "Default Title",
    "price": "1.00",
    "sku": "",
    "position": 5,
    "grams": 0,
    "inventory_policy": "deny",
    "compare_at_price": null,
    
    "inventory_management": null,
    "option1": "Default Title",
    "option2": null,
    "option3": null,
    "created_on": "2015-12-08T11:41:22Z",
    "modified_on": "2015-12-08T11:41:22Z",
    "requires_shipping": true,
    
    "barcode": null,
    "inventory_quantity": 1,
    
    "image_id": null,
    "weight": 0.0,
    "weight_unit": "kg"
  }
}
PUT/admin/variants/808950810.json

Cập nhật một Product Variant

Cập nhật kho

PUT /admin/variants/#{id}.json
{
  "variant": {
    "id": 808950810,
    "inventory_quantity": 100
    
  }
}
Xem kết quả
HTTP/1.1 200 OK
{
  "variant": {
    "id": 808950810,
    "product_id": 632910392,
    "title": "Pink",
    "price": "199.00",
    "sku": "IPOD2008PINK",
    "position": 1,
    "grams": 200,
    "inventory_policy": "continue",
    "compare_at_price": null,
    
    "inventory_management": "bizweb",
    "option1": "Pink",
    "option2": null,
    "option3": null,
    "created_on": "2015-12-08T11:40:19Z",
    "modified_on": "2015-12-08T11:41:21Z",
    "requires_shipping": true,
    
    "barcode": "1234_pink",
    "inventory_quantity": 100,
    
    "image_id": 562641783,
    "weight": 0.2,
    "weight_unit": "kg"
  }
}

Thêm một ảnh đã tồn tại vào một Variant

PUT /admin/variants/#{id}.json
{
  "variant": {
    "id": 808950810,
    "image_id": 562641783
  }
}
Xem kết quả
HTTP/1.1 200 OK
{
  "variant": {
    "id": 808950810,
    "product_id": 632910392,
    "title": "Pink",
    "price": "199.00",
    "sku": "IPOD2008PINK",
    "position": 1,
    "grams": 200,
    "inventory_policy": "continue",
    "compare_at_price": null,
    
    "inventory_management": "bizweb",
    "option1": "Pink",
    "option2": null,
    "option3": null,
    "created_on": "2015-12-08T11:40:19Z",
    "modified_on": "2015-12-08T11:41:23Z",
    "requires_shipping": true,
    
    "barcode": "1234_pink",
    "inventory_quantity": 10,
    
    "image_id": 562641783,
    "weight": 0.2,
    "weight_unit": "kg"
  }
}

Thêm một metafield vào Variant

PUT /admin/variants/#{id}.json
{
  "variant": {
    "id": 808950810,
    "metafields": [
      {
        "key": "new",
        "value": "newvalue",
        "value_type": "string",
        "namespace": "global"
      }
    ]
  }
}
Xem kết quả
HTTP/1.1 200 OK
{
  "variant": {
    "id": 808950810,
    "product_id": 632910392,
    "title": "Pink",
    "price": "199.00",
    "sku": "IPOD2008PINK",
    "position": 1,
    "grams": 200,
    "inventory_policy": "continue",
    "compare_at_price": null,
    
    "inventory_management": "bizweb",
    "option1": "Pink",
    "option2": null,
    "option3": null,
    "created_on": "2015-12-08T11:40:19Z",
    "modified_on": "2015-12-08T11:41:24Z",
    "requires_shipping": true,
    
    "barcode": "1234_pink",
    "inventory_quantity": 10,
    
    "image_id": 562641783,
    "weight": 0.2,
    "weight_unit": "kg"
  }
}

Cập nhật kho sử dụng số lượng điều chỉnh

PUT /admin/variants/#{id}.json
{
  "variant": {
    "id": 808950810,
    "inventory_quantity_adjustment": -5
  }
}
Xem kết quả
HTTP/1.1 200 OK
{
  "variant": {
    "id": 808950810,
    "product_id": 632910392,
    "title": "Pink",
    "price": "199.00",
    "sku": "IPOD2008PINK",
    "position": 1,
    "grams": 200,
    "inventory_policy": "continue",
    "compare_at_price": null,
    
    "inventory_management": "bizweb",
    "option1": "Pink",
    "option2": null,
    "option3": null,
    "created_on": "2015-12-08T11:40:19Z",
    "modified_on": "2015-12-08T11:41:25Z",
    "requires_shipping": true,
    
    "barcode": "1234_pink",
    "inventory_quantity": 5,
    
    "image_id": 562641783,
    "weight": 0.2,
    "weight_unit": "kg"
  }
}

Cập nhật tiêu đề và giá của Variant

PUT /admin/variants/#{id}.json
{
  "variant": {
    "id": 808950810,
    "option1": "Not Pink",
    "price": "99.00"
  }
}
Xem kết quả
HTTP/1.1 200 OK
{
  "variant": {
    "id": 808950810,
    "product_id": 632910392,
    "title": "Not Pink",
    "price": "99.00",
    "sku": "IPOD2008PINK",
    "position": 1,
    "grams": 200,
    "inventory_policy": "continue",
    "compare_at_price": null,
    
    "inventory_management": "bizweb",
    "option1": "Not Pink",
    "option2": null,
    "option3": null,
    "created_on": "2015-12-08T11:40:19Z",
    "modified_on": "2015-12-08T11:41:26Z",
    "requires_shipping": true,
    
    "barcode": "1234_pink",
    "inventory_quantity": 10,
    
    "image_id": 562641783,
    "weight": 0.2,
    "weight_unit": "kg"
  }
}
DELETE/admin/products/632910392/variants/808950810.json

Xóa một Product Variant

DELETE /admin/products/#{id}/variants/#{id}.json
Xem kết quả
HTTP/1.1 200 OK
{}

Bài viết trên có hữu ích cho bạn không?

Hữu ích Không hữu ích
Số lượt đánh giá hữu ích: