baks-dev/yandex-market-products
Модуль интеграции продукции с Yandex Market для проектов BaksDev: установка через Composer, установка ассетов и конфигурации, миграции Doctrine, запуск тестов PHPUnit (group yandex-market-products). Требует PHP 8.4+.
Installation
composer require baks-dev/yandex-market baks-dev/yandex-market-products
php bin/console baks:assets:install
php bin/console doctrine:migrations:diff
php bin/console doctrine:migrations:migrate
Publish Config Publish the default config to customize API keys, endpoints, or behavior:
php bin/console config:dump-reference | grep yandex_market
Or manually publish:
php artisan vendor:publish --provider="BaksDev\YandexMarketProducts\YandexMarketProductsServiceProvider" --tag="config"
First Use Case Fetch a product by ID:
use BaksDev\YandexMarketProducts\Client\YandexMarketClient;
use BaksDev\YandexMarketProducts\Services\ProductService;
$client = app(YandexMarketClient::class);
$productService = app(ProductService::class);
$product = $productService->getProductById(12345); // Replace with a real Yandex Market product ID
Product Management
// Get a single product
$product = $productService->getProductById($id);
// Search products (with optional filters)
$products = $productService->searchProducts(['query' => 'laptop', 'limit' => 10]);
ProductBulkService for batch operations (e.g., updating prices or inventory):
$bulkService = app(ProductBulkService::class);
$results = $bulkService->updatePrices([123, 456, 789], 19.99);
Integration with Laravel Ecosystem
SyncProductsJob::dispatch()->onQueue('yandex_market');
public function handle(ProductSynced $event) {
// Log or process synced product
}
Caching Strategies
$product = Cache::remember("yandex_product_{$id}", now()->addHours(1), function() use ($id) {
return $productService->getProductById($id);
});
API Rate Limiting
$client->setRetryOptions(['max_retries' => 3, 'delay' => 1000]);
API Key Management
YANDEX_MARKET_API_KEY is set in .env or config. Hardcoding keys in code violates security best practices.env() helper or config() to access keys:
$apiKey = config('services.yandex_market.api_key');
Rate Limits and Throttling
429 Too Many Requests) and implement exponential backoff.$client->setLogger(app(\Monolog\Logger::class)->withName('yandex_market'));
Data Mismatches
if (!isset($response['data']['id'])) {
throw new \RuntimeException('Invalid product data format');
}
Time Zone Handling
$createdAt = Carbon::parse($product['created_at'])->timezone('Europe/Moscow');
Enable Debug Mode
Set YANDEX_MARKET_DEBUG=true in .env to log raw API responses:
$client->setDebug(true);
Test Locally with Mocks Use Laravel’s HTTP client mocking to test without hitting the real API:
$mock = Mockery::mock(\Illuminate\Http\Client\PendingRequest::class);
$mock->shouldReceive('get')->andReturn(response()->json(['data' => []]));
$this->app->instance(\Illuminate\Http\Client\PendingRequest::class, $mock);
Database Schema Conflicts
order) in Yandex Market’s response fields. Rename columns in your schema:
Schema::table('yandex_products', function (Blueprint $table) {
$table->renameColumn('order', 'sort_order');
});
Custom Response Transformers
Extend BaksDev\YandexMarketProducts\Transformers\ProductTransformer to map API fields to your domain model:
class CustomProductTransformer extends ProductTransformer {
public function transform($data) {
$data['custom_field'] = $this->mapCustomField($data);
return parent::transform($data);
}
}
Webhook Handling Implement a webhook listener for real-time updates (if Yandex Market supports it):
Route::post('/yandex-market/webhook', [YandexMarketWebhookController::class, 'handle']);
Custom Sync Logic
Override the default sync behavior in YandexMarketProductsServiceProvider:
$this->app->bind(ProductService::class, function ($app) {
return new CustomProductService($app->make(YandexMarketClient::class));
});
How can I help you explore Laravel packages today?