diff --git a/bin/is_realized.php b/bin/is_realized.php index 2f401fc..e538808 100644 --- a/bin/is_realized.php +++ b/bin/is_realized.php @@ -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'], diff --git a/src/Service/V2/Posting/FbsService.php b/src/Service/V2/Posting/FbsService.php index 8ca6f84..76abf3a 100644 --- a/src/Service/V2/Posting/FbsService.php +++ b/src/Service/V2/Posting/FbsService.php @@ -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 { @@ -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 + */ + 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); + } } diff --git a/src/Service/V2/ProductService.php b/src/Service/V2/ProductService.php index ed6edbf..a1f9356 100644 --- a/src/Service/V2/ProductService.php +++ b/src/Service/V2/ProductService.php @@ -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) diff --git a/tests/Service/V2/Posting/FbsServiceTest.php b/tests/Service/V2/Posting/FbsServiceTest.php index e7d98e0..3ec65d0 100644 --- a/tests/Service/V2/Posting/FbsServiceTest.php +++ b/tests/Service/V2/Posting/FbsServiceTest.php @@ -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"}]}', + ]; + + } + }