> ## Knowledge Base Index
> Fetch the complete knowledge base index at: https://help.bentoweb.com/sitemap.xml
> Use this file to discover available pages before exploring further.
> Pure-Markdown content can be obtained by appending a '.md' suffix to the content URLs listed in the sitemap (without the trailing slash).

# วิธีกำหนดราคา Wholesale ผ่าน API

### **การกำหนดราคาขายส่ง (Wholesale Pricing) ผ่าน API**
สามารถตั้งค่าราคาขายส่งได้ผ่าน 3 Endpoints ดังนี้:
**1. สร้างสินค้าใหม่ (Create Product)**
`POST /product`
**2. สร้างตัวเลือกสินค้าใหม่ (Create Variant)**
`POST /product-variant`
**3. แก้ไขตัวเลือกสินค้า (Update Variant)**
`PUT /product-variant/{product_variant_id}`
#### **โครงสร้างข้อมูล (JSON Structure)**
ในการส่งข้อมูล ให้เพิ่ม Field `wholesale_range` และ `max_wholesale_range_price` เข้าไปใน Payload:
JSON
```
{
  "has_wholesale": 1,
  "wholesale_range": [
    { "range": 5,  "price": 11.00 },
    { "range": 10, "price": 10.00 },
    { "range": 20, "price": 9.00 }
  ],
  "max_wholesale_range_price": 8.00
}
```
> **ข้อสำคัญ:** ข้อมูลใน Array `wholesale_range` จะต้องเรียงลำดับค่า `range` จาก **น้อยไปมาก** เสมอ
#### **คำอธิบายตรรกะราคา (Pricing Logic)**
จากตัวอย่าง JSON ด้านบน ระบบจะคำนวณราคาขายตามจำนวนชิ้นที่ลูกค้าซื้อ ดังนี้:
| **ช่วงจำนวนสินค้า (Qty)** | **เงื่อนไขใน JSON** | **ราคาต่อชิ้น (บาท)** |
| **ชิ้นที่ 1 - 5** | `"range": 5` | **11.00** |
| **ชิ้นที่ 6 - 10** | `"range": 10` | **10.00** |
| **ชิ้นที่ 11 - 20** | `"range": 20` | **9.00** |
| **ชิ้นที่ 21 ขึ้นไป** | `max_wholesale_range_price` | **8.00** |
* **wholesale_range:** ใช้กำหนดช่วงราคาแบบขั้นบันได (Step Pricing)
* **max_wholesale_range_price:** ใช้กำหนดราคาเมื่อจำนวนสินค้า **เกินกว่า** ช่วงที่ระบุไว้ทั้งหมด (Infinity Range)
#### **การเปิด/ปิด ใช้งานระบบขายส่ง**
ใช้ Endpoint: `PUT /product-variant/{product_variant_id}`
และส่งค่าผ่าน Field `has_wholesale`:
* **`0`** : ปิดใช้งาน (Disable)
* **`1`** : เปิดใช้งาน (Enable)