Multi site redirect based on location

Help for integrating the Laravel package
Forum rules
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
User avatar
VirtualSpy
Advanced
Posts: 122
Joined: 05 Jul 2022, 07:55

Multi site redirect based on location

Post by VirtualSpy » 27 Dec 2022, 00:58

laravel version 9.36.4 , Aimeos version 2022.10.3 and PHP version 8.1.3 (Win)

Multi site automatically redirect on default site so i want redirect multi site based on location please tell me is it possible and what will it's process.

User avatar
aimeos
Administrator
Posts: 7941
Joined: 01 Jan 1970, 00:00

Re: Multi site redirect based on location

Post by aimeos » 28 Dec 2022, 21:03

What is "location" in terms of what you know from the user? IP? Zip code?
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

User avatar
VirtualSpy
Advanced
Posts: 122
Joined: 05 Jul 2022, 07:55

Re: Multi site redirect based on location

Post by VirtualSpy » 28 Dec 2022, 23:24

aimeos wrote: 28 Dec 2022, 21:03 What is "location" in terms of what you know from the user? IP? Zip code?
Location is based on IP address

User avatar
aimeos
Administrator
Posts: 7941
Joined: 01 Jan 1970, 00:00

Re: Multi site redirect based on location

Post by aimeos » 30 Dec 2022, 19:10

You should implement a redirect for the home page ("/") using a GeoIP database.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

User avatar
VirtualSpy
Advanced
Posts: 122
Joined: 05 Jul 2022, 07:55

Re: Multi site redirect based on location

Post by VirtualSpy » 03 Jan 2023, 04:55

aimeos wrote: 30 Dec 2022, 19:10 You should implement a redirect for the home page ("/") using a GeoIP database.
i tried like this

Code: Select all

$ip = \Request::ip();
$currentUserInfo = Location::get($ip);
if($currentUserInfo!==false) {
$country=$currentUserInfo->countryName;
}
if (config('app.shop_multishop')) {
    if(isset($country)) {
    if($country!=="India") {
    $conf['prefix'] .= '/uae';
    }
}
   else {
    $conf['prefix'] .= '/{site}';
    $conf['where']['site'] = '[A-Za-z0-9\.\-]+';
}
}

if ($conf['prefix']) {
    Route::get('/', function () use ($params) {
        return redirect(airoute('aimeos_home', $params));
    });
}

i am getting $conf['prefix'] = /uae
but it is not redirecting on uae site because it is redirecting from shop.php

Code: Select all

 'mshop' => [
        'locale' => [
            'site' => 'in', // used instead of "default"
        ],
    ],
please tell me where this config is using or tell me other solution

User avatar
VirtualSpy
Advanced
Posts: 122
Joined: 05 Jul 2022, 07:55

Re: Multi site redirect based on location

Post by VirtualSpy » 04 Jan 2023, 14:14

VirtualSpy wrote: 03 Jan 2023, 04:55
aimeos wrote: 30 Dec 2022, 19:10 You should implement a redirect for the home page ("/") using a GeoIP database.
i tried like this

Code: Select all

$ip = \Request::ip();
$currentUserInfo = Location::get($ip);
if($currentUserInfo!==false) {
$country=$currentUserInfo->countryName;
}
if (config('app.shop_multishop')) {
    if(isset($country)) {
    if($country!=="India") {
    $conf['prefix'] .= '/uae';
    }
}
   else {
    $conf['prefix'] .= '/{site}';
    $conf['where']['site'] = '[A-Za-z0-9\.\-]+';
}
}

if ($conf['prefix']) {
    Route::get('/', function () use ($params) {
        return redirect(airoute('aimeos_home', $params));
    });
}

i am getting $conf['prefix'] = /uae
but it is not redirecting on uae site because it is redirecting from shop.php

Code: Select all

 'mshop' => [
        'locale' => [
            'site' => 'in', // used instead of "default"
        ],
    ],
please tell me where this config is using or tell me other solution
i got this config

Code: Select all

 'mshop' => [
        'locale' => [
            'site' => 'in', // used instead of "default"
        ],
    ],
is using in airoute function of aimeos-laravel but can i overwrite or extend this function please tell me

User avatar
VirtualSpy
Advanced
Posts: 122
Joined: 05 Jul 2022, 07:55

Re: Multi site redirect based on location

Post by VirtualSpy » 04 Jan 2023, 14:46

VirtualSpy wrote: 04 Jan 2023, 14:14
VirtualSpy wrote: 03 Jan 2023, 04:55
aimeos wrote: 30 Dec 2022, 19:10 You should implement a redirect for the home page ("/") using a GeoIP database.
i tried like this

Code: Select all

$ip = \Request::ip();
$currentUserInfo = Location::get($ip);
if($currentUserInfo!==false) {
$country=$currentUserInfo->countryName;
}
if (config('app.shop_multishop')) {
    if(isset($country)) {
    if($country!=="India") {
    $conf['prefix'] .= '/uae';
    }
}
   else {
    $conf['prefix'] .= '/{site}';
    $conf['where']['site'] = '[A-Za-z0-9\.\-]+';
}
}

if ($conf['prefix']) {
    Route::get('/', function () use ($params) {
        return redirect(airoute('aimeos_home', $params));
    });
}

i am getting $conf['prefix'] = /uae
but it is not redirecting on uae site because it is redirecting from shop.php

Code: Select all

 'mshop' => [
        'locale' => [
            'site' => 'in', // used instead of "default"
        ],
    ],
please tell me where this config is using or tell me other solution
i got this config

Code: Select all

 'mshop' => [
        'locale' => [
            'site' => 'in', // used instead of "default"
        ],
    ],
is using in airoute function of aimeos-laravel but can i overwrite or extend this function please tell me
ok now i understand i should use redirect()->intended in place of airoute function.

User avatar
aimeos
Administrator
Posts: 7941
Joined: 01 Jan 1970, 00:00

Re: Multi site redirect based on location

Post by aimeos » 06 Jan 2023, 12:14

Your route code also doesn't work because "/{site}" must be always the path prefix and "uae" is only a value for that placeholder. The correct code should look something like this:

Code: Select all

if (config('app.shop_multishop')) {
	if(($currentUserInfo = Location::get(\Request::ip())) !== false
		&& $currentUserInfo->countryName !== 'India') {
		$param['site'] = 'uae';
	} 
	$conf['prefix'] .= '/{site}';
	$conf['where']['site'] = '[A-Za-z0-9\.\-]+';
}
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply