PHP code example of edwinylil1 / laravelshoppingcart

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

    

edwinylil1 / laravelshoppingcart example snippets


    'default_aliquot' => 0,
    'taxes' => [
        '0' => [
            'name' => 'GENERAL',
            'value' => 16.00
        ],
        '1' => [
            'name' => 'EXEMPT',
            'value' => 0.00
        ],
        '2' => [
            'name' => 'REDUCED',
            'value' => 8.00
        ],
        '3' => [
            'name' => 'LUXURY',
            'value' => 31.00
        ]
    ]

Cart::add('P001', 'Hammer', 1, 10.00, 0, ['image' => '/img/hammer.jpg']);
$item = Cart::add('P001', 'Hammer', 2, 10.00, 0, ['image' => '/img/hammer.jpg']);
// One P001 line: qty = 3, options.image = /img/hammer.jpg

Cart::add('P001', 'Hammer', 1, 10.00, 0, []);
// A separate line from P001 with ['image' => '/img/hammer.jpg'].

Cart::add(['id' => 'P002', 'name' => 'Pliers', 'qty' => 1, 'price' => 12.00]);

$item = Cart::get($rowId);
Cart::update($rowId, $item->qty + 1);
// Alternative when P001 identifies exactly one line:
$item = Cart::get('P001');
Cart::update('P001', $item->qty + 1);

$item = Cart::add('P001', 'Hammer', 1, 10.00, 0, ['image' => '/img/hammer.jpg']);
Cart::update($item->rowId, 2);
// Only qty changes; id, name, price, aliquot and options.image are preserved.

$item = Cart::update($rowId, ['name' => 'New name', 'price' => 11.00]);
$item = Cart::update($item->rowId, $product); // $product implements Buyable

    Cart::content();

    Cart::instance('wishlist')->content();

Cart::get('P001');
Cart::update('P001', 2);
Cart::remove('P001');

$item = Cart::get($rowId);

    $cart->search(function ($cartItem, $rowId) {
        return $cartItem->name === 'tube';
    });

    Cart::total();

    Cart::tax();

    Cart::subtotal();

    Cart::count();

    Cart::addCost($name, $price)

    Cart::getCost($name)

Cart::remove($rowId);
// Alternative for a unique product code:
Cart::remove('P001');

Cart::destroy();

    Cart::instance('Instance name');

    Cart::instance('shopping')->add('code', 'Product 1', 1, 9.99);
    // Get the content of the 'shopping' cart
    Cart::content();
    Cart::instance('wishlist')->add('code', 'Product 2', 1, 19.95, 1, ['image' => 'url image']);
    // 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();

    Cart::store('username');

    Cart::instance('custom name')->store('code');

Cart::restore('username');

Cart::instance('custom name')->restore('code');

Cart::merge('username');

Cart::instance('custom name')->merge('code');

    Cart::content()->count();

    Cart::content()->groupBy('id');

    // First we'll add the item to the cart.
    $cartItem = Cart::add('code', 'Product name', 1, 9.99);
    // Next we associate a model with the item.
    Cart::associate($cartItem->rowId, 'Product');
    // Or even easier, call the associate method on the CartItem!
    $cartItem->associate('Product');
    // You can even make it a one-liner
    Cart::add('code', 'Product name', 1, 9.99)->associate('Product');
    // Now, when iterating over the content of the cart, you can access the model.
    foreach(Cart::content() as $row) {
        echo 'You have ' . $row->qty . ' items of ' . $row->model->name . ' with description: "' . $row->model->description . '" in your cart.';
    }
bash
    php artisan vendor:publish --provider="JeleDev\Shoppingcart\ShoppingcartServiceProvider" --tag="config"
bash
    php artisan vendor:publish --provider="JeleDev\Shoppingcart\ShoppingcartServiceProvider" --tag="config"
bash
    php artisan vendor:publish --provider="JeleDev\Shoppingcart\ShoppingcartServiceProvider" --tag="migrations"
bash
php artisan migrate