首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Cart API: cart.data.data.cart_amount没有正确计算.我认为

Cart API: cart.data.data.cart_amount没有正确计算.我认为
EN

Stack Overflow用户
提问于 2018-08-23 19:32:02
回答 1查看 133关注 0票数 0
  1. 增加了一个产品到购物车使用API价格是29美元
  2. GET /v3/carts/cartId saw cart_amount是正确的
  3. 将产品价格改为100美元
  4. GET /v3/carts/cartId认为cart_amount错了--它没有看到产品价格发生了变化。

我是不是做错什么了。你需要更多的信息来帮助我吗?

代码语言:javascript
复制
bc.add_to_cart = (data,next) => {
    let payload = {
        line_items: data.line_items,
        option_selections: data.option_selections,
        gift_certificatesL: null
    }
    return bc_v3.post(`/carts/${data.cartId}/items`, payload).then(data => {
        return data; // data only show initial product cost
    }).catch(next);
};

编辑

下面我张贴的GET carts/id u的结果,将看到lineItem (id: 125)显示原始价格,29.95。在得到购物车后,我立即向GET /catalog/products/125提出了一个请求--该请求显示了更新的价格。

GET: carts/${cartId}

代码语言:javascript
复制
{
    "data": {
        "id": "15219c6d-51a8-4267-a38c-29fe62a49182",
        "customer_id": 0,
        "email": "",
        "currency": {
            "code": "USD"
        },
        "tax_included": false,
        "base_amount": 409.7,
        "discount_amount": 0,
        "cart_amount": 409.7,
        "coupons": [],
        "line_items": {
            "physical_items": [
                {
                    "id": "d755137f-b09c-4a02-9da6-cab8da1ae332",
                    "parent_id": null,
                    "variant_id": 89,
                    "product_id": 124,
                    "sku": "test_config",
                    "name": "Test Configurable item",
                    "url": "http://fornida.mybigcommerce.com/test-configurable-item/",
                    "quantity": 2,
                    "taxable": true,
                    "image_url": "https://cdn7.bigcommerce.com/s-2bihpr2wvz/products/124/images/389/overview-3-lg-c__55453.1534430965.220.290.jpg?c=2",
                    "discounts": [],
                    "coupons": [],
                    "discount_amount": 0,
                    "coupon_amount": 0,
                    "list_price": 115,
                    "sale_price": 115,
                    "extended_list_price": 230,
                    "extended_sale_price": 230,
                    "is_require_shipping": true
                },
                {
                    "id": "eb5695d6-85e5-4b58-891b-a4bd8b48c56e",
                    "parent_id": null,
                    "variant_id": 90,
                    "product_id": 125,
                    "sku": "test_compt_1",
                    "name": "test component 1",
                    "url": "http://fornida.mybigcommerce.com/test-component-1/",
                    "quantity": 6,
                    "taxable": true,
                    "image_url": "https://cdn7.bigcommerce.com/r-03b8fdf5d1037c0feebbcedfd701c709422a962e/themes/ClassicNext/images/ProductDefault.gif",
                    "discounts": [],
                    "coupons": [],
                    "discount_amount": 0,
                    "coupon_amount": 0,
                    "list_price": 29.95,
                    "sale_price": 29.95,
                    "extended_list_price": 179.7,
                    "extended_sale_price": 179.7,
                    "is_require_shipping": true
                }
            ],
            "digital_items": [],
            "gift_certificates": []
        },
        "created_time": "2018-08-23T15:41:10+00:00",
        "updated_time": "2018-08-23T18:57:55+00:00"
    },
    "meta": {}
}

获取/catalog/products/125

代码语言:javascript
复制
{
    "data": {
        "id": 125,
        "name": "test component 1",
        "type": "physical",
        "sku": "test_compt_1",
        "description": "<p>Type a description for this product here...</p>",
        "weight": 2,
        "width": 0,
        "depth": 0,
        "height": 0,
        "price": 125,
        "cost_price": 0,
        "retail_price": 0,
        "sale_price": 0,
        "map_price": 0,
        "tax_class_id": 0,
        "product_tax_code": "",
        "calculated_price": 125,
        "categories": [
            23,
            18
        ],
        "brand_id": 0,
        "option_set_id": 38,
        "option_set_display": "right",
        "inventory_level": 0,
        "inventory_warning_level": 0,
        "inventory_tracking": "none",
        "reviews_rating_sum": 0,
        "reviews_count": 0,
        "total_sold": 0,
        "fixed_cost_shipping_price": 0,
        "is_free_shipping": false,
        "is_visible": true,
        "is_featured": false,
        "related_products": [
            -1
        ],
        "warranty": "",
        "bin_picking_number": "",
        "layout_file": "product.html",
        "upc": "",
        "mpn": "",
        "gtin": "",
        "search_keywords": "",
        "availability": "available",
        "availability_description": "",
        "gift_wrapping_options_type": "any",
        "gift_wrapping_options_list": [],
        "sort_order": 0,
        "condition": "New",
        "is_condition_shown": false,
        "order_quantity_minimum": 0,
        "order_quantity_maximum": 0,
        "page_title": "",
        "meta_keywords": [],
        "meta_description": "",
        "date_created": "2018-08-15T13:46:57+00:00",
        "date_modified": "2018-08-23T18:22:52+00:00",
        "view_count": 7,
        "preorder_release_date": null,
        "preorder_message": "",
        "is_preorder_only": false,
        "is_price_hidden": false,
        "price_hidden_label": "",
        "custom_url": {
            "url": "/test-component-1/",
            "is_customized": false
        },
        "base_variant_id": 90,
        "open_graph_type": "product",
        "open_graph_title": "",
        "open_graph_description": "",
        "open_graph_use_meta_description": true,
        "open_graph_use_product_name": true,
        "open_graph_use_image": true
    },
    "meta": {}
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-08-24 14:52:34

更新控制面板中项目的价格或使用API不会更改现有购物车中的价格。如果您创建了一个新的购物车,那么价格将反映所做的更改。

原来的购物车line_item是25美元,税金也包括在内,cart_amount是29.12美元

代码语言:javascript
复制
{
    "data": {
        "id": "3a4c8e16-e279-4c30-83df-0010f6d54fba",
        "customer_id": 0,
        "email": "",
        "currency": {
            "code": "USD"
        },
        "tax_included": false,
        "base_amount": 25,
        "discount_amount": 0,
        "cart_amount": 29.12,
        "coupons": [],
        "line_items": {
            "physical_items": [
                {
                    "id": "1e08875e-bf6f-4f1f-b8ba-b2e3cee10394",
                    "parent_id": null,
                    "variant_id": 363,
                    "product_id": 192,
                    "sku": "",
                    "name": "Smith Journal 13",
                    "url": "http://{store_hash}}.mybigcommerce.com/all/smith-journal-13/",
                    "quantity": 1,
                    "taxable": true,
                    "image_url": "https://cdn8.bigcommerce.com/s-{{store_hash}}/products/192/images/480/smithjournal1_1024x1024__85081__38998.1534344545.330.500.jpg?c=2",
                    "discounts": [],
                    "coupons": [],
                    "discount_amount": 0,
                    "coupon_amount": 0,
                    "list_price": 25,
                    "sale_price": 25,
                    "extended_list_price": 25,
                    "extended_sale_price": 25,
                    "is_require_shipping": true
                }
            ],
            "digital_items": [],
            "gift_certificates": []
        },
        "created_time": "2018-08-24T14:41:17+00:00",
        "updated_time": "2018-08-24T14:41:17+00:00"
    },
    "meta": {}
}

更新line_item价格/{store_hash}/v3/carts/{cartId}/items/{itemId}

代码语言:javascript
复制
{
    "line_item":
        {
            "list_price": 30,
            "quantity": 1,
            "product_id": 192
        }
}

响应-- base_amount现在为30,cart_amount也更新为34.96。这只会改变购物车的价格,而不会改变产品的价格。

代码语言:javascript
复制
{
    "data": {
        "id": "3a4c8e16-e279-4c30-83df-0010f6d54fba",
        "customer_id": 0,
        "email": "",
        "currency": {
            "code": "USD"
        },
        "tax_included": false,
        "base_amount": 30,
        "discount_amount": 0,
        "cart_amount": 34.96,
        "coupons": [],
        "line_items": {
            "physical_items": [
                {
                    "id": "1e08875e-bf6f-4f1f-b8ba-b2e3cee10394",
                    "parent_id": null,
                    "variant_id": 363,
                    "product_id": 192,
                    "sku": "",
                    "name": "Smith Journal 13",
                    "url": "http://{store_hash}.mybigcommerce.com/all/smith-journal-13/",
                    "quantity": 1,
                    "taxable": true,
                    "image_url": "https://cdn8.bigcommerce.com/s-{store_hash}/products/192/images/480/smithjournal1_1024x1024__85081__38998.1534344545.330.500.jpg?c=2",
                    "discounts": [],
                    "coupons": [],
                    "discount_amount": 0,
                    "coupon_amount": 0,
                    "list_price": 30,
                    "sale_price": 30,
                    "extended_list_price": 30,
                    "extended_sale_price": 30,
                    "is_require_shipping": true
                }
            ],
            "digital_items": [],
            "gift_certificates": []
        },
        "created_time": "2018-08-24T14:41:17+00:00",
        "updated_time": "2018-08-24T14:41:17+00:00"
    },
    "meta": {}
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51993065

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档