Skip to content

Write a plugin

A plugin adds things to the store without touching its code: listening to what happens, changing what is calculated, putting a screen in the panel.

Terminal window
npx pcc-plugin nuevo my-plugin
cd my-plugin && npm install && npm run dev

You save a file and it reloads itself. No need to restart the store.

import { definirPlugin } from "@pcreative/plugin-contract"
export default definirPlugin({
arrancar(api, { registro }) {
api.on("pedido.creado", (pedido) => {
registro.info(`Order ${pedido.number}: ${pedido.total.amount} €`)
})
},
})

Type api.on(" and the editor shows you the available events, already typed. It is the only thing you need to know to start.

An event tells you about something that has already happened. You cannot change the result:

api.on("cliente.registrado", (cliente) => { /* welcome them */ })

A filter lets you modify something before it is used:

api.filtro("carrito.totales", (totales, carrito) => {
// e.g. a discount of your own
return totales
})

The hooks that exist today:

Events Filters
pedido.creado, pedido.cancelado carrito.totales
cliente.registrado envios.disponibles
carrito.abandonado pagos.disponibles
inventario.agotado correo.contenido
menu.principal, inicio.tarjeta

The last two are UI: they put an entry in the panel menu or a card on the home page.

Copy the plugin folder into the backend’s plugins/. It appears in Panel → Extensions.

If your plugins live somewhere else, say so with PLUGINS_DIR.

To turn one off without uninstalling it:

Terminal window
PLUGINS_DISABLED=one,another

Handy when a plugin is causing trouble and you want to keep selling while you look at it.

If your plugin declares settings, they appear by themselves in Panel → Extensions: you do not have to write the screen. Secrets are stored apart and not returned to the browser — the panel shows “a key is stored”, never the key.

The contract includes licence checking. It is verified against a public key (LICENSE_PUBLIC_KEY), and verified offline: a store that loses its internet cannot lose its plugins.

The key is public on purpose: it can only check signatures, never create them.

The contract does not depend on the internal engine

Section titled “The contract does not depend on the internal engine”

On purpose. A plugin written today should keep working if the store changes engine underneath tomorrow. That is why the events talk about pedido and carrito, not the engine’s internal entities.

  • Plugin contract README