Skip to end of metadata
Go to start of metadata

 

Shopware is a powerful and flexible application that can be used to build eCommerce experiences. It is based on a number of Symfony2 framework components, supported in PhpStorm through core features and the Symfony2 Plugin (an Open Source plugin maintained by Daniel Espendiller). A Shopware-specific plugin adds additional support for developing Shopware eCommerce with PhpStorm.

In this tutorial, we'll have a look at the Shopware-specific functionality. Feel free to explore Symfony Development using PhpStorm and the generic PhpStorm tutorials for more.

Prerequisites (plugin installation and configuration)

First of all, you need to install the Shopware Plugin in PhpStorm. Under Settings (Preferences) | Plugins, click the Browse repositories... button and search for Shopware. We can install it by using the context menu. The Shopware Plugin depends on the Symfony2 Plugin, which will be installed automatically.

Icon

While not required for all Shopware development, the PHP Annotations plugin can also be installed for help with Doctrine support.

Restart the IDE to complete the installation of the plugins.

As soon as both the Shopware Plugin and Symfony2 Plugin are installed, we will have to enable the Symfony2 Plugin in our project. We can do this from Settings (Preferences) | Other Settings | Symfony2 Plugin | Enable Plugin for this Project. We'll have to restart the IDE once more to load the plugin's additional features for Symfony2.

Icon

In case of any problems with the completion and navigation support provided by these plugins, select File | Invalidate Caches / Restart to reindex your project.

Code Completion, Navigation and Quick Fixes in PHP Code

Controllers, Hooks and Events for subscribeEvent

When initializing a plugin, we can subscribe to events provided by Shopware and other plugins in our installation. The Shopware plugin provides completion for controllers, hooks and events.


We can also navigate to the controller, hook or event using Ctrl+Click (CMD-Click on Mac OS X) or Go To Declaration (Ctrl+B / CMD-B). Simply hovering the mouse with the Ctrl or CMD key pressed will show additional details.

From an event listener, we can use the line marker to navigate back to the subscribeEvent method where we're subscribing to the event.

When we subscribe to an event and our listener is not created, the Shopware plugin will provide us with a quick-fix (Alt+Enter) which will generate an event handler stub for us.


ModelManager and Forms Parameter Completion

When using Shopware's ModelManager, responsible for initializing adapter classes, we can make use of code completion for arguments of addAttribute and generateAttributeModels.

Completion is also available for forms, for example using the setElement method. The Shopware plugin provides completion for array keys and values.


Array Parameters for Enlight_Controller_Router::assemble

When assembling a URL using the Enlight_Controller_Router's assemble method, the Shopware Plugin provides completion for array parameters like module, controller and action. It knows about the different parameters as well as their possible values.


Holding Ctrl (or CMD on Mac OS X) while hovering over any of the array values will provide additional information about the module, controller or action referenced.

Using Ctrl+Click (CMD-Click on Mac OS X) or Go To Declaration (Ctrl+B / CMD-B) will navigate.

Plugin Bootstrap getInfo and Path

As we create a plugin in Shopware, we can have our bootstrap class provide information to Shopware by implementing the getInfo and/or Path methods. The Shopware plugin provides completion for array keys.

Code Completion and Navigation for Smarty templates

Block Names

When working in Smarty templates, the Shopware plugin provides completion for block names. Using Ctrl+Space (CMD-Space on Mac OS X)

Hovering the mouse while holding Ctrl (or CMD on Mac OS X) will provide additional information about bock name. Using Go To Declaration (Ctrl+B / CMD-B) or Ctrl+Click (CMD-Click on Mac OS X) will navigate to where the block is defined. If multiple targets were found, the Shopware plugin lets us choose where we want to navigate.

When in a block definition, we can navigate to the templates where the block is implemented or overwritten. Using the marker in the left gutter, we can select the target where we want to navigate.

Including and Extending Templates

When including or extending other templates, we can use the {extends file="..."} and {include file="..."} syntax to do so. The Shopware plugin provides code completion on the file argument, so we can easily pick an existing template file to include or extend.

Using Go To Declaration (Ctrl+B / CMD-B) or Ctrl+Click (CMD-Click on Mac OS X) navigates directly to the template file. If multiple templates were found, the Shopware plugin provides us with a menu where we can select the template to navigate to.

Icon

The Shopware plugin also provides completion and navigation when referencing Smarty templates in PHP code, for example when using the extendsTemplate function.

Referencing Files, Controllers, Actions

In a template, we can reference files, like scripts, stylesheets or images. Shopware will convert the relative paths provided to the URL required to properly reference these files. The Shopware plugin provides code completion for file references. The Ctrl+Space (CMD+Space on Mac OS X) shortcut provides us with a list of files, filtered by folder.

In addition to file references, it also provides completion for controllers and actions, for example when using the {url} function. The Ctrl+Space (CMD-Space on Mac OS X) shortcut provides us with controllers and actions known in our Shopware project.

From within the template, we can use Go To Declaration (Ctrl+B / CMD-B) or Ctrl+Click (CMD-Click on Mac OS X) to navigate directly to the file, controller or action. If multiple items are found, we can select where we want to navigate from a list.

Namespace Tags for Snippets and Widgets

When using snippets in our Smarty templates, we have to use the correct namespace for them. Pressing Ctrl+Space (CMD-Space on Mac OS X) provides code completion for snippet namespaces.

Navigate to Related

The Shopware plugin provides a convenient way of navigating from a Smarty template to related files, for example a Shopware controller, and vice versa. When in a template, we can use the marker in the left gutter and select the target we want to navigate to.

When in a Shopware controller, we can use a similar marker to navigate to a Smarty template.

Doctrine

The Shopware plugin enhances the base Symfony2 plugin with several utilities. It provides completion and navigation for Doctrine repositories when calling into getRepository. Ctrl+Space (CMD-Space on Mac OS X) will show completion results.

Icon

Check out our tutorial Working with Doctrine - Symfony Development using PhpStorm to learn more about Doctrine support in the Symfony2 plugin.

ExtJs

Working on the Shopware backend means working with ExtJs. The Shopware plugin for PhpStorm adds several features to make navigation between controllers and ExtJs code easier. For example, when working in an ExtJs view, a marker in the left gutter lets us navigate to the controller that fuels it.

The Shopware plugin also provides ExtJs code that targets models or controllers with completion information, for example when creating model associations.

What else is there? Features from Symfony2 Plugin and PHP Annotations Plugin

There are a lot of features available in the Symfony2 Plugin, and most of them are relevant to the Symfony-specific part of our Shopware development. Check out our tutorial about the Symfony2 Plugin to learn about Symfony Framework related features such as type inference, code completion and navigation for Symfony Core, Symfony Components, Twig templates, Doctrine, and more.

Do explore the PHP Annotations plugin. It provides support for PHP class annotations in DocTags, Code | Optimize Imports for annotations, automatic alias detection on use statements, filtering of annotation classes on targets like methods, classes and properties, and much more!

  • No labels