PHP code example of mugenzo / laravel-shopping-cart

1. Go to this page and download the library: Download mugenzo/laravel-shopping-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/ */

    

mugenzo / laravel-shopping-cart example snippets


Cart::add('293ad', 'Product 1', 1, 9.99, 550);

Cart::add('293ad', 'Product 1', 1, 9.99, 550, ['size' => 'large']);

Cart::add(['id' => '293ad', 'name' => 'Product 1', 'qty' => 1, 'price' => 9.99, 'weight' => 550, 'options' => ['size' => 'large']]);

$rowId = 'da39a3ee5e6b4b0d3255bfef95601890afd80709';

Cart::update($rowId, 2);

$rowId = 'da39a3ee5e6b4b0d3255bfef95601890afd80709';

Cart::update($rowId, ['options'  => ['size' => 'small']]); // Will update the size option with new value

$rowId = 'da39a3ee5e6b4b0d3255bfef95601890afd80709';

Cart::remove($rowId);

$rowId = 'da39a3ee5e6b4b0d3255bfef95601890afd80709';

Cart::get($rowId);

Cart::content();

Cart::destroy();

Cart::total();

Cart::discount();

Cart::initial();

Cart::count();
$cart->count();

$cart->search(function ($cartItem, $rowId) {
	return $cartItem->id === 1;
});

Cart::setDiscount('percent', 10);
$cart->setDiscount('percent', 10);

Cart::setDiscount('flat', 100);
$cart->setDiscount('flat', 100);