Magento2:默认Api响应变化

时间:2018-02-25 01:19:47

标签: magento2 php-7 magento2.2 magento-2.0.7

我正在使用Magento2默认api /V1/carts/mine/payment-information

此api的回复是

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

想在商品中添加images标签,以显示商品/商品的图片。但是这个标签没有在项目的界面中定义,即

  

TotalsItemInterface.php

我在自定义模块中复制了TotalsItemInterface,并添加了Totalsinterface中的所有getter和setter以及setImages和getImages Tag。因此在内部我调用该方法并通过我的自定义apiInterfaces显示它。

如果我们想要更改apis中显示的数据,是否有更好或适当的Magento2方式?

1 个答案:

答案 0 :(得分:0)

您可以为其使用扩展名属性。您可以在devdocs中找到有关它们的更多信息: https://devdocs.magento.com/guides/v2.3/extension-dev-guide/extension_attributes/adding-attributes.html