How to Get Merchant/User Specific Route?

How to configure and adapt Aimeos based shops as developer
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!
godadada@yahoo.com
Posts: 56
Joined: 15 Mar 2021, 01:03

How to Get Merchant/User Specific Route?

Post by godadada@yahoo.com » 26 Sep 2021, 12:18

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

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

Re: How to Get Merchant/User Specific Route?

Post by aimeos » 27 Sep 2021, 08:18

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, Image give us a star

godadada@yahoo.com
Posts: 56
Joined: 15 Mar 2021, 01:03

Re: How to Get Merchant/User Specific Route?

Post by godadada@yahoo.com » 28 Sep 2021, 00:32

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

godadada@yahoo.com
Posts: 56
Joined: 15 Mar 2021, 01:03

Re: How to Get Merchant/User Specific Route?

Post by godadada@yahoo.com » 29 Sep 2021, 09:30

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,

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

Re: How to Get Merchant/User Specific Route?

Post by aimeos » 29 Sep 2021, 10:04

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?
Yes, that make a lot of sense.
Can you create a pull request for that improvement?
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

godadada@yahoo.com
Posts: 56
Joined: 15 Mar 2021, 01:03

Re: How to Get Merchant/User Specific Route?

Post by godadada@yahoo.com » 29 Sep 2021, 22:53

I will give a shot.

Regards

godadada@yahoo.com
Posts: 56
Joined: 15 Mar 2021, 01:03

Re: How to Get Merchant/User Specific Route?

Post by godadada@yahoo.com » 02 Oct 2021, 08:11

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$
Attachments
helpers.zip
(1.18 KiB) Downloaded 104 times

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

Re: How to Get Merchant/User Specific Route?

Post by aimeos » 02 Oct 2021, 08:51

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
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

godadada@yahoo.com
Posts: 56
Joined: 15 Mar 2021, 01:03

Re: How to Get Merchant/User Specific Route?

Post by godadada@yahoo.com » 02 Oct 2021, 23:04

You are right on excessive db access. I will look into it.

godadada@yahoo.com
Posts: 56
Joined: 15 Mar 2021, 01:03

Re: How to Get Merchant/User Specific Route?

Post by godadada@yahoo.com » 04 Oct 2021, 00:24

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,

Post Reply