Problem/Motivation

Other order data may be required, e.g. shipping info, and currently there isn't an easy way to do work with this data from other modules.

Proposed resolution

Include a module alter hook for the order and original data.

Remaining tasks

Review and test patch.

API changes

Extra module hook (hook_decoupled_order_alter)

Comments

Dubs created an issue. See original summary.

dubs’s picture

Status: Active » Needs review
StatusFileSize
new1.7 KB

Patch supplied

dubs’s picture

Issue summary: View changes
kalabro’s picture

Thank you very much for your contribution @Dubs! Could you please share a bit more about the use case you have?

I used commerce_order.place.post_transition event subscriber in the past (comes out of the box with Commerce) to make changes to the placed order. The raw data in this case can be obtained from POST params.

dubs’s picture

Hi @Kalabro,

Thanks for responding so quickly!

A bit of background.... in this case we are using this module for a client to accept orders from a third-party API (this API is from a company who specialise in integrating eBay, Amazon, and many other third-party marketplaces into one API). We can specify to them the format of the REST data structure. Their API will send order data to Drupal which is the central system the client already uses (most of their orders will come from the existing Drupal site).

So, we will receive shipping information from the third-party API. I want to write a hook in a custom module to process the shipment data. If you think this is useful I am happy to include the code as another class in this module via a patch?

I know we can use event subscribers, but it keeps it in line with this existing hooks this module provides and expands the API a little more so I thought the patch to add a hook may be beneficial. Another thing we can do it add any other data the third-party API may need into the order before the response is sent back, or replace the whole order object with a different response object if we wanted to.

Thanks again for getting back to me on this :-)

Dubs

dubs’s picture

Hello again, I've attached a new patch, which contains two new hooks: -

1. hook_decoupled_order_data_alter - allows the order data to be altered.
2. hook_decoupled_order_alter - allows the order to be altered. In my case we adding a shipment to the orders.

I've also moved the validation hook below the order_checkout_prepare hook so we can change the incoming data. In my case, the third party sends an EAN code as a lookup as opposed to the SKU, so we find the product variations that way and change the order data to have the skus instead.

iamdroid’s picture

Status: Needs review » Reviewed & tested by the community

Hi @Dubs, Thanks for this.

I've reviewed the patch, it has been applied smoothly, code changes look good, the module works normally, and no problems were found.

RTBC

  • pavel.bulat committed 6238dfb2 on 8.x-1.x
    Issue #3318503 by Dubs, kalabro, iamdroid: Allow other modules to work...
pavel.bulat’s picture

Thank you all for working on it! I have merged the path.

pavel.bulat’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.