How to get url for specific store in magento

How to get url for specific store in magento

July 6, 2026 · Illustrated author avatarBy Stefan Bogdanescu
How to get url for specific store in magento

Getting Specific Store URLs in Magento: A Developer’s Guide

Hello developers! I’m here to help you navigate one of those tricky Magento corner cases that can trip up even the most seasoned e-commerce programmers. Let’s dive into how to get the correct URL for a specific store when implementing your own custom payment module.

Understanding the Problem

You’re currently redirecting users to your payment gateway using Mage::getUrl('comm/comm/redirect'). This works fine for your primary store (www.abc.com), but it fails to distinguish between multiple stores when multistore functionality is enabled. When a customer checks out from www.def.com, the URL generated still points to the primary store’s base URL.

The issue lies in Magento’s default behavior of not considering the current store context for URL generation in some cases. We need to override this and tell Magento to respect the specific store being used during checkout.

Solving the Issue

To resolve this, we’ll use a combination of Magento’s built-in multistore features along with some custom code. Here’s how you can get it working:

Step 1: Determine the Current Store Context

First, let’s ensure that Mage::app()->getStore() correctly retrieves the current store being used during checkout.

$currentStore = Mage::app()->getStore();

In a multistore setup, this will return an instance of Mage_Core_Model_Store representing the active store.

Step 2: Build the URL for the Specific Store

Now that we have the current store object, we can build the correct URL using it. Magento provides the getBaseUrl() method which will respect the specified store’s base URL.

$storeUrl = $currentStore->getBaseUrl();

This will give us something like ‘http://www.def.com/’ for a store with that domain set as its base URL.

Step 3: Append the Routing Path

Finally, we need to append our routing path (‘comm/comm/redirect’) to this base URL.

$fullUrl = $storeUrl . 'index.php/comm/comm/redirect';

Putting it all together:

$currentStore = Mage::app()->getStore();
$storeUrl = $currentStore->getBaseUrl();
$fullUrl = $storeUrl . 'index.php/comm/comm/redirect';

echo $fullUrl;

This code will now generate the correct full URL for the specific store being used during checkout, allowing your custom payment module to redirect users appropriately.

Best Practices

  • Always make sure you’re working in the correct scope when handling multistore setups. Use Mage::app()->setCurrentStore($store); if needed.
  • Remember that URLs should be generated using getBaseUrl() or getUrl() methods that respect store context, rather than hardcoding them.

Conclusion

In this post, we’ve explored how to generate specific store URLs in Magento for use with custom payment modules. By understanding the default behavior and building on Magento’s built-in multistore features, you can ensure your e-commerce platform remains robust even when handling multiple stores.

Don’t forget to check out our other posts on Laravel and Magento development at LaravelCompany. Happy coding!

References

Checkout Extensions Customers Errors

Our network