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

Price Rule

Bạn có thể sử dụng PriceRule để tự động tạo giảm giá với các các điều kiện khác nhau. Chủ shop có thể phân phối mã giảm giá cho khách hàng sử dụng. Với PriceRule, bạn có thể tạo một cách linh hoạt các loại giảm giá: chiết khấu theo %, hay giảm giá tiền, hoặc miễn phí vận chuyển; bạn cấu hình quyền lợi, điều kiện tiên quyết và các thuộc tính khác để tự động tạo các loại giảm giá này.

Tạo một PriceRule với Code

Bạn có thể tạo PriceRule với các quyền lợi và điều kiện tiên quyết. Quyền lợi mô tả rõ những sản phẩm nào, phiên bản nào hay danh mục nào được chỉ định áp dụng trong PriceRule. Điều kiện tiên quyết mô tả các yêu cầu cần phải đáp ứng để mã giảm giá có thể áp dụng được trên các đối tượng được chỉ định hưởng quyền lợi. Ví dụ: Bạn có thể muốn chiết khấu chỉ áp dụng trên một phạm vi phí vận chuyển hoặc giá trị đơn hàng nhất định.

Bạn có thể sử dụng các quyền lợi, các điều kiện tiên quyết hoặc các điều kiện khác để tạo các loại giảm giá như sau:

  • Giảm 10.000 VND nếu tổng giá trị đơn hàng lớn hơn hoặc bằng 40.000 VND
  • Giảm 15% cho một danh mục sản phẩm được chọn
  • Miễn phí vận chuyển cho đơn hàng trên 100.000 VND, có thể áp dụng mã 20 lần, chỉ áp dụng cho khu vực Hà Nội.

Dưới đây là thông tin chi tiết các phương thức POST để có thể tạo được PriceRule

Bạn có thể làm gì với PriceRule

API Sapo cho phép bạn thực hiện như sau:

Các thuộc tính của PriceRule

created_on
 "created_on" : "2017-03-13T16:09:54-04:00" 

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

id
 "id" : 505071 

Số duy nhất định danh cho PriceRule.

title
 "title" : KHUYENMAI24H 

Tiêu đề của PiceRule.
Cảnh báo: Bạn nên sử dụng title của PriceRule và code của nó giống nhau vì chỉ có tiêu đề mới có thể được tìm kiếm trong quản trị website. Ví dụ:
price_rule.title = ABC123 và
discount_code.code = ABC123

target_type
 "target_type" : "line_item" 

Giá trị hợp lệ:

  • line_item: áp dụng cho các mặt hàng trong giỏ hàng
  • shipping_line: áp dụng cho phí vận chuyển của đơn hàng
target_selection
"target_selection": "entitled"

Giá trị hợp lệ:

  • all: áp dụng cho tất cả mặt hàng trong giỏ hàng.
  • entitled: chỉ áp dụng cho một số mặt hàng nhất định hưởng quyền giảm giá.
allocation_method
"allocation_method": "each"

Giá trị hợp lệ:

  • each: giảm giá sẽ được áp dụng cho từng mặt hàng được quyền áp dụng. Ví dụ với một PriceRule giảm giá 15.000 VNĐ thì từng mặt hàng trong checkout mỗi mặt hàng đều được giảm 15.000 VNĐ.
  • across: Số tiền giảm giá sẽ được áp dụng trên toàn bộ mặt hàng được quyền hưởng. Ví dụ với một PriceRule giảm giá 15.000 VNĐ, tổng số tiền giảm giá trên đơn hàng tối đa là 15.000 VNĐ và áp dụng cho các mặt hàng được quyền hưởng.
value_type
"value_type": "percentage"

Giá trị hợp lệ:

  • fixed_amount: áp dụng theo giá trị "value" trong PriceRule. Ví dụ, nếu "value" ="-12000" và định dạng tiền tệ của website đang cấu hình là VNĐ thì 12.000 sẽ được trừ khi giảm giá được áp dụng.
  • percentage: áp dụng theo giá trị "value" tron PriceRule. Ví dụ, nếu "value" = "-30", thì 30% tổng tiền của những mặt hàng được hưởng khuyến mại sẽ được trừ đi khi giảm giá được áp dụng.
  • Fixed_price: áp dụng theo giá trị “value” trong PriceRule. Ví dụ, nếu “value” = “12000” và định dạng tiền tệ của website đang cấu hình là VNĐ thì tất cả sản phẩm phù hợp điều kiện sẽ đồng giá 12.000.

Nếu target_type = shipping_line thì "value_type" chỉ có thể bằng percentage.

Nếu value_type = fixed_price thì "value" có giá trị dương.

value
"value": -35

Giá trị chiết khấu của PriceRule.
Nếu target_type = shipping_line thì value chỉ có thể bằng 100 . Giá trị chiết khấu luôn là một số âm.

exclude_type
"exclude_type": true

Khi một mã giảm giá được tạo ra sẽ mặc định không áp dụng chung với chương trình khuyến mãi. Giá trị hợp lệ: true hoặc false

once_per_customer
"once_per_customer": true

Khi một chiết khấu được tạo ra sẽ chỉ định áp dụng một lần duy nhất trên một khách hàng hoặc không. Kiểm tra theo id của khách hàng. Giá trị hợp lệ: true hoặc false.

usage_limit
"usage_limit": 10

Số lần sử dụng tối đa của khuyến mại.

customer_selection
"customer_selection": "prerequisite"

Giá trị hợp lệ:

  • all: Khuyến mại cho toàn bộ khách hàng.
  • prerequisite: Khuyến mại áp dụng cho những khách hàng thuộc một trong các nhóm khách hàng được chỉ định theo prerequisite_saved_search_ids.
prerequisite_saved_search_ids
"prerequisite_saved_search_ids": ["112345Z2345","43535363636"]

Là một danh sách các giá trị của prerequisite_customer_saved_search_ids. Để có thể áp dụng được khuyến mại, khách hàng phải thuộc nhóm khách hàng đã được lưu trước đó.

prerequisite_subtotal_range
"prerequisite_subtotal_range": ["greater_than_or_equal_to": "40.0"]

Giá trị thiết lập cho prerequisite_subtotal_range. Tổng giá trị của những mặt hàng được quyền áp dụng khuyến mại phải lớn hơn hoặc bằng giá trị được thiết lập ở đây.

prerequisite_quantity_range
"prerequisite_quantity_range": ["greater_than_or_equal_to": 2]

Giá trị thiết lập cho prerequisite_quantity_range. Số lượng sản phẩm tối thiểu được áp dụng phải lơn hơn hoặc bằng giá trị thiết lập ở đây.

Lưu ý: Giá trị tối thiểu là 2

prerequisite_shipping_price_range
"prerequisite_shipping_price_range": ["less_than_or_equal_to": "10.0"]

Giá trị thiết lập cho prerequisite_shipping_price_range. Phí vận chuyển phải nhỏ hơn hoặc bằng giá trị được thiết lập ở đây. Chỉ có thể thiết lập khi target_type = shipping_line.

entitled_product_ids
"entitled_product_ids": ["7897397755","42382368242"]

Danh sách id của sản phẩm sẽ được áp dụng khuyến mại. entitled_product_ids chỉ có thể được sử dụng khi target_type được thiết lập là line_itemtarget_selection được thiết lập là entitled. Có thể sử dụng kết hợp với entitled_variant_ids.

entitled_variant_ids
"entitled_variant_ids": ["6798798798","5675765905"]

Danh sách id của phiên bản sẽ được áp dụng khuyến mại. entitled_variant_ids chỉ có thể được sử dụng khi target_type được thiết lập là line_itemtarget_selection được thiết lập là entitled. Có thể sử dụng kết hợp với entitled_product_ids.

entitled_collection_ids
"entitled_collection_ids": ["4564654869","8979761006"]

Danh sách id của danh mục sản phẩm sẽ được áp dụng khuyến mại. entitled_collection_ids chỉ có thể được sử dụng khi target_type được thiết lập là line_itemtarget_selection được thiết lập là entitled. Không thể sử dụng kết hợp với với entitled_product_ids hoặc entitled_variant_ids.

entitled_country_ids
" entitled_country_ids": ["7897987023","3569053679"]

Danh sách id của các tỉnh thành sẽ được áp dụng khuyến mại. entitled_province_ids chỉ có thể được sử dụng khi target_type được thiết lập là shipping_linetarget_selection được thiết lập là entitled.

starts_on
"starts_on": "2017-01-19T17:59:10Z"

Thời gian bắt đầu áp dụng khuyến mại. API trả về kết quả theo định dạng chuẩn ISO 8601.

ends_on
"ends_on": "2017-04-19T17:59:10Z"

Thời gian kết thúc việc áp dụng khuyến mại. Phải luôn đứng sau starts_on. API trả về kết quả theo định dạng chuẩn ISO 8601.

Endpoints

POST/admin/price_rules.json
Tạo một PriceRule với Code

Tạo một giảm giá Miễn phí vận chuyển cho đơn hàng trên 50.000 VNĐ và có thể áp dụng tới 20 lần

POST /admin/price_rules.json
{
  "price_rule": {
    "title": "FREESHIPPING",
    "target_type": "shipping_line",
    "target_selection": "all",
    "allocation_method": "each",
    "value_type": "percentage",
    "value": "-50000",
    "usage_limit": 20,
    "customer_selection": "all",
    "prerequisite_subtotal_range": {
      "greater_than_or_equal_to": "50.0"
    },
    "starts_on": "2017-01-19T17:59:10Z"
  }
}
Xem kết quả
HTTP/1.1 201 Created
{
  "price_rule": {
    "id": 996341490,
    "value_type": "percentage",
    "value": "-100.0",
    "customer_selection": "all",
    "target_type": "shipping_line",
    "target_selection": "all",
    "allocation_method": "each",
    "once_per_customer": false,
    "usage_limit": 20,
    "starts_on": "2017-01-19T12:59:10-05:00",
    "ends_at": null,
    "created_at": "2017-09-12T16:23:14-04:00",
    "updated_at": "2017-09-12T16:23:14-04:00",
    "entitled_product_ids": [
    ],
    "entitled_variant_ids": [
    ],
    "entitled_collection_ids": [
    ],
    "entitled_country_ids": [
    ],
    "prerequisite_saved_search_ids": [
    ],
    "prerequisite_subtotal_range": {
      "greater_than_or_equal_to": "50.0"
    },
    "prerequisite_shipping_price_range": null,
    "title": "FREESHIPPING"
  }
}

Tạo mã giảm giá Giảm 5.000 VNĐ trên đơn hàng cho một nhóm khách hàng

POST /admin/price_rules.json
{
  "price_rule": {
    "title": "5OFFCUSTOMERGROUP",
    "target_type": "line_item",
    "target_selection": "all",
    "allocation_method": "across",
    "value_type": "fixed_amount",
    "value": "-5000",
    "customer_selection": "prerequisite",
    "prerequisite_saved_search_ids": [
      789629109
    ],
    "starts_on": "2017-01-19T17:59:10Z"
  }
}
Xem kết quả
HTTP/1.1 201 Created
{
  "price_rule": {
    "id": 996341491,
    "value_type": "fixed_amount",
    "value": "-5.0",
    "customer_selection": "prerequisite",
    "target_type": "line_item",
    "target_selection": "all",
    "allocation_method": "across",
    "once_per_customer": false,
    "usage_limit": null,
    "starts_on": "2017-01-19T12:59:10-05:00",
    "ends_at": null,
    "created_at": "2017-09-12T16:23:14-04:00",
    "updated_at": "2017-09-12T16:23:14-04:00",
    "entitled_product_ids": [
    ],
    "entitled_variant_ids": [
    ],
    "entitled_collection_ids": [
    ],
    "entitled_country_ids": [
    ],
    "prerequisite_saved_search_ids": [
      789629109
    ],
    "prerequisite_subtotal_range": null,
    "prerequisite_shipping_price_range": null,
    "title": "5OFFCUSTOMERGROUP"
  }
}

Tạo mã giảm giá Giảm 15% trên một nhóm danh mục sản phẩm

POST /admin/price_rules.json
{
  "price_rule": {
    "title": "15OFFCOLLECTION",
    "target_type": "line_item",
    "target_selection": "entitled",
    "allocation_method": "across",
    "value_type": "percentage",
    "value": "-15.0",
    "customer_selection": "all",
    "entitled_collection_ids": [
      841564295
    ],
    "starts_on": "2017-01-19T17:59:10Z"
  }
}
Xem kết quả
HTTP/1.1 201 Created
{
  "price_rule": {
    "id": 996341492,
    "value_type": "percentage",
    "value": "-15.0",
    "customer_selection": "all",
    "target_type": "line_item",
    "target_selection": "entitled",
    "allocation_method": "across",
    "once_per_customer": false,
    "usage_limit": null,
    "starts_on": "2017-01-19T12:59:10-05:00",
    "ends_at": null,
    "created_at": "2017-09-12T16:23:15-04:00",
    "updated_at": "2017-09-12T16:23:15-04:00",
    "entitled_product_ids": [
    ],
    "entitled_variant_ids": [
    ],
    "entitled_collection_ids": [
      841564295
    ],
    "entitled_country_ids": [
    ],
    "prerequisite_saved_search_ids": [
    ],
    "prerequisite_subtotal_range": null,
    "prerequisite_shipping_price_range": null,
    "title": "15OFFCOLLECTION"
  }
}

Tạo mã giảm giá Giảm 10.000 VNĐ trên một đơn hàng.

POST /admin/price_rules.json
{
  "price_rule": {
    "title": "SUMMERSALE10OFF",
    "target_type": "line_item",
    "target_selection": "all",
    "allocation_method": "across",
    "value_type": "fixed_amount",
    "value": "-10000",
    "customer_selection": "all",
    "starts_on": "2017-01-19T17:59:10Z"
  }
}
Xem kết quả
HTTP/1.1 201 Created
{
  "price_rule": {
    "id": 996341493,
    "value_type": "fixed_amount",
    "value": "-10.0",
    "customer_selection": "all",
    "target_type": "line_item",
    "target_selection": "all",
    "allocation_method": "across",
    "once_per_customer": false,
    "usage_limit": null,
    "starts_on": "2017-01-19T12:59:10-05:00",
    "ends_at": null,
    "created_at": "2017-09-12T16:23:15-04:00",
    "updated_at": "2017-09-12T16:23:15-04:00",
    "entitled_product_ids": [
    ],
    "entitled_variant_ids": [
    ],
    "entitled_collection_ids": [
    ],
    "entitled_country_ids": [
    ],
    "prerequisite_saved_search_ids": [
    ],
    "prerequisite_subtotal_range": null,
    "prerequisite_shipping_price_range": null,
    "title": "SUMMERSALE10OFF"
  }
}
PUT/admin/price_rules/507328175.json
Cập nhật các thuộc tính của một giảm giá

Cập nhật tiêu đề của một giảm giá

PUT /admin/price_rules/#{id}.json
{
  "price_rule": {
    "id": 507328175,
    "value_type": "fixed_amount",
    "value": "-10000",
    "customer_selection": "all",
    "target_type": "line_item",
    "target_selection": "all",
    "allocation_method": "across",
    "once_per_customer": false,
    "usage_limit": null,
    "starts_at": "2017-09-06T16:23:01-04:00",
    "ends_at": "2017-09-18T16:23:01-04:00",
    "created_at": "2017-09-12T16:23:01-04:00",
    "updated_at": "2017-09-12T16:23:01-04:00",
    "entitled_product_ids": [
    ],
    "entitled_variant_ids": [
    ],
    "entitled_collection_ids": [
    ],
    "entitled_country_ids": [
    ],
    "prerequisite_saved_search_ids": [
    ],
    "prerequisite_subtotal_range": null,
    "prerequisite_shipping_price_range": null,
    "title": "WINTER SALE"
  }
}
Xem kết quả
HTTP/1.1 200 OK
{
  "price_rule": {
    "id": 507328175,
    "value_type": "fixed_amount",
    "value": "-10000",
    "customer_selection": "all",
    "target_type": "line_item",
    "target_selection": "all",
    "allocation_method": "across",
    "once_per_customer": false,
    "usage_limit": null,
    "starts_at": "2017-09-06T16:23:01-04:00",
    "ends_at": "2017-09-18T16:23:01-04:00",
    "created_at": "2017-09-12T16:23:01-04:00",
    "updated_at": "2017-09-12T16:23:14-04:00",
    "entitled_product_ids": [
    ],
    "entitled_variant_ids": [
    ],
    "entitled_collection_ids": [
    ],
    "entitled_country_ids": [
    ],
    "prerequisite_saved_search_ids": [
    ],
    "prerequisite_subtotal_range": null,
    "prerequisite_shipping_price_range": null,
    "title": "WINTER SALE"
  }
}
GET/admin/price_rules.json
Lấy thông tin của một danh sách Giảm giá
limit

Số lượng kết quả trả về

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

Số trang

(mặc định: 1)
created_on_min

Hiển thị các Giảm giá được tạo sau ngày này (định dạng: 2017-03-25 03:00)

created_on_max

Hiển thị các Giảm giá được tạo trước ngày này (định dạng: 2017-03-25 03:00)

updated_on_min

Hiển thị các Giảm được cập nhật lần cuối sau ngày này (định dạng: 2017-03-25 06:00)

updated_on_max

Hiển thị các Giảm giá được cập nhật lần cuối trước ngày này (định dạng: 2017-03-25 03:00)

starts_on_min

Hiển thị các Giảm giá được bắt đầu áp dụng sau ngày này (định dạng: 2017-03-25 03:00)

starts_on_max

Hiển thị các Giảm giá được bắt đầu áp dụng trước ngày này (định dạng: 2017-03-25 03:00)

ends_on_min

Hiển thị các Giảm giá hết hạn áp dụng sau ngày này (định dạng: 2017-03-25 03:00)

ends_on_max

Hiển thị các Giảm giá hết hạn áp dụng trước ngày này (định dạng: 2017-03-25 03:00)

times_used

Hiển thị các Giảm giá theo số lần đã sử dụng

Lấy danh sách tất cả Giảm giá

GET /admin/price_rules.json
Xem kết quả
HTTP/1.1 200 OK
{
  "price_rules": [
    {
      "id": 507328175,
      "value_type": "fixed_amount",
      "value": "-1000.00",
      "customer_selection": "all",
      "target_type": "line_item",
      "target_selection": "all",
      "allocation_method": "across",
      "once_per_customer": false,
      "usage_limit": null,
      "starts_at": "2017-09-06T16:23:01-04:00",
      "ends_at": "2017-09-18T16:23:01-04:00",
      "created_at": "2017-09-12T16:23:01-04:00",
      "updated_at": "2017-09-12T16:23:01-04:00",
      "entitled_product_ids": [
      ],
      "entitled_variant_ids": [
      ],
      "entitled_collection_ids": [
      ],
      "entitled_country_ids": [
      ],
      "prerequisite_saved_search_ids": [
      ],
      "prerequisite_subtotal_range": null,
      "prerequisite_shipping_price_range": null,
      "title": "SUMMERSALE10OFF"
    }
  ]
}
GET/admin/price_rules/507328175.json
Lấy thông tin một Giảm giá

Lấy thông tin của một Giảm giá

GET /admin/price_rules/#{id}.json
Xem kết quả
HTTP/1.1 200 OK
{
  "price_rule": {
    "id": 507328175,
    "value_type": "fixed_amount",
    "value": "-1000.00",
    "customer_selection": "all",
    "target_type": "line_item",
    "target_selection": "all",
    "allocation_method": "across",
    "once_per_customer": false,
    "usage_limit": null,
    "starts_at": "2017-09-06T16:23:01-04:00",
    "ends_at": "2017-09-18T16:23:01-04:00",
    "created_at": "2017-09-12T16:23:01-04:00",
    "updated_at": "2017-09-12T16:23:01-04:00",
    "entitled_product_ids": [
    ],
    "entitled_variant_ids": [
    ],
    "entitled_collection_ids": [
    ],
    "entitled_country_ids": [
    ],
    "prerequisite_saved_search_ids": [
    ],
    "prerequisite_subtotal_range": null,
    "prerequisite_shipping_price_range": null,
    "title": "SUMMERSALE10OFF"
  }
}
DELETE/admin/price_rules/507328175.json
Xóa một giảm giá

Xóa vĩnh viễn một giảm giá

DELETE /admin/price_rules/#{id}.json
Xem kết quả
HTTP/1.1 204 No Content

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: