1. Go to this page and download the library: Download jamesdb/cart library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
jamesdb / cart example snippets
use jamesdb\Cart\CartItem;
$item = new CartItem([
...
'price' => 1099, // Instead of £10.99 or $10.99 etc.
...
]);
use jamesdb\Cart\Cart;
use jamesdb\Cart\Storage\NativeSessionDriver;
use Money\Currencies\ISOCurrencies;
use Money\Currency;
use Money\Formatter\DecimalMoneyFormatter;
$cart = new Cart('cart', new NativeSessionDriver);
$cart->setCurrency(new Currency('GBP'));
$cart->setFormatterCallback(function ($money) {
$currencies = new ISOCurrencies();
$moneyFormatter = new DecimalMoneyFormatter($currencies);
return $moneyFormatter->format($money); // outputs in decimal format.
});
use jamesdb\Cart\Cart;
use jamesdb\Cart\CartItem;
$cart = new Cart(...);
/**
* Assign properties via __set.
*/
$item1 = new CartItem();
$item1->id = 2731;
$item1->name = 'Product';
$item1->price = 1099;
$item1->quantity = 1;
$cart->add($item1);
/**
* ----------
*/
/**
* Assign properties via ArrayAccess.
*/
$item2 = new CartItem([
'id' => 2731,
'name' => 'Product',
'price' => 1099,
'quantity' => 1
]);
$cart->add($item2)