PHP code example of itmosoft / laravel-orders

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

    

itmosoft / laravel-orders example snippets


use ItmoSoft\Orders\Services\OrderService;

$order = app(OrderService::class)->create([
    'customer' => $user, // optional Eloquent model (morph relation)
    'currency' => 'USD',
    'subtotal' => 100,
    'discount_total' => 10,
    'tax_total' => 9,
    'shipping_total' => 5,
    'grand_total' => 104,
    'billing_address' => [
        'name' => 'Jane Doe',
        'line1' => '10 Main Street',
        'city' => 'Lahore',
        'country' => 'PK',
    ],
    'items' => [
        [
            'product_type' => App\\Models\\Product::class,
            'product_id' => 42,
            'name' => 'Product name',
            'sku' => 'SKU-42',
            'quantity' => 2,
            'unit_price' => 50,
            'discount_total' => 10,
            'tax_total' => 9,
            'line_total' => 99,
            'product_snapshot' => [
                'name' => 'Product name',
                'sku' => 'SKU-42',
                'attributes' => ['size' => 'M'],
            ],
        ],
    ],
]);

$order = app(OrderService::class)->createFromCheckoutSession($checkoutSession, [
    // Optional overrides for your application's field mapping.
    'notes' => 'Created from checkout',
]);

use ItmoSoft\\Orders\\Services\\OrderService;

$order = app(OrderService::class)->changeStatus(
    $order,
    'processing',
    'Payment confirmed'
);
bash
composer vendor:publish --tag=itmosoft-orders-config
php artisan migrate