Skip to content

nova-framework/phpcart

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 

Repository files navigation

PHPCart

Simple framework agnostic shopping cart.

This is been ported over from https://github.com/anam-hossain/phpcart this version has been configured to work with Nova Framework.

Features

  • Simple API
  • Support multiple cart instances
  • Nova Framework integration

Requirements

  • PHP 5.4+

Installation

Download this repo and place inside the Shared folder.

open the config/app.php

In the $providers array add the following service provider.

'Shared\Cart\CartServiceProvider'

Add the facade of this package to the $aliases array.

'Cart' => 'Shared\Cart\Facades\Cart'

You can now use this facade in place of instantiating the Cart yourself.

Usage

Add Item

The add method required id, name, price and quantity keys. However, you can pass any data that your application required.

Cart::add([
    'id'       => 1001,
    'name'     => 'Skinny Jeans',
    'quantity' => 1,
    'price'    => 90
]);

Update Item

Cart::update([
    'id'       => 1001,
    'name'     => 'Hoodie'
]);

Update quantity

Cart::updateQty(1001, 3);

Update price

Cart::updatePrice(1001, 30);

Remove an Item

Cart::remove(1001);

Get all Items

Cart::getItems();
// or
Cart::items();

Get an Item

Cart::get(1001);

Determining if an Item exists in the cart

Cart::has(1001);

Get the total number of items in the cart

Cart::count();

Get the total quantities of items in the cart

Cart::totalQuantity();

Total sum

Cart::getTotal();

Empty the cart

Cart::clear();

Multiple carts

PHPCart supports multiple cart instances, so that you can have as many shopping cart instances on the same page as you want without any conflicts.

$cart = new Cart('cart1');
// or
$cart->setCart('cart2');
$cart->add([
    'id'       => 1001,
    'name'     => 'Skinny Jeans',
    'quantity' => 1,
    'price'    => 90
]);

//or
$cart->named('cart3')->add([
    'id'       => 1001,
    'name'     => 'Jeans',
    'quantity' => 2,
    'price'    => 100
]);

About

Simple Nova Framework shopping cart

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%