-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added ProductService V4 with method infoPrices (#58)
Added ProductService V4 with method infoPrices
- Loading branch information
1 parent
e70eb28
commit 4fe01ad
Showing
3 changed files
with
122 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}' | ||
]; | ||
} | ||
} |