Skip to content
This repository has been archived by the owner on Oct 8, 2024. It is now read-only.

storefront:hot-proxy not working with multiple sales channels #111

Open
AlexBa opened this issue Jul 21, 2020 · 4 comments
Open

storefront:hot-proxy not working with multiple sales channels #111

AlexBa opened this issue Jul 21, 2020 · 4 comments

Comments

@AlexBa
Copy link

AlexBa commented Jul 21, 2020

Hey,
I have an annoying issue which I first have discovered 1-2 months ago: If I want to use "./psh.phar storefront:hot-proxy" with multiple sales channels, the resulting site is broken.

With broken I mean: Specific templates like the header are applied multiple times to the site. Additionally, I'm using a premium theme from the community store (Orion), but the used theme in the hot proxy is still the default Storefront theme. Some styling is missing too.

If I delete all sales channels except the one with the premium theme, everything is working correctly. Deleting a sales channel means: Delete all related orders, documents, customers & newsletter recipients which are using the sales channel (with a raw MySQL query).

Unfortunately, it's not possible to delete a sales channel in the admin easily. If I click on "delete", nothing happens. Only an error appears in the AJAX response. The problem are the foreign key constraints in the DB. I think deleting a sales channels with existing data should be handled differently. But this is a different topic.

Does anyone have the same problem?

@AlexBa
Copy link
Author

AlexBa commented Jul 21, 2020

By the way: I'm using Shopware 6.2.2

@JustusNBB
Copy link

Hello, being a big fan of Hot Module Reload, I have been digging around in the Shopware (6.4+) Webpack setup (with the goal of optimising storefront performance). I have it working with a couple of hacks and pitfalls for multiple themes for different sales channels!

Let's discuss and improve from here:

  1. Theme Compilation/Dump Order is non-deterministic across deployments with different identifiers (files/ ordered by ThemeID).

This means which Theme Configuration ends up in var/ is random, it always contains exactly one Theme Config (the LAST one). The Hot-Proxy setup however is geared to read the FIRST theme configuration, as soon as there are are multiple themes, the Hot-Proxy is not able to select the right Theme+Config combination anymore.

For now I've made this work by adding a THEME_INDEX env override, which allows to pick the Theme instead of always using whatever is the first one.

  1. Secondary sales channel (under e.g. subdomain.localhost:9998) font asset routing is unsupported, the following hack works, but really feels like the wrong idea:
// Addition in build/proxy-server-hot/index.js
if (client_req.url.indexOf('/font/') >= 0) {
                requestOptions.host = '127.0.0.1';
                requestOptions.port = 80; // route to apache
}

Maybe this is something the asset server on port 9999, could handle?
Is shopware/shopware#1910 related?

$app-css-relative-asset-path: '/theme/<themehashid>/assets';
// webpack.config.js
const scssEntryFileContent = (() => {
        const themeMappings = JSON.parse(fs.readFileSync(path.resolve(projectRootPath, 'files/theme-config/index.json'), { encoding: 'utf8' }));
        const assetIds = Object.keys(themeMappings).map(salesChannelId => md5(themeMappings[salesChannelId] + salesChannelId)); // like the MD5ThemePathBuilder.assemblePath method
        const themeHashForAssetPath = assetIds[THEME_INDEX];
        const themeConfig = JSON.parse(fs.readFileSync(path.resolve(projectRootPath, `files/theme-config/${Object.values(themeMappings)[THEME_INDEX]}.json`), { encoding: 'utf8' }));
       // [...] now we need `var/` contents, but it's only for the one theme...
  1. I am aspiring to build all themes in parallel with Webpack (so they work without restarts & hacks like a THEME_INDEX override), but I haven't found the way to manipulate Webpack Chunking without the ThemeCompiler interfering... how do we get subdomain.localhost:9998 to select the correct theme (entrypoint)?

@AlexBa does my information help you "to make it work" for you too?
I hope to find more time to refine this solution when I come back from vacation in September!

@jellesiderius
Copy link

Any update on this? This would be nice to have as basic functionality.

@mitelg
Copy link
Member

mitelg commented Oct 8, 2024

hey @jellesiderius

please check if the Symfony Flex template is now providing what you need: https://github.com/shopware/recipes

If not, please open an issue there. As stated here in the readme file, this repo is deprecated

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants