bitbag/shopware-app-system-bundle
Installation Add the bundle via Composer in your Laravel project:
composer require bitbag/shopware-app-system-bundle
Register the bundle in config/app.php under providers:
BitBag\ShopwareAppSystemBundle\ShopwareAppSystemBundle::class,
Configuration Publish the bundle’s config file:
php artisan vendor:publish --provider="BitBag\ShopwareAppSystemBundle\ShopwareAppSystemBundle" --tag="config"
Update config/shopware-app-system.php with your Shopware 6 API credentials (client ID, secret, base URL).
First Use Case: Fetching Shopware Data Use the bundle’s service container to interact with Shopware’s API:
use BitBag\ShopwareAppSystemBundle\Service\ShopwareService;
class MyController extends Controller
{
public function __construct(private ShopwareService $shopwareService) {}
public function getProducts()
{
$products = $this->shopwareService->get('/product');
return response()->json($products);
}
}
API Integration
ShopwareService to retrieve entities (e.g., products, categories, orders):
$products = $shopwareService->get('/product', ['limit' => 10]);
$newProduct = [
'name' => 'Test Product',
'price' => ['gross' => 1000, 'net' => 800],
];
$createdProduct = $shopwareService->post('/product', $newProduct);
Authentication
ShopwareService. Configure scopes in config/shopware-app-system.php:
'scopes' => ['read_products', 'write_products'],
Event-Driven Sync
order.created) via Laravel’s events system:
// In a service provider
Event::listen('shopware.order.created', function ($event) {
// Sync order to Laravel DB
});
ShopwareWebhookService to register webhooks:
$webhook = $shopwareWebhookService->createWebhook(
url: route('shopware.webhook'),
events: ['order.created']
);
Data Transformation
Resource classes to shape Shopware responses:
use Illuminate\Http\Resources\Json\JsonResource;
class ProductResource extends JsonResource
{
public function toArray($request)
{
return [
'id' => $this->id,
'name' => $this->name,
'price' => $this->price['net'],
];
}
}
Token Expiry
try {
$shopwareService->get('/product');
} catch (\BitBag\ShopwareAppSystemBundle\Exception\ShopwareException $e) {
Log::error('Shopware API error: ' . $e->getMessage());
}
Rate Limiting
use Symfony\Component\HttpClient\RetryableHttpClient;
$client = new RetryableHttpClient(
$baseClient,
[
'max_retries' => 3,
'delay' => 1000,
]
);
Data Mismatches
snake_case for nested fields (e.g., price.gross), while Laravel often uses camelCase. Normalize responses:
$normalized = collect($response)->map(function ($item) {
return (array) json_decode(json_encode($item), true);
});
config/shopware-app-system.php:
'debug' => env('APP_DEBUG', false),
ShopwareService::getRawResponse() to debug:
$response = $shopwareService->get('/product', [], true);
dd($response->getContent());
Custom API Clients
Extend ShopwareService to add middleware:
namespace App\Services;
use BitBag\ShopwareAppSystemBundle\Service\ShopwareService;
class CustomShopwareService extends ShopwareService
{
public function __construct()
{
$this->addMiddleware(function ($request) {
$request->headers->set('X-Custom-Header', 'value');
});
}
}
Webhook Handlers Create custom event listeners for Shopware webhooks:
namespace App\Listeners;
use BitBag\ShopwareAppSystemBundle\Event\ShopwareWebhookEvent;
class HandleOrderCreated
{
public function handle(ShopwareWebhookEvent $event)
{
if ($event->getEventName() === 'order.created') {
// Process order
}
}
}
GraphQL Support
The bundle primarily uses REST. For GraphQL, integrate webonyx/graphql-php and wrap calls:
$query = '
query {
products(first: 10) {
edges {
node {
name
}
}
}
}
';
$client = new \Webonyx\GraphQL\Client();
$client->setUrl('https://your-shopware-store.com/api/graphql');
$client->setHeaders(['Authorization' => 'Bearer ' . $token]);
$result = $client->query($query);
How can I help you explore Laravel packages today?