PHP developers
include 'Cart.php';
JS developers
<script type="text/javascript" src="Cart.js"></script>
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!
PHP Developers
// add 2 shirts to cart
Cart::getInstance()->add($shirt,2);
JS Developers
// add 2 shirts to cart
Cart.getInstance().add(shirt, 2);
PHP Developers
Cart::getInstance()->all();
JS Developers
Cart.getInstance().all();
PHP Developers
// reduce shirt by 1
Cart::getInstance()->reduce($shirt,1);
JS Developers
// reduce shirt by 1
Cart.getInstance().reduce(shirt, 1);
PHP Developers
Cart::getInstance()->get($shirt);
JS Developers
Cart.getInstance().get(shirt);
PHP Developers
Cart::getInstance()->getTotalQty();
JS Developers
Cart.getInstance().getTotalQty();
PHP Developers
Cart::getInstance()->getTotalPrice();
JS Developers
Cart.getInstance().getTotalPrice();
PHP Developers
Cart::getInstance()->getSubQty($shirt);
JS Developers
Cart.getInstance().getSubQty(shirt);
PHP Developers
Cart::getInstance()->getSubPrice($shirt);
JS Developers
Cart.getInstance().getSubPrice(shirt);
PHP Developers
Cart::getInstance()->remove($shirt)
JS Developers
Cart.getInstance().remove(trousers)
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);
PHP Developers
Cart::getInstance()->clear()
JS Developers
Cart.getInstance().clear()
PHP Developers
Cart::getInstance()->getLastItem()
PHP Developers
Cart::getInstance()->getFirstItem()
contact me : [email protected]