Basics of saving and retrieving data

4 0 1

So I am trying to build something for my store but a few basic things are somewhat unclear.

  1. If I need to save some user settings do I need my own backend just for that app specifically? For simplicity sake, I want build an app to save and display a custom message in cart-template.liquid. To achieve that, my app should make a request to my backend (lets say, on heroku) and save it in some db that app is using.

  2. How do I retrieve that data in cart-template.liquid? I guess I build a snippet that calls a public endpoint of my backend that returns that saved message using fetch() or maybe axios.get and embed it using {% render 'fetch-custom-message-snippet' %} ?

  3. Say I ask for user input, ie. "Engraved message" and the form is in cart-template.liquid, of course. The following snippet is used:

    <p class="line-item-property__field">
      <label for="engraved-message">Engraved message</label>
      <input id="engraved-message" type="text" name="properties[Engraved message]">

    How do I make sure that bit of information is captured and passed to me? I guess I want to see it somewhere in the order details.

51 11 15

Hey mate, 

you don't have to spin up a DB for this if you don't want to. 
you can utilise shopify's metafields. Setting the metafield for the customer in your backend, and retreiving it on the front end (using liquid)

if this is a basic message, you can get your backend to write the message to the customer's shopify account as a metafield. 
then on your frontend you can use the customer object 

{{ customer.metafields.YOURMETAFIELDHERE }}

if the customer is logged in it'll show the message.  

4 0 1

Well, it was just an example, it has to be more complex than just a message. I pretty much figured it out but I am not sure if there are any good practises of actually calling 3rd party services. For instance, I need to call this endpoint - how would you go about doing it?