App Bundle
The App Bundle integrates the PHP App SDK with Symfony. The source repository is app-bundle-symfony.
Installation
With SQL-based storage (Doctrine)
composer require shopware/app-bundle doctrine/orm symfony/doctrine-bridgeWith NoSQL-based storage (DynamoDB)
composer require shopware/app-bundle async-aws/async-aws-bundle async-aws/dynamo-dbQuick Start using SQL-based storage (Doctrine)
1. Create a new Symfony project (skip if you already have one)
composer create-project symfony/skeleton:"6.2.*" my-app2. Install the App Bundle in your Symfony Project
composer require shopware/app-bundle doctrine/orm symfony/doctrine-bridgeIt is also recommended to install the monolog bundle to have logging:
composer require logger3. Create a new App manifest
Here is an example app manifest:
<?xml version="1.0" encoding="UTF-8"?>
<manifest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/shopware/shopware/trunk/src/Core/Framework/App/Manifest/Schema/manifest-3.0.xsd">
<meta>
<name>TestApp</name>
<label>TestApp</label>
<label lang="de-DE">TestApp</label>
<description/>
<description lang="de-DE"/>
<author>Your Company</author>
<copyright>(c) by Your Company</copyright>
<version>1.0.0</version>
<icon>Resources/config/plugin.png</icon>
<license>MIT</license>
</meta>
<setup>
<registrationUrl>http://localhost:8000/app/lifecycle/register</registrationUrl>
<secret>TestSecret</secret>
</setup>
<webhooks>
<webhook name="appActivated" url="http://localhost:8000/app/lifecycle/activate" event="app.activated"/>
<webhook name="appDeactivated" url="http://localhost:8000/app/lifecycle/deactivate" event="app.deactivated"/>
<webhook name="appDeleted" url="http://localhost:8000/app/lifecycle/delete" event="app.deleted"/>
</webhooks>
</manifest>Change the app name and app secret to suit your needs, and adjust the environment variables in your .env file to match.
By default, the following routes are registered:
/app/lifecycle/register- Register the app/app/lifecycle/activate- Activate the app/app/lifecycle/deactivate- Deactivate the app/app/lifecycle/delete- Delete the app
You can change the prefix by editing the config/routes/shopware_app.yaml file.
The registration flow also dispatches events for the different lifecycle stages. See the App SDK documentation for details.
4. Connecting Doctrine to a Database
The App Bundle ships with a basic Shop entity to store the shop information. You can extend this entity to store more information about your app if needed.
Symfony configures doctrine to use PostgreSQL by default. Change the DATABASE_URL environment variable in your .env file if you want to use MySQL. You can also use SQLite by setting the DATABASE_URL to sqlite:///%kernel.project_dir%/var/app.db for development.
After choosing your database engine, you need to require two extra composer packages.
composer req symfony/maker-bundle migrationsAnd create your first migration using bin/console make:migration (which is using the AbstractShop Class) and apply it to your database with bin/console doctrine:migrations:migrate.
5. Implement action buttons, webhooks, and payment handling
You can also check out the APP SDK documentation.
Optional: Webhook as Symfony Events
The app bundle also registers a generic webhook controller that dispatches each incoming webhook as a Symfony event. To use it, point your Shopware webhooks at the generic webhook URL, which defaults to /app/webhook.
<webhook name="productWritten" url="http://localhost:8000/app/webhook" event="product.written"/>With this setup, you can write a Symfony event listener or subscriber to handle the event.
#[AsEventListener(event: 'webhook.product.written')]
class ProductUpdatedListener
{
public function __invoke(WebhookAction $action): void
{
// handle the webhook
}
}