noahenrik/cart2go

There is no license information available for the latest version (v0.1) of this package.

A simple shopping cart.

v0.1 2020-08-04 19:46 UTC

This package is auto-updated.

Last update: 2024-10-05 08:23:41 UTC


README

This is a simple cart system made for PHP that will allow you to save item IDs to add to your cart. Saving prices is risky and should always be checked in the back-end.

Installation

Use composer to install cart2go.

composer require noahenrik/cart2go

Make sure to update your autoloader. For composer:

composer dump-autoload

Usage

Import the namespace with class:

$cart = new \Cart\Cart();

Add items to cart:

The addItemToCart method takes 2 paramaters, itemId and $amount. Amount is an optional paramater.

If the user clicks on an item that's already in the cart, the amount will automatically be incremented by 1.

If you specify an amount, the existing amount will be updated to the amount given and not incremented by 1.

$cart->addItemToCart($itemId, $amount);

//OR

$cart->addItemToCart($itemId);

Grab all items currently in the cart:

This method will grab all the items currently in the cart.

$allCartItems = $cart->grabAllItems();

Example

$allCartItems = $cart->grabAllItems();

foreach ($allCartItems as $key => $cartItem) {
  
  echo "Amount: " . $allCartItems[$key]['amount'] . " ItemId: " . $allCartItems[$key]['itemId'];
}    

Reset a cart:

This will remove all items within the cart.

$cart->reset();

Grab single item:

This will grab only the selected item from the cart.

$cart->grabItem($itemId);

Remove item from cart:

This will remove a selected item from the cart.

$cart->removeItem($itemId);

License

GNU Affero General Public License v3.0