购物车信息
好热闹TeaShop
获取购物车
Method and Url Structure
Method |
Resource URL |
GET |
/cart/ |
cURL Example
curl -X GET -H 'Authorization: Token 7dccb47cbeb6a283013708ed983712fc6488aa74'
http://127.0.0.1:8000/market/cart/
JSON Response
{
"pk": 2,
"product_set": []
}
添加商品
Method and Url Structure
Method |
Resource URL |
PUT |
/market/cart/add/ |
Request and Parameters
Name |
Description |
Required |
Default |
product |
商品 pk |
YES |
|
Request
{
"product": 2
}
cURL Example
curl -X PUT -H 'Authorization: Token 7dccb47cbeb6a283013708ed983712fc6488aa74'
http://127.0.0.1:8000/market/cart/add/
JSON Response
{
"pk": 2,
"product_set": [
{
"cart_item": 3,
"product": {
"pk": 2,
"name": "冰红茶",
"content": "冰力十足",
"image": "https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=2077117511,2743730327&fm=200&gp=0.jpg",
"price": "5.00",
"offer_price": "3.00",
"isoffer": false,
"bought": 0
},
"quantity": 1,
"selected": false,
"amount": 3
},
{
"cart_item": 2,
"product": {
"pk": 1,
"name": "青梅绿茶",
"content": "绿茶配青梅还是头一回",
"image": "https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=1031155128,3611764703&fm=27&gp=0.jpg",
"price": "6.00",
"offer_price": "4.00",
"isoffer": false,
"bought": 0
},
"quantity": 3,
"selected": false,
"amount": 12
}
]
}
减少商品
Method and Url Structure
Method |
Resource URL |
PUT |
/market/cart/subtract/ |
Request and Parameters
Name |
Description |
Required |
Default |
product |
商品 pk |
YES |
|
Request
{
"product": 2
}
cURL Example
curl -X PUT -H 'Authorization: Token 7dccb47cbeb6a283013708ed983712fc6488aa74'
http://127.0.0.1:8000/market/cart/subtract/
JSON Response
{
"pk": 2,
"product_set": [
{
"cart_item": 3,
"product": {
"pk": 2,
"name": "冰红茶",
"content": "冰力十足",
"image": "https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=2077117511,2743730327&fm=200&gp=0.jpg",
"price": "5.00",
"offer_price": "3.00",
"isoffer": false,
"bought": 0
},
"quantity": 1,
"selected": false,
"amount": 3
},
{
"cart_item": 2,
"product": {
"pk": 1,
"name": "青梅绿茶",
"content": "绿茶配青梅还是头一回",
"image": "https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=1031155128,3611764703&fm=27&gp=0.jpg",
"price": "6.00",
"offer_price": "4.00",
"isoffer": false,
"bought": 0
},
"quantity": 2,
"selected": false,
"amount": 8
}
]
}
移除商品
Method and Url Structure
Method |
Resource URL |
PUT |
/market/cart/remove/ |
Request and Parameters
Name |
Description |
Required |
Default |
product |
商品 pk |
YES |
|
Request
{
"product": 2
}
cURL Example
curl -X PUT -H 'Authorization: Token 7dccb47cbeb6a283013708ed983712fc6488aa74'
http://127.0.0.1:8000/market/cart/remove/
JSON Response
{
"pk": 2,
"product_set": [
{
"cart_item": 2,
"product": {
"pk": 1,
"name": "青梅绿茶",
"content": "绿茶配青梅还是头一回",
"image": "https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=1031155128,3611764703&fm=27&gp=0.jpg",
"price": "6.00",
"offer_price": "4.00",
"isoffer": false,
"bought": 0
},
"quantity": 2,
"selected": false,
"amount": 8
}
]
}
选中商品/取消选中
Method and Url Structure
Method |
Resource URL |
PUT |
/market/cart/select/ |
PUT |
/market/cart/cancel_select/ |
Request and Parameters
Name |
Description |
Required |
Default |
product |
商品 pk |
YES |
|
Request
{
"product": 2
}
cURL Example
curl -X PUT -H 'Authorization: Token 7dccb47cbeb6a283013708ed983712fc6488aa74'
http://127.0.0.1:8000/market/cart/select/
JSON Response
{
"pk": 2,
"product_set": [
{
"cart_item": 2,
"product": {
"pk": 1,
"name": "青梅绿茶",
"content": "绿茶配青梅还是头一回",
"image": "https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=1031155128,3611764703&fm=27&gp=0.jpg",
"price": "6.00",
"offer_price": "4.00",
"isoffer": false,
"bought": 0
},
"quantity": 2,
"selected": true,
"amount": 8
}
]
}
全选/取消全选
Method and Url Structure
Method |
Resource URL |
PUT |
/market/cart/select_all/ |
PUT |
/market/cart/cancel_all_select/ |
cURL Example
curl -X PUT -H 'Authorization: Token 7dccb47cbeb6a283013708ed983712fc6488aa74'
http://127.0.0.1:8000/market/cart/select_all/
JSON Response
{
"pk": 2,
"product_set": [
{
"cart_item": 4,
"product": {
"pk": 2,
"name": "冰红茶",
"content": "冰力十足",
"image": "https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=2077117511,2743730327&fm=200&gp=0.jpg",
"price": "5.00",
"offer_price": "3.00",
"isoffer": false,
"bought": 0
},
"quantity": 1,
"selected": true,
"amount": 3
},
{
"cart_item": 2,
"product": {
"pk": 1,
"name": "青梅绿茶",
"content": "绿茶配青梅还是头一回",
"image": "https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=1031155128,3611764703&fm=27&gp=0.jpg",
"price": "6.00",
"offer_price": "4.00",
"isoffer": false,
"bought": 0
},
"quantity": 2,
"selected": true,
"amount": 8
}
]
}
清空购物车
Method and Url Structure
Method |
Resource URL |
DELETE |
/market/cart/clear/ |
cURL Example
curl -X PUT -H 'Authorization: Token 7dccb47cbeb6a283013708ed983712fc6488aa74'
http://127.0.0.1:8000/market/cart/clear/