Platform

Storefront banners in Go

A Go package that keeps the pictures on a storefront’s home page as rows, one per picture: slides across the top, and grids of tiles under a heading. Each is a picture, an optional phone picture, a title that is also its alternative text, and a link. The storefront reads them at /x/banners?page=home, already split into slides and grids.

What it does

In the package’s own words, banners are “the pictures a shop puts on its storefront’s pages: slides across the top of a page, and grids of tiles under a heading, each a picture and a link.” They are kept as rows, one per picture, so a shop adds, reorders and switches off one banner without rewriting a page.

A banner has a placement, slide or grid, and a grid tile has a heading: tiles with the same heading on a page form one grid. The picture is wide enough for a desktop; an optional narrower crop is for phones, and without one the wide picture is used there too. The order is the shop’s own and runs across the whole page.

Each banner names its page, so other pages can follow, but only the home page is accepted until a storefront shows banners anywhere else. A store that starts with the sample shop gets three slides and a Shop by collection grid, made from the sample shop’s photographs.

Configuration

There is nothing to set in Go: Config is an empty struct, there so a setting can arrive without changing how the module is installed. Banners are rows an operator edits on the admin’s Content › Banners screen or through the API.

Banners module settings — 1 setting, 0 required
SettingEnvironment variableRequiredWhat it does
banners
Banners, on the Plugins screen
— No The plugin’s switch, on by default. Off, GET /x/banners answers 404 while the Banners screen and its admin routes keep working, so banners can be prepared before they show.

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 banners.New to gocommerce.New, as below, or start the reference binary with -banners. It adds one table.
  2. Add the picturesOn Content › Banners, add a slide or a grid tile: a picture chosen from Files or typed in as a link, an optional phone picture, a title and a link such as /collections/new-in.
  3. Put them in orderMove banners with the arrows on the screen. The page’s whole order is saved at once, with PUT /api/admin/x/banners/order.
  4. Render themThe storefront reads GET /x/banners?page=home and gets slides and grids, each grid with its heading and its tiles in order. Only switched-on banners are served.

main.go

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

app, err := gocommerce.New(cfg,
	// Config has nothing to set yet.
	banners.New(banners.Config{}),
)

The package doc has no example of its own; this is how the reference binary’s -banners flag installs it. cfg is your gocommerce.Config. Import path github.com/itswadesh/gocommerce/ext/banners.

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 Banners module

What does the storefront read?

GET /x/banners?page=home on the host that serves your GoCommerce API. It answers the page name, a list of slides and a list of grids, each grid with its heading and tiles, already in the shop’s order.

Can a banner show on a collection page?

No. Only the home page is accepted, because no storefront shows banners anywhere else yet.

Can I schedule a banner?

No. A banner has an on and off switch and no dates. Switch it on when it should show, and off afterwards.

What size should the pictures be?

The module does not say or check. It takes a wide picture for desktops and an optional narrower one for phones; without the phone picture the wide one is used on phones too.

Source

Everything on this page is read from ext/banners 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