├── .eslintignore
├── image1.png
├── plugin.png
├── .githooks
├── install_hooks.sh
└── pre-commit
├── composer.json
├── Resources
├── views
│ ├── frontend
│ │ ├── index
│ │ │ └── index.tpl
│ │ └── _public
│ │ │ └── src
│ │ │ └── js
│ │ │ └── jquery.redirect.js
│ └── widgets
│ │ └── swag_browser_language
│ │ └── get_modal.tpl
├── snippets
│ └── frontend
│ │ └── swag_browser_language
│ │ └── main.ini
├── services.xml
└── config.xml
├── .php_cs.dist
├── LICENSE
├── Subscriber
├── Javascript.php
└── Frontend.php
├── SwagBrowserLanguage.php
├── README.md
├── plugin.xml
├── Components
├── Translator.php
└── ShopFinder.php
└── Controllers
└── Widgets
└── SwagBrowserLanguage.php
/.eslintignore:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/image1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shopware5/SwagBrowserLanguage/HEAD/image1.png
--------------------------------------------------------------------------------
/plugin.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shopware5/SwagBrowserLanguage/HEAD/plugin.png
--------------------------------------------------------------------------------
/.githooks/install_hooks.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env php
2 |
11 |
12 | {/block}
13 | {/block}
--------------------------------------------------------------------------------
/Resources/snippets/frontend/swag_browser_language/main.ini:
--------------------------------------------------------------------------------
1 | [en_GB]
2 | modal/main_title = "Automatic forwarding available"
3 | modal/text = "We may automatically redirect you to the shop in your language. If you don't want this, you can simply close this window."
4 | modal/go = "Go to the recommended shop"
5 | modal/close = "Close window"
6 | modal/choose = "Or choose a shop from below:"
7 | modal/recommendation = "Recommended shop:"
8 |
9 | [de_DE]
10 | modal/main_title = "Automatische Weiterleitung verfügbar"
11 | modal/text = "Wir können Sie automatisch auf den Shop Ihrer Sprache weiterleiten. Ist das nicht gewünscht, können sie einfach dieses Fenster schließen"
12 | modal/go = "Zum empfohlenden Shop wechseln"
13 | modal/close = "Fenster schließen"
14 | modal/choose = "Oder wählen Sie hier einen Shop aus:"
15 | modal/recommendation = "Empfohlender shop:"
--------------------------------------------------------------------------------
/.php_cs.dist:
--------------------------------------------------------------------------------
1 | in(__DIR__)
5 | ;
6 |
7 | $header = <<
9 |
10 | For the full copyright and license information, please view the LICENSE
11 | file that was distributed with this source code.
12 | EOF;
13 |
14 | return PhpCsFixer\Config::create()
15 | ->setUsingCache(false)
16 | ->setRules([
17 | '@PSR2' => true,
18 | '@Symfony' => true,
19 | 'header_comment' => ['header' => $header, 'separate' => 'bottom', 'commentType' => 'PHPDoc'],
20 | 'no_useless_else' => true,
21 | 'no_useless_return' => true,
22 | 'ordered_class_elements' => true,
23 | 'ordered_imports' => true,
24 | 'phpdoc_order' => true,
25 | 'phpdoc_summary' => false,
26 | 'blank_line_after_opening_tag' => false,
27 | 'concat_space' => ['spacing' => 'one'],
28 | 'array_syntax' => ['syntax' => 'short']
29 | ])
30 | ->setFinder($finder)
31 | ;
32 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2015 ShopwareLabs
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
23 |
--------------------------------------------------------------------------------
/Subscriber/Javascript.php:
--------------------------------------------------------------------------------
1 |
4 | *
5 | * For the full copyright and license information, please view the LICENSE
6 | * file that was distributed with this source code.
7 | */
8 |
9 | namespace SwagBrowserLanguage\Subscriber;
10 |
11 | use Doctrine\Common\Collections\ArrayCollection;
12 | use Enlight\Event\SubscriberInterface;
13 |
14 | class Javascript implements SubscriberInterface
15 | {
16 | /**
17 | * @var string
18 | */
19 | private $viewDir;
20 |
21 | /**
22 | * @param string $viewDir
23 | */
24 | public function __construct($viewDir)
25 | {
26 | $this->viewDir = $viewDir;
27 | }
28 |
29 | /**
30 | * {@inheritdoc}
31 | */
32 | public static function getSubscribedEvents()
33 | {
34 | return [
35 | 'Theme_Compiler_Collect_Plugin_Javascript' => 'addJsFiles',
36 | ];
37 | }
38 |
39 | /**
40 | * Provide the needed javascript files
41 | *
42 | * @return ArrayCollection
43 | */
44 | public function addJsFiles()
45 | {
46 | $jsPath = [
47 | $this->viewDir . '/frontend/_public/src/js/jquery.redirect.js',
48 | ];
49 |
50 | return new ArrayCollection($jsPath);
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/SwagBrowserLanguage.php:
--------------------------------------------------------------------------------
1 |
4 | *
5 | * For the full copyright and license information, please view the LICENSE
6 | * file that was distributed with this source code.
7 | */
8 |
9 | namespace SwagBrowserLanguage;
10 |
11 | use Shopware\Components\Plugin;
12 | use Shopware\Components\Plugin\Context\ActivateContext;
13 | use Shopware\Components\Plugin\Context\DeactivateContext;
14 | use Shopware\Components\Plugin\Context\UninstallContext;
15 | use Symfony\Component\DependencyInjection\ContainerBuilder;
16 |
17 | class SwagBrowserLanguage extends Plugin
18 | {
19 | /**
20 | * @param ContainerBuilder $container
21 | */
22 | public function build(ContainerBuilder $container)
23 | {
24 | $container->setParameter('swag_browser_language.plugin_dir', $this->getPath());
25 | parent::build($container);
26 | }
27 |
28 | /**
29 | * @param ActivateContext $context
30 | */
31 | public function activate(ActivateContext $context)
32 | {
33 | $context->scheduleClearCache(ActivateContext::CACHE_LIST_FRONTEND);
34 | }
35 |
36 | /**
37 | * @param DeactivateContext $context
38 | */
39 | public function deactivate(DeactivateContext $context)
40 | {
41 | $context->scheduleClearCache(DeactivateContext::CACHE_LIST_FRONTEND);
42 | }
43 |
44 | /**
45 | * @param UninstallContext $context
46 | */
47 | public function uninstall(UninstallContext $context)
48 | {
49 | $context->scheduleClearCache(UninstallContext::CACHE_LIST_FRONTEND);
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # SwagBrowserLanguage
2 | > Working with Shopware version 5.2.0 to 5.2.27.
3 | > Higher versions may work either but were not tested.
4 | > Use the version 1.1.1 for older Shopware versions
5 |
6 | ## Description
7 | This plugin automatically detects the language settings of your customer’s browsers and forwards them to the appropriate language or subshop. The browser languages are checked according to their priority.
8 |
9 | The following situations can occur:
10 |
11 | * The browser language corresponds to the language of your main shop (no forwarding)
12 | * The browser language matches one of the languages offered in your store (forwarded to the appropriate shop)
13 | * The browser language does not match any of the languages offered in your store (forwarded to the main shop, unless otherwise specified)
14 | * The browser language matches one of the subshops but the subshop has not been linked to the main shop (forwarded to the default shop)
15 | * In addition the user will be informed about the redirection before he's being redirected so he can cancel the redirection process manually at any time to stay at the current shop. Beside the proposal it is possible for the user to decide another shop than the suggested one.
16 |
17 | Your are missing a language or you found a missing or wrong translation? Help us to improve the available translations of shopware via [crowdin](../../../shopware.phpn.com/project/shopware)
18 |
19 | ## Images
20 |
21 |
22 | ## License
23 |
24 | The MIT License (MIT). Please see [License File](LICENSE) for more information.
25 |
--------------------------------------------------------------------------------
/Resources/services.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
7 |
8 | %swag_browser_language.plugin_dir%/Resources/views
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 | %swag_browser_language.plugin_dir%
23 |
24 |
25 |
26 | %swag_browser_language.view_dir%
27 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/Resources/views/widgets/swag_browser_language/get_modal.tpl:
--------------------------------------------------------------------------------
1 | {block name="frontend_index_browser_language_modal"}
2 |
38 | {/block}
39 |
--------------------------------------------------------------------------------
/Subscriber/Frontend.php:
--------------------------------------------------------------------------------
1 |
4 | *
5 | * For the full copyright and license information, please view the LICENSE
6 | * file that was distributed with this source code.
7 | */
8 |
9 | namespace SwagBrowserLanguage\Subscriber;
10 |
11 | use Enlight\Event\SubscriberInterface;
12 | use Enlight_Event_EventArgs;
13 | use Enlight_View_Default;
14 | use Shopware_Controllers_Frontend_Index;
15 |
16 | class Frontend implements SubscriberInterface
17 | {
18 | /**
19 | * @var string
20 | */
21 | private $pluginDir;
22 |
23 | /**
24 | * @var array
25 | */
26 | private $controllerWhiteList = ['detail', 'index', 'listing'];
27 |
28 | /**
29 | * @param string $pluginDir
30 | */
31 | public function __construct($pluginDir)
32 | {
33 | $this->pluginDir = $pluginDir;
34 | }
35 |
36 | /**
37 | * {@inheritdoc}
38 | */
39 | public static function getSubscribedEvents()
40 | {
41 | return [
42 | 'Enlight_Controller_Dispatcher_ControllerPath_Widgets_SwagBrowserLanguage' => 'onGetFrontendController',
43 | 'Enlight_Controller_Action_PostDispatchSecure_Frontend' => 'onPostDispatchFrontend',
44 | ];
45 | }
46 |
47 | /**
48 | * Returns the path to the frontend controller.
49 | *
50 | * @return string
51 | */
52 | public function onGetFrontendController()
53 | {
54 | return $this->pluginDir . '/Controllers/Widgets/SwagBrowserLanguage.php';
55 | }
56 |
57 | /**
58 | * Event listener function of the Enlight_Controller_Action_PostDispatch event.
59 | *
60 | * @param Enlight_Event_EventArgs $arguments
61 | */
62 | public function onPostDispatchFrontend(Enlight_Event_EventArgs $arguments)
63 | {
64 | /** @var $controller Shopware_Controllers_Frontend_Index */
65 | $controller = $arguments->get('subject');
66 |
67 | /** @var \Enlight_Controller_Request_RequestHttp $request */
68 | $request = $controller->Request();
69 |
70 | if (!in_array($request->getControllerName(), $this->controllerWhiteList)) {
71 | return;
72 | }
73 |
74 | /** @var $view Enlight_View_Default */
75 | $view = $controller->View();
76 |
77 | $view->addTemplateDir($this->pluginDir . '/Resources/views');
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/Resources/config.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 | default
7 |
8 |
9 | Forward to this shop if not found any shop languages matching browser language
10 | Auf diesen Shop wird weitergeleitet, wenn kein zu den Browsersprachen passender Shop existiert.
11 | base.ShopLanguage
12 |
13 |
14 | assignedShops
15 |
16 |
17 | Forwards to these shops, if the browser language equals the shop language.
18 | Auf diese Shops wird weitergeleitet, wenn die Browsersprache der Shopsprache entspricht.
19 | base.ShopLanguage
20 |
21 | true
22 |
23 |
24 |
25 | fallbackLanguage
26 |
27 |
28 | en_GB
29 | This is the locale for the translation that will be used by default, if no matching translation was found for the user to be displayed in the infobox in the frontend.
30 | Dies ist die locale für die Übersetzung, auf die, wenn keine passende Übersetzung für die vom Benutzer gewählte Sprache existiert, zurückgegriffen wird, um die Infobox im Frontend zu übersetzen.
31 |
32 |
33 | forceBrowserMainLocale
34 |
35 |
36 | 0
37 | Additional locales on browser language will be ignored
38 | Zusätzliche Lokalisierungen werden in der Browsersprache ignoriert
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/plugin.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 | 2.0.1
7 | Shopware AG
8 | MIT
9 |
10 | Dieses Plugin entscheidet anhand der im Browser des Kunden eingestellten Sprachen, auf welchen Sprachshop der Kunde weitergeleitet wird. Die Browsersprachen werden dabei Ihrer Priorität nach geprüft.
12 |
13 |
Daraus ergeben sich folgende Fälle:
14 |
15 |
16 |
Die gegenwärtig geprüfte Browsersprache entspricht dem Hauptshop -> keine Weiterleitung
17 |
Die gegenwärtig geprüfte Browsersprache entspricht einem Sprachshop -> Weiterleitung auf den entsprechenden Sprachshop
18 |
Keine der Browsersprachen entspricht einem Sprachshop -> Weiterleitung auf den in der Pluginkonfiguration eingestellten Fallback-Sprachshop, sofern dieser nicht dem Hauptshop entspricht, sonst keine Weiterleitung
19 |
20 |
21 |
Sobald zu einer Sprache ein passender Shop gefunden wurde, wird die weitere Suche beendet.
22 |
23 |
Weiterhin besteht in der Pluginkonfiguraion die Möglichkeit eine Infobox zu aktivieren. Diese zeigt dem Benutzer im Falle einer durch das Plugin verursachten Weiterleitung einen kurzen Hinweis an und bietet die Möglichkeit zurück auf den Hauptshop zu gelangen.
24 | ]]>
25 |
26 |
27 | This plugin automatically detects the language settings of your customer’s browsers and forwards them to the appropriate language or subshop. The browser languages are checked according to their priority.
29 |
30 |
The following situations can occur:
31 |
32 |
33 |
The browser language corresponds to the language of your main shop (no forwarding)
34 |
The browser language matches one of the languages offered in your store (forwarded to the appropriate shop)
35 |
The browser language does not match any of the languages offered in your store (forwarded to the main shop, unless otherwise specified)
36 |
The browser language matches one of the subshops but the subshop has not been linked to the main shop (forwarded to the default shop)
37 |
In addition the user will be informed about the redirection before he's being redirected so he can cancel the redirection process manually at any time to stay at the current shop. Beside the proposal it is possible for the user to decide another shop than the suggested one.