PHP code example of munna / shopping-cart

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

    

munna / shopping-cart example snippets


// Use this as namespace
use Munna\ShoppingCart\Cart;

// call the cart class
// as a parameter we can pass the instance name.
// default instance is = shopping-cart
// you can use any of instances name as you like
$cart = new Cart();
// Example 
$info = $cart->info();
// You will get all info about your default instance like as bellow
return $info;

// Use this as namespace
use Munna\ShoppingCart\Facades\Cart;

// init the cart class by calling init() method
// as a parameter we can pass the instance name into the init() method.
// default instance is = shopping-cart
// you can use any of instances name as you like

$cart = Cart::init();
// Example 
return Cart::info();

// If you want to use this globally as static class, then just add this line 
// at your config/app.php into aliases array
'Cart' => Munna\ShoppingCart\Facades\Cart::class,

// You will get all info about your default instance like as bellow

// default instance = shoppint-cart

// 1st Example
$cart = new Cart('whishlist');
// Example 
return $cart->info();


// 2nd Example
Cart::init('whishlist');
// Example 
$cart = Cart::info();
return $cart;

// You must maintaince these parameter value

// Require Fields
$product_id  = "You product Id", // Required
$product_name = "Product Name", // Required
$product_qty = "Product Quantity", // Required
$product_price = "Product Price", // Required

// Optional Fields
$product_weight = 0, // Optional
$product_thumb = null, // Optional
$discount = 0, // Optional
$shipping_charge = 0, // Optional
$tax = 0, // Optional
$product_info = [];// Optional


// 1st example
$cart = new Cart();
$cart->add($product_id, $product_name, $product_qty, $product_price, $product_weight = 0, $product_thumb = null, $discount = 0, $shipping_charge = 0, $tax = 0, $product_info = []);

// 2nd example
Cart::add($product_id, $product_name, $product_qty, $product_price, $product_weight = 0, $product_thumb = null, $discount = 0, $shipping_charge = 0, $tax = 0, $product_info = []);

// You must maintaince these parameter value

// Require Fields
$uid  = "You uid Id", // Required  // Like as something 82qdiieeqvl0wftwyv7b1cfhidi4ry6k
$quantity = 3; // Required

// 1st example
$cart = new Cart();
$cart->update($uid, $quantity);


// 2nd example
Cart::update($uid, $quantity);

// You must maintaince these parameter value

// Require Fields
$uid  = "You uid Id", // Required  // Like as something m1ueddkrrayhkwi4prtjvxfyoytjmxpz

// 1st example
$cart = new Cart();
$cart->remove($uid);


// 2nd example
Cart::remove($uid);

// You must maintaince these parameter value

// Require Fields
$uid  = "You uid Id", // Required  // Like as something m1ueddkrrayhkwi4prtjvxfyoytjmxpz

// 1st example
$cart = new Cart();
$cart->search($uid);
$cart->get($uid);


// 2nd example
Cart::search($uid);
Cart::get($uid);

// 1st example
$cart = new Cart();
$cart->clear();

// 2nd example
Cart::clear();

// 1st example
$cart = new Cart();
$cart->total();

// 2nd example
Cart::total();

// 1st example
$cart = new Cart();
$cart->subtotal();

// 2nd example
Cart::subtotal();

// 1st example
$cart = new Cart();
$cart->discount();

// 2nd example
Cart::discount();

// 1st example
$cart = new Cart();
$cart->shipping();

// 2nd example
Cart::shipping();

// 1st example
$cart = new Cart();
$cart->tax();

// 2nd example
Cart::tax();

// 1st example
$cart = new Cart();
$cart->count();

// 2nd example
Cart::count();

// 1st example
$cart = new Cart();
$cart->items();

// 2nd example
Cart::items();

// items() methos support a parameter that can able to sorted your cart item by ascending
// You can sort your item by price, total, subtotal, product name or any key that exists.

// Example

Cart::items('price');
// or
Cart::items('name');
// or
Cart::items('qty');
// or 
Cart::items('total')  //etc

// 1st example
$cart = new Cart();
$cart->info();

// 2nd example
Cart::info();

// info() methos support a parameter that can able to sorted your cart item by ascending
// You can sort your item by price, total, subtotal, product name or any key that exists.

// Example
Cart::info('price');
// or
Cart::info('name');
// or
Cart::info('qty');
// or 
Cart::info('total')  //etc