1.0.0 • Published 9 months ago
get-shopping-cart v1.0.0
Shopping Cart Tool
The Shopping Cart Tool is a utility library designed to simplify the management of shopping cart selections within web applications. It provides a set of functions to help you handle the selection state of items, merchants, and products in a shopping cart.
Installation
You can install the Shopping Cart Tool via npm:
npm install shopping-cart-tool
Usage
Here's a quick example of how you can use the Shopping Cart Tool in your application:
const getShoppingCarts = require('shopping-cart-tool')
// Replace this with your actual data and options
const newData = [] // Your data array
const options = {
pid: 'mid', // Replace with your actual property names
superset_name: 'mname' // Replace with your actual property names
}
const shoppingCarts = getShoppingCarts(newData, options)
// Example: Update all items in a merchant
shoppingCarts.updateAll(true, 'merchantId')
// Example: Update selected state for a product
shoppingCarts.updateSelected(true, 'merchantId', 'productId')
API
getShoppingCarts(data, options)
Creates a shopping cart utility instance.
- data (Array): The initial data array representing shopping cart items.
- options (Object, optional): Configuration options for the utility.
- pid (String): Property name representing parent ID (default: 'mid').
- superset_name (String): Property name representing superset name (default: 'mname').
Returns an object with the following methods:
- updateChooseAll(selected, type): Updates the selection state for all items.
- updateAll(selected, id, type): Updates the selection state for all items within a merchant.
- updateSelected(selected, pid, id, type): Updates the selection state for a specific product.
License
This project is licensed under the MIT License. See the LICENSE
file for details.
1.0.0
9 months ago