0

I have to edit the SKU with some other data. When I use this rest API below

http://localhost.com/rest/V1/orders/1

I get SKU in two places like below. Place one at the first like below

"items": [
        {
        
            "sku": "Test1-20,
            "store_id": 9,
            "tax_amount": 795.94,
            "tax_invoiced": 795.94,
            "tax_percent": 9.375,
            "updated_at": "2021-11-17 19:45:18",
            "weee_tax_applied": "[]",
            "weight": 610,
            "product_option": {
                "extension_attributes": {
                    "custom_options": [
                        {
                            "option_id": "1919",
                            "option_value": "13817"
                        },
                        
                    ]
                }
            },
 ]

And inside extension attributes like below.

"extension_attributes": {
    "shipping_assignments": [
        {
            "shipping": {
                "address": {
                    "address_type": "shipping",
                    "city": "ttes",
                    "country_id": "US",
                    "email": "[email protected]",
                    "entity_id": 111,
                    "firstname": "123",
                    "lastname": "111",
                    "parent_id": 1,
                    "postcode": "636006",
                    "region": "TN",
                    "region_code": "TN",
                    "region_id": 1,
                    "street": [
                        "Fort street"
                    ],
                    "telephone": "123123"
                },
                "method": "free-ship",
            "items": [
                {
                    "sku": "Test1-20",
                    "store_id": 9,
                    "tax_amount": 795.94,
                    "tax_invoiced": 795.94,
                    "tax_percent": 9.375,
                    "updated_at": "2021-11-17 19:45:18",
                    "weee_tax_applied": "[]",
                    "weight": 610,
                }
            ]
        }
    ],

Need to change SKU in the both places but couldn't find one exact professional way.

1 Answer 1

0

The best way should be to create plugins for OrderRepository and OrderItemRepository, in detail:

  • create plugin OrderRepository:afterGet() method
  • create plugin OrderItemRepository:afterGetList() method

This will give you control over OrderInterface and OrderItemInterface, and so manipulating the sku as you like.

Here you find an answer about creating OrderRepository plugins How to override order api in magento 2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.