0

I am using Magento2 default API: /V1/carts/mine/payment-information.

The response from this API is:

{
    "payment_methods": [
        {
            "code": "payu",
            "title": "PayUMoney"
        },
        {
            "code": "checkmo",
            "title": "Check / Money order"
        },
        {
            "code": "paytm",
            "title": "Paytm PG"
        }
    ],
    "totals": {
        "grand_total": 195,
        "base_grand_total": 195,
        "subtotal": 45,
        "base_subtotal": 45,
        "discount_amount": 0,
        "base_discount_amount": 0,
        "subtotal_with_discount": 45,
        "base_subtotal_with_discount": 45,
        "shipping_amount": 150,
        "base_shipping_amount": 150,
        "shipping_discount_amount": 0,
        "base_shipping_discount_amount": 0,
        "tax_amount": 0,
        "base_tax_amount": 0,
        "weee_tax_applied_amount": null,
        "shipping_tax_amount": 0,
        "base_shipping_tax_amount": 0,
        "subtotal_incl_tax": 45,
        "shipping_incl_tax": 150,
        "base_shipping_incl_tax": 150,
        "base_currency_code": "INR",
        "quote_currency_code": "INR",
        "items_qty": 1,
        "items": [
            {
                "item_id": 41,
                "price": 45,
                "base_price": 45,
                "qty": 1,
                "row_total": 45,
                "base_row_total": 45,
                "row_total_with_discount": 0,
                "tax_amount": 0,
                "base_tax_amount": 0,
                "tax_percent": 0,
                "discount_amount": 0,
                "base_discount_amount": 0,
                "discount_percent": 0,
                "price_incl_tax": 45,
                "base_price_incl_tax": 45,
                "row_total_incl_tax": 45,
                "base_row_total_incl_tax": 45,
                "options": "[{\"value\":\"Green\",\"label\":\"Color\"},{\"value\":\"29\",\"label\":\"Size\"}]",
                "weee_tax_applied_amount": null,
                "weee_tax_applied": null,
                "name": "Erika Running Short"
            }
        ],
        "total_segments": [
            {
                "code": "subtotal",
                "title": "Subtotal",
                "value": 45
            },
            {
                "code": "shipping",
                "title": "Shipping & Handling (Fixed)",
                "value": 150
            },
            {
                "code": "tax",
                "title": "Tax",
                "value": 0,
                "extension_attributes": {
                    "tax_grandtotal_details": []
                }
            },
            {
                "code": "grand_total",
                "title": "Grand Total",
                "value": 195,
                "area": "footer"
            }
        ]
    } 
}

I want to add the images tag inside items to display images of the items/products. But this tag is not defined in the interface of items, i.e

TotalsItemInterface.php

I replicated TotalsItemInterface in my custom module and added all getters and setters from Totalsinterface along with setImages and getImages Tag. Thus internally I call the method to use and show it by my custom apiInterfaces.

Is there a better or a proper "Magento 2 way" if we want to change the data displayed in the APIs?

TylerH
  • 20,799
  • 66
  • 75
  • 101
Rohit Rai
  • 375
  • 4
  • 21

1 Answers1

0

You may use extension attributes for it. You can find more information about them in the devdocs there: https://devdocs.magento.com/guides/v2.3/extension-dev-guide/extension_attributes/adding-attributes.html