Jump to content

PS 1.7: Link::getModuleLink returns different URL for default store


kostandin

Recommended Posts

I'm working with PrestaShop 1.7.1.0 (default installation). Shop is set to debug mode with cache disabled.

I have a backend module that has both backend and frontend controllers. Shop settings:

post-1424809-0-92745000-1501146141_thumb.png

 

Task

I want to generate link to my frontend controller and send it to external system so it can call it. I need to generate this link sometimes from my module's backend controller and sometimes from my module's frontend.

 

My solution:

From both controllers I use this code to generate link URL:

$url = Context::getContext()->link->getModuleLink('cleverreach', 'auth'); 

 

Problem:

Link is not generated the same from backend and from frontend in different scenarios.

 

Background:

I had one shop with multistore option disabled. With this setup, links were generated properly.

 

Then, I enabled multistore option and added additional shop group called "Second", added one store to it and made it default: 

post-1424809-0-26519500-1501146194_thumb.png

 

Store settings are here:

post-1424809-0-24789200-1501146369_thumb.png

 

Settings for store "demoshop 1.7":

post-1424809-0-24669800-1501147051_thumb.png

 

Settings for store "second":

post-1424809-0-12667100-1501147056_thumb.png

 

With this setup, from backend controller I got this link:

http://testshops.rs/prestashop1.7/en/module/cleverreach/auth

This URL works properly and links to my controller. But when I use the same code from this frontend controller ("auth"), I get this link:

http://testshops.rs/prestashop1.7/en/en/module/cleverreach/auth

Note that "/en" prefix is added twice. This link also works but it creates a problem for external system that uses it because those 2 links do not match.

 

Now, I could fix this problem with this code:

$url = Context::getContext()->link->getModuleLink(
    'cleverreach',
    'auth',
    array(),
    null,
    null,
    Configuration::get('PS_SHOP_DEFAULT')
); 

So, I added default shop ID and this generated this link in both cases:

http://testshops.rs/prestashop1.7/en/module/cleverreach/auth 

Now I wanted to test this code if multistore is not enabled so I went to configuration and disabled multistore. I logged out, cleared cache (just in case) and tested again, but the links are now again different. From backend controller it is:

http://testshops.rs/prestashop1.7/en/module/cleverreach/auth  

and from frontend controller it is again with double "/en" prefix:

http://testshops.rs/prestashop1.7/en/en/module/cleverreach/auth

I checked context object and shop and with this setup, backend is returning "second" for context->shop, and frontend is returning "demoshop 1.7", which probably causes the error. The main problem is that with this setup (enabled multistore, set second store as default and then disabled multistore) I cannot manage to get the same link anyhow.

 

Is this a bug or I'm missing something?

 

Thanks.

 

EDIT: I have 3 languages in my shop, this is why /en is added, but the problem is still the same: URLs are not the same.

Edited by kostandin (see edit history)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...