Skip to content

Instantly share code, notes, and snippets.

@kolaente
Last active December 15, 2021 14:07
Show Gist options
  • Save kolaente/4634f8760f40776561fbb2dade658be9 to your computer and use it in GitHub Desktop.
Save kolaente/4634f8760f40776561fbb2dade658be9 to your computer and use it in GitHub Desktop.
Shopware 6 Cheat Sheet

Shopware 6 Cheat Sheet

Creating a new static plugin (in static-plugins)

  1. Follow this guide: https://developer.shopware.com/docs/guides/plugins/plugins/plugin-base-guide
  2. Install the plugin with composer require name/of-the-plugin to make shopware recognize it
  3. bin/console plugin:refresh
  4. Install it: bin/console plug:in --activate NameOfThePlugin
  5. Cache clear bin/console ca:c

Creating new custom fields from a plugin update

Basically, in your plugin class:

    public function update(UpdateContext $updateContext): void
    {
        $this->addCustomProductField($updateContext);
    }

    protected function addCustomProductField(UpdateContext $updateContext)
    {
        $customFieldSetRepository = $this->container->get('custom_field_set.repository');
        $customFieldSetRepository->create([
            [
                'name' => 'custom_product_detail',
                'config' => [
                    'label' => [
                        'en-GB' => 'Product Detail Fields',
                        'de-DE' => 'Produktdetailfelder',
                    ],
                ],
                'customFields' => [
                    [
                        'name' => 'custom_product_detail_faq',
                        'type' => CustomFieldTypes::HTML,
                        'config' => [
                            'type' => CustomFieldTypes::HTML,
                            'label' => [
                                'en-GB' => 'FAQ',
                                'de-DE' => 'FAQ',
                            ],
                            'componentName' => 'sw-text-editor',
                            'customFieldType' => 'textEditor',
                            'customFieldPosition' => 3,
                        ],
                    ],
                ],
            ],
        ], $updateContext->getContext());
    }

Using the container in a migration in combination with the ContainerAwareTrait does not work, hence the update script in the plugin class.

Then run

bin/console plugin:update <Plugin Name>

Useful Docs: https://developer.shopware.com/docs/guides/plugins/plugins/framework/custom-field/add-custom-field#add-custom-fields-to-an-entity

Custom Static Assets (like images) from plugins

https://developer.shopware.com/docs/guides/plugins/plugins/storefront/add-custom-assets

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment