Forum Replies Created

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter pmsn

    (@pmsn)

    Hi Sébastien

    Thank you for your answer.

    After many attempts I found out it is because of cookies.

    So my project have 3 parts
    1. Store app using React
    2. Rest api for React app using php
    3. WP site for woocommerce api and cocart api

    When React app need to make a request to cocart api it not call to cocart api directly it call to php rest api (number 2) and php will send request to cocart api server and then return response back to React app. So I think with this workflow somehow it can’t not set cookies from cocart response to browser so it can’t track my cart.

    My workaround it get set-cookies from cocart api and using React-Cookie to store it and when React app make a request to php server I will add this cookie with
    request headers and send it to cocart api and I can get my cart.

    Thread Starter pmsn

    (@pmsn)

    Also I tried not send cart_key. Only send jwtoken. When I add item with cart/add-item endpoint it return cart data like this.

    {
        "cart_hash": "dadf5550c07e784cc4d7bcbd95570906",
        "cart_key": "2",
        "currency": { ... },
        "customer": { ... },
        "items": [
            {
                "item_key": "d82c8d1619ad8176d665453cfb2e55f0",
                "id": 53,
                "name": "Black, size: XL, prompt: eeee",
                "title": "Black, size: XL, prompt: eeee",
                "price": "15000",
                "quantity": {
                    "value": 1,
                    "min_purchase": 1,
                    "max_purchase": -1
                },
                "totals": {
                    "subtotal": "15000",
                    "subtotal_tax": 0,
                    "total": 150,
                    "tax": 0
                },
                "slug": "black-size-xl-prompt-eeee",
                "meta": {
                    "product_type": "simple",
                    "sku": "",
                    "dimensions": {
                        "length": "",
                        "width": "",
                        "height": "",
                        "unit": "cm"
                    },
                    "weight": 0,
                    "variation": [],
                    "virtual": false,
                    "downloadable": false
                },
                "backorders": "",
                "cart_item_data": [],
                "featured_image": "...",
                "categories": [ ... ],
                "tags": false,
                "stock_status": {
                    "status": "In Stock",
                    "stock_quantity": null,
                    "hex_color": "#7ad03a"
                },
                "gallery": { ... },
                "permalink": "...",
                "is_discounted": false,
                "price_regular": "15000",
                "price_sale": "0",
                "price_discounted": "0"
            }
        ],
        "item_count": 1,
        "items_weight": 0,
        "coupons": [],
        "needs_payment": true,
        "needs_shipping": true,
        "shipping": { ... },
        "fees": [],
        "taxes": [],
        "totals": { ... },
        "removed_items": [],
        "cross_sells": [],
        "notices": { ... }
    }

    When I check response header for CoCart-API-Cart-Key I see “a4ab59e0b4b2af619fac4e54e929aeb0” so I check my database and I saw cart row with this cart_key in cart table.

    And then I get cart again using /cart endpoint I got this result.

    {
        "cart_hash": "",
        "cart_key": "2",
        "currency": { ... },
        "customer": { ... }
        "items": [],
        "item_count": 0,
        "items_weight": 0,
        "coupons": [],
        "needs_payment": false,
        "needs_shipping": false,
        "shipping": {
            "total_packages": 0,
            "show_package_details": false,
            "has_calculated_shipping": false,
            "packages": []
        },
        "fees": [],
        "taxes": [],
        "totals": { .... },
        "removed_items": [],
        "cross_sells": [],
        "notices": []
    }

    I got same cart_key but no items. and CoCart-API-Cart-Key from response header is “905dd0ba1e5e55b137230d34c7391771” but there’s no cart row with this cart_key in my database.

Viewing 2 replies - 1 through 2 (of 2 total)