You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, notification payloads are ad-hoc defined in CoreShop\Bundle\CoreBundle\EventListener\NotificationRules listeners and CoreShop\Bundle\NotificationBundle\Processor\EventedRuleProcessor.
The idea here is to streamline these payloads into a common structure which is easier to rely on if, for example, we dispatch these notifications to outside systems (think webhooks). One external example we can inspire oureselves from is Azure Alerts Common Schema or Cloud events.
Subject
The $subject is the object the notification is dealing with and it needs to be instance of \CoreShop\Component\Resource\Model\ResourceInterface. Here's a list of current subject types across listeners:
It's obvious the subject is meant to be directly the resource we're talking about, that part is fine.
Rule Type
Rule type is the type of rules we want to apply, it's defined by the conditions and actions available for the type.
Currently available are: user, order, shipment, invoice, payment, quote.
Params type
This is where we're getting to the crux of this issue, the inconsistencies between different rule appliers becomes visible here. Since the rule type defined above represents the rule type, not the event type, events are optionally named in the $params payload. This allows the conditions / actions to differentiate between different notifications triggered by the same rule, for example.
Some of these are defined as consts (example in CustomerListener), some are hardcoded (example in OrderCommentsListener), in some it's not set (example in OrderDocumentWorkflowListener).
This property should be be normalized and always defined.
DTO
My proposal is to introduce a DTO the purpose of which is to solve these common scenarios and streamline the params payload.
The proposed DTO schema is as follows:
timestamp: <autopopulated on object creation>type: <namespaced previous params type> # example: user.password.reset_requestuser: <reference to the user which performed the action which triggered the event>, can be nullcustomer: <reference to the customer which performed the action which triggered the event>, can be nullcontext:
store: <reference to the store which triggered the event>locale: <locale used when performing the action which triggered the event>parent: <reference to a "parent" of the subject, if applicable> # example, order for order comment or documentreference: # optionallink: <link provided for the action> # example, password reset, newsletter subscribetoken: <token used in the link>workflow: # optionalname: <workflow name used>from: <from state>to: <to state>transition: <transtion name>attributes: # free form, what currently $params isfoo: 123
The "reference" in the description would mean either an object or a reasonable (serializeable) representation of the object in question, most probably always looking like
Example usage: password reset on behalf of customer
type: user.password.reset_requestuser: {id: 9} # user triggering the password resetcustomer: {id: 123} # on behalf of the customercontext:
store: {id: 1, name: Store CH}locale: dereference:
link: http://example.ch/reset?token=123token: 123attributes:
Example usage: order comment
type: order.commentuser: {id: 9} # user adding the commentcustomer: {id: 123} # for the customercontext:
store: {id: 1, name: Store CH}locale: deparent: {id: 1234} # order which this comment belongs toattributes:
comment: sehr gut # mandatory for type: order.commentsubmitAsEmail: true
Example usage: order document
type: order.documentcustomer: {id: 123}context:
store: {id: 1, name: Store CH}locale: deparent: {id: 1234} # order which this document belongs toworkflow:
name: Some name herefrom: preparingto: readytransition: print
Example usage: order workflow
type: order.workflowcustomer: {id: 123}context:
store: {id: 1, name: Store CH}locale: deworkflow:
name: Some name herefrom: completingto: completedtransition: finalize
Example usage: payment workflow
type: payment.workflowcustomer: {id: 123}context:
store: {id: 1, name: Store CH}locale: deparent: {id: 1234} # order which this payment belongs toworkflow:
name: Some name herefrom: completingto: completedtransition: finalize
The text was updated successfully, but these errors were encountered:
Currently, notification payloads are ad-hoc defined in
CoreShop\Bundle\CoreBundle\EventListener\NotificationRules
listeners andCoreShop\Bundle\NotificationBundle\Processor\EventedRuleProcessor
.The idea here is to streamline these payloads into a common structure which is easier to rely on if, for example, we dispatch these notifications to outside systems (think webhooks). One external example we can inspire oureselves from is Azure Alerts Common Schema or Cloud events.
Subject
The
$subject
is the object the notification is dealing with and it needs to be instance of\CoreShop\Component\Resource\Model\ResourceInterface
. Here's a list of current subject types across listeners:CustomerListener
CoreShop\Component\Core\Model\CustomerInterface
OrderCommentsListener
CoreShop\Component\Core\Model\OrderInterface
OrderDocumentWorkflowListener
CoreShop\Component\Order\Model\OrderDocumentInterface
OrderWorkflowListener
CoreShop\Component\Order\Model\OrderInterface
PaymentWorkflowListener
CoreShop\Component\Core\Model\PaymentInterface
It's obvious the subject is meant to be directly the resource we're talking about, that part is fine.
Rule Type
Rule type is the type of rules we want to apply, it's defined by the conditions and actions available for the type.
Currently available are:
user
,order
,shipment
,invoice
,payment
,quote
.Params
type
This is where we're getting to the crux of this issue, the inconsistencies between different rule appliers becomes visible here. Since the rule type defined above represents the rule type, not the event type, events are optionally named in the
$params
payload. This allows the conditions / actions to differentiate between different notifications triggered by the same rule, for example.Some of these are defined as consts (example in
CustomerListener
), some are hardcoded (example inOrderCommentsListener
), in some it's not set (example inOrderDocumentWorkflowListener
).This property should be be normalized and always defined.
DTO
My proposal is to introduce a DTO the purpose of which is to solve these common scenarios and streamline the params payload.
The proposed DTO schema is as follows:
The "reference" in the description would mean either an object or a reasonable (serializeable) representation of the object in question, most probably always looking like
but used consistently.
Example usage: own password reset
Example usage: password reset on behalf of customer
Example usage: order comment
Example usage: order document
Example usage: order workflow
Example usage: payment workflow
The text was updated successfully, but these errors were encountered: