Closed (fixed)
Project:
Commerce Decoupled Checkout
Version:
8.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
1 Nov 2022 at 12:16 UTC
Updated:
18 May 2023 at 10:49 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
dubs commentedPatch supplied
Comment #3
dubs commentedComment #4
kalabroThank 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_transitionevent 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.Comment #5
dubs commentedHi @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
Comment #6
dubs commentedHello 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.
Comment #7
iamdroid commentedHi @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
Comment #9
pavel.bulatThank you all for working on it! I have merged the path.
Comment #10
pavel.bulat