0

I have a fully working Magento 2 website, now I want to use the API to create a mobile application so I am using rest API to checkout and place and order.

The problem in the shipping-information API which does not return order items and order totals so I can show them in the mobile app checkout page. The flow I am using is like this:

  1. get customer token using this API POST {{base_url}}/integration/customer/token
  2. create quote for customer using this api POST {{base_url}}/carts/mine which return quote_id
  3. add items to cart using this API POST {{base_url}}/carts/mine/items and the request body is
    {
    "cartItem":{
        "qty":1,
        "quoteId":"87846",
        "sku":"8681124614421"
        }
    }

and the response is

    {
    "item_id": 48508,
    "sku": "8681124614421",
    "qty": 2,
    "name": "MUSK Eau De Parfum 100 ml",
    "price": 644.07,
    "product_type": "simple",
    "quote_id": "87846"
    }
  1. calls estimate shipping method as follow POST {{base_url}}/carts/mine/estimate-shipping-methods request body:
    {
    "address": {
        "street": [
            "dsfsdf"
        ],
        "city": "aaasdd",
        "region": "",
        "country_id": "TR",
        "postcode": "12345",
        "firstname": "aaa",
        "lastname": "bbb",
        "telephone": "3213510",
        "custom_attributes": [
            {
                "attribute_code": "student",
                "value": "",
                "label": " "
            }
        ],
        "save_in_address_book": 1
    }
    }

and response is:

    [
    {
        "carrier_code": "dhl",
        "method_code": null,
        "carrier_title": "DHL",
        "amount": 0,
        "base_amount": null,
        "available": false,
        "error_message": "This shipping method is currently unavailable. If you would like to ship using this shipping method, please contact us.",
        "price_excl_tax": 0,
        "price_incl_tax": 0
    },
    {
        "carrier_code": "flatrate",
        "method_code": "flatrate",
        "carrier_title": "Flat Rate",
        "method_title": "Fixed",
        "amount": 10,
        "base_amount": 10,
        "available": true,
        "error_message": "",
        "price_excl_tax": 8.47,
        "price_incl_tax": 10
    }
    ]
  1. finally where the problem is, I call POST {{base_url}}/carts/mine/shipping-information with this request body:
    {
    "addressInformation": {
        "shipping_address": {
            "countryId": "TR",
            "region": "",
            "street": [
                "dsfsdf"
            ],
            "telephone": "3213510",
            "postcode": "12345",
            "city": "aaasdd",
            "firstname": "owais",
            "lastname": "hamouda",
            "saveInAddressBook": 1,
            "customAttributes": [
                {
                    "attribute_code": "student",
                    "value": "",
                    "label": " "
                }
            ]
        },
        "billing_address": {
            "customerAddressId": "206",
            "countryId": "TR",
            "regionId": "43",
            "regionCode": null,
            "region": "Turkey",
            "customerId": "492",
            "street": [
                "160 1st St."
            ],
            "company": "Sawaftech",
            "telephone": "516-555-1111",
            "fax": null,
            "postcode": "11501",
            "city": "Mineola",
            "firstname": "Jane",
            "lastname": "Doe",
            "middlename": null,
            "prefix": null,
            "suffix": null,
            "vatId": null,
            "customAttributes": []
        },
        "shipping_method_code": "flatrate",
        "shipping_carrier_code": "flatrate",
        "extension_attributes": {}
    }
    }

and the response is:

    {
    "payment_methods": [
        {
            "code": "iyzipay",
            "title": "Kredi/Banka Kartı ile Ödeme"
        },
        {
            "code": "banktransfer",
            "title": "Banka Havalesi Ödeme"
        },
        {
            "code": "cashondelivery",
            "title": "Cash On Delivery"
        },
        {
            "code": "stripe_payments",
            "title": "Stripe"
        }
    ],
    "totals": {
        "grand_total": 0,
        "weee_tax_applied_amount": null,
        "items": [],
        "total_segments": [
            {
                "code": "subtotal",
                "title": "Subtotal",
                "value": 0
            },
            {
                "code": "shipping",
                "title": "Shipping & Handling",
                "value": null
            },
            {
                "code": "tax",
                "title": "Tax",
                "value": 0,
                "extension_attributes": {
                    "tax_grandtotal_details": []
                }
            },
            {
                "code": "grand_total",
                "title": "Grand Total",
                "value": null,
                "area": "footer"
            }
        ]
    }
   }

Here as you see the totals and sub totals, grand totals, items not returned from the API. I also tried calling the collect-totals API, and totals API and didn't get any value. I am stuck on this issue for two weeks now, please help and advice what could be the problem, or how can I trace it or debug it if it is from an installed plugin for example.

Please note all the API calls I called it with header Authorization Bearer <customer token> And note that the flow from the website is working correctly.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
AlaaL
  • 333
  • 9
  • 28

2 Answers2

0

I've been using the same APIs too. I haven't encountered these issues. But I have updated the total price manually. I'd recommend trying one of the following steps:

  1. Check if any other module is overriding the totals data. For example, check if one of these methods are called

     $quote->setTriggerRecollect(1);
     $quote->collectTotals()->save();
     $quote->save();
    
  2. Since you get the price when you add to cart, add a plugin or create your own API to see if you can manually set the total after each POST/PUT/DELETE request. I have created a GET request that displays custom cart data based on quote ID. Something like that could be replicated too.

Saranya
  • 36
  • 4
0

The problem was a modification to the core modules from previous developer, I had to compare source code with fresh install of Magento to address the issue.

AlaaL
  • 333
  • 9
  • 28