1. Go to this page and download the library: Download texhub/moy-sklad 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/ */
texhub / moy-sklad example snippets
use TexHub\MoySklad\MoySklad;
use TexHub\MoySklad\Query;
$ms = MoySklad::withToken('YOUR_ACCESS_TOKEN');
// or: MoySklad::withLogin('login', 'password');
// List products with stock-friendly query:
$products = $ms->products()->list(
Query::make()->limit(50)->filter('archived', '=', 'false')->expand('images')->search('iphone')
);
foreach ($products->rows() as $product) {
echo $product['name'] . ' — ' . ($product['code'] ?? '') . PHP_EOL;
}
$token = MoySklad::withLogin('login', 'password')->tokens()->create();
// store $token and reuse it
// Create with description and a sale price:
$product = $ms->products()->create([
'name' => 'Смартфон X',
'code' => 'SKU-001',
'article' => 'ART-001',
'description' => 'Полное описание товара…',
'salePrices' => [['value' => 999000, 'priceType' => ['meta' => ['href' => $priceTypeHref, 'type' => 'pricetype', 'mediaType' => 'application/json']]]],
]);
// Update:
$ms->products()->update($product->id(), ['description' => 'Обновлённое описание']);
// Images:
$ms->products()->images($product->id()); // list
$ms->products()->addImageFromFile($product->id(), '/path/photo.jpg');
$ms->products()->addImage($product->id(), 'photo.jpg', $binary); // base64 handled for you
$ms->products()->deleteImage($product->id(), $imageId);
$ms->reports()->stockAll(); // отчёт «Остатки» по всем товарам
$ms->reports()->stockByStore(); // остатки по складам
$ms->reports()->assortment(Query::make()->limit(100)); // товары+модификации+услуги со складскими данными
$ms->counterparties()->list();
$ms->customerOrders()->get($orderId, Query::make()->expand('positions', 'agent'));
$ms->entity('demand')->create([...]); // any MoySklad entity type
$ms->entity('store')->metadata();