代码之家  ›  专栏  ›  技术社区  ›  Omar

Cart API:Cart.data.data.Cart_金额计算不正确…我认为

  •  0
  • Omar  · 技术社区  · 7 年前
    1. 使用API将产品添加到购物车的价格为29美元
    2. GET /v3/carts/cartId cart_amount
    3. 将产品价格更改为100美元
    4. 获取/v3/carts/cartId 购物车数量 错了,它没有看到产品价格有变化。

    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 29.95 GET /catalog/products/125 那个显示了最新价格。

    GET: carts/${cartId}

    {
        "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

    {
        "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": {}
    }
    
    1 回复  |  直到 7 年前
        1
  •  2
  •   T.J.    7 年前

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

    原始购物车的商品是25美元,含税,购物车的价格是29.12美元

    {
        "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": {}
    }
    

    /{store_hash}/v3/carts/{cartId}/items/{itemId}

    {
        "line_item":
            {
                "list_price": 30,
                "quantity": 1,
                "product_id": 192
            }
    }
    

    {
        "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": {}
    }