How to install shopware plugin with composer

How to Install Shopware 6 Plugin from Store via Composer

Installing plugins with the composer is very handy when you deploy your Shopware 6 using a CD pipeline. The sources of the purchased plugins don't need to be pushed to your project code repository anymore. Thus the codebase becomes cleaner.

Prerequisites

  • Create a Shopware account if you don't have one yet.
  • Register your Shopware online store.
  • At the Shopware Store purchase the plugin you would like to install and associate this plugin with your Shopware online store.

First Time Project Composer Configuring

The first step is to install composer-installer-extender composer plugin.
It will enable a non-standard (from the composer perspective) installation directory for our plugins, which is custom/plugins. Because, by default, the composer installs everything in vendor/ directory.

composer require oomphinc/composer-installers-extender:~2.0

Next, declare the custom plugins directory in the composer.json:

composer config --json extra.installer-types '["shopware-platform-plugin"]' 
&&  composer config --json extra.installer-paths '{"custom/plugins/{$name}": ["type:shopware-platform-plugin"]}' 
&&  composer config repositories.shopware '{"type": "composer", "url": "https://packages.friendsofshopware.com/"}'

Add the friendsofshopware package repository to your composer.json by running:

composer config repositories.shopware '{"type": "composer", "url": "https://packages.friendsofshopware.com/"}'

Authentication

Log in to packages.friendsofshopware.com using your Shopware account login and password.

NOTE: packages.friendsofshopware doesn't store any credentials. It only authenticates you at the Shopware Account API.

Next, you'll be asked to choose the store previously registered in your Shopware account. Then, click the "Setup Repository in Project" button.

Setup repository in project button

Copy the authentication token JSON object and save it as auth.json in your Shopware root folder (where composer.json is). It should look like this example below:

{
    "bearer": {
        "packages.friendsofshopware.com": "abcdefABCDJDCCXXDLJJFghijklm,noppsdkd/.kkd=="
    }
}

Installing Shopware Plugin

Find the package you would like to install and run:

composer require store.shopware.com/plugin-packagename

Once it completes, run:

./bin/console plugin:refresh

Your freshly installed plugin should be visible in the list. Finally, execute the plugin install and activate commands to get the plugin active.

./bin/console plugin:install pluginname 
&& ./bin/console plugin:activate pluginname

Self-hosted Package Repository

The package repository project is open-source, and you can find its sources on Github.
Follow the README file to get it up and running on your own server.

Once it's online, you can use your new repository hostname instead of packages.friendsofshopware.com in the composer.json as well as in the auth.json.

Happy installing!

FacebookTwitterPinterest