1.0.2 ā€¢ Published 8 months ago

cartmanagerjs v1.0.2

Weekly downloads
-
License
ISC
Repository
github
Last release
8 months ago

Shopify Cart Manager JS

A mini Cart Management Vanilla Javascript Library made for Shopify developers with No Dependency + Jquery. The idea was initally mapped with CartJS.Org ,to make a cartjs library without Jquery and add-on Improvmenets

Features

  • Zero Dependency Shopify Javascript library for cart management.
  • No requirement for jQuery.
  • Methods like AddCartitem,updatecartitem,getCart,clearCart avaiable similar to CartJS.
  • PatchCart Method added : Add products if it doesn't exist to cart or Update the cart qty.
  • Small size.
  • Returns Updated CartData with each request.
  • Custom properties supported.
  • Update/ Add product to cart Based upon variatnID / cart line item KEY

Getting started

npm i cartmanagerjs

Example usage:

const cartManager = new CartManager();

šŸ‘€ Get cart items
cartManager.getCart().then(cartData => {
   console.log('Cart Data:', cartData);
 });

šŸ‘€ Add item to cart
cartManager.addItem('123456789', 2).then(cartData => {
   console.log('Added to Cart:', cartData);
    });

šŸ‘€ Add item to cart with custom line item properties
 const customProperties = {
   color: 'Red',
   size: 'Large',
   customField: 'Value',
 };

 cartManager.addItem('123456789', 2, customProperties).then(cartData => {
   console.log('Added to Cart with Custom Properties:', cartData);
 });

šŸ‘€ Remove item from cart
cartManager.removeItem('123456789').then(cartData => {
   console.log('Removed from Cart:', cartData);
 });

šŸ‘€ Update item quantity in cart
 cartManager.updateItem('123456789', 3).then(cartData => {
   console.log('Updated Cart:', cartData);
 });


šŸ‘€ Fetch the cart
cartManager.fetchCart().then(() => {
   Update a cart item by key
    cartManager.updateItem('your_item_key_here', 2, { custom_property: 'new_value' });

   // Or update a cart item by variantId
   cartManager.updateItem('your_variant_id_here', 3, { custom_property: 'another_value' });
 });

šŸ‘€  Patch the CartItem
cartManager.patchCartItem('your-identifier', 'your-variant-id', 2, { customProperty: 'value' });

Improvement

Please ā­ļø star this repo to add more frequest updates, PR's welcomes

Todo

  • Support for setNotes in CartJS
1.0.2

8 months ago

1.0.1

8 months ago

1.0.0

8 months ago