Marketing

Ecommerce wishlist in Go

A Go package for what shoppers wanted and did not buy yet. A list is kept by a token the storefront holds, the way a cart is, so a guest can save a product before there is an account. The shop’s side ranks products by how many lists hold them and shows which of those are out of stock. Nothing is required.

What it does

In the package’s own words, a wishlist is “what shoppers wanted and did not buy yet.” The storefront creates a list with POST /x/wishlist, which answers with its token, and then adds and removes products under /x/wishlist/{token}. Each item comes back with the product’s title, slug, SKU, price and how many the store could sell this minute.

The price and the stock come from the variant an item names, or from the product’s cheapest active variant when it names none, which is what a product card shows. Saving the same thing twice is not an error and not a second row. A list can carry an email when the shopper gives one, so the shop can write to the people waiting for a restock.

The package calls the shop’s side “the more interesting half”. The Wishlists screen ranks products by how many lists hold them, with how many of those lists gave an email, and can show only the ones out of stock: “a demand signal no other screen in the panel carries.”

Configuration

Nothing is required. One Go setting bounds a list; the Plugins screen holds the page heading and whether the storefront asks for an email.

Wishlist module settings — 3 settings, 0 required
SettingEnvironment variableRequiredWhat it does
MaxItems — No How many products one list may hold: 200 when zero. A list at the limit refuses another product with 409. Go only.
heading
Page heading
— No The wishlist page’s heading, “Your wishlist” by default. Public. Panel only; there is no Config field for it.
collect_email
Ask for an email on the wishlist page
— No The panel’s hint: so the shop can write when something wished for comes back in stock. Public, for the storefront to read; the module accepts an email whichever way it is set. Panel only.

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 wishlist.New to gocommerce.New, as below, or start the reference binary with -wishlist. It adds two tables, and the plugin starts switched on.
  2. Keep the tokenPOST /x/wishlist, with an email or with no body at all, answers with the new list and its token. The storefront stores the token as it does a cart’s; it is the only key to that list.
  3. Save and showPOST /x/wishlist/{token}/items with a product_id, and a variant_id if the shopper chose one. GET /x/wishlist/{token} draws the page, stock included.
  4. Read the demandThe Wishlists screen, or GET /api/admin/x/wishlist/wanted?out_of_stock=1, lists the most-wanted products the store cannot sell right now.

main.go

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

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

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

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

Does a shopper need an account?

No. A list is created with POST /x/wishlist and kept by the token it returns, the way a cart is, so a guest can save products. The module has no link to customer accounts.

Does it email shoppers when something is back in stock?

No. It keeps the emails shoppers give and counts, for each product, how many lists with an email hold it. Sending the notice is left to something else.

What happens when a list is full?

The next save answers 409, “a wishlist holds at most 200 products”. MaxItems in Config changes the number.

Who can see what shoppers saved?

An operator with wishlists.read, which managers and staff hold by default. Switching the plugin off closes the storefront routes only; the Wishlists screen keeps working.

Source

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