<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
timothydc / laravel-lightspeed-retail-api example snippets
use TimothyDC\LightspeedRetailApi\Scope;
use TimothyDC\LightspeedRetailApi\Facades\LightspeedRetailApi;
$scope = Scope::EMPLOYEE_ALL;
return redirect()->to(LightspeedRetailApi::redirectToAuthorizationPortal($scope));
use \TimothyDC\LightspeedRetailApi\Http\Controllers\SaveAccessTokenController;
Route::get('your-redirect-uri', [SaveAccessTokenController::class, '__invoke']);
use TimothyDC\LightspeedRetailApi\Facades\LightspeedRetailApi;
// get all
$account = LightspeedRetailApi::api()->account()->get();
// filter with GET with a limit and custom sorting (full details: https://developers.lightspeedhq.com/retail/introduction/parameters/)
$categories = LightspeedRetailApi::api()->category()->get(null, ['limit' => 10, 'sort' => 'name']);
// get category with ID 20
$categories = LightspeedRetailApi::api()->category()->get(20);
// same as above, but better
$categories = LightspeedRetailApi::api()->category()->first(20);
// advanced filtering
// get categories with an ID > 10
$categories = LightspeedRetailApi::api()->category()->get(null, ['categoryID' => ['operator' => '>', 'value' => 10]]);
// get products with their "Category" and "Note" relation
$products = LightspeedRetailApi::api()->item()->get(null, ['load_relations' => ['Category', 'Note']]);
// get sales sorted by timestamp in descending order
$sales = LightspeedRetailApi::api()->sale()->get(null, ['sort' => '-timestamp']);
use \TimothyDC\LightspeedRetailApi\Services\Lightspeed\ResourceSale;
$response = LightspeedRetailApi::api()->sale()->getWithPagination();
$attributes = $response['@attributes'];
// collect([
// 'next' => (request url),
// 'previous' => (request url),
// 'after' => (token),
// 'before' => (token),
// ])
$sales = $response[ResourceSale::$resource];
// Sales data as a collection
public function getLightspeedRetailResourceName(): string
{
return \TimothyDC\LightspeedRetailApi\Services\Lightspeed\ResourceItem::$resource;
}
use TimothyDC\LightspeedRetailApi\Traits\HasLightspeedRetailResources;
use TimothyDC\LightspeedRetailApi\Services\Lightspeed\{ResourceItem, ResourceVendor};
class Product extends \Illuminate\Database\Eloquent\Model
{
use HasLightspeedRetailResources;
public static function getLightspeedRetailResourceMapping(): array
{
return [
ResourceVendor::$resource => [
ResourceVendor::$name => 'product_vendor'
],
ResourceItem::$resource => [
ResourceItem::$description => 'name',
ResourceItem::$manufacturerId => ['manufacturer_id', 'manufacturer.id'],
ResourceItem::$archived => ['active', 'archive'],
],
];
}
}
public function getArchivedAttribute(): bool
{
return $this->attributes['active'] === false;
}
use TimothyDC\LightspeedRetailApi\Traits\HasLightspeedRetailResources;
class Product extends \Illuminate\Database\Eloquent\Model
{
use HasLightspeedRetailResources;
public static function getLightspeedRetailApiTriggerEvents(): array
{
return ['created', 'updated', 'deleted'];
}
}
use TimothyDC\LightspeedRetailApi\Traits\HasLightspeedRetailResources;
class Product extends \Illuminate\Database\Eloquent\Model
{
use HasLightspeedRetailResources;
public array $lsForceSyncFields = ['ean'];
}