1. Go to this page and download the library: Download jackiedo/shoppingcart 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/ */
/**
* Add a new item to the cart
*
* @param string|int $id ID of the item (such as product's id)
* @param string $title Name of the item
* @param int $qty Item qty to add to the cart
* @param float $price Price of one item
* @param array $options Array of additional options, such as 'size' or 'color'
* @return Jackiedo\Shoppingcart\CartItem|null
*/
Cart::add( $id, $title, $quantity, $price [, $options = array()] );
/**
* Update the quantity of one row of the cart
*
* @param string $rawId The rawId of the item you want to update
* @param int|array $attribute New quantity of the item|Array of attributes to update
* @return Jackiedo\Shoppingcart\CartItem
*/
Cart::update(string $rawId, int $quantity);
Cart::update(string $rawId, array $arrtibutes);
$rawId = '8a48aa7c8e5202841ddaf767bb4d10da';
// Update title and options
$row = Cart::update($rawId, ['title' => 'New item name', 'options' => ['color' => 'yellow']]);
// or only update quantity
$row = Cart::update($rawId, 5);
/**
* Get the cart content
*
* @return \Illuminate\Support\Collection
*/
Cart::all();
// or use alias
Cart::content();
/**
* Get a row of the cart by its unique ID
*
* @param string $rawId The ID of the row to fetch
* @return Jackiedo\Shoppingcart\CartItem
*/
Cart::get(string $rawId);
/**
* Get the price total
*
* @return float
*/
Cart::total();
$total = Cart::total();
/**
* Get the number of items in the cart
*
* @param boolean $totalItems Get all the items (when false, will return the number of rows)
* @return int
*/
Cart::count(false);
// or use alias
Cart::countRows();
/**
* Get the number of items in the cart
*
* @param boolean $totalItems Get all the items (when false, will return the number of rows)
* @return int
*/
Cart::count($totalItems = true);
/**
* Search if the cart has a item
*
* @param array $search An array with the item ID and optional options
* @return Illuminate\Support\Collection;
*/
Cart::search(array $conditions);
Cart::instance('shopping')->add('37', 'Product 1', 1, 9.99);
// Get the content of the 'shopping' cart
Cart::content();
Cart::instance('wishlist')->add('42', 'Product 2', 1, 19.95, array('size' => 'medium'));
// Get the content of the 'wishlist' cart
Cart::content();
// If you want to get the content of the 'shopping' cart again...
Cart::instance('shopping')->content();
// And the count of the 'wishlist' cart again
Cart::instance('wishlist')->count();
/**
* Set the associated model
*
* @param string $modelName The name of the model
* @param string $modelNamespace The namespace of the model
* @return Jackiedo\Shoppingcart\Cart
*/
Cart::associate(string $modelName, string $modelNamespace = null);
Cart::associate('ShoppingProduct', 'App\Models');
$item = Cart::get('8a48aa7c8e5202841ddaf767bb4d10da');
$item->shopping_product->title; // $item->shopping_product is instance of 'App\Models\ShoppingProduct'