bagisto/bagisto-api
REST and GraphQL API layer for Bagisto 2.3.8+, built on API Platform. Quickly install via Composer and an Artisan installer to get API docs, GraphQL Playground, and shop/admin endpoints for e‑commerce integrations and extensions.
## Getting Started
This package is now a **fully-fledged eCommerce API platform** built on Laravel, API Platform, and GraphQL, with **v1.0.5** introducing significant enhancements. For new developers, start with:
1. **Installation** (updated for v1.0.5):
```bash
composer require bagisto/api-platform:^1.0.5
php artisan bagisto-api-platform:install --force --optimize # Added --optimize flag for production-ready setup
php artisan migrate --seed --with-test-data # New flag for comprehensive test data seeding
The install command now includes optimized database configurations and pre-configured queues for async operations.
First Use Case (updated):
CustomerOrderProvider with v1.0.5's enhanced analytics:
$orders = $this->customerOrderProvider->getOrders($customerId, [
'filter' => ['status' => ['eq' => 'completed'], 'analytics' => true],
'sort' => ['-created_at']
]);
/graphiql to explore new v1.0.5 subscriptions and persisted queries:
subscription {
orderStatusUpdates {
orderId
status
# New field: analytics
analytics {
lifetimeValue
avgOrderValue
}
}
}
/api/seed-data?comprehensive=true endpoint for full test suite data:
curl -X GET http://your-app.test/api/seed-data?comprehensive=true
Key Configs (updated):
config/api-platform.php for new OpenAPI v3.1.1 compliance and async operation support.config/api-platform-vendor.php for queue-based rate limit overrides (now supports delayed throttling).Accept-Language now supports negotiation strategies (e.g., Accept-Language: en-US;q=0.9,en;q=0.8;strategy=strict).config/api-platform-webhooks.php with retry policies and event batching.Customer-Centric APIs (updated):
CustomerOrderAnalyticsProvider:
$analytics = $this->customerOrderAnalyticsProvider->getAnalytics($customerId);
// Returns: { lifetimeValue: 1250.50, avgOrderValue: 75.00, orderCount: 17 }
SubscriptionOrderProcessor with new pause/resume logic:
$this->subscriptionOrderProcessor->pause($subscriptionId, $customerId);
$this->subscriptionOrderProcessor->resume($subscriptionId, $customerId);
CustomerProfileOutput with new privacy controls:
$profile = $this->customerProfileHelper->getProfile($customerId, maskSensitiveData: true);
Catalog & Storefront (updated):
includeMediaMetadata flag (v1.0.5):
GET /api/locales?includeMediaMetadata=true
Accept-Language: fr-CA
timezone and bufferMinutes parameters:
query {
bookingSlots(productId: "123", timezone: "Europe/Paris", bufferMinutes: 15) {
availableSlots
bufferWarning
}
}
version and draftMode parameters:
$page = $this->pageProvider->getByUrlKey('about-us', version: 'draft', draftMode: true);
Cart/Wishlist/Compare (updated):
CartTokenProcessor with new mergeStrategy and conflictResolver:
$mergedCart = $this->cartTokenProcessor->merge($token1, $token2, [
'strategy' => 'prioritize_latest',
'conflictResolver' => 'overwrite' // Options: 'overwrite', 'merge', 'skip'
]);
MoveWishlistToCartProcessor with new excludeOutOfStock flag:
$this->moveWishlistToCartProcessor->execute(
new MoveWishlistToCartInput($wishlistId, $customerId, excludeOutOfStock: true)
);
CompareProductProvider with enhanced attribute handling:
$comparison = $this->compareProductProvider->getComparison([$productId1, $productId2], [
'includeAttributes' => ['color', 'size', 'material']
]);
Infrastructure (updated):
OrderPlacementJob for background processing:
$this->orderPlacementJob->dispatch($orderData);
$orders = $this->customerOrderProvider->getOrders($customerId, [
'pagination' => [
'type' => 'cursor',
'pageSize' => 20,
'includeMetadata' => true,
'async' => true
]
]);
php artisan bagisto-api-platform:cache:clear --group=orders --ttl=3600
Webhooks (updated):
$webhook = $this->webhookService->create([
'url' => 'https://your-webhook-endpoint.com',
'events' => ['order.placed', 'inventory.low'],
'retryPolicy' => ['maxRetries' => 3, 'delay' => 60]
]);
$this->webhookService->triggerBatch('order.placed', [$order1, $order2]);
subscription OrderStatusUpdate($orderId: ID!) {
orderStatusUpdates(filter: {orderId: {eq: $orderId}}) {
orderId
status
}
}
Accept-Language headers with new negotiation strategies:
Accept-Language: en-US;q=0.9,en;q=0.8;strategy=strict
api-platform-vendor.php:
'rate_limits' => [
'storefront/products' => ['limit' => 60, 'period' => 'minute', 'queue' => true],
],
WebhookEventBatch class for bulk event handling:
use Bagisto\ApiPlatform\Events\WebhookEventBatch;
event(new WebhookEventBatch('order.placed', [$order1, $order2]));
Breaking Changes (updated):
sync flag for synchronous behavior:
$this->orderPlacementJob->dispatch($orderData, sync: true);
http:// only in development with explicit config:
config(['api-platform-webhooks.allow_http' => true]);
failed_jobs table for timeouts.graphql-persist CLI tool:
php artisan graphql-persist:generate
Common Bugs (updated):
null translations if active status isn’t set. Use:
$product->setTranslationFallback(true)->setActive(true)->save();
excludeOutOfStock (default:How can I help you explore Laravel packages today?