# Hugo data driven ecommerce

**URL:** <https://discourse.gohugo.io/t/hugo-data-driven-ecommerce/24565>\
**Category:** support\
**Created:** [April 8, 2020, 10:17pm UTC](https://discourse.gohugo.io/t/hugo-data-driven-ecommerce/24565 "2020-04-08T22:17:34Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![rwslippey](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/rwslippey/32/11080_2.png) [@rwslippey](https://discourse.gohugo.io/u/rwslippey)\
**Post date:** [April 8, 2020, 10:17pm UTC](https://discourse.gohugo.io/t/hugo-data-driven-ecommerce/24565/1 "2020-04-08T22:17:34Z")

</div>

I’m a little confused on specifics of using hugo with snipcart. I’m working on building out an ecommerce site for a client and I’m really looking to Hugo as I like many of it’s features and the entire concept of not having to deal with a database or cms, etc. Got some experience in static site generators but this would be only my second go with hugo.

Anyway, looking at this from snipcart [https://snipcart.com/blog/hugo-tutorial-static-site-ecommerce](https://snipcart.com/blog/hugo-tutorial-static-site-ecommerce) I’m seeing that they’re adding product details to a single json file. However looking at other themes and reading here I’m seeing that pages can’t be created based on data. In all honesty, I didn’t try that tutorial as I’m still just researching.

So my question is, can a json file be utilized with a layout to build many pages for products. Or should I be creating a page per product in the content directory. As an aside, anybody write a CSV to yaml toml or json script yet?

Next question is, am I barking up the wrong tree with trying to use Hugo for a larger ecommerce site with many products, categories, manufacturers, etc. The site is for a distributor of large equipment so freight shipping in snipcart or whatever backend we use will also be an issue.

thanks for any thoughts or comments…

---

<div class="post-metadata">

**Author:** ![maiki](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/maiki/32/16384_2.png) [@maiki](https://discourse.gohugo.io/u/maiki)\
**Post date:** [April 9, 2020, 12:01am UTC](https://discourse.gohugo.io/t/hugo-data-driven-ecommerce/24565/2 "2020-04-09T00:01:46Z")

</div>

Ask snipcart. Your questions are answered on their end, they know how to use Hugo for their product.

---

<div class="post-metadata">

**Author:** ![rwslippey](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/rwslippey/32/11080_2.png) [@rwslippey](https://discourse.gohugo.io/u/rwslippey)\
**Post date:** [April 9, 2020, 12:03am UTC](https://discourse.gohugo.io/t/hugo-data-driven-ecommerce/24565/3 "2020-04-09T00:03:44Z")

</div>

Thanks for the reply… my question really is more geared towards Hugo though. Specifically how to create product pages in mass. Individual content pages vs data driven. But I will give them a shot

thanks

---

<div class="post-metadata">

**Author:** ![alexandros](https://avatars.discourse-cdn.com/v4/letter/a/ecc23a/32.png) [@alexandros](https://discourse.gohugo.io/u/alexandros)\
**Post date:** [April 9, 2020, 12:10am UTC](https://discourse.gohugo.io/t/hugo-data-driven-ecommerce/24565/4 "2020-04-09T00:10:11Z")

</div>

Currently as you’ve seen Hugo does NOT support the automatic generation of pages from data.

This is the most anticipated feature at the moment and you may want to track:

> <https://github.com/gohugoio/hugo/issues/5074>
>
> Currently Hugo handles internal and external data source with getJSON/getCSV whi…ch is great for using data source in a template.
> 
> But Hugo cannot, using a data set of items, build a page for each of them plus related list pages like it does from the content directory files.
> 
> Here is a fresh start on specing this important step in the roadmap.
> 
> As a user, I can only see the configuration aspect of the task.
> 
> I don’t see many configuration tied issues except for the mapping of the key/values collected from the data source and the obvious external or internal endpoint of the data set. The following are suggestions regarding how those configurations could be managed by the users followed by a code block example.
> 
> \### Endpoint/URL/Local file
> 
> Depending on use cases there may be a need of one or several url/path. 
> 
> For many projects, not every page types (post, page etc…) may be built from the same source. Type could be defined from a data source key or as a source parameter.
> 
> I suppose there could be other parameters per sources.
> 
> \### Front Matter mapping
> User must be able to map the keys from the data source to Hugo’s commonly used Front Matter Variables (title, permalink, slug, taxonomies, etc…). 
> Every keys not referenced in the map configuration could be stored as is a user-define Front Matter available in the \`.Params\` object but this should not be default as there maybe way too many.
> 
> \### Example:
> 
> This is a realtor agency, a branch of a bigger one. 
> 
> Their pages are built with hugo's local markdown
> 
> They have an old wordpress site whose \> 100 blog posts they did not want to convert to markdown. So they load those blog posts from a local data file on top of the local Hugo's own markdown posts.
> 
> They use a tier service to create job posts when they need to fill a new position. They want to hosts those job listing on their site though. Their jobs are served by \`https://ourjobs.com/api/client/george-and-son/jobs.json\`
> 
> The most important part of the website are their realty listings. They add their listing to their mother company's own website whose API in turn serves those at \`https://api.mtl-realtors/listings/?branch=george-and-son&status=available\`
> 
> \#### Configuration
> \`\`\`yaml
> title: George and Son (A MTL Realtors Agency)
> 
> dataSources:
> - source: data/old\_site\_posts.json
> contentPath: blog
> mapping: 
> Title: post\_title
> Date: post\_date
> Type: post\_type
> Content: post\_content
> Params.location.city: post\_meta.city
> Params.location.country: post\_meta.country
> 
> - source: https://ourjobs.com/api/client/george-and-son/jobs.json
> contentPath: jobs
> mapping: 
> Title: job\_label
> Content: job\_description
> 
> - source: https://api.mtl-realtors/listings/?branch=george-and-son&status=available
> contentPath: listings/:Type/
> grabAllFrontMatter: true
> mapping: 
> Type: amenity\_kind
> Title: name
> Content: description
> Params.neighbourhood: geo.neighbour
> Params.city: geo.city
> \`\`\`
> 
> \#### Content structure
> This results in a content "shadow" structure. Hard lines dir/files are local, while dashed ones are remote.
> 
> \`\`\`
> content
> ├── \_index.md
> ├── about.md
> ├── contact.md
> ├── blog
> │ ├─── happy-halloween.md
> │ ├─── merry-christmas.md
> │ ├- - nice-summer
> │ └- - hello-world
> ├- -listings
> │ ├- - appartment
> │ │ ├- - opportunity-studio
> │ │ ├- - mile-end-condo
> │ │ └- - downtown-tower-1
> │ └- - house
> │ └- - cottage-green
> └- - jobs
> ├- - marketing-director
> └- - accountant-internship
> \`\`\`

> <https://github.com/gohugoio/hugo/issues/6310>
>
> There are existing issues about this, but I prefer to start fresh when I have ne…w ideas on a subject. I thought about this again when having my hair washed at the hairdresser today. Maybe the hair massage helped.
> 
> I think I have been too hung up in the technical challenges of this (remote adapters, how to effectively do partial updates etc.), making the whole issue too big to start with. What we have talked about earlier have also been "\_something different on the side of what we already have\_".
> 
> But what we have is:
> 
> \* A virtual \`/content\` directory that can be composed via Hugo Modules (with overrides on file level)
> \* Virtual mounts support (you can mount any directory or file, even from remote GitHub repos into \`/content\`)
> \* A front matter based metadata model with cascade keyword etc.
> \* Partial server updates based on filesystem events.
> \* ...
> 
> With that I mind, I thought about adding a new reserved filename in \`/content\` starting with \`\_content\`.
> 
> Given the example below:
> 
> \* \`\_content.json\`, \`\_content.toml\` (and YAML) would be fairly straight forward, i.e. metadata + content. We should probably support a tree structure somehow, so you can build a complete content structure from one root \`\_content\`file. We should probably support multiple files per directory so you could do \`\_content\_products.json\` etc.
> \* \`\_content.go\` would represent the dynamic content, some kind of content adapter, possibly remote. This is obviously the area with most open questions (\`\_content.js\` would be a thought), but having the naming in place is a start. 
> 
> \`\`\`bash
> content
> ├── \_content.json
> ├── \_index.md
> ├── blog
> │   ├── \_content.toml
> │   ├── \_index.md
> │   ├── image.png
> │   └── post1.md
> └── docs
> ├── \_content.go
> └── \_index.md
> \`\`\`
> 
> /cc @regisphilibert @onedrawingperday @digitalcraftsman @budparr @moorereason @kaushalmodi and gang.

However there is a workaround mentioned here: [JSON as data for websites - #4 by alexandros](https://discourse.gohugo.io/t/json-as-data-for-websites/24382/4)

The linked technique can be automated even further by generating a [Custom Output Format](https://gohugo.io/templates/output-formats#readout) to create the CLI commands for the pages’ generation and then execute it as part of the website build.

With the above said:

> [@rwslippey](#):
>
> Next question is, am I barking up the wrong tree with trying to use Hugo for a larger ecommerce site with many products, categories, manufacturers, etc. The site is for a distributor of large equipment so freight shipping in snipcart or whatever backend we use will also be an issue.

It all depends on the complexity of the ecommerce site. [Someone else](https://medium.com/@rferrazz/serverless-e-commerce-lessons-learned-608b90cbdc39) made a Hugo ecommerce site by using Stripe as the backend because they found Snipcart to be expensive.

One can easily create a Google Merchant XML Feed per product with Hugo and populate a Stripe backend or even a Facebook Product Catalogue or whatever…

I am in the process of doing all of the above myself. I still have a few blanks that I need to work out like connecting Stripe payments with a JS cart for the Hugo site… but we’ll see…

There is no tutorial out there about creating a Hugo ecommerce website step-by-step.  
We have to figure it out ourselves…

---

<div class="post-metadata">

**Author:** ![rwslippey](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/rwslippey/32/11080_2.png) [@rwslippey](https://discourse.gohugo.io/u/rwslippey)\
**Post date:** [April 9, 2020, 12:35am UTC](https://discourse.gohugo.io/t/hugo-data-driven-ecommerce/24565/5 "2020-04-09T00:35:59Z")

</div>

Thanks for the reply… I guess where I’m struggling to understand is more of the technical aspects as to why it isn’t possible. I saw/read something where a json file was used to generate content on a page so maybe that’s my disconnect, oh well. I’ll take your word for it as you’re obviously more experienced than I.

Looking at your solution is intriguing and I’ll be sure to dig into it more. I did notice that some of the ecommerce themes I found are using files in the content directory for each product, so with that I think that might be route I go. As an alternative to formatting all this I could probably just whip up a quick python script to convert my CSV data to a new file for each product.

It’s good to know that merchant feeds are possible with Hugo. Honestly the thought hadn’t grossed my mind.

I’m probably a bit confused on the issue with snipcarts pricing though. $10 a month doesn’t seem that unreasonable to me. Sure a percentage would be nice at the low end and a percentage at the high end is not so easy to swallow. I guess it depends on perspective.

Getting into the complexity of the site, I expect a substantial number of products, 100s definitely, thousands, probably not. As far as complexity, we’re probably looking at a 4 or 5 manufactures and a few categories at most. Later I’ll probably want to add filtering (if it’s even possible, if not I could write a page) that targets specific industry uses. Products rarely change, we don’t track inventory on hand at our level as the manufacturers just don’t have this capability yet. The client is sort of the middleman and acts as a retailer/distributor to the end business.

I didn’t expect a tutorial and look forward to a challenge. It’s good to finally be on the cutting edge, feel like I’ve been a day late and a dollar sure my entire life 😆

Good luck with your project as well, I’d be interested to hear how it works out for you.

---

<div class="post-metadata">

**Author:** ![rwslippey](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/rwslippey/32/11080_2.png) [@rwslippey](https://discourse.gohugo.io/u/rwslippey)\
**Post date:** [April 9, 2020, 12:38am UTC](https://discourse.gohugo.io/t/hugo-data-driven-ecommerce/24565/6 "2020-04-09T00:38:04Z")

</div>

And it all just clicked for why snipcarts tutorial worked and I didn’t make the connection… They’re demo is a single page…

Now it makes sense…

---

<div class="post-metadata">

**Author:** ![alexandros](https://avatars.discourse-cdn.com/v4/letter/a/ecc23a/32.png) [@alexandros](https://discourse.gohugo.io/u/alexandros)\
**Post date:** [April 9, 2020, 7:22am UTC](https://discourse.gohugo.io/t/hugo-data-driven-ecommerce/24565/7 "2020-04-09T07:22:42Z")

</div>

> [@rwslippey](#):
>
> I’m probably a bit confused on the issue with snipcarts pricing though. $10 a month doesn’t seem that unreasonable to me

They also charge 2% on sales. Add up the payment gateway fees and you will be having a missing chunk of around 6% per product along with the 10$ monthly fee.

Current JamStack JS cart solutions have a heavy overhead for small businesses.

The Python Script sounds good.

More or less that is the spirit. Think of Hugo as a storefront. You can enter product details in a CSV and output it to Markdown files.

The Google Product Feed that can be outputted with Hugo will be the means to populate the database of a remote dynamic backend.

Then you need some kind of a JS cart in the Hugo storefront that sends a POST request with the product’s SKU to the backend.

That is more or less the way to use Hugo as a cheap storefront.

If one thinks about the costs involved running a Shopify or Squarespace shop there can be vast savings.

The catch is that currently there are NO real e-commerce themes for Hugo.

The ones listed in the Hugo Themes directory are pretty limited in their scope and rely on Snipcart.

So one needs to do the heavy lifting by themselves.

---

<div class="post-metadata">

**Author:** ![alexandros](https://avatars.discourse-cdn.com/v4/letter/a/ecc23a/32.png) [@alexandros](https://discourse.gohugo.io/u/alexandros)\
**Post date:** [April 9, 2020, 7:59am UTC](https://discourse.gohugo.io/t/hugo-data-driven-ecommerce/24565/8 "2020-04-09T07:59:37Z")

</div>

Also [here](https://discourse.gohugo.io/t/work-around-for-making-pages-from-data/13964/15) is a variation of the technique, that I linked to above, that creates pages from a CSV with the Hugo CLI.

---

<div class="post-metadata">

**Author:** ![rwslippey](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/rwslippey/32/11080_2.png) [@rwslippey](https://discourse.gohugo.io/u/rwslippey)\
**Post date:** [April 21, 2020, 5:06pm UTC](https://discourse.gohugo.io/t/hugo-data-driven-ecommerce/24565/11 "2020-04-21T17:06:40Z")

</div>

Thanks for the reply again. Got tied up with the honey do list this weekend.

I must have misunderstood SnipCart’s pricing. I thought it was 2% unless under $500 then $10 a month only. Still the percentage is kind of a kick in the pants when it doesn’t include processing.

I’m looking into maybe how we can do this with stripe. Bonus points if we can do stripe with ACH but thats for some more playing.

On another note… is it possible to use data to fill in certain info about a product, or does this fall into the realm of what we’re still waiting for. I’ve got so much reading to do to catch up on where everything is at but I’d be perfectly okay with content files, but I think it’d be cool to be able to pull pricing in from a json file or other config file, having it all in once place would be nice.

I did manage to write a pretty dirty script to create all of the content files for about 800 products. Worked pretty well, it’s probably not useful to anyone else as it’s very specific to this manufacturer.

---

<div class="post-metadata">

**Author:** ![angel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/angel/32/6325_2.png) [@angel](https://discourse.gohugo.io/u/angel)\
**Post date:** [April 21, 2020, 5:41pm UTC](https://discourse.gohugo.io/t/hugo-data-driven-ecommerce/24565/12 "2020-04-21T17:41:26Z")

</div>

You can use getJSON to pull in the data or you could use a data fir that’s pulled in (e.g gulp)

---

<div class="post-metadata">

**Author:** ![alexandros](https://avatars.discourse-cdn.com/v4/letter/a/ecc23a/32.png) [@alexandros](https://discourse.gohugo.io/u/alexandros)\
**Post date:** [April 21, 2020, 6:22pm UTC](https://discourse.gohugo.io/t/hugo-data-driven-ecommerce/24565/13 "2020-04-21T18:22:13Z")

</div>

> [@rwslippey](#):
>
> I’m looking into maybe how we can do this with stripe.

See: [Tutorial: Netlify + Stripe serverless eCommerce on the JAMstack - #2 by divinerites](https://discourse.gohugo.io/t/tutorial-netlify-stripe-serverless-ecommerce-on-the-jamstack/24822/2)
