# Cross Products between related stores The purpose of this implementation is to synchronize some information for the same product (determined by SKU) between different stores. ## CMR Opportunity to buy using **CMR Program Points** On the products page of www.linio.cl, we should show a module making clear the opportunity to buy the same product using CMR points. Information such as **points** should be shown for the same product, along with a button *or link* that can redirect the customer to the same product page in the CMR store, for example https://tienda.cmrpuntos.com.cl/. To enable this data integration, we will need to change the product synchronization flow in **node-lister**. Today, each store has its own separate Redis cluster, making it impossible for a store to consult details of the same product in another store (identified by the same SKU between stores). ### Actual flow #### node-listener ```sequence node listener->rabbitmq: fetch products rabbitmq->node listener: return products needs be synced node listener->search adapters: send the product to the search adapters node listener->cache adapters: send the product to the cache adapters search adapters->algolia: update/remove the product search adapters->catalyst: update/remove the product cache adapters->redis: update/remove the product node listener->rabbitmq: ack Note left of rabbitmq: even if the process of sending product to the adapters fails, the message will be ack ``` For each synchronized product, a key is created in the store cluster, for example: `cl:product:GE872HL0E8L48LACL`. To make it possible, we will need to synchronize the product from the **CL-CMR** store to the **CL** cluster. However, we must only synchronize "chunks" of information, which for current functionality will need to be synchronized: ```json= "price": 4000, // price in points in CL-CMR store ``` #### Example > CL-CMR: https://tienda.cmrpuntos.cl/p/balanza-pesa-digital-ban-o-vidrio-180-kg-ooz4n3?qid=0bcbc140e83df82576596a89cc5d1b36&oid=GE872HL0E8L48LACL&position=1&sku=GE872HL0E8L48LACL > CL: https://www.linio.cl/p/balanza-pesa-digital-ban-o-vidrio-180-kg-vd5mi4 For this product, the **CL** store should show: ![](https://i.imgur.com/0iD5o7G.png) Plus the information that it is possible to buy the same product for **4000** points in the CL-CMR store. For this, when the **node-listener** receives an update for products from the **CL-CMR** store, a configuration must determine that the price of the product needs to be sent to the Redis of the **CL** store. Thus, when a customer visits a product page in the store https://www.linio.cl/p/balanza-pesa-digital-ban-o-vidrio-180-kg-vd5mi4 a shop-front module will search inside **CL** redis for the key `crossstore:cl-cmr:cl:GE872HL0E8L48LACL`, which will contain: ```json= { "GE872HL0E8L48LACL-5384157": { "price": 4000, }, … "updated_at": "2021-07-01 21:10:17", "is_purchasable": true, } ``` Points to consider: 1. Before sending the new key to **CL-CMR** Redis, the node-listener must "search" if the product exists on **CL** store's Redis, doing a simple search ```php= return $this->clRedis->exists('cl:product:sku'); ``` If the product exists in both stores, it means that it is a `cross-store` 2. **node-listener** must first synchronize the product normally to **CL-CMR** store Redis, after that, it will activate a **processor** that will extract the price of each **simple product**, after extracting, should be sent to the **CL** Redis. #### Product link to another store As the **SKU** of the product is the same between both stores, for this we can use the shop-front search functionality, creating the simple link: https://tienda.cmrpuntos.cl/search?scroll=&q=GE872HL0E8L48LACL This way, this link will redirect the customer to the correct page for the same product. > https://tienda.cmrpuntos.cl/search?scroll=&q=GE872HL0E8L48LACL -> https://tienda.cmrpuntos.cl/p/balanza-pesa-digital-ban-o-vidrio-180-kg-ooz4n3 Possible questions: 1. Why not simply consult the product directly on the secondary store's Redis? A: Because this architecture can considerably increase the read on Redis of `CL-CMR`, which can negatively affect performance, being necessary to increase resources such as memory/CPU. Furthermore, this would increase the amount of code and responsibility of the shop-front in extracting information from two Redis to the same product page.