PHP code example of johannesschobel / laravel-shoppingcart

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

    

johannesschobel / laravel-shoppingcart example snippets


php artisan vendor:publish --provider="JohannesSchobel\ShoppingCart\ShoppingCartServiceProvider" --tag="migrations"

php artisan db:migrate

php artisan vendor:publish --provider="JohannesSchobel\ShoppingCart\ShoppingCartServiceProvider" --tag="config"

ShoppingCart::load($identifier, $name = null);

ShoppingCart::clear();

ShoppingCart::addItem(
   $id, 
   $name = null, 
   $type = null, 
   $qty = 1, 
   Money $price = null, 
   $uri = null, 
   array $options = []
);

ShoppingCart::addItem(
   '1234', 
   'Basic T-Shirt', 
   'products', 
   10, 
   new Money(999, new Currency('EUR')), // note the value is added in cents! 
   '/products/1234', 
   ['size' => 'large', 'color' => 'black']
);

$product = Product::find(1234); // remember, Product must implement the Buyable interface!
ShoppingCart::addBuyable(
   $product, 
   10, 
   ['size' => 'large', 'color' => 'black']
);

ShoppingCart::removeItem($row)

$rowId = "30168b5f5a78bc48d08b4d5a125a9d90";
ShoppingCart::removeItem($rowId);

ShoppingCart::updateItem($row, $qty = 1, array $options = [])

$rowId = "30168b5f5a78bc48d08b4d5a125a9d90";
ShoppingCart::updateItem($rowId, 1, ['color' => 'red']);
 php
'providers' => [
   ... ,
   JohannesSchobel\ShoppingCart\ShoppingCartServiceProvider::class,
],
 php
'aliases' => [
   ... ,
   'ShoppingCart' => JohannesSchobel\ShoppingCart\Facades\ShoppingCart::class,
],