diff --git a/src/Service/ProductsService.php b/src/Service/ProductsService.php index f2b4bb3..e903d10 100755 --- a/src/Service/ProductsService.php +++ b/src/Service/ProductsService.php @@ -47,16 +47,6 @@ public function classify(array $income) return $this->request('POST', '/v1/product/classify', ['body' => \GuzzleHttp\json_encode($income)]); } - /** - * @deprecated v0.2 use import - */ - public function create(array $income, bool $validateBeforeSend = true) - { - @trigger_error('Method `create` deprecated. Use `import`', E_USER_DEPRECATED); - - return $this->import($income, $validateBeforeSend); - } - /** * Creates product page in our system. * @@ -128,16 +118,6 @@ public function importBySku(array $income) return $this->request('POST', '/v1/product/import-by-sku', ['body' => \GuzzleHttp\json_encode($income)]); } - /** - * @deprecated since 0.2.2. use importInfo - */ - public function creationStatus(int $taskId) - { - @trigger_error(sprintf('Call deprecated method `creationStatus` use `importInfo` instead'), E_USER_DEPRECATED); - - return $this->importInfo($taskId); - } - /** * Product creation status. * @@ -197,7 +177,7 @@ public function infoBy(array $query) * * @return array */ - public function stockInfo(array $pagination = []) + public function infoStocks(array $pagination = []) { $pagination = array_merge( ['page' => 1, 'page_size' => 100], @@ -216,7 +196,7 @@ public function stockInfo(array $pagination = []) * * @return array */ - public function pricesInfo(array $pagination = []) + public function infoPrices(array $pagination = []) { $pagination = array_merge( ['page' => 1, 'page_size' => 100], @@ -257,7 +237,7 @@ public function list(array $filter = [], array $pagination = []) * * @return array */ - public function updatePrices(array $prices) + public function importPrices(array $prices) { foreach ($prices as &$p) { $p = $this->faceControl($p, ['product_id', 'offer_id', 'price', 'old_price', 'premium_price']); @@ -287,7 +267,7 @@ public function updatePrices(array $prices) * * @return array */ - public function updateStocks(array $stocks) + public function importStocks(array $stocks) { if (array_key_exists('stocks', $stocks)) { trigger_error('You should pass stocks arg without stocks key', E_USER_NOTICE); @@ -399,7 +379,7 @@ public function price(array $filter = [], array $pagination = []) } /** - * @see https://cb-api.ozonru.me/apiref/ru/#t-prepayment_set + * @see https://cb-api.ozonru.me/apiref/en/#t-prepayment_set * * @param array $data ['is_prepayment', 'offers_ids', 'products_ids'] * @@ -411,4 +391,60 @@ public function setPrepayment(array $data) return $this->request('POST', '/v1/product/prepayment/set', ['body' => \GuzzleHttp\json_encode($data)]); } + + // + + /** + * @deprecated since v0.2.6 and will be deleted in v0.3. use `importPrices`. + */ + public function updatePrices(array $prices) + { + return $this->importPrices($prices); + } + + /** + * @deprecated since v0.2.6 and will be deleted in v0.3. use `importStocks`. + */ + public function updateStocks(array $stocks) + { + return $this->importStocks($stocks); + } + + /** + * @deprecated since v0.2.6 and will be deleted in v0.3. use `infoStocks`. + */ + public function stockInfo(array $pagination = []) + { + return $this->infoStocks($pagination); + } + + /** + * @deprecated since v0.2.6 and will be deleted in v0.3. use `infoPrices`. + */ + public function pricesInfo(array $pagination = []) + { + return $this->infoPrices($pagination); + } + + /** + * @deprecated since 0.2.2 and will be deleted in v0.3. use `importInfo` + */ + public function creationStatus(int $taskId) + { + @trigger_error(sprintf('Call deprecated method `creationStatus` use `importInfo` instead'), E_USER_DEPRECATED); + + return $this->importInfo($taskId); + } + + /** + * @deprecated v0.2 and will be deleted in v0.3. use `import` + */ + public function create(array $income, bool $validateBeforeSend = true) + { + @trigger_error('Method `create` deprecated. Use `import`', E_USER_DEPRECATED); + + return $this->import($income, $validateBeforeSend); + } + + // } diff --git a/src/Service/Seller/ActionsService.php b/src/Service/Seller/ActionsService.php new file mode 100644 index 0000000..8fdab13 --- /dev/null +++ b/src/Service/Seller/ActionsService.php @@ -0,0 +1,101 @@ + + */ +class ActionsService extends AbstractService +{ + private $path = '/sa/v1/actions'; + + public function __construct(int $clientId, string $apiKey, string $host = 'https://seller-api.ozon.ru/') + { + parent::__construct($clientId, $apiKey, $host); + } + + /** + * Promotional offers list. + * + * @see https://cb-api.ozonru.me/apiref/en/#t-title_action_available + */ + public function list(): array + { + return $this->request('GET', $this->path); + } + + /** + * List of products which can participate in the promotional offer. + * + * @see https://cb-api.ozonru.me/apiref/en/#t-title_action_available_products + */ + public function candidates(int $actionId, int $offset = 0, int $limit = 10): array + { + $body = [ + 'action_id' => $actionId, + 'offset' => $offset, + 'limit' => $limit, + ]; + + return $this->request('POST', "{$this->path}/candidates", ['body' => \GuzzleHttp\json_encode($body)]); + } + + /** + * List of products which participate in the promotional offer. + * + * @see https://cb-api.ozonru.me/apiref/en/#t-title_action_products + */ + public function products(int $actionId, int $offset = 0, int $limit = 10) + { + $body = [ + 'action_id' => $actionId, + 'offset' => $offset, + 'limit' => $limit, + ]; + + return $this->request('POST', "{$this->path}/products", ['body' => \GuzzleHttp\json_encode($body)]); + } + + /** + * Add product to the promotional offer. + * + * @see https://cb-api.ozonru.me/apiref/en/#t-title_action_add_products + */ + public function productsActivate(int $actionId, array $products): array + { + if (array_key_exists('product_id', $products)) { + $products = [$products]; + } + + foreach ($products as &$p) { + $p = $this->faceControl($p, ['product_id', 'action_price']); + } + unset($p); + + $body = [ + 'action_id' => $actionId, + 'products' => $products, + ]; + + return $this->request('POST', "{$this->path}/products/activate", ['body' => \GuzzleHttp\json_encode($body)]); + } + + /** + * This method allows to delete products from the promotional offer. + * + * @see https://cb-api.ozonru.me/apiref/en/#t-title_action_add_products + */ + public function productsDeactivate(int $actionId, array $productIds): array + { + $body = [ + 'action_id' => $actionId, + 'product_ids' => $productIds, + ]; + + return $this->request('POST', "{$this->path}/products/deactivate", ['body' => \GuzzleHttp\json_encode($body)]); + } +} diff --git a/tests/ApiReferenceTest.php b/tests/ApiReferenceTest.php index 64a266c..814161c 100644 --- a/tests/ApiReferenceTest.php +++ b/tests/ApiReferenceTest.php @@ -10,6 +10,7 @@ use Gam6itko\OzonSeller\Service\Posting\FbsService; use Gam6itko\OzonSeller\Service\ProductsService; use Gam6itko\OzonSeller\Service\ReportService; +use Gam6itko\OzonSeller\Service\Seller\ActionsService; use PHPHtmlParser\Dom; use PHPUnit\Framework\TestCase; @@ -18,6 +19,10 @@ */ class ApiReferenceTest extends TestCase { + const IGNORE_PREFIXES = [ + '/v1/order', + ]; + const CONFIG = [ CategoriesService::class => [ 'prefix' => '/v1/category', @@ -26,24 +31,20 @@ class ApiReferenceTest extends TestCase ], ], ChatService::class => ['prefix' => '/v1/chat'], - OrderService::class => [ - 'prefix' => '/v1/order', - 'mapping' => [ - '123456?translit=true' => 'info', - 'approve/crossborder' => 'approve', - 'cancel-reason/list' => 'itemsCancelReasons', - 'cancel/fbs' => 'itemsCancelFbs', - 'items/cancel/crossborder' => 'itemsCancelCrossboarder', - 'shipping-provider/list' => 'shippingProviders', - ], - ], +// OrderService::class => [ +// 'prefix' => '/v1/order', +// 'mapping' => [ +// '123456?translit=true' => 'info', +// 'approve/crossborder' => 'approve', +// 'cancel-reason/list' => 'itemsCancelReasons', +// 'cancel/fbs' => 'itemsCancelFbs', +// 'items/cancel/crossborder' => 'itemsCancelCrossboarder', +// 'shipping-provider/list' => 'shippingProviders', +// ], +// ], ProductsService::class => [ 'prefix' => '/v1/product', 'mapping' => [ - 'import/prices' => 'updatePrices', //todo rename - 'import/stocks' => 'updateStocks', //todo rename - 'info/prices' => 'pricesInfo', //todo rename - 'info/stocks' => 'stockInfo', //todo rename 'prepayment/set' => 'setPrepayment', ], ], @@ -71,6 +72,13 @@ class ApiReferenceTest extends TestCase 'cancel-reason/list' => 'cancelReasons', ], ], + //Seller + ActionsService::class => [ + 'prefix' => '/sa/v1/actions', + 'mapping' => [ + '' => 'list', + ], + ], ]; /** @@ -107,6 +115,12 @@ public function testActualRealization() private function isRealized($path): bool { + foreach (self::IGNORE_PREFIXES as $ignore) { + if (0 === strpos($path, $ignore)) { + return true; + } + } + foreach (self::CONFIG as $class => $config) { if (0 !== strpos($path, $config['prefix'])) { continue;