Giter VIP home page Giter VIP logo

cart's Introduction

Cart

Set Up

PHP developers include 'Cart.php';

JS developers <script type="text/javascript" src="Cart.js"></script>

Create Product Objects

PHP developers

class Product{
    // required fields
    
	public $id;           // product id
	public $price;        // product unit price
      
    // add optional product fields
      public $name;
}
    
$shirt = new Product();
$trousers = new Product();

//  Set the id and unit price

$shirt->id = 1;
$shirt->price = 5.0;

$trousers->id = 5;
$trousers->price = 10.0;

JS developers

    function Product(){
    // required fields
    
	this.id;            // product id
	this.price;         // product unit price
	
    // add optional fields
  }

var shirt = new Product();
var trousers = new Product();

//  Set the id and unit price

shirt.id = 1;
shirt.price = 5.0;

trousers.id = 5;
trousers.price = 10.0;

In both cases the id and price fields are required

No need going through all this if product is coming from a database, the product should just have the id and price field

Thats it!

Add To Cart

PHP Developers

 // add 2 shirts to cart
 Cart::getInstance()->add($shirt,2);

JS Developers

   // add 2 shirts to cart
  Cart.getInstance().add(shirt, 2);

Retrieve all items in Cart

PHP Developers

Cart::getInstance()->all();

JS Developers

Cart.getInstance().all();

Reduce a cart item

PHP Developers

// reduce shirt by 1
Cart::getInstance()->reduce($shirt,1);

JS Developers

// reduce shirt by 1
Cart.getInstance().reduce(shirt, 1);

Get a cart item

PHP Developers

Cart::getInstance()->get($shirt);

JS Developers

Cart.getInstance().get(shirt);

Get total quantity of items in cart

PHP Developers

Cart::getInstance()->getTotalQty();

JS Developers

Cart.getInstance().getTotalQty();

Get total price of items in cart

PHP Developers

Cart::getInstance()->getTotalPrice();

JS Developers

Cart.getInstance().getTotalPrice();

Get product sub quantity

PHP Developers

Cart::getInstance()->getSubQty($shirt);

JS Developers

Cart.getInstance().getSubQty(shirt);

Get product sub price

PHP Developers

Cart::getInstance()->getSubPrice($shirt);

JS Developers

Cart.getInstance().getSubPrice(shirt);

Remove an item from cart

PHP Developers

Cart::getInstance()->remove($shirt)

JS Developers

 Cart.getInstance().remove(trousers)

Update an item in the cart

PHP Developers

\\ clear shirt quantity and set it to 3
Cart::getInstance()->update($shirt,3)

JS Developers

\\ clear shirt quantity and set it to 3
Cart.getInstance().update(shirt,3);

Clear Cart

PHP Developers

Cart::getInstance()->clear()

JS Developers

Cart.getInstance().clear()

Get last item in cart

PHP Developers

Cart::getInstance()->getLastItem()

Get first item in cart

PHP Developers

Cart::getInstance()->getFirstItem()

contact me : [email protected]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.