Receiving recommendation from Python to Shopify store

mlbrains
Tourist
5 0 0

We have setup webhooks on our Shopify store. The process we have automated is as follows:

1. We have a store where end-customer can select product and add to cart

2. End-customer selects a product and adds to the cart
3. A webhook event with cart-creation is triggered to our external URL
3. In the external URL, we have a Python based flask engine running. This engine receives the webhook with the product data
4. Based on the product selected, we process and create a list of recommendation products. Example, if end customer selects shoe and adds to the cart, the Python based engine recommends socks.  

Question:
• How can we send the list of recommended products back to the shopify shop?  
• How can this list of recommended products be displayed to the end-customer?

 

Replies 3 (3)

BStubbs
Shopify Partner
136 16 62

You'll need some javascript in the shop to display the recommended products. 

Have a look at the App Proxy for displaying data on the site. https://shopify.dev/tutorials/display-data-on-an-online-store-with-an-application-proxy-app-extensio...

You could have a flask endpoint that is requested by some javascript through the app proxy that would return the list of recommended products.

Was this helpful? Press like!
Did it fix the problem? Mark it as the solution for others!
Buy me a beer? Well, sure!
mlbrains
Tourist
5 0 0

Can you share more links for creating the Javascript files. 

Also, going back to the original question, do you know how to send data from Python to a particular JSON file in Shopify? We can use this JSON file to display the recommendation to the user. Refer screen shot below. 

Screenshot 2021-02-05 114606.png

BStubbs
Shopify Partner
136 16 62

I'm not sure how you would go about identifying the session that needs the recommended products. If you have a very small number of products and no dynamic mapping then the json idea might work. 

Consider this: If you have two customers viewing the shop at one time, and one of them puts a pair of shoes in the cart, they should be shown a recommended product of socks. But if customer number 2 is viewing the shop and puts a shovel in their cart, they will need to be shown a different recommended product, like a bucket. If you want to load all of these items into your json file, that might work, but its going to be a very large file eventually, which will ultimately slow down the shop <- not good!

For the Javascript, I find the Fetch API to be the easiest one to implement and use. It will allow you to make a request back to your python app to get data to then display on the page.

https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API

 

 

Was this helpful? Press like!
Did it fix the problem? Mark it as the solution for others!
Buy me a beer? Well, sure!