Platform

Ecommerce FAQ API in Go

A Go package that holds the questions a shop is asked often, and its answers. Operators write them on the admin’s FAQ screen, group them into sections they name, and drag them into order. The storefront reads the whole published set at /x/faq.

What it does

In the package’s words, every storefront has a page of these and every shop writes the same ones, “where is my order, how do I return this, what does delivery cost”, so the engine gives the answers a table, the panel a screen, and the storefront one address to read them from.

An entry is a question, an answer, a section such as “Delivery” or “Returns”, a position within that section, and a published flag. An entry with no section belongs to the ungrouped set, which the storefront shows first. A question with no answer is refused: in the module’s words, “an unanswered question helps nobody”.

GET /x/faq answers with the page’s heading, the line under it, and the published entries grouped by section, each with its id, question and answer. The storefront gets no positions or timestamps, because the order is the order the entries arrive in.

Configuration

Two settings, both optional. The heading can be set in Config or on the Plugins screen, which wins; the line under it is set on the Plugins screen only.

FAQ module settings — 2 settings, 0 required
SettingEnvironment variableRequiredWhat it does
Heading
Page heading
— No What the storefront’s page is called. “Frequently asked questions” when empty. A value in Config becomes the panel field’s default.
blurb
Line under the heading
— No A line the storefront shows under the heading. Panel only; there is no Config field for it.

The module reads its Config struct, not the environment. The variable names are the ones the package’s own example or the reference binary uses; in your own main() you choose where each value comes from. Where a setting has a panel label, the admin’s settings drawer can hold it too, and a value typed there wins over Config.

Setting it up

  1. Install the modulePass faq.New to gocommerce.New, as below, or start the reference binary with -faq. The FAQ plugin starts switched on.
  2. Write the questionsOn the FAQ screen, or POST /api/admin/x/faq with a question, an answer and a section. An entry is published unless the request says published is false.
  3. Put them in orderDrag them on the FAQ screen, which saves the whole list with PUT /api/admin/x/faq/order: every entry’s id and section, in the order they should read.
  4. Read them from the storefrontGET /x/faq answers with the heading, the line under it, and the published entries grouped by section.

main.go

import (
	"github.com/itswadesh/gocommerce/core"
	"github.com/itswadesh/gocommerce/ext/faq"
)

app, err := gocommerce.New(cfg, faq.New(faq.Config{}))

The package doc’s own example, with its imports; cfg is your gocommerce.Config. The reference binary’s -faq flag and examples/store/main.go install it the same way. Import path github.com/itswadesh/gocommerce/ext/faq.

How it works

What it does not do

Read these before an order depends on it. No store is known to run GoCommerce in production yet, so these come from the code, not from anyone’s experience.

FAQ

Questions about the FAQ module

What does the storefront get from /x/faq?

One response with heading, blurb and sections. Each section has its name and its published entries, each with an id, a question and an answer, in the order the shop arranged them within the section.

Can I hide the FAQ without deleting it?

Yes. Switch the FAQ plugin off on the Plugins screen and /x/faq answers 404; the entries stay and the FAQ screen still works. A single entry can be hidden by saving it with published off.

Can I have an FAQ in each language?

No. Entries carry no language, so the store has one FAQ. The cms module’s content pages are the ones that keep a copy per language.

Who can edit the FAQ?

An operator with faq.write, which managers hold by default; an owner holds every right. Staff hold faq.read and can see the entries but not change them. Either right can be granted to another role on the Roles screen.

Source

Everything on this page is read from ext/faq in the GoCommerce repository, MIT licensed. When this page and the code disagree, the code is right and this page is out of date.

Try it against a store of your own

The backend + admin quick start runs GoCommerce’s API and admin on your own machine, without a storefront. Add this module to it and try it on test orders before a real one depends on it.

Chat on WhatsApp