An asynchronous cart object, that works when the ERP is offline, by storing transactions
that add or remove product quantities from the cart in local storage, and sending them
to the ERP when it becomes offline, using the /cart/v2/sync
endpoint.
Changes to the cart are notified to consumer (such as UI components) via an observer parttern.
/!\ this is WIP - TODO:
- check that the cart uuid we have in local storage matches the cart uuid we got from the erp, to avoid applying transactions on the wrong cart in the client - I think we should discard the local storage if the cart uuid differs from the one we got from the erp
npm i shopinvader-js-cart
You first need an ErpFetch
object from
shopinvader-js, which encapsulate the
ERP authentication mechanism.
You then create a cart object:
const cart = Cart(
erpFetch,
new WebStorageCartStorage(window.localStorage)
);
cart.registerObjserver(observer);
cart.addTransaction(new CartTransaction(productId, qty));
cartData = cart.getData();
// cartData.hasPendingTransactions indicates that transactions are pending synchronization
// cartData.syncError indicates that there was an error syncing the cart with the ERP
To scan the project for linting and formatting errors, run
npm run lint
To automatically fix linting and formatting errors, run
npm run format
To execute a single test run:
npm run test
To run the tests in interactive watch mode run:
npm run test:watch
For most of the tools, the configuration is in the package.json
to reduce the amount of files in your project.
If you customize the configuration a lot, you can consider moving them to individual files.
npm start
To run a local development server that serves the basic demo located in demo/index.html
This works best when the demo backend server is running. To do this:
cd demo
python3 -m venv .venv
source .venv/bin/activate
python3 -m pip install requirements.txt.in
python3 demoserver.py
- Laurent Mignon laurent.mignon@acsone.eu
- Stéphane Bidoul stephane.bidoul@acsone.eu