PHP code example of malikad778 / laravel-nexus

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

    

malikad778 / laravel-nexus example snippets


// Identical API regardless of channel
Nexus::driver('shopify')->fetchProduct($remoteId);
Nexus::driver('amazon')->updateInventory($remoteId, 42);
Nexus::driver('woocommerce')->getProducts(now()->subHours(24));

// Push a single inventory update to specific channels
Nexus::product($product)
    ->updateInventory(quantity: 42)
    ->sync(['shopify', 'amazon']);

// Bulk sync your entire catalog across all channels
$batch = Nexus::catalog($products)->syncAll();

// Monitor batch progress
$status = Nexus::batch($batchId)->status();

class PropagateInventoryToOtherChannels
{
    public function handle(InventoryUpdated $event): void
    {
        $others = ['shopify', 'amazon', 'woocommerce', 'etsy'];

        Nexus::product($event->product)
            ->updateInventory($event->newQuantity)
            ->sync(array_diff($others, [$event->channel]));
    }
}

use Malikad778\\LaravelNexus\Traits\Syncable;

class Product extends Model
{
    use Syncable;
    // Adds: $product->channelMappings(), $product->syncTo('shopify')
}

// In AppServiceProvider::boot()
Nexus::extend('ebay', function ($app) {
    return new EbayInventoryDriver(
        config: $app['config']['nexus.channels.ebay'],
        client: $app->make(EbayApiClient::class)
    );
});

// eBay is now a first-class channel
Nexus::product($product)->updateInventory(10)->sync(['shopify', 'ebay']);

NexusProduct::fromShopify($payload);     // variants[], inventory_item_id, barcode
NexusProduct::fromWooCommerce($payload); // stock_quantity, variations[]
NexusProduct::fromAmazon($payload);      // ASIN, seller_sku, quantity
NexusProduct::fromEtsy($payload);        // listing_id, skus[], price divisor

use Malikad778\\LaravelNexus\Facades\Nexus;

// All configured channels
Nexus::product($product)->updateInventory(quantity: 42)->sync();

// Specific channels only
Nexus::product($product)->updateInventory(quantity: 42)->sync(['shopify', 'amazon']);

$batch = Nexus::catalog($products)->syncAll();

$product  = Nexus::driver('shopify')->fetchProduct('gid://shopify/Product/789');
$products = Nexus::driver('woocommerce')->getProducts(now()->subHours(24));
$success  = Nexus::driver('etsy')->pushInventory($nexusInventoryUpdate);

// In EventServiceProvider
protected $listen = [
    \Malikad778\\LaravelNexus\Events\InventoryUpdated::class => [
        PropagateInventoryToOtherChannels::class,
    ],
    \Malikad778\\LaravelNexus\Events\BeforeInventorySync::class => [
        EnforceSafetyStockListener::class,
    ],
    \Malikad778\\LaravelNexus\Events\InventorySyncFailed::class => [
        AlertOpsTeamListener::class,
    ],
    \Malikad778\\LaravelNexus\Events\ProductImported::class => [
        CreateLocalProductListener::class,
    ],
];

use Malikad778\\LaravelNexus\Traits\Syncable;

class Product extends Model
{
    use Syncable;
}

// Access channel mappings
$shopifyId = $product->channelMappings()->where('channel', 'shopify')->value('remote_id');

'dashboard_middleware' => ['web', 'auth'],
bash
php artisan vendor:publish --tag="nexus-config"
php artisan vendor:publish --tag="nexus-migrations"
php artisan migrate
bash
php artisan queue:work redis --queue=nexus,default