PHP code example of chiragparekh / katana-php-sdk

1. Go to this page and download the library: Download chiragparekh/katana-php-sdk 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/ */

    

chiragparekh / katana-php-sdk example snippets




hirag\KatanaPhpSdk\Katana;

$katana = new Katana('your-api-token');

// Get all products with pagination
$products = $katana->products()->all();

foreach ($products as $product) {
    echo "Product: {$product->name} - SKU: {$product->sku}\n";
}

// Get products with specific query parameters
$products = $katana->products()->all(['page' => 1, 'per_page' => 50]);

$product = $katana->products()->get(1);
echo "Product Name: {$product->name}\n";
echo "Description: {$product->description}\n";

$newProduct = $katana->products()->create([
    'name' => 'New Product',
    'sku' => 'NP-001',
    'description' => 'A new product description',
    'type' => 'product',
    'sales_price' => 99.99,
    'purchase_price' => 50.00,
]);

echo "Created product with ID: {$newProduct->id}\n";

$updatedProduct = $katana->products()->update(1, [
    'name' => 'Updated Product Name',
    'sales_price' => 129.99,
    'description' => 'Updated description',
]);

echo "Updated product: {$updatedProduct->name}\n";

$katana->products()->delete(1);
echo "Product deleted successfully\n";

// List all sales orders
$salesOrders = $katana->salesOrders()->all();

// Create a new sales order
$salesOrder = $katana->salesOrders()->create([
    'customer_id' => 1,
    'location_id' => 1,
    'currency' => 'USD',
    'delivery_date' => '2024-12-31T08:00:00.000Z',
    'sales_order_rows' => [
        [
            'variant_id' => 1,
            'quantity' => 2,
            'price_per_unit' => 75.0,
            'tax_rate_id' => 1,
            'location_id' => 1,
        ]
    ]
]);

// Get returnable items for a sales order
$returnableItems = $katana->salesOrders()->getReturnableItems(1);

// List all manufacturing orders
$manufacturingOrders = $katana->manufacturingOrders()->all();

// Create a new manufacturing order
$manufacturingOrder = $katana->manufacturingOrders()->create([
    'variant_id' => 1,
    'planned_quantity' => 10,
    'location_id' => 1,
    'production_deadline_date' => '2024-12-31T08:00:00.000Z',
]);

// Get current inventory
$inventory = $katana->inventory()->all();

// Update reorder point
$reorderPoint = $katana->inventory()->updateReorderPoint([
    'variant_id' => 1,
    'location_id' => 1,
    'value' => 50,
]);

// Get variants with negative stock
$negativeStock = $katana->inventory()->negativeStock();

// List all BOM rows
$bomRows = $katana->bomRows()->all();

// Create a single BOM row
$bomRow = $katana->bomRows()->create([
    'product_item_id' => 1,
    'product_variant_id' => 1,
    'ingredient_variant_id' => 2,
    'quantity' => 3.5,
    'notes' => 'Main ingredient',
    'rank' => 10000,
]);

// Batch create multiple BOM rows
$batchBomRows = $katana->bomRows()->batchCreate([
    [
        'product_item_id' => 1,
        'product_variant_id' => 1,
        'ingredient_variant_id' => 2,
        'quantity' => 2.0,
        'rank' => 10000,
    ],
    [
        'product_item_id' => 1,
        'product_variant_id' => 1,
        'ingredient_variant_id' => 3,
        'quantity' => 1.5,
        'rank' => 20000,
    ]
]);

try {
    $product = $katana->products()->get(999);
} catch (Exception $e) {
    echo "Error: " . $e->getMessage();
}

// Get first page
$products = $katana->products()->all(['page' => 1]);

// Get specific page with custom per_page
$products = $katana->products()->all(['page' => 2, 'per_page' => 25]);

$product = $katana->products()->get(1);

// Access properties with full IDE support
echo $product->name;           // string
echo $product->salesPrice;     // float
echo $product->createdAt;      // string (ISO 8601 date)
echo $product->isActive;       // bool
bash
composer