How to add Shopify cart to Hugo Ecommerce site - shopify

I have created a Static e-commerce site using Hugo.
Hugo ecommerce site
want to add products thro' Shopify admin, and get it reflected on my site.
I'm quite familiar with liquid templating. Kindly let me know how to achieve this?
So far,
I have created a Shopify store, added a theme and added one product.
I'm not looking to customize an existing theme, but completely remove that theme add my website theme in it.

You should be able to get your products using the Shopify API. This endpoint could be the one for you. From Hugo, you can then retrieve the products by getJson function with telling it the Shopify authorization header X-Shopify-Access-Token. Like this:
{{ $data := getJSON "https://your-store.myshopify.com/admin/api/2022-01/products.json" (dict "X-Shopify-Access-Token" "your-token") }}
{{ range $data }}
{{ . }}
{{ end }}
Just make sure that you've replaced both the your-store and your-token strings.

Related

Is there any way to add metafields data on the homepage of shopify site?

I want to show some content on the homepage of my shopify site, the content is added in metafields created for pages. Is there any way to add metafields data on the homepage of shopify site?
You can access metafields of a page resource like this:
{{ page.metafields.namespace.key }}
If you are on another page (e.g. the homepage) you need to request the page object first in order to access its metafields:
{{ pages['page-handle'].metafields.namespace.key }}
Note: Make sure to replace page-handle with the handle of your page.

How to Include Snippet from App in Shopify Liquid

What I am trying to do:
I am trying to create an app that inserts content to the merchant's product page.
It appears that an app extension into the merchant's Online Store is the most effective way to do this (see https://shopify.dev/docs/app-extensions/extension-areas#online-store/).
In order to display the content, I am trying to use either a snippet or a section. However, I cannot get either of them to work properly.
I have taken these steps for the snippet:
I have enabled Online store as an extension area within my app (see https://shopify.dev/tutorials/add-a-new-app-extension)
With the Online store extension enabled, I have created a new snippet and a new section with very basic liquid code <h2>{{ product.title }}</h2>
I have enabled my app into a test store on my Shopify Partner account
I have added the {% render 'shopify://apps/etc... %} code into the correct position within the product page
Problem:
The content is not rendered
I have even tried this with the Sections Compatible version of the Debut template (see https://shopify.dev/tutorials/develop-theme-get-started-with-online-store-design-experience). Still nothing.
Is someone able to point me in the right direction here?

Shopify get published or unpublished state from Liquid

Is there a method in Liquid that can tell me if a theme is the store's live theme or if it's unpublished?
I am wondering is something like {{ theme.role }} is possible (I know that this particular one was deprecated) and then I would get published or unpublished in return.
{{ theme.role }} - it's available for now, but not documented as far as I see. It returns:
main - for published theme
unpublished

Shopify Liquid - Can You Get a Specific Page's Metafields On A Product Page?

I have a product page in my store. All my products have an associated vendor. For each vendor, I have a custom Shopify page and on this page is attached several metafields. Metafields include things like the vendor (company) country, year founded, etc...
On my product page, I would like to show the above info about the vendor. I can get to the metafields for the vendor if I was on the custom vendor page by using something like:
{% assign vendor_country = page.metafields.mynamespace.country %}
Is there anyway to get the same metafield info if I was on a product page? In this case, the context of the Liquid page variable would not be correct by default. I need a way to set this context based on the product.vendor variable and then request the custom vendor page data.
This is possible if you know the page handle. To do so you will have to make use of pages global object. So just get a page by handle and then call the metafields.
Example Code in Product template
{{ pages['page-handle'].metafields.namespace.fieldName }}
Global Pages Object

Shopify shortcode for product page

I'm trying to display my only product's salespage on homepage through a shortcode.
I downloaded plugin from github and installed shortcode.liquid and shortcode-render.liquid.
I uploaded shortcode-youtube.liquid example.
I activated shortcode functionality by changing liquid tag from
{{ page.content }}
to
{% include 'shortcode' load: page.content %}
I used shortcode [youtube] on a test page and it works fine! It displays video on a homepage through a shortcode.
Question: How do I do the same for a products sales page?
I know I need to create shortcode-product.liquid file but what code do I put inside it?
Cheers for help,
Rafal