as of version 5.3.0 Edit this page on GitHub

Cheat-Sheet for developers


This article will give you brief information about often used functionalities, methods and good practises for developers, who are working on shopware.

This list is not complete. If you miss something important, feel free to open a pull request with the GitHub link in the top.


Have a look here for a Smarty Cheat-Sheet

Disable Smarty Rendering


Add json Rendering

Useful for ajax calls


Dynamic snippet names / namespaces

{"Snippet Content"|snippet:$dynamicName:$dynamicNamespace}

Events and hooks

Use your main plugin class or a subscriber class which implements the \Enlight\Event\SubscriberInterface to register new events or hooks


public static function getSubscribedEvents()
    return [
        'EVENT_NAME3' => [
            ['EVENT_LISTENER3_1', POSITION],

The POSITION defines the execution order of the event listener methods. The default value is 0. The higher the number, the later the event listener method is executed. For example a position like -10 will be executed quite early. On the contrary a position like 10 quite late.


types: before / after / replace

public static function getSubscribedEvents()
    return [


Creating a new attribute / update an existing attribute

$attributeCrudService = $this->container->get('shopware_attribute.crud_service');
        'displayInBackend' => true,
        'position' => 10,
        'custom' => true,
        'defaultValue' => 'test'

Naming - Attribute generation

If you get the Error: Unrecognized field: my_field when querying for your attribute it could be that you forgot to generate the attribute models:


or ran into naming issues:

  • the field name gets lower cased before added to the database
  • when using underscores(_) in field names they must be queried in camel case

Delete existing attribute

$attributeCrudService = $this->container->get('shopware_attribute.crud_service');
$attributeCrudService->delete('s_articles_attributes', 'swag_test_attribute');

Translate label, help text, support text

create SwagTest\Resources\snippets\backend\attribute_columns.ini

s_articles_attributes_swag_test_attribute_label = "English label"
s_articles_attributes_swag_test_attribute_supportText = "English support text"
s_articles_attributes_swag_test_attribute_helpText = "English help text"

s_articles_attributes_swag_test_attribute_label = "Deutsches Label"
s_articles_attributes_swag_test_attribute_supportText = "Deutscher Supporttext"
s_articles_attributes_swag_test_attribute_helpText = "Deutscher Hilfetext"

Plugin configuration

see this article

DI container configuration

see this article

Create menu item

see this article

Database queries

Select with queryBuilder

$queryBuilder = $this->container->get('dbal_connection')->createQueryBuilder();
    ->where('active = :active')
    ->setParameter('active', true);
$data = $queryBuilder->execute()->fetchAll();

with fetch mode

$queryBuilder = $this->container->get('dbal_connection')->createQueryBuilder();
    ->from('s_articles_details', 'variants')
    ->where('variants.kind = :kind')
    ->setParameter('kind', 1);

$data = $queryBuilder->execute()->fetchAll(\PDO::FETCH_COLUMN);

Select with plain SQL

$connection = $this->container->get('dbal_connection');
$sql = 'SELECT * FROM s_articles WHERE active = :active';
$data = $connection->fetchAll($sql, [':active' => true]);


Custom model

create SwagTest\Models\TestCustomModel

namespace SwagTest\Models;

use Shopware\Components\Model\ModelEntity;
use Doctrine\ORM\Mapping as ORM;

 * @ORM\Entity()
 * @ORM\Table(name="swag_test_table", options={"collate"="utf8_unicode_ci"})
class TestCustomModel extends ModelEntity
    * @var int
    * @ORM\Column(name="id", type="integer", nullable=false)
    * @ORM\Id
    * @ORM\GeneratedValue(strategy="IDENTITY")
    private $id;
    * @var string
    * @ORM\Column(name="test_name", type="string")
    private $testName;
     * @return int
    public function getId()
        return $this->id;

     * @param string $testName
    public function setName($testName)
        $this->testName = $testName;

     * @return string
    public function getName()
        return $this->testName;

Create database table from model

Make sure that you use the same database collation as Shopware in your custom model, if you have relations to Shopware default tables

$em = $this->container->get('models');
$tool = new \Doctrine\ORM\Tools\SchemaTool($em);
$classes = [$em->getClassMetadata(\SwagTest\Models\TestCustomModel::class)];

Delete database table

$em = $this->container->get('models');
$tool = new \Doctrine\ORM\Tools\SchemaTool($em);
$classes = [$em->getClassMetadata(\SwagTest\Models\TestCustomModel::class)];


select some data

$builder = $this->container->get('models')->createQueryBuilder();
$builder->select(['product', 'mainVariant'])
    ->from(\Shopware\Models\Article\Article::class, 'product')
    ->innerJoin('product.mainDetail', 'mainVariant')
    ->where(' = :productId')
    ->setParameter('productId', 2);
// array with \Shopware\Models\Article\Article objects
$objectData = $builder->getQuery()->getResult();

// array with arrays
$arrayData = $builder->getQuery()->getArrayResult();