Trexology / laravel-order by trexology

Order for Laravel Application.
121
9
3
Package Data
Maintainer Username: trexology
Maintainer Contact: trexlim@gmail.com (trexology)
Package Create Date: 2015-12-01
Package Last Update: 2020-10-31
Language: PHP
License: MIT
Last Refreshed: 2024-04-17 15:04:54
Package Statistics
Total Downloads: 121
Monthly Downloads: 0
Daily Downloads: 0
Total Stars: 9
Total Watchers: 3
Total Forks: 2
Total Open Issues: 3

Latest Stable Version Total Downloads Latest Unstable Version License

laravel-order

Basic Ordering Package for Laravel 5+

Installation

composer require trexology/laravel-order:2.*

After installation,go to config/app.php under providers section to add the following:

Trexology\LaravelOrder\LaravelOrderServiceProvider::class

and under "aliases" add:

'Order'     => Trexology\LaravelOrder\Facades\OrderFacade::class

publish the migration and config files with the commands:

php artisan vendor:publish

Edit additional settings at config/order.php

    return [

        /*
        |--------------------------------------------------------------------------
        | Order Status Name
        |--------------------------------------------------------------------------
        | Customize the status name recorded
        |
        */

        'init' => "init",
        'complete' => "complete",

        'ignoredFields' => []

    ];

Upgrade Guide from 1.*

• This package uses VentureCraft/revisionable to track order changes

• Remove the old migration file '2015_12_02_150448_create_orderLogs_table.php'

• Column line_item_id in Orderitems table has been changed from integer to string for greater flexibility (version 1 user have to change the column type manually)

Usage

Create a new order

Order Order::order(int $user_id, array $data = null, bool $draft = FALSE)

    $data = [
        //Custom fields
        'cust_first_name' => $cust->first_name,
        'cust_last_name' => $cust->last_name
    ];

    $order = Order::order($cust->id, $data);

Add item to Order

Order Order::addItem(Order $order, Model $object, double $price, int $quantity, array $data = null, double $vat = 0);

    $data = [
      'description' => "My item descriptions",
      'currency' => "SGD"
    ];
    $order = Order::addItem($order, $object, 25.5, 2, $data, 7);

Add item to Order (Non Eloquent Style)

Order Order::addItemManual(Order $order, string $object_id, string $object_type, double $price, int $quantity, array $data = null, double $vat = 0)

    $data = [
      'description' => "My item descriptions",
      'currency' => "SGD"
    ];
    $order = Order::addItem($order, 22, "App\Model\Object", 25.5, 2, $data, 7);

Batch Adding item to Order

Order Order::batchAddItems(Order $order, array $order_Items)

    $order_Items = [
        [
            "description" => "Some Description",
            "currency" => "USD",
            "line_item_id" => 1,
            "line_item_type" => "App\\Models\\Package",
            "price" => 1802,
            "quantity" => 1,
            "vat" => 0,
        ],
        [
            "description" => "Some Description",
            "currency" => "USD",
            "line_item_id" => 1,
            "line_item_type" => "App\\Models\\Package",
            "price" => 1802,
            "quantity" => 1,
            "vat" => 0,
        ]
    ];
    $order = Order::batchAddItems($order, $order_Items);

Get an order

    Order Order::getOrder(int $order_id);

Get user's orders

    Collection Order::getUserOrders(int $user_id);

Update Order Status

    boolean Order::updateStatus(int $order_id, string $status);

Delete an Order

    boolean Order::deleteOrder(int $order_id);

Update Order quantity

    OrderItem Order::updateQty(int $item_id, int qty);

Calculate an Order total amount

    float Order::total(Order $order);

Calculate an Order total item count

    int Order::count(Order $order);