[关闭]
@JackieQu 2018-06-12T17:06:24.000000Z 字数 4179 阅读 522

购物车信息

好热闹TeaShop


获取购物车

Method and Url Structure

Method Resource URL
GET /cart/

cURL Example

  1. curl -X GET -H 'Authorization: Token 7dccb47cbeb6a283013708ed983712fc6488aa74'
  2. http://127.0.0.1:8000/market/cart/

JSON Response

  1. {
  2. "pk": 2,
  3. "product_set": []
  4. }

添加商品

Method and Url Structure

Method Resource URL
PUT /market/cart/add/

Request and Parameters

Name Description Required Default
product 商品 pk YES

Request

  1. {
  2. "product": 2
  3. }

cURL Example

  1. curl -X PUT -H 'Authorization: Token 7dccb47cbeb6a283013708ed983712fc6488aa74'
  2. http://127.0.0.1:8000/market/cart/add/

JSON Response

  1. {
  2. "pk": 2,
  3. "product_set": [
  4. {
  5. "cart_item": 3,
  6. "product": {
  7. "pk": 2,
  8. "name": "冰红茶",
  9. "content": "冰力十足",
  10. "image": "https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=2077117511,2743730327&fm=200&gp=0.jpg",
  11. "price": "5.00",
  12. "offer_price": "3.00",
  13. "isoffer": false,
  14. "bought": 0
  15. },
  16. "quantity": 1,
  17. "selected": false,
  18. "amount": 3
  19. },
  20. {
  21. "cart_item": 2,
  22. "product": {
  23. "pk": 1,
  24. "name": "青梅绿茶",
  25. "content": "绿茶配青梅还是头一回",
  26. "image": "https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=1031155128,3611764703&fm=27&gp=0.jpg",
  27. "price": "6.00",
  28. "offer_price": "4.00",
  29. "isoffer": false,
  30. "bought": 0
  31. },
  32. "quantity": 3,
  33. "selected": false,
  34. "amount": 12
  35. }
  36. ]
  37. }

减少商品

Method and Url Structure

Method Resource URL
PUT /market/cart/subtract/

Request and Parameters

Name Description Required Default
product 商品 pk YES

Request

  1. {
  2. "product": 2
  3. }

cURL Example

  1. curl -X PUT -H 'Authorization: Token 7dccb47cbeb6a283013708ed983712fc6488aa74'
  2. http://127.0.0.1:8000/market/cart/subtract/

JSON Response

  1. {
  2. "pk": 2,
  3. "product_set": [
  4. {
  5. "cart_item": 3,
  6. "product": {
  7. "pk": 2,
  8. "name": "冰红茶",
  9. "content": "冰力十足",
  10. "image": "https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=2077117511,2743730327&fm=200&gp=0.jpg",
  11. "price": "5.00",
  12. "offer_price": "3.00",
  13. "isoffer": false,
  14. "bought": 0
  15. },
  16. "quantity": 1,
  17. "selected": false,
  18. "amount": 3
  19. },
  20. {
  21. "cart_item": 2,
  22. "product": {
  23. "pk": 1,
  24. "name": "青梅绿茶",
  25. "content": "绿茶配青梅还是头一回",
  26. "image": "https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=1031155128,3611764703&fm=27&gp=0.jpg",
  27. "price": "6.00",
  28. "offer_price": "4.00",
  29. "isoffer": false,
  30. "bought": 0
  31. },
  32. "quantity": 2,
  33. "selected": false,
  34. "amount": 8
  35. }
  36. ]
  37. }

移除商品

Method and Url Structure

Method Resource URL
PUT /market/cart/remove/

Request and Parameters

Name Description Required Default
product 商品 pk YES

Request

  1. {
  2. "product": 2
  3. }

cURL Example

  1. curl -X PUT -H 'Authorization: Token 7dccb47cbeb6a283013708ed983712fc6488aa74'
  2. http://127.0.0.1:8000/market/cart/remove/

JSON Response

  1. {
  2. "pk": 2,
  3. "product_set": [
  4. {
  5. "cart_item": 2,
  6. "product": {
  7. "pk": 1,
  8. "name": "青梅绿茶",
  9. "content": "绿茶配青梅还是头一回",
  10. "image": "https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=1031155128,3611764703&fm=27&gp=0.jpg",
  11. "price": "6.00",
  12. "offer_price": "4.00",
  13. "isoffer": false,
  14. "bought": 0
  15. },
  16. "quantity": 2,
  17. "selected": false,
  18. "amount": 8
  19. }
  20. ]
  21. }

选中商品/取消选中

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

  1. {
  2. "product": 2
  3. }

cURL Example

  1. curl -X PUT -H 'Authorization: Token 7dccb47cbeb6a283013708ed983712fc6488aa74'
  2. http://127.0.0.1:8000/market/cart/select/

JSON Response

  1. {
  2. "pk": 2,
  3. "product_set": [
  4. {
  5. "cart_item": 2,
  6. "product": {
  7. "pk": 1,
  8. "name": "青梅绿茶",
  9. "content": "绿茶配青梅还是头一回",
  10. "image": "https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=1031155128,3611764703&fm=27&gp=0.jpg",
  11. "price": "6.00",
  12. "offer_price": "4.00",
  13. "isoffer": false,
  14. "bought": 0
  15. },
  16. "quantity": 2,
  17. "selected": true,
  18. "amount": 8
  19. }
  20. ]
  21. }

全选/取消全选

Method and Url Structure

Method Resource URL
PUT /market/cart/select_all/
PUT /market/cart/cancel_all_select/

cURL Example

  1. curl -X PUT -H 'Authorization: Token 7dccb47cbeb6a283013708ed983712fc6488aa74'
  2. http://127.0.0.1:8000/market/cart/select_all/

JSON Response

  1. {
  2. "pk": 2,
  3. "product_set": [
  4. {
  5. "cart_item": 4,
  6. "product": {
  7. "pk": 2,
  8. "name": "冰红茶",
  9. "content": "冰力十足",
  10. "image": "https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=2077117511,2743730327&fm=200&gp=0.jpg",
  11. "price": "5.00",
  12. "offer_price": "3.00",
  13. "isoffer": false,
  14. "bought": 0
  15. },
  16. "quantity": 1,
  17. "selected": true,
  18. "amount": 3
  19. },
  20. {
  21. "cart_item": 2,
  22. "product": {
  23. "pk": 1,
  24. "name": "青梅绿茶",
  25. "content": "绿茶配青梅还是头一回",
  26. "image": "https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=1031155128,3611764703&fm=27&gp=0.jpg",
  27. "price": "6.00",
  28. "offer_price": "4.00",
  29. "isoffer": false,
  30. "bought": 0
  31. },
  32. "quantity": 2,
  33. "selected": true,
  34. "amount": 8
  35. }
  36. ]
  37. }

清空购物车

Method and Url Structure

Method Resource URL
DELETE /market/cart/clear/

cURL Example

  1. curl -X PUT -H 'Authorization: Token 7dccb47cbeb6a283013708ed983712fc6488aa74'
  2. http://127.0.0.1:8000/market/cart/clear/
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注