@flyeralarmdigital/fad-cart

FlyerAlarm Digital Cart

Usage no npm install needed!

<script type="module">
  import flyeralarmdigitalFadCart from 'https://cdn.skypack.dev/@flyeralarmdigital/fad-cart';
</script>

README

FlyerAlarm @Digital

Npm Cart Package

Cart is a FlyerAlarm Future Labs product. This package will allow your NodeJS, ReactJS, Angular or Java based systesm to communicate with our Cart systems.

You are required to have a registered application and a valid API Client Key to use our systems. For more information, please contact use at info@flyeralarm.digital.

Features

  • Session cart
  • User cart
  • Fully calculated carts
  • Cart auto merging

This NPM will require the @flyeralarmdigital/fad-authentication package to function. A user must be authenticated in our system and registerd as the valid cart owner to be abel to add or edit cart items.

Session Cart

A user may add, remove, edit a view a cart even if they are not logged in. This cart is owned by the session_id. A valid session_is is set by the @flyeralarmdigital/fad-authentication package as a session cookie. In the event that a cookie does not exist, you may manually set a Cookie or 'session' and then some random string to function as your session_id. If a user leaves your site then they may risk loosing their cart as a new session would be created per visit.

User Cart

Once a user is logged in, a user cart is now in affect. A user can only have one user cart. If they previously had been shopping as a guest and had items in their session cart, then those items will be merged to the user cart upon requesting the user cart. Then that session cart would be destroyed.

Cart calculations

Your cart items should have a price. When they have a price, then the cart will auto calculate the subtotal, total, tax and taxrate based on your registered firm and or software locale. Ever CRUD operation will return a full cart object which also includes the resutls of this calculation.

Methods

Get a cart

Method:

getCart({API})

Requires: no parameters, but will get the user from @flyeralarmdigital/fad-authentication .user() method & will get the session id from the cookie

Add item to cart

Method

addItem({
            item,  //The actual item to add
            price, // (INT) The subtotal/net price of item
            product_id, //Your item MUST have a product_id
            quantity, // (INT) default is 1
            toast, //Bool - activates a toast message on response
            toast_text, 
            API // api overide
        })

Requires: item{...price: INTEGER} an item{} Object to be added to the cart. This object will be added to cart.items[] and will result is a return of a calculated cart object. An item must include a price key and this must be an integer value. For example if your item will cost € 99, then you must submit 9900 as the price value.

toast(optional, default true) Once an item is successfully added, a Toast will show, provding feedback to your UI. This may be disabled with toast = false.

toast_text(optional, default: 'Item has been added to your cart.') The toast will have a text involved to be shown to your UI. You may change that text by submitting a toast_text string.

Returns: fully calculated cart.

Remove item from cart

Method

removeItem({
        item_id, // This UUID of the item in the cart
        toast, // Bool
        toast_text, 
        API // Api override
    })

Requires: item_id. The user must also possess the cart session id and or the user token, meaning this user which is removing, adding, editing cart items must be the owner of the cart.

toast(optional, default true) Once an item is successfully added, a Toast will show, provding feedback to your UI. This may be disabled with toast = false.

toast_text(optional, default: 'Item has been added to your cart.') The toast will have a text involved to be shown to your UI. You may change that text by submitting a toast_text string.

Returns: fully calculated cart.

Duplicate cart item

Method

duplicateItem({
        target_item_id, 
        toast, 
        toast_text, 
        API
    })

Requires: item_id. The user must also possess the cart session id and or the user token, meaning this user which is removing, adding, editing cart items must be the owner of the cart.

toast(optional, default true) Once an item is successfully added, a Toast will show, provding feedback to your UI. This may be disabled with toast = false.

toast_text(optional, default: 'Item has been added to your cart.') The toast will have a text involved to be shown to your UI. You may change that text by submitting a toast_text string.

Returns: fully calculated cart.

Sample item

ITEM{}

Sample return

CART{}

Empty a user cart

Method

clearCart()

Clearing a User cart will require only the user.access_token which is automatically obtained from the Auth package. The user cart is retrieved and then the items[] is cleared. This effectively empties a User cart.