- Since it doesn't say anything about if PIM expects any feedback if all products were updated or not, the assumption is that PIM expects only 200 response and doesn't need to know if some products don't exist or were not updated
- The task is only about product update - no product create, no product delete
- No authentication/authorization towards Magento 2 ecomm or System A or System B
idis PIM system product ID and is not related to product ID in Magento 2 system, but is used as SKU in Magento 2
- It doesn't say if the System A needs only products that were updated successfully in Magento 2, the assumption is that the System A needs all data from the original PIM request regardless if products exist or were updated successfully in Magento 2
- Magento 2 ecomm doesn't need to know about the response from System A - if it was successful or not
- It doesn't say if ids needs to be only for the products that are valid and were updated in M2. The assumption is that System B needs all ids from the original PIM request
- Magento 2 ecomm doesn't need to know about the response from System B - if it was successful or not
I decided to use Magento 2 Message Queues as the main solution for the task. Due to a risk of running out of time for the response to PIM(3 sec), using an async solution i see as a better approach.
A request from PIM comes to Magento 2 ecomm to the endpoint /V1/kpim/products(it is described in Kpim_WebApi module and it uses Kpim_Integration interface).
The request's payload is described as Kpim\Integration\Api\Data\ProductInformationInterface.
The endpoint is implemented in Kpim_Pim module. After the request came to the endpoint it's payload is published into two queues:
- k.products.updated - a queue for products' ids(PIM id) that were received from PIM
- k.product.update - a queue for each product from PIM's request that needs an update in Magento 2 ecomm
The k.products.updated handler uses a service to notify System B about the latest updates.
The k.product.update handler uses services to update Magento 2 ecomm product information and to dispatch an event k_product_update_from_pim.
The observer Ksa\Update\Observer\ProductUpdateInformation listens to the event k_product_update_from_pim and publishes a message to the Magento 2 Message Queue k.system.a.product.update.
The k.system.a.product.update handler uses a service to notify System A about a product update.
The module with API declarations for the Kpim_Pim module
The module with a description of the web API for Kpim_Integration
The module implements interfaces from Kpim_Integration
- It saves all products' ids into the Magento 2 Message Queue - k.products.updated
- It saves each product from the request's payload as a separate message in the Magento 2 Message Queue - k.product.update
The module has a queue handler for the queue k.product.update.
- It updates Magento 2 product(no creation)
- It triggers a custom event - k_product_update_from_pim
The module has a queue handler for the queue k.products.updated
- It triggers a custom event - k_latest_updated_products
The module has an observer that listens to the event k_product_update_from_pim. The observer saves a message to Magento 2 Message Queue - k.system.a.product.update
It has the queue k.system.a.product.update handler. It makes the update request to the System A.
The module has an observer that listens to the event k_latest_updated_products. It updates the System B.