PHP code example of selli / commerce

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

    

selli / commerce example snippets


use Selli\Commerce\Cart\CartManager;
use Selli\Commerce\Order\Actions\PlaceOrder;
use Selli\Commerce\Order\Actions\TransitionOrderState;
use Selli\Commerce\Order\States\Confirmed;

$carts = app(CartManager::class);

$cart = $carts->forOwner('user', (string) $user->id, 'EUR');
$carts->add($cart, $product, quantity: 2, options: ['size' => 'L']);

$calculation = $carts->calculate($cart);   // deterministic, explainable
$calculation->grandTotal();                 // Brick\Money\Money
$calculation->breakdown();                  // subtotal, discounts, tax, lines

$order = app(PlaceOrder::class)->handle($cart);   // transactional, emits OrderPlaced
$order->state;                                     // Pending

app(TransitionOrderState::class)->handle($order, Confirmed::class, by: $agent, reason: 'payment ok');
bash
composer vendor:publish --tag="commerce-migrations"
php artisan migrate