0

I am trying to integrate Google maps in a shopware PseudoModalUtil modal window. I then have to add the marker cluster library and add a few clusters.

The thing is, the Google maps API and the marker cluster library are JavaScript files that are normally fetched from a URL, hence the script tag.

However, I don't want to add random script tags in my twig templates, as I am sure nobody would. I guess my two left options would be:

  • Either create two distinct JS files for the Google maps API JS response and marker cluster JS response respectively, and then include them in my storefront JS module.
  • Or try to install them as web-pack modules and include them in my storefront module. But I think I need to add a package.json file somewhere, and them somehow use web-pack to install everything and include installed modules.

I do not know which approach, if any of these two, is good. I did not find anything in the developer documentation for shopware 6, and on the slack channel nobody seems to answer this question.

I found two links here that are somewhat useful:

I think that's about it.

Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
Gabriel
  • 371
  • 1
  • 3
  • 18
  • 2
    It's a very good question. I don't know why it was closed. I think what you are asking is how to integrate 3rd party Javascript code properly? There is a node-js-package of the maps api: https://medium.com/@paw145/using-the-google-maps-api-with-webpack-npm-and-a-handy-promise-returning-helper-19c9312971b0 - but I also do not know in which package.json to require this. I actually think the approach to load the scripts from google directly via script tags is also not too bad - but I hope this question will be reopend. – Alex Jul 03 '21 at 09:43
  • see also https://stackoverflow.com/questions/68174012/how-to-add-external-js-files-in-shopware6-4 – Alex Jul 03 '21 at 09:47
  • 1
    I recommend using @googlemaps/js-api-loader https://www.npmjs.com/package/@googlemaps/js-api-loader – Justin Poehnelt Jul 06 '21 at 14:46
  • Did @jpoehnelt's suggestion work? – Alex Sep 11 '21 at 15:39
  • The feature was removed, I did not try this further. – Gabriel Oct 07 '21 at 13:56

0 Answers0