PHP code example of beziworld / laravel-idosell

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

    

beziworld / laravel-idosell example snippets


'connections' => [
    'default' => ['domain' => env('IDOSELL_DOMAIN'), 'api_key' => env('IDOSELL_API_KEY')],
    'outlet' => ['domain' => 'outlet.example.pl', 'api_key' => env('IDOSELL_OUTLET_KEY')],
],

use Beziworld\IdoSell\Facades\IdoSell;

IdoSell::orders()->statuses();                         // default connection
IdoSell::connection('outlet')->products()->find(31);

// Credentials stored per tenant; the name identifies the shop in webhook events
$client = IdoSell::using(['domain' => $shop->domain, 'api_key' => $shop->api_key], name: 'shop-'.$shop->id);

// IdoSell Apps authorised with OAuth use a bearer token instead of the key
IdoSell::using(['domain' => $shop->domain, 'access_token' => $token]);

use Beziworld\IdoSell\Enums\OrderStatus;

foreach (IdoSell::orders()->iterate(['ordersStatuses' => ['new', 'payment_waiting']]) as $order) {
    $order->serialNumber;              // 1234 (the number shown in the panel)
    $order->status;                    // OrderStatus::New, null for statuses defined in the panel
    $order->statusName;                // raw status code
    $order->addedAt;                   // CarbonImmutable, Europe/Warsaw
    $order->currency;                  // "PLN"
    $order->productsCost;              // "259.98"
    $order->deliveryCost;              // "15.99"
    $order->total();                   // "276.07" (exact decimal addition)
    $order->billingAddress->taxId;     // "5260001246"
    $order->deliveryAddress->city;
    $order->pickupPoint?->id;          // "KRA010"
    foreach ($order->lines as $line) {
        $line->code; $line->sizeId; $line->quantity; $line->priceGross; $line->totalGross();
    }
    $order->payments[0]->amount;       // "276.07"
    $order->raw;                       // the original record, including fields not mapped
}

IdoSell::orders()->find(1234);                         // ?Order
IdoSell::orders()->findByExternalId('AL-555');         // marketplace order id
IdoSell::orders()->setStatus(1234, OrderStatus::Packed);
IdoSell::orders()->setStatus(1234, 17);                // status defined in the panel, by id
IdoSell::orders()->setNote(1234, 'Gift wrap');
IdoSell::orders()->update([['orderSerialNumber' => 1234, 'clientNoteToCourier' => 'Call first']]);

// routes/console.php
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Schedule;

Schedule::call(function () {
    $since = Cache::get('idosell:orders:since', now()->subDay());
    $started = now();

    IdoSell::orders()->modifiedSince($since)->each(function (Order $order) {
        LocalOrder::updateOrCreate(['idosell_sn' => $order->serialNumber], [
            'status' => $order->statusName,
            'total' => $order->total(),          // store as DECIMAL, no float rounding
            'currency' => $order->currency,
        ]);
    });

    Cache::forever('idosell:orders:since', $started->subMinutes(2));   // small overlap, upserts are idempotent
})->everyFiveMinutes()->withoutOverlapping();

foreach (IdoSell::products()->iterate(['productIsVisible' => 'y']) as $product) {
    $product->id; $product->code; $product->name;           // name in "pol" (all languages in $product->names)
    $product->retailPrice;                                    // "49.90"
    foreach ($product->sizes as $size) {
        $size->id;            // "uniw" for products without sizes
        $size->codeExternal;  // EAN / external code
        $size->stock;         // [1 => "3.00", 2 => "2.00"] keyed by warehouse id
    }
}

IdoSell::products()->changedSince(now()->subHour(), 'quantity_changed');
IdoSell::products()->stocks([31, 32]);                       // list<StockLevel> per warehouse and size

// Stock: set, add or subtract; grouped per product and sent in chunks of 100
IdoSell::products()->setStock(31, warehouseId: 1, quantity: 12, sizeId: 'M');
$result = IdoSell::products()->updateStockLevels([
    ['product' => 'MUG-1', 'warehouse' => 1, 'quantity' => 5, 'size' => 'uniw'],
    ['product' => 'MUG-2', 'warehouse' => 1, 'quantity' => 2, 'operation' => Products::OPERATION_ADD],
], identType: 'index');
$result->successful();      // false when any product failed
$result->errors;            // list<ItemError>: path, code, message

// Prices: gross retail price by product id, or any price fields
IdoSell::products()->updatePrices([31 => 49.90, 32 => ['productRetailPrice' => 10.0, 'productWholesalePrice' => 8.0]]);

IdoSell::shipments()->couriers('PL');                                  // list<Courier>
IdoSell::shipments()->addTrackingNumber(1234, courierId: 100, trackingNumber: '6200123456789');
IdoSell::orders()->packages([1234]);                                   // list<Package>: trackingNumber, trackingUrl, courierName

// Courier shipment through the panel integration; labels come back as binary contents
$labels = IdoSell::shipments()->createLabels(1234, parcelParameters: ['weight' => '1.2']);
Storage::put('labels/1234.'.$labels[0]->extension(), $labels[0]->contents);   // pdf, zpl, epl, ...

IdoSell::shipments()->labels(55, Shipments::EVENT_RETURN);             // labels of a return

IdoSell::returns()->createdSince(now()->subDay())->each(fn (OrderReturn $return) => ...);
IdoSell::returns()->create(1234, warehouseId: 1, products: [['id' => 31, 'size' => 'uniw', 'quantity' => 1, 'price' => 49.9]]);
IdoSell::returns()->setStatus(77, 2);
IdoSell::rma()->setStatus(4, 2, 'We will send a replacement.');

$invoices = IdoSell::documents()->get([1234], 'vat_invoice');          // list<Document>, PDF decoded
Storage::put('invoices/'.$invoices[0]->filename(), $invoices[0]->contents);
IdoSell::documents()->create([1234], 'vat_invoice');
IdoSell::documents()->upload(1234, 'FV 1/11/2026', file_get_contents('erp-invoice.pdf'));

IdoSell::get('system/shopsData');
IdoSell::post('vouchers/vouchers/search', ['resultsLimit' => 10]);   // wrapped in {"params": ...}
IdoSell::put('menu/menu', ['menu_list' => [...]], wrap: false);     // endpoints without the wrapper
IdoSell::request('DELETE', 'packages/packages', ['packageId' => 9]);

use Beziworld\IdoSell\Enums\EventType;
use Beziworld\IdoSell\Events\WebhookReceived;

Event::listen(function (WebhookReceived $event) {
    if ($event->eventType === EventType::OrderStatusUpdated) {
        foreach ($event->orders() as $order) { /* $event->connection, $order->status */ }
    }
    // $event->eventUid stays the same on redelivery: make listeners idempotent
});