PHPackages                             pixelant/pxa-site-choice-recommendation - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. pixelant/pxa-site-choice-recommendation

ActiveTypo3-cms-extension

pixelant/pxa-site-choice-recommendation
=======================================

Suggest localized version of site depends on user location and user language.

v2.1.0(5y ago)05.1kGPL-2.0+PHPPHP &gt;=7.1

Since Apr 18Pushed 5y ago4 watchersCompare

[ Source](https://github.com/pixelant/pxa_site_choice_recommendation)[ Packagist](https://packagist.org/packages/pixelant/pxa-site-choice-recommendation)[ RSS](/packages/pixelant-pxa-site-choice-recommendation/feed)WikiDiscussions master Synced today

READMEChangelog (10)Dependencies (2)Versions (12)Used By (0)

Site choice recommendation
==========================

[](#site-choice-recommendation)

What does it do?
----------------

[](#what-does-it-do)

Suggest localized version of site depends on user location and user language. It will show bar on top of the page with possibility to choose site language. Select box options are sorted by priority calculated by checking user location and accept language.

**Note:** To get option based on user location, a EventListner needs to be created in a separate extension.

How to install it
-----------------

[](#how-to-install-it)

Like a regular extension you need to do a few steps.

1. Composer install `composer require pixelant/pxa-site-choice-recommendation`
2. Go to extension manager to isntall extension.
3. Include TypoScript. There are two options to include:
    - *Site choice recommendation - default configuration required for extension to work*
    - *Site choice JS and CSS assets - will include Js and Css libs*

Extension plugins
-----------------

[](#extension-plugins)

Extension has two plugins:

1. Choice bar extension - Loaded by ajax to propose user to change site version. Can't be added on a page.
2. Site choice recommendation splash page - Use as page content in order to show for user ALL available choices. Just select corresponding site choice configuration in order to show it's options.

How to create site choice configuration
---------------------------------------

[](#how-to-create-site-choice-configuration)

Create new record "Site Choice Configuration". It could be created in any storage folder. "Site Choice Configuration" tabs: Main "**General**" tab:

- *Name* - just whatever you want
- *Connect to sites* - choose **rootpages where bar should appear**
- *Max Items* - maximum items in select box in bar
- *Splash pages links* - splash page link for every root page. Each root page might have it's own splash page.

"**Choices**" tab include available site choices for bar and splash page. Each site choice require next configration fields:

- *Title* - title of choice. **It's text area** because it could have **different versions(localizations)** of title. You could specify different localization versions each in new row in a format "Title text|locale":

```
Default title
Swedish title|sv_SE
Ukrainian title|uk_UA

```

- *Flag* - flag icon to show in select box and splash page
- *Select country* - select country. This field represents ISO code (for ex. "us" for USA). This code will be used when check if choice match by user IP. [ISO codes](https://en.wikipedia.org/wiki/List_of_ISO_3166_country_codes)
- *Select language* - select language from list. This field represents short ISO code (for ex. "en" for English). This code will be used for check by user language.
- *Link* - **if choice target to external url**
- *Language layer* - **if choice should lead to site langauge layer**. *Link* need to be empty if language layer is used.

Expected results
----------------

[](#expected-results)

After TypoScript is included and *Site Choice Configuration* is connected to root page, you should get bar with proposal of best matching country / region based on location. **Note:** bar will remain invisible in case you already has visited website localization version that best match you location/language.

Enable choices based on user location
-------------------------------------

[](#enable-choices-based-on-user-location)

Extension has "built in" support to suggest options based on user location.

To enable it, you will need to create a EventListner in a separate extension and also download GeoLite2-Country.mmdb from MaxMind, available from [](https://www.maxmind.com).

Example:

### 1. Registering the event listener

[](#1-registering-the-event-listener)

Following is an example of how to enable the IPDetecor.

In file `your_extension_name/Configuration/Services.yaml` file add following:

```
  VendorName\YourExtensionName\EventListener\IpDetectorFactoryEvent:
    tags:
      - name: event.listener
        identifier: 'yourExtensionNameIpDetectorFactoryEvent'
        event: Pixelant\PxaSiteChoiceRecommendation\Detector\Event\AddDetectorFactoryEvent
        after: acceptLanguageDetectorFactoryEvent
```

### 2. The event listener class

[](#2-the-event-listener-class)

Create file `your_extension_name/Classes/EventListener/IpDetectorFactoryEvent.php` file add following:

```
