generated from AdobeDocs/dev-site-documentation-template
-
Notifications
You must be signed in to change notification settings - Fork 29
CEXT-5400: Add origData to the event payload and release notes #459
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 20 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
8f73c84
CEXT-5400: Add origData to the event payload
oshmyheliuk 9d1616a
CEXT-5400: Add origData to the event payload
oshmyheliuk 7e2a73e
CEXT-5400: Add origData to the event payload
oshmyheliuk 95492d6
CEXT-5400: Add origData to the event payload
oshmyheliuk b19380c
CEXT-5400: Add origData to the event payload
oshmyheliuk f961ea7
CEXT-5400: Add origData to the event payload
oshmyheliuk 4383a7c
Merge branch 'main' into CEXT-5400
oshmyheliuk 16681dc
CEXT-5400: Add origData to the event payload
oshmyheliuk 5c07f81
Merge remote-tracking branch 'oshmyheliuk/CEXT-5400' into CEXT-5400
oshmyheliuk 409fe5a
CEXT-5400: Add origData to the event payload
oshmyheliuk 1891498
Apply suggestion from @keharper
oshmyheliuk dd63c8a
Apply suggestion from @keharper
oshmyheliuk 565ecce
Apply suggestion from @keharper
oshmyheliuk 5e3402e
Apply suggestion from @keharper
oshmyheliuk 5fc78b9
Apply suggestion from @keharper
oshmyheliuk e98499e
Apply suggestion from @keharper
oshmyheliuk 987b6de
Apply suggestion from @keharper
oshmyheliuk 615e73f
Apply suggestion from @keharper
oshmyheliuk 9a3a3fb
CEXT-5400: Add origData to the event payload
oshmyheliuk c9f12b5
Correct badging
keharper 745c130
CEXT-5400: Add origData to the event payload
oshmyheliuk ecf2e1a
CEXT-5400: Add origData to the event payload
oshmyheliuk be2ec8c
Add links and fix grammar
keharper 6171340
Merge branch 'main' into CEXT-5400
keharper File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| --- | ||
| title: Create event subscriptions with original data | ||
| description: Use original event data in Adobe Commerce events. | ||
| edition: paas | ||
| keywords: | ||
| - Events | ||
| - Extensibility | ||
| --- | ||
|
|
||
| # Create event subscriptions with original data | ||
|
|
||
| Events that are based on objects that implement a specific interface in Adobe Commerce can include the original data of the object in the event payload. The original data represents the state of the object before any changes were made. This is particularly useful for events that are triggered by updates to objects, as it allows you to compare the previous state with the new state. | ||
|
|
||
| If the object is new (such as when a new product is created), the original data will be empty. Events that support original data also include an `_isNew` field in the payload, which indicates whether the object is new or existing. | ||
|
|
||
| To check if an event includes original data in its payload, you can visit **System** > Events > **Events List** page or use the following command [`bin/magento events:info <event_code>`](./commands.md#return-event-details). Keep in mind that that the returned payload for some events, especially those that are dynamically defined, might not include full details. | ||
|
|
||
| To include original data in the event payload, the event must be configured to include the `_origData` field even if the wildcard `*` is used to include all fields. For example, if you want to receive the whole payload including original data for the `observer.catalog_product_save_after` event, you can configure it as follows: | ||
|
|
||
| <InlineAlert variant="warning" slots="text" /> | ||
|
|
||
| The `_origData` field is not included by default even when using the wildcard `*`, so you must explicitly add it to the event configuration. | ||
|
|
||
| ```xml | ||
| <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module-commerce-events-client/etc/io_events.xsd"> | ||
| <event name="observer.catalog_product_save_after"> | ||
| <fields> | ||
| <field name="*"/> | ||
| <field name="_origData"/> | ||
| </fields> | ||
| </event> | ||
| </config> | ||
| ``` | ||
|
|
||
| As a result, the event payload will include the `_origData` field with the original data of the product before it was saved: | ||
|
|
||
| ```json | ||
| { | ||
| "sku": "Simple product", | ||
| "name": "Simple product", | ||
| "price": "500.000000", | ||
| "quantity_and_stock_status": { | ||
| "is_in_stock": "1", | ||
| "qty": "3126" | ||
| }, | ||
| ..... | ||
| "_origData": { | ||
| "sku": "Simple product", | ||
| "name": "Simple product New Name", | ||
| "price": "600.000000", | ||
| "quantity_and_stock_status": { | ||
| "is_in_stock": true, | ||
| "qty": 3125 | ||
| }, | ||
| ..... | ||
| }, | ||
| "_isNew": false | ||
| } | ||
| ``` | ||
|
|
||
| For some events with a complex payload structure, the original data might not be available as a root node. In such cases, you can provide a custom path to include the original data. For example, for the `observer.checkout_cart_product_add_before` event, you can configure it as follows: | ||
|
|
||
| ```xml | ||
| <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module-commerce-events-client/etc/io_events.xsd"> | ||
| <event name="observer.checkout_cart_product_add_before"> | ||
| <fields> | ||
| <field name="*"/> | ||
| <field name="product._origData"/> | ||
| <field name="quote_item._origData"/> | ||
| </fields> | ||
| </event> | ||
| </config> | ||
| ``` | ||
|
|
||
| You can define specific original and new fields to be included in the event payload. For example, if you want to include only the `sku` and `quantity_and_stock_status.qty` fields, along with their original values, configure the event as follows: | ||
|
|
||
| ```xml | ||
| <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module-commerce-events-client/etc/io_events.xsd"> | ||
| <event name="observer.catalog_product_save_after"> | ||
| <fields> | ||
| <field name="sku"/> | ||
| <field name="quantity_and_stock_status.qty"/> | ||
| <field name="_origData.sku"/> | ||
| <field name="_origData.quantity_and_stock_status.qty"/> | ||
| </fields> | ||
| </event> | ||
| </config> | ||
| ``` | ||
|
|
||
| As a result, the event payload will include only the selected fields and their original values: | ||
|
|
||
| ```json | ||
| { | ||
| "sku": "Simple product", | ||
| "quantity_and_stock_status": { | ||
| "qty": "3126" | ||
| }, | ||
| "_origData": { | ||
| "sku": "Simple product", | ||
| "quantity_and_stock_status": { | ||
| "qty": 3125 | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| The original data can be used in conditional events using the `onChange` operator to trigger events only when specific fields have changed. For more information, see [Create conditional events](./conditional-events.md#trigger-events-on-specific-field-changes). |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we also add an example when the events need to be triggered once qty or price is being changed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem here is that we don't have
ORrules, all rules are processed asAND.By adding the next rules:
The event will be triggered only if both price and quantity are changed.
Currently, it's possible to resolve by creating a separate subscription with an Alias name, one for price change and one for quantity change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should we state somewhere that OR rules aren't supported.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have the next definition at the beginning of that page.
Should we mention it one more time?