0

I've create a plugin to listen to api POST /V1/order/:orderId/refund

and I would like to receive custom field. I've added a field for testing like: name:['test']

Body E.G:

{
    "items": [
        {
            "extension_attributes": {},
            "order_item_id": 7,
            "qty": 1
        }
    ],
    "isOnline": false,
    "notify": true,
    "appendComment": true,
    "name": [
      { 
          "test": "ok" 
      }
    ], //THIS IS MY CUSTOM FIELD
    "comment": {
        "extension_attributes": {},
        "comment": "refund has been created",
        "is_visible_on_front": 0
    },
    "arguments": {
        "shipping_amount": 0,
        "adjustment_positive": 0,
        "adjustment_negative": 0,
        "extension_attributes": {
            "return_to_stock_items": []
        }
    }
}

beforeExecute Method:

...
    /**
     * Create refund for invoice
     *
     * @param int $invoiceId
     * @param \Magento\Sales\Api\Data\CreditmemoItemCreationInterface[] $items
     * @param bool|null $isOnline
     * @param bool|null $notify
     * @param bool|null $appendComment
     * @param \Magento\Sales\Api\Data\CreditmemoCommentCreationInterface|null $comment
     * @param \Magento\Sales\Api\Data\CreditmemoCreationArgumentsInterface|null $arguments
     * @param mixed $name
     * @return int
     * @since 100.1.3
     */

    public function beforeExecute (
        \Magento\Sales\Model\RefundOrder $subject,
        $orderId,
        array $items = [],
        $notify = false,
        $appendComment = false,
        \Magento\Sales\Api\Data\CreditmemoCommentCreationInterface $comment = null,
        \Magento\Sales\Api\Data\CreditmemoCreationArgumentsInterface $arguments = null,
        array $name = []
    ) {
        print_r($name);die;
      }
...

My custom field name is an array similar to items: but I am receiving an empty array from Response: s

Anyone any help Appreciated!

0

It does not fully answer my question but it helps, we can add custom_attribute to any extension_attributes I've used the arguments by doing the following :

create vendor/module/etc/extension_attributes.xml:

... <extension_attributes for="Magento\Sales\Api\Data\CreditmemoCreationArgumentsInterface">
        <attribute code="name" type="string" />
    </extension_attributes> ...

Block doc : * @param \Magento\Sales\Api\Data\CreditmemoCreationArgumentsInterface|null $name

beforeExecute method:

...\Magento\Sales\Api\Data\CreditmemoCreationArgumentsInterface $name = null,...

then:

print_r($arguments->getExtensionAttributes()->getName());

Wallahhhh! enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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