PHP code example of vaened / swift-cart

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

    

vaened / swift-cart example snippets


// initialize cart
$taxes = Taxes::from([
    Inclusive::proporcional(18, 'IGV')
]);

$cart = new ShoppingCart($taxes);

// add products
$mouse = $cart->push(Product::findOrFail(1), quantity: 2);

// assign individual charges and discounts
$mouse->add(
    Charge::proporcional(percentage: 5)->named('Delivery'),
    Charge::fixed(amount: 2)->named('Random'),
);
$mouse->apply(
    Discount::proporcional(percentage: 10)->named('NewUser')
);

// update quantity
$mouse->update(quantity: 3);

// assign global charges and discounts
$cart->addAsGlobal(
    Charge::fixed(amount: 2)->named('Express')
);
$cart->applyAsGlobal(
    Discount::proporcional(percentage: 1)
);

// get summary
$cart->summary();