Install Dependencies:
composer require baks-dev/ozon-package baks-dev/ozon-manufacture
composer.json for PHP 8.4+ compatibility.Publish Configuration and Assets:
php artisan baks:assets:install
config/ozon-manufacture.php) and migrations to your project.Run Database Migrations:
php artisan doctrine:migrations:diff
php artisan doctrine:migrations:migrate
manufacturing_orders, production_steps tables).Configure .env:
Add Ozon API credentials:
OZON_API_KEY=your_api_key
OZON_API_SECRET=your_secret
OZON_WEBHOOK_URL=https://your-app.com/ozon/webhook
First Use Case: Trigger Manufacturing for an Order Use the package’s service class to start manufacturing:
use BaksDev\OzonManufacture\Facades\OzonManufacture;
$orderId = 'ozon_order_12345';
$result = OzonManufacture::startProduction($orderId);
if ($result->isSuccess()) {
// Manufacturing initiated; check status later
} else {
// Handle failure (e.g., order not found, API error)
}
Verify Webhook Setup (if applicable):
POST /ozon/webhook).// Start production for a single order
OzonManufacture::startProduction($orderId);
// Bulk process orders (if supported)
OzonManufacture::bulkStartProduction([$orderId1, $orderId2]);
orders.placed event to auto-trigger manufacturing:
Event::listen(OrderPlaced::class, function ($event) {
OzonManufacture::startProduction($event->order->ozon_id);
});
$status = OzonManufacture::getProductionStatus($orderId);
// $status->currentStep, $status->isCompleted, $status->errors
// app/Console/Commands/CheckManufacturingStatus.php
public function handle() {
$pendingOrders = Order::where('manufacturing_status', 'pending')->get();
foreach ($pendingOrders as $order) {
$status = OzonManufacture::getProductionStatus($order->ozon_id);
if ($status->isCompleted()) {
$order->update(['manufacturing_status' => 'completed']);
}
}
}
// routes/web.php
Route::post('/ozon/webhook', [OzonWebhookController::class, 'handle']);
// app/Http/Controllers/OzonWebhookController.php
public function handle(Request $request) {
$payload = $request->json()->all();
OzonManufacture::handleWebhook($payload);
}
// Configure in config/ozon-manufacture.php
'queue' => [
'driver' => 'database',
'retry_after' => 60, // seconds
];
// Dispatch a job with retry logic
OzonManufacture::dispatchProductionJob($orderId);
OzonManufacture::failed(function ($job, $exception) {
// Send Slack/email alert
Notification::route('mail', 'team@example.com')
->notify(new ManufacturingFailed($exception));
});
// app/Services/CustomOzonManufacture.php
use BaksDev\OzonManufacture\Services\OzonManufacture as BaseOzonManufacture;
class CustomOzonManufacture extends BaseOzonManufacture {
public function startProduction($orderId) {
// Add custom validation
if (!$this->isOrderEligible($orderId)) {
throw new \Exception("Order not eligible for manufacturing");
}
return parent::startProduction($orderId);
}
protected function isOrderEligible($orderId) {
// Your custom logic
return true;
}
}
AppServiceProvider:
$this->app->bind(
\BaksDev\OzonManufacture\Contracts\OzonManufacture::class,
\App\Services\CustomOzonManufacture::class
);
// app/Models/CustomProductionStep.php
use BaksDev\OzonManufacture\Models\ProductionStep;
class CustomProductionStep extends ProductionStep {
protected $customAttribute = 'value';
// Add custom logic for step transitions
}
ProductionStep::observe(CustomProductionStepObserver::class);
php artisan test --group=ozon-manufacture
public function test_custom_manufacturing_workflow() {
$order = Order::factory()->create(['ozon_id' => 'test_123']);
$this->actingAs(user())
->post('/ozon/webhook', ['event' => 'order.received'])
->assertOk();
$this->assertDatabaseHas('production_steps', [
'order_id' => $order->id,
'step' => 'cutting',
]);
}
Ozon API Rate Limits:
429 Too Many Requests.use Symfony\Component\HttpClient\RetryableHttpClient;
$client = new RetryableHttpClient(
$baseClient,
[
'max_retries' => 3,
'delay' => 1000, // ms
'multiplier' => 2,
'max_delay' => 5000,
]
);
Database Locking:
production_steps).DB::transaction(function () use ($orderId) {
OzonManufacture::startProduction($orderId);
}, 5); // Retry 5 times on deadlock
Webhook Idempotency:
public function handle(Request $request) {
$payload = $request->json()->all();
$signature = $request->header('X-Ozon-Signature');
if (!$this->verifySignature($payload, $signature)) {
abort(403);
}
$eventId = $payload['event_id'];
if (WebhookLog::where('event_id', $eventId)->exists()) {
return response()->json(['status' => 'already_processed']);
}
OzonManufacture::handleWebhook($payload);
WebhookLog::create(['event_id' => $eventId]);
}
**
How can I help you explore Laravel packages today?