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.
Getting started
Section titled “Getting started”npx pcc-plugin nuevo my-plugincd my-plugin && npm install && npm run devYou save a file and it reloads itself. No need to restart the store.
The whole plugin
Section titled “The whole plugin”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.
Events and filters
Section titled “Events and filters”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.
Installing it
Section titled “Installing it”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:
PLUGINS_DISABLED=one,anotherHandy when a plugin is causing trouble and you want to keep selling while you look at it.
Settings
Section titled “Settings”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.
Paid plugins
Section titled “Paid plugins”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.
See also
Section titled “See also”Plugin contract README