Skip to content

Commit

Permalink
Added ProductService V4 with method infoPrices (#58)
Browse files Browse the repository at this point in the history
Added ProductService V4 with method infoPrices
  • Loading branch information
ElectroMyStyle committed Jul 6, 2022
1 parent e70eb28 commit 4fe01ad
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 0 deletions.
6 changes: 6 additions & 0 deletions bin/is_realized.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Gam6itko\OzonSeller\Service\V2\Posting\FbsService;
use Gam6itko\OzonSeller\Service\V2\ProductService as V2ProductService;
use Gam6itko\OzonSeller\Service\V2\ReturnsService as V2ReturnsService;
use Gam6itko\OzonSeller\Service\V4\ProductService as V4ProductService;
use GuzzleHttp\Client;

const MAPPING = [
Expand Down Expand Up @@ -47,6 +48,11 @@
'/v2/products/info/attributes' => [V2ProductService::class, 'infoAttributes'],
'/v2/returns/company/fbo' => [V2ReturnsService::class, 'company'],
'/v2/returns/company/fbs' => [V2ReturnsService::class, 'company'],

// V3 - TODO

// V4
'/v4/product/info/prices' => [V4ProductService::class, 'infoPrices'],
];

$client = new Client();
Expand Down
42 changes: 42 additions & 0 deletions src/Service/V4/ProductService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

declare(strict_types=1);

namespace Gam6itko\OzonSeller\Service\V4;

use Gam6itko\OzonSeller\Enum\Visibility;
use Gam6itko\OzonSeller\Service\AbstractService;
use Gam6itko\OzonSeller\Utils\ArrayHelper;

/**
* @author David Bakhmach <electroyoustyle@gmail.com>
*/
class ProductService extends AbstractService
{
private $path = '/v4/product';

/**
* Receive products prices info.
*
* @see https://docs.ozon.ru/api/seller/#operation/ProductAPI_GetProductInfoPricesV4
*
* @param array $requestData - ['filter' => array( 'offer_id' => array(string), 'product_id' => array(int|string), 'visibility' => string ), 'last_id' => string, 'limit' => int]
*
* @return array - ['items' => array, 'total' => int, 'last_id' => string]
*/
public function infoPrices(array $requestData = []) : array
{
$default = [
'filter' => [],
'last_id' => '',
'limit' => 100,
];

$requestData = array_merge(
$default,
ArrayHelper::pick($requestData, array_keys($default))
);

return $this->request('POST', "{$this->path}/info/prices", $requestData);
}
}
74 changes: 74 additions & 0 deletions tests/Service/V4/ProductServiceTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

declare(strict_types=1);

namespace Gam6itko\OzonSeller\Tests\Service\V4;

use Gam6itko\OzonSeller\Enum\Visibility;
use Gam6itko\OzonSeller\Service\V4\ProductService;
use Gam6itko\OzonSeller\Tests\Service\AbstractTestCase;

/**
* @coversDefaultClass \Gam6itko\OzonSeller\Service\V4\ProductService
*/
class ProductServiceTest extends AbstractTestCase
{
protected function getClass(): string
{
return ProductService::class;
}

/**
* @param array $productsFilter
* @param string $expectedJsonString
* @dataProvider dataInfoPrices
*/
public function testInfoPrices(array $productsFilter, string $expectedJsonString): void
{
$this->quickTest(
'infoPrices',
[$productsFilter],
[
'POST',
'/v4/product/info/prices',
$expectedJsonString
]
);
}

public function dataInfoPrices(): iterable
{
$arguments = [
'filter' => [
'visibility' => Visibility::ALL
],
'last_id' => '',
'limit' => 100
];
$offer_ids = [ '3244378', '1107890', 'PRD-1' ];
$product_ids = [ 243686911 ];

$arguments['filter']['offer_id'] = $offer_ids;
yield [
$arguments,

'{"filter":{"offer_id":["3244378","1107890","PRD-1"],"visibility":"ALL"},"last_id":"","limit":100}'
];

unset($arguments['filter']['offer_id']);
$arguments['filter']['product_id'] = $product_ids;
yield [
$arguments,

'{"filter":{"product_id":[243686911],"visibility":"ALL"},"last_id":"","limit":100}'
];

$arguments['filter']['offer_id'] = $offer_ids;
$arguments['filter']['product_id'] = $product_ids;
yield [
$arguments,

'{"filter":{"offer_id":["3244378","1107890","PRD-1"],"product_id":[243686911],"visibility":"ALL"},"last_id":"","limit":100}'
];
}
}

0 comments on commit 4fe01ad

Please sign in to comment.