baks-dev/wildberries-products
Модуль продукции Wildberries для PHP 8.4+: установка через Composer, установка ресурсов (baks:assets:install) и обновление схемы БД через Doctrine migrations. Подходит для интеграции и управления каталогом Wildberries в проекте.
composer require baks-dev/wildberries-products
php artisan baks:assets:install
php artisan doctrine:migrations:migrate
php artisan --group=wildberries-orders
use BaksDev\WildberriesProducts\Facades\Wildberries;
// Fetch a product by Wildberries' internal ID
$product = Wildberries::product()->find(123456789);
// Sync to your database
$syncResult = $product->sync();
config/wildberries.php (auto-published by baks:assets:install).app/Console/Commands/Wildberries* for bulk operations.app/Models/WildberriesProduct.php (core entity).tests/Feature/Wildberries* for integration examples.$products = Wildberries::product()->search(['query' => 'smartphone']);
foreach ($products as $wbProduct) {
$wbProduct->sync(); // Maps to your DB schema
}
event(new ProductSynced($wbProduct));
// Trigger after sync
event(new InventoryUpdated($wbProduct->sku, $wbProduct->stock));
$historicalPrices = Wildberries::price()->history($wbProduct->id);
// Listen for Wildberries API webhook events
Route::post('/wildberries/webhook', [WildberriesWebhookHandler::class, 'handle']);
Use Laravel Queues for large syncs:
// Dispatch a job to sync all products
SyncWildberriesProducts::dispatch();
// In the job:
public function handle() {
$products = Wildberries::product()->all();
foreach ($products as $product) {
$product->sync();
}
}
Extend the base model to handle Wildberries-specific fields:
use BaksDev\WildberriesProducts\Models\WildberriesProduct as BaseProduct;
class ExtendedWildberriesProduct extends BaseProduct
{
protected $casts = [
'wildberries_seller_id' => 'integer',
'wildberries_category_id' => 'integer',
];
public function getCustomAttribute($key) {
return $this->attributes["wb_{$key}"] ?? null;
}
}
Schema Conflicts:
article for SKUs, but your system might use sku. Override the getSkuAttribute() method in the model:
public function getSkuAttribute() {
return $this->article ?? $this->wb_sku;
}
php artisan doctrine:migrations:diff before migrating to preview changes.API Rate Limits:
SyncWildberriesProducts::dispatch()->delay(now()->addMinutes(1));
Localization Issues:
nm_gtin for GTIN). Ensure your DB supports UTF-8 and collations like utf8mb4_unicode_ci.Console Command Dependencies:
baks:assets:install may fail if the public/ directory lacks permissions. Run:
chmod -R 755 storage bootstrap/cache public
Wildberries::setDebug(true); // Logs API requests/responses
$response = Wildberries::client()->get('/products/123456789');
dd($response->getBody());
API Key Management:
.env:
WILDBERRIES_API_KEY=your_key_here
WILDBERRIES_API_SECRET=your_secret
Vault or AWS Secrets Manager for production.Timeouts:
config/wildberries.php:
'timeout' => 30, // seconds
Fallback for Missing Fields:
public function getPriceAttribute() {
return $this->price ?? 0;
}
Custom Sync Logic:
sync() method in your model:
public function sync() {
$this->updateFromWildberries();
$this->triggerCustomLogic();
return $this;
}
Add New Endpoints:
Wildberries facade:
// app/Providers/WildberriesServiceProvider.php
public function register() {
$this->app->extend('wildberries', function ($app) {
return new ExtendedWildberriesManager($app['wildberries.client']);
});
}
Webhook Support:
use BaksDev\WildberriesProducts\Events\WebhookReceived;
event(new WebhookReceived($payload));
$products = Wildberries::product()->batch(100)->fetch();
wb_article, category_id):
Schema::table('wildberries_products', function (Blueprint $table) {
$table->index('wb_article');
});
$client = Mockery::mock(WildberriesClient::class);
$client->shouldReceive('get')->andReturn(new Response(200, [], json_encode(['id' => 123])));
php artisan test --group=wildberries-orders
$this->assertDatabaseHas('wildberries_products', [
'wb_article' => '123456789',
'name' => 'Test Product',
]);
How can I help you explore Laravel packages today?