PHP code example of adarshhaldar / unicart

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

    

adarshhaldar / unicart example snippets


use Unicart\Unicart;
                    
try {
    $cart = new Unicart();
                
    $cart->addItem('item_1', 200, 2);    // (id, price, quantity)
                
    $cart->applyFlatDiscountOnItem('item_1', 10);    // (id, discount)
    $cart->applyDeliveryChargeOnCart(50); // delivery charge
                
    $summary = $cart->toArray(); // Also available: toJson(), toObject()
    print_r($summary);
} catch (Exception $e) {
    echo $e->getMessage();
}