PHP code example of evgeek / moysklad

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

    

evgeek / moysklad example snippets


use Evgeek\Moysklad\Api\Record\Objects\Entities\Product;
use Evgeek\Moysklad\MoySklad;

$ms = new MoySklad(['token']);

//Конструктор запросов
$product = $ms->query()
    ->entity()
    ->product()
    ->byId('25cf41f2-b068-11ed-0a80-0e9700500d7e')
    ->get();

//Active Record
$product = Product::make($ms);
$product->id = '25cf41f2-b068-11ed-0a80-0e9700500d7e';
$product->get();
//Или
$product = Product::make($ms, ['id' => '25cf41f2-b068-11ed-0a80-0e9700500d7e'])->get();

$products = $ms->query()
    ->entity()
    ->product()
    ->order('name')
    ->limit(3)
    ->get();

foreach ($products as $product) {
    var_dump($product->name);
}

Product::collection($ms)
    ->eachGenerator(function (Product $product) {
        $product->name = mb_strtoupper($product->name);
        $product->update();
    });