Skip to content

Commit

Permalink
Merge pull request #7 from va-fursenko/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
va-fursenko authored May 21, 2020
2 parents 2259fc9 + 4b48081 commit b589a3a
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 7 deletions.
20 changes: 15 additions & 5 deletions src/Client/EntityClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
namespace MoySklad\Client;

use MoySklad\ApiClient;
use MoySklad\Entity\Meta;
use MoySklad\Http\RequestExecutor;
use MoySklad\Util\Exception\ApiClientException;

class EntityClient
{
Expand Down Expand Up @@ -144,11 +147,6 @@ public function group(): GroupClient
return new GroupClient($this->api);
}

public function image(): ImageClient
{
return new ImageClient($this->api);
}

/**
* @return OrganizationClient
*/
Expand Down Expand Up @@ -276,4 +274,16 @@ public function getEntityByClass(string $class): string
$class = explode('\\', $class);
return array_pop($class);
}

/**
* Получение модели по её мета-данным
*
* @param Meta $meta
* @return object
* @throws ApiClientException
*/
public function getByMeta(Meta $meta): object
{
return RequestExecutor::path($this->api, $meta->href)->get($meta->getClassName());
}
}
46 changes: 46 additions & 0 deletions src/Client/StockClient.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace MoySklad\Client;

use MoySklad\ApiClient;
use MoySklad\Client\Endpoint\GetEntitiesListEndpoint;
use MoySklad\Client\Endpoint\GetEntityEndpoint;
use MoySklad\Client\Endpoint\GetMetadataAttributeEndpoint;
use MoySklad\Client\Endpoint\GetMetadataEndpoint;
use MoySklad\Entity\Stock;

/**
* Class StockClient
* @package MoySklad\Client
*
* Клиент работы с отчётом остатков
*
* @copyright CDEK.MARKET, Ltd. (ООО «СДЭК.МАРКЕТ» http://cdek.market)
* @project ms-lib
* @date 20.05.2020 14:23
* @author Viktor.Fursenko
*/
class StockClient extends EntityClientBase
{
use GetEntitiesListEndpoint,
GetMetadataEndpoint,
GetMetadataAttributeEndpoint,
GetEntityEndpoint;

/**
* ServiceClient constructor.
* @param ApiClient $api
*/
public function __construct(ApiClient $api)
{
parent::__construct($api, '/report/stock/all');
}

/**
* @return string
*/
protected function getMetaEntityClass(): string
{
return Stock::class;
}
}
8 changes: 8 additions & 0 deletions src/Entity/Characteristic.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,12 @@ class Characteristic
* @Generator()
*/
public $value;

/**
* @return Meta|null
*/
public function getMeta(): ?Meta
{
return $this->meta;
}
}
19 changes: 19 additions & 0 deletions src/Entity/Meta.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,23 @@ public static function getClassNameByType(string $type): string

return self::TYPES[$type];
}

/**
* @return string
*/
public function getClassName(): string
{
return static::getClassNameByType($this->type);
}

/**
* id не всегда передаётся в объекты, зато всегда есть в ссылке на объект в мета-данных
*
* @return string
*/
public function getId() : string
{
$href = explode('/', $this->href);
return end($href);
}
}
4 changes: 2 additions & 2 deletions src/Entity/StockTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
* @package MoySklad\Entity
*
* Трейт сущностей, которые хранятся на складе - товары и варианты
* Данные поля по большей части используются только в отчёте остатков. Но поскольку у нас формат респонса типизованный
* и вендор задал тип Product или Variant, то придётся добавить в них все когда-либо использованные поля
* Данные поля по большей части используются только в отчёте остатков и ассортименте, но отсутствуют в списке товаров
* Но поскольку у нас формат респонса типизованный и вендор задал тип Product или Variant, то придётся добавить в них все когда-либо использованные поля
*
* При этом, на них нельзя повесить генераторы для тестов, потому что тогда упадут тесты создания базовых сущностей
* А уж как тогда тестировать отчёты... разве что только руками
Expand Down

0 comments on commit b589a3a

Please sign in to comment.