Skip to content

Commit

Permalink
add /v2/posting/fbs/product/country/list and set methods, add tests (#98
Browse files Browse the repository at this point in the history
)

/v2/posting/fbs/product/country/list and set methods added
tests for /v2/fbs/posting/tracking-number/set added
wrong 'deprecated' tag removed from /v2/products/stocks
  • Loading branch information
exlh authored Feb 1, 2025
1 parent ab66274 commit 0806078
Show file tree
Hide file tree
Showing 4 changed files with 166 additions and 1 deletion.
2 changes: 2 additions & 0 deletions bin/is_realized.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
'/v2/posting/crossborder/cancel-reason/list' => [CrossborderService::class, 'cancelReasons'],
'/v2/posting/crossborder/shipping-provider/list' => [CrossborderService::class, 'shippingProviders'],
'/v2/posting/fbs/cancel-reason/list' => [FbsService::class.'cancelReasons'],
'/v2/posting/fbs/product/country/list' => [FbsService::class, 'productCountryList'],
'/v2/posting/fbs/product/country/set' => [FbsService::class, 'productCountrySet'],
'/v2/products/info/attributes' => [V2ProductService::class, 'infoAttributes'],
'/v2/returns/company/fbo' => [V2ReturnsService::class, 'company'],
'/v2/returns/company/fbs' => [V2ReturnsService::class, 'company'],
Expand Down
42 changes: 42 additions & 0 deletions src/Service/V2/Posting/FbsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@
* offset?: int,
* limit?: int,
* }
* @psalm-type TCountry = array{
* name: string,
* country_iso_code: string,
* }
* @psalm-type TProductCountrySetResponse = array{
* product_id: int,
* is_gtd_needed: bool,
* }
*/
class FbsService extends AbstractService implements HasOrdersInterface, HasUnfulfilledOrdersInterface, GetOrderInterface
{
Expand Down Expand Up @@ -336,4 +344,38 @@ public function digitalActGetPdf(int $id, string $docType): array
'doc_type' => $docType,
]);
}

/**
* Receive list of manufacturing countries.
*
* @see https://docs.ozon.ru/api/seller/en/#operation/PostingAPI_ChangeFbsPostingProduct
*
* @return list<TCountry>
*/
public function productCountryList(string $nameSearch): array
{
$body = [
'name_search' => $nameSearch,
];

return $this->request('POST', "{$this->path}/product/country/list", $body);
}

/**
* Set the manufacturing country.
*
* @see https://docs.ozon.ru/api/seller/en/#operation/PostingAPI_SetCountryProductFbsPostingV2
*
* @return TProductCountrySetResponse
*/
public function productCountrySet(string $postingNumber, int $productId, string $countryIsoCode): array
{
$body = [
'posting_number' => $postingNumber,
'product_id' => $productId,
'country_iso_code' => $countryIsoCode,
];

return $this->request('POST', "{$this->path}/product/country/set", $body);
}
}
1 change: 0 additions & 1 deletion src/Service/V2/ProductService.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ public function infoPrices(array $pagination = [])
*
* @return array
*
* @deprecated use V3\ProductService::infoStocks
* @see https://docs.ozon.ru/api/seller/#operation/ProductAPI_ProductsStocksV2
*/
public function importStocks(array $input)
Expand Down
122 changes: 122 additions & 0 deletions tests/Service/V2/Posting/FbsServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,4 +283,126 @@ public function testDigitalActGetPdf(): void
])
);
}

/**
* @covers ::productCountryList
*/
public function testProductCountryList(): void
{
$this->quickTest(
'productCountryList',
[
'Китай',
],
[
'POST',
'/v2/posting/fbs/product/country/list',
'{"name_search":"Китай"}',
],
\json_encode([
[
'name' => 'Китайская Республика',
'country_iso_code' => 'TW',
],
[
'name' => 'Китай (Китайская Народная Республика)',
'country_iso_code' => 'CN',
],
]),
static function ($result): void {
self::assertCount(2, $result);
self::assertArrayHasKey('name', $result[0]);
self::assertArrayHasKey('country_iso_code', $result[0]);
self::assertEquals('CN', $result[1]['country_iso_code']);
}
);
}

/**
* @covers ::productCountrySet
*/
public function testProductCountrySet(): void
{
$this->quickTest(
'productCountrySet',
[
'57195475-0050-3',
180550365,
'NO',
],
[
'POST',
'/v2/posting/fbs/product/country/set',
'{"posting_number":"57195475-0050-3","product_id":180550365,"country_iso_code":"NO"}',
],
\json_encode([
'product_id' => 180550365,
'is_gtd_needed' => true,
]),
static function ($result): void {
self::assertCount(2, $result);
self::assertArrayHasKey('product_id', $result);
self::assertArrayHasKey('is_gtd_needed', $result);
self::assertEquals(180550365, $result['product_id']);
self::assertTrue($result['is_gtd_needed']);
}
);
}

/**
* @covers ::setTrackingNumber
*
* @dataProvider dataSetTrackingNumber
*/
public function testSetTrackingNumber(array $productsFilter, string $expectedJsonString): void
{
$this->quickTest(
'setTrackingNumber',
$productsFilter,
[
'POST',
'/v2/fbs/posting/tracking-number/set',
$expectedJsonString,
]
);
}

public function dataSetTrackingNumber(): iterable
{
$arguments = [
'trackingNumbers' => [
[
'posting_number' => '48173252-0033-2',
'tracking_number' => '123123123',
],
[
'posting_number' => '48173251-0021-1',
'tracking_number' => '3214567-Fa',
],
],
];
yield [
$arguments,
'{"tracking_numbers":[{"posting_number":"48173252-0033-2","tracking_number":"123123123"},{"posting_number":"48173251-0021-1","tracking_number":"3214567-Fa"}]}',
];

$arguments['trackingNumbers'][1]['extra_data'] = 'useless value';
yield [
$arguments,
'{"tracking_numbers":[{"posting_number":"48173252-0033-2","tracking_number":"123123123"},{"posting_number":"48173251-0021-1","tracking_number":"3214567-Fa"}]}',
];

$arguments = [
'trackingNumbers' => [
'posting_number' => '48173252-0033-2',
'tracking_number' => '123123123',
],
];
yield [
$arguments,
'{"tracking_numbers":[{"posting_number":"48173252-0033-2","tracking_number":"123123123"}]}',
];

}

}

0 comments on commit 0806078

Please sign in to comment.