1. Go to this page and download the library: Download aiarmada/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/ */
aiarmada / cart example snippets
use AIArmada\Cart\Facades\Cart;
// Add items
Cart::add('laptop-001', 'MacBook Pro 16"', 249900, 1, [
'sku' => 'MBP16-2024',
'color' => 'Space Gray',
]);
// Get totals
echo Cart::count(); // Total quantity
echo Cart::total()->format(); // "$2,499.00"
// Apply conditions
Cart::addDiscount('promo', '10%');
Cart::addTax('vat', '8%');
Cart::addShipping('standard', '15.00');
// Work with items
$item = Cart::get('laptop-001');
Cart::update('laptop-001', ['quantity' => 2]);
Cart::remove('laptop-001');
// Multiple instances
Cart::setInstance('wishlist')->add('monitor-001', 'Display', 59900);
use AIArmada\Cart\Storage\StorageInterface;
$this->app->bind(StorageInterface::class, function ($app): StorageInterface {
return new App\Cart\Storage\CustomStorage(...);
});
use AIArmada\Cart\Conditions\CartCondition;
use AIArmada\Cart\Conditions\Enums\ConditionPhase;
use AIArmada\Cart\Conditions\Target;
// Percentage discount
Cart::addDiscount('summer-sale', '20%');
// Fixed amount
Cart::addDiscount('welcome', '-10.00');
// Custom condition
$condition = new CartCondition(
name: 'vip-discount',
type: 'discount',
target: Target::cart()->phase(ConditionPhase::CART_SUBTOTAL)->applyAggregate()->build(),
value: '-15%',
rules: [fn($cart) => auth()->user()?->isVip()],
);
Cart::addCondition($condition);