Basket
On this pageShowHide

Basket

HTML
<script>
  SP.init("WEBSITE_ID", function () {
    var basketValue = SP.getBasketValue();
  });
</script>

Trustisto keeps the visitor’s basket in the browser. You can read it with the methods below, e.g. to show a free delivery threshold.

Methods

  • SP.getBasket() - the products in the basket, as saved by Add To Basket, Basket Page or Save Basket. Returns [] when the basket is empty.
  • SP.getBasketSize() - the number of items in the basket (the sum of quantities)
  • SP.getBasketValue() - the basket value: the sum of sum, or price × quantity when sum is missing

The basket is cleared on the Thank You Page.

Basket changes

HTML
<script>
  SP.go('addBasketListener', function () {
    console.log('Basket value:', SP.getBasketValue());
  });
</script>

SP.addBasketListener(callback) calls callback every time a product is added, removed or the basket is saved.

It returns nothing, so it doesn’t need the callback of SP.init(): with SP.go('addBasketListener', ...) it is queued and registered as soon as the library is loaded, in order with your other queued calls. Queue it before the basket calls you want it to catch. Inside the callback of SP.init() you can call SP.addBasketListener(...) directly.