How to Get Merchant/User Specific Route?
Forum rules
Always add your Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
Always add your Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
-
- Posts: 56
- Joined: 15 Mar 2021, 01:03
How to Get Merchant/User Specific Route?
Greetings,
I need to make following routes reflecting login user's sites/locale/currency: aimeos_shop_list and aimeos_shop_account. I notice from aimeos examples following statement may work:
href="{{ route('aimeos_shop_list',['site'=>Route::current()->parameter('site','default'),'locale'=>Route::current()->parameter('locale','en'),'currency'=>Route::current()->parameter('currency','EUR')]) }}"
but it only gives default site and corresponding locale and currency.
How can I make the route have login user's site/locale/currency? any document, pointers, examples will be appreciated.
Regards
I need to make following routes reflecting login user's sites/locale/currency: aimeos_shop_list and aimeos_shop_account. I notice from aimeos examples following statement may work:
href="{{ route('aimeos_shop_list',['site'=>Route::current()->parameter('site','default'),'locale'=>Route::current()->parameter('locale','en'),'currency'=>Route::current()->parameter('currency','EUR')]) }}"
but it only gives default site and corresponding locale and currency.
How can I make the route have login user's site/locale/currency? any document, pointers, examples will be appreciated.
Regards
Re: How to Get Merchant/User Specific Route?
You can use Laravel's Auth::user() facade to get the "siteid" property. Afterwards, you have to lookup the site code by the site ID in the mshop_locale_site table and use that value as default parameter for "site".
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, give us a star
If you like Aimeos, give us a star
-
- Posts: 56
- Joined: 15 Mar 2021, 01:03
Re: How to Get Merchant/User Specific Route?
Thanks for the response.
You approach of reaching out to db table will work.
Is there shorter and easier path?
For example should Route::current()->parameter('site','default')... to be updated for current login user?
Regards
You approach of reaching out to db table will work.
Is there shorter and easier path?
For example should Route::current()->parameter('site','default')... to be updated for current login user?
Regards
-
- Posts: 56
- Joined: 15 Mar 2021, 01:03
Re: How to Get Merchant/User Specific Route?
Hey,
Here is my latest discovery and thoughts.
I did a global search of Route::current()->parameter... found the values are first from url request, if not available 'site' becomes 'default', 'locales' 'en', and 'currency' 'EUR'.
Would it be preferable to get the parameters first from url request, second from logged-in user db table mshop_locale, third from hard coded default values?
Any input is appreciated.
Regards,
Here is my latest discovery and thoughts.
I did a global search of Route::current()->parameter... found the values are first from url request, if not available 'site' becomes 'default', 'locales' 'en', and 'currency' 'EUR'.
Would it be preferable to get the parameters first from url request, second from logged-in user db table mshop_locale, third from hard coded default values?
Any input is appreciated.
Regards,
Re: How to Get Merchant/User Specific Route?
Yes, that make a lot of sense.godadada@yahoo.com wrote: ↑29 Sep 2021, 09:30 Would it be preferable to get the parameters first from url request, second from logged-in user db table mshop_locale, third from hard coded default values?
Can you create a pull request for that improvement?
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, give us a star
If you like Aimeos, give us a star
-
- Posts: 56
- Joined: 15 Mar 2021, 01:03
Re: How to Get Merchant/User Specific Route?
I will give a shot.
Regards
Regards
-
- Posts: 56
- Joined: 15 Mar 2021, 01:03
Re: How to Get Merchant/User Specific Route?
I have something to show, first cut only. It seems to do what I need, may not be bug-free. I have changed function airoute to have 'site' in order of, url slug, login user site, default site.
I have not done git pull request for some years, have to relearn it for me to do it. Hope someone carry it from here, do what ever change necessary.
following is the diff, also attached changed Helpers.php file.
dude@galaxy:~/small$ diff vendor/aimeos/aimeos-core/lib/mshoplib/src/MShop/Context/Item/Standard.php ~/tests/aimeos/vendor/aimeos/aimeos-core/lib/mshoplib/src/MShop/Context/Item/Standard.php
dude@galaxy:~/small$ diff vendor/aimeos/aimeos-laravel/src/helpers.php ~/tests/aimeos/vendor/aimeos/aimeos-laravel/src/helpers.php
24,34c24
< $site = null;
< if(config( 'app.shop_multishop' ) || config( 'app.shop_registration' )) {
< $user = Auth::user();
< if( $user && $user->exists() ) {
< $siteid = current( array_reverse( explode( '.', trim( $user->siteid, '.' ) ) ) );
< $context = app( 'aimeos.context' )->get();
< $site = \Aimeos\MShop::create( $context, 'locale/site' )->get( $siteid )->getCode();
< } else {
< $site = 'default';
< }
< }
---
> $site = config( 'app.shop_multishop' ) || config( 'app.shop_registration' ) ? 'default' : null;
dude@galaxy:~/small$
I have not done git pull request for some years, have to relearn it for me to do it. Hope someone carry it from here, do what ever change necessary.
following is the diff, also attached changed Helpers.php file.
dude@galaxy:~/small$ diff vendor/aimeos/aimeos-core/lib/mshoplib/src/MShop/Context/Item/Standard.php ~/tests/aimeos/vendor/aimeos/aimeos-core/lib/mshoplib/src/MShop/Context/Item/Standard.php
dude@galaxy:~/small$ diff vendor/aimeos/aimeos-laravel/src/helpers.php ~/tests/aimeos/vendor/aimeos/aimeos-laravel/src/helpers.php
24,34c24
< $site = null;
< if(config( 'app.shop_multishop' ) || config( 'app.shop_registration' )) {
< $user = Auth::user();
< if( $user && $user->exists() ) {
< $siteid = current( array_reverse( explode( '.', trim( $user->siteid, '.' ) ) ) );
< $context = app( 'aimeos.context' )->get();
< $site = \Aimeos\MShop::create( $context, 'locale/site' )->get( $siteid )->getCode();
< } else {
< $site = 'default';
< }
< }
---
> $site = config( 'app.shop_multishop' ) || config( 'app.shop_registration' ) ? 'default' : null;
dude@galaxy:~/small$
- Attachments
-
- helpers.zip
- (1.18 KiB) Downloaded 222 times
Re: How to Get Merchant/User Specific Route?
The airoute() helper might be not the best place because the database queries are executed every time the function is used somewhere in the code. You should consider moving your code to the Support.php class can cache the result in a class property:
https://github.com/aimeos/aimeos-larave ... upport.php
https://github.com/aimeos/aimeos-larave ... upport.php
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, give us a star
If you like Aimeos, give us a star
-
- Posts: 56
- Joined: 15 Mar 2021, 01:03
Re: How to Get Merchant/User Specific Route?
You are right on excessive db access. I will look into it.
-
- Posts: 56
- Joined: 15 Mar 2021, 01:03
Re: How to Get Merchant/User Specific Route?
Greetings,
This is becoming hairy and hope not beyond me.
There are 35 aimeos routes that can have 'site' parameters, which means all of them need reflecting logged-in user's site choice. But at the moment there are 15 that have done so through 'admin' related routes. 'admin' has taken care of it in file ./vendor/aimeos/aimeos-laravel/src/Aimeos/Shop/Controller/AdminController.php. I would think this solution may have consiered cache/db relations and precedence. If that is the case there is an easy solution for all routes, by making a 'trait' out of 'admin' solution and making calls from other controllers/methods. If it is not the case it would be too involved and tough for me to do it.
Please confirm if suggested solution workable.
Regards,
This is becoming hairy and hope not beyond me.
There are 35 aimeos routes that can have 'site' parameters, which means all of them need reflecting logged-in user's site choice. But at the moment there are 15 that have done so through 'admin' related routes. 'admin' has taken care of it in file ./vendor/aimeos/aimeos-laravel/src/Aimeos/Shop/Controller/AdminController.php. I would think this solution may have consiered cache/db relations and precedence. If that is the case there is an easy solution for all routes, by making a 'trait' out of 'admin' solution and making calls from other controllers/methods. If it is not the case it would be too involved and tough for me to do it.
Please confirm if suggested solution workable.
Regards,