Benny's Shopware Notebook
  • Introduction
    • How to Get in Touch
  • ddev for Shopware
    • Less than 5 Minutes Install with ddev and Symfony Flex
    • Storefront and Admin Watchers with ddev
    • Message Queue Setup with ddev
    • Contribute with ddev
    • Performance Tweaks
    • RabbitMQ with ddev
    • phpstan pro with ddev
    • Fetch Media from Production or Staging Server
  • Hosting
    • Setting up a Cloud Server with ddev
    • How to Trouble-shoot and Evaluate Environment Variables
    • Media URLs Out Of Sync between Servers
    • RabbitMQ
    • Running Shopware CE with PaaS
    • SFTP-Users
    • Basic-Auth for Shopware 6 with nginx
    • How to Avoid Failed Systemd Units
    • JWT-Secrets as Environment Variables
  • Deployment
    • Close-to-Zero Downtime Deployment
    • Docker-Images for Deployment with Gitlab-Runners
    • PHP Cache Related Issues
  • Development
    • Patching the Core
    • How to Discover Available Updates?
    • Local Testing of Shopware Commercial Features
  • Administration
  • Database
  • Migration
    • Side Effects
Powered by GitBook
On this page
  • How To
  • Identifying the Relative Filenames for the Patch File

Was this helpful?

  1. Development

Patching the Core

This page explains, how to use the Composer package cweagans/composer-patches to patch Shopware 6 core modules.

PreviousDevelopmentNextHow to Discover Available Updates?

Last updated 7 months ago

Was this helpful?

There are several means of customizing Shopware code to your project's needs, like Shopware's event system or Symfony's service decorator patterns to name just two. From time to time, however, you might encounter a situation, where customization requirements make a change to Shopware core code inevitable.

Now, changing Shopware's core code within the vendor folder is not a good idea, for obvious reasons. Fortunately, a Composer based solution is available. It is called composer-patches and is very well documented for Typo3 in the .

The power of this: You can do almost everything. The obvious downside: You'l lose your update capability.

Needless to say that the following instructions allow to patch any Shopware plugin and any other Composer required package as well.

How To

In short, you need to require the following composer extension to your project:

composer require cweagans/composer-patches

Create a folder to store your actual patches. I have created a new subfolder patches within the custom folder of my Shopware project for this purpose.

To activate a patch, amend the code in the "extra" section of your composer.json, like in the following example:

    "extra": {
        "patches": {
            "shopware/core": {
                "Append trailing slash to sitemap home url": "custom/patches/shopware/add_trailing_slash_to_sitemap_home_url.diff"
            }
        },
 ...
    }

Apply the patch by running composer install:

composer install

Identifying the Relative Filenames for the Patch File

I use to create my patch files using PhpStorm's diff functionality. However, the resulting relative filenames need to be adjusted to match the composer setup of the Shopware project.

In my example, my patch file looks like this:

# shopware/custom/patches/shopware/add_trailing_slash_to_sitemap_home_url.diff
diff --git a/Content/Sitemap/Service/SitemapExporter.php b/Content/Sitemap/Service/SitemapExporter.php
--- a/Content/Sitemap/Service/SitemapExporter.php
+++ b/Content/Sitemap/Service/SitemapExporter.php
@@ -167,7 +167,7 @@ class SitemapExporter implements SitemapExporterInterface
 
             foreach ($result->getUrls() as $url) {
                 $newUrl = clone $url;
-                $newUrl->setLoc(empty($newUrl->getLoc()) ? $host : $host . '/' . $newUrl->getLoc());
+                $newUrl->setLoc(rtrim($host, '/') . '/' . $newUrl->getLoc());
                 $urls[] = $newUrl;
             }

As you see, the relative filenames are relative to the root of the Symfony component, i.e. vendor/shopware/core.

docs