gam6itko / ozon-seller
Ozon Seller Api for transhore sales
Installs: 39 465
Dependents: 0
Suggesters: 0
Security: 0
Stars: 75
Watchers: 10
Forks: 38
Open Issues: 3
Requires
- php: >=7.1
- ext-json: *
- psr/http-client: ^1.0
Requires (Dev)
- ext-curl: *
- dg/bypass-finals: ^1.2
- friendsofphp/php-cs-fixer: ^3.0
- guzzlehttp/psr7: ^1.6
- http-interop/http-factory-guzzle: ^1.0
- nyholm/psr7: ^1.3
- php-http/guzzle6-adapter: ^2.0
- phpunit/phpunit: ^7.4||^8.0||^9.0
- symfony/http-client: ^4.1||^5.1
- vimeo/psalm: ^4.0||^5.13
- vlucas/phpdotenv: ^5.3
Suggests
- nyholm/psr7: For use with Symfony
- php-http/guzzle6-adapter: For use not with Symfony
- symfony/http-client: For use with Symfony
- v0.13.0
- v0.12.0
- v0.11.0
- v0.10.0
- dev-master / 0.9.x-dev
- v0.9.4
- v0.9.3
- v0.9.2
- v0.9.1
- v0.9
- v0.8.21
- v0.8.20
- v0.8.19
- v0.8.18
- v0.8.17
- v0.8.16
- v0.8.15
- v0.8.14
- v0.8.13
- v0.8.12
- v0.8.11
- v0.8.10
- v0.8.9
- v0.8.8
- v0.8.7
- v0.8.6
- v0.8.5
- v0.8.4
- v0.8.3
- v0.8.2
- v0.8.1
- v0.8.0
- v0.7.3
- v0.7.2
- v0.7.1
- v0.7.0
- v0.6.0
- v0.5.4
- v0.5.3
- v0.5.2
- v0.5.1
- v0.5.0
- v0.4.5
- v0.4.4
- v0.4.3
- v0.4.2
- v0.4.1
- v0.4.0
- v0.3.0
- v0.2.6
- v0.2.5
- v0.2.4
- v0.2.3
- v0.2.2
- v0.2.1
- v0.2.0
- v0.1.6
- v0.1.5
- v0.1.4
- v0.1.3
- v0.1.2
- v0.1.1
- v0.1.0
- dev-issue71
- dev-issue70
- dev-test-fix
- dev-empty_object
This package is auto-updated.
Last update: 2024-11-30 20:47:01 UTC
README
Документация Ozon Api
https://docs.ozon.ru/api/seller
Установка
composer require gam6itko/ozon-seller
Для взаимодействия библиотеки с Ozon-Api нужно дополнительно установить реализации PSR-18: HTTP Client и PSR-17: HTTP Factories.
Использование с Symfony
https://symfony.com/doc/current/components/http_client.html#psr-18-and-psr-17
composer require symfony/http-client composer require nyholm/psr7
use Gam6itko\OzonSeller\Service\V1\ProductService; use Symfony\Component\HttpClient\Psr18Client; $config = [$_SERVER['CLIENT_ID'], $_SERVER['API_KEY'], $_SERVER['API_URL']]; $client = new Psr18Client(); $svc = new ProductService($config, $client); //do stuff
Использование без Symfony
composer require php-http/guzzle6-adapter
use Gam6itko\OzonSeller\Service\V1\CategoriesService; use GuzzleHttp\Client as GuzzleClient; use Http\Adapter\Guzzle6\Client as GuzzleAdapter; use Http\Factory\Guzzle\RequestFactory; use Http\Factory\Guzzle\StreamFactory; $config = [ 'clientId' => '<ozon seller client-id>', 'apiKey' => '<ozon seller api-key>', 'host' => 'http://cb-api.ozonru.me/' ]; $client = new GuzzleAdapter(new GuzzleClient()); $requestFactory = new RequestFactory(); $streamFactory = new StreamFactory(); $svc = new CategoriesService($config, $client, $requestFactory, $streamFactory); //do stuff
Реализованные методы
Чтобы узнать какой класс и метод реализуют запрос на нужный URL воспользуйтесь скриптом bin/is_realized.php
php bin/is_realized.php | grep /v2/posting/fbs/get
output
/v2/posting/fbs/get: Gam6itko\OzonSeller\Service\V2\Posting\FbsService::get /v2/posting/fbs/get-by-barcode: NotRealized
Автор не всегда успевает добавлять реализации новых методов. Если нужного вам метода нет в библиотеке, то не стесняйтесь открыть issue или PR.
Примеры использования
Больше примеров смотрите в папке tests/Service/
Categories
use Gam6itko\OzonSeller\Service\V1\CategoriesService; use GuzzleHttp\Client as GuzzleClient; use Http\Adapter\Guzzle6\Client as GuzzleAdapter; $config = [ 'clientId' => '<ozon seller client-id>', 'apiKey' => '<ozon seller api-key>', 'host' => 'http://cb-api.ozonru.me/' //sandbox ]; $adapter = new GuzzleAdapter(new GuzzleClient()); $svc = new CategoriesService($config, $adapter); //Server Response example: https://cb-api.ozonru.me/apiref/en/#t-title_categories $categoryTree = $svc->tree(); //Server Response example: https://cb-api.ozonru.me/apiref/en/#t-title_get_categories_attributes $attributes = $svc->attributes(17038826);
Posting Crossborder
get info
/v2/posting/crossborder/get
use Gam6itko\OzonSeller\Service\V2\Posting\CrossborderService; use GuzzleHttp\Client as GuzzleClient; use Http\Adapter\Guzzle6\Client as GuzzleAdapter; $config = [ 'clientId' => '<ozon seller client-id>', 'apiKey' => '<ozon seller api-key>', 'host' => 'http://cb-api.ozonru.me/' ]; $adapter = new GuzzleAdapter(new GuzzleClient()); $svc = new CrossborderService($config, $adapter); $postingNumber = '39268230-0002-3'; $orderArr = $svc->get($postingNumber); echo json_encode($orderArr);
{ "result": [ { "address": { "address_tail": "г. Москва, ул. Центральная, 1", "addressee": "Петров Иван Владимирович", "city": "Москва", "comment": "", "country": "Россия", "district": "", "phone": "+7 495 123-45-67", "region": "Москва", "zip_code": "101000" }, "auto_cancel_date": "2019-11-18T11:30:11.571Z", "cancel_reason_id": 76, "created_at": "2019-11-18T11:30:11.571Z", "customer_email": "petrov@email.com", "customer_id": 60006, "in_process_at": "2019-11-18T11:30:11.571Z", "order_id": 77712345, "order_nr": "1111444", "posting_number": "39268230-0002-3", "products": [ { "name": "Фитнес-браслет", "offer_id": "DEP-1234", "price": "1900.00", "quantity": 1, "sku": 100056 } ], "shipping_provider_id": 0, "status": "awaiting_approve", "tracking_number": "" } ] }
Products
import
/v1/product/import
use Gam6itko\OzonSeller\Service\V1\ProductService; use GuzzleHttp\Client as GuzzleClient; use Http\Adapter\Guzzle6\Client as GuzzleAdapter; $config = [ 'clientId' => '<ozon seller client-id>', 'apiKey' => '<ozon seller api-key>', // use prod host by default ]; $adapter = new GuzzleAdapter(new GuzzleClient()); $svcProduct = new ProductService($config, $adapter); $product = [ 'barcode' => '8801643566784', 'description' => 'Red Samsung Galaxy S9 with 512GB', 'category_id' => 17030819, 'name' => 'Samsung Galaxy S9', 'offer_id' => 'REDSGS9-512', 'price' => '79990', 'old_price' => '89990', 'premium_price' => '75555', 'vat' => '0', 'vendor' => 'Samsung', 'vendor_code' => 'SM-G960UZPAXAA', 'height' => 77, 'depth' => 11, 'width' => 120, 'dimension_unit' => 'mm', 'weight' => 120, 'weight_unit' => 'g', 'images' => [ [ 'file_name' => 'https://ozon-st.cdn.ngenix.net/multimedia/c1200/1022555115.jpg', 'default' => true, ], [ 'file_name' => 'https://ozon-st.cdn.ngenix.net/multimedia/c1200/1022555110.jpg', 'default' => false, ], [ 'file_name' => 'https://ozon-st.cdn.ngenix.net/multimedia/c1200/1022555111.jpg', 'default' => false, ], ], 'attributes' => [ [ 'id' => 8229, 'value' => '4747', ], [ 'id' => 9048, 'value' => 'Samsung Galaxy S9', ], [ 'id' => 4742, 'value' => '512 ГБ', ], [ 'id' => 4413, 'collection' => ['1', '2', '13'], ], [ 'id' => 4018, 'complex_collection' => [ [ 'collection' => [ [ 'id' => 4068, 'value' => 'Additional video', ], [ 'id' => 4074, 'value' => '5_-NKRVn7IQ', ], ], ], [ 'collection' => [ [ 'id' => 4068, 'value' => 'Another one video', ], [ 'id' => 4074, 'value' => '5_-NKRVn7IQ', ], ], ], ], ], ], ]; $svcProduct->import($product); // or $svcProduct->import([$product, $product1, $product2, ...]); // or $res = $svcProduct->import(['items' => [$product, $product1, $product2, ...] ]); echo $res['task_id']; // save it for checking by `importInfo`