Magento - select the current domain, not the base domain.

We run the Magento installation across multiple domains and use a script to extract information from the database to help users filter products.

In our coding, we have the $_SERVER function that calls the repository, which seems to be repository 1 (which is located on domain 1), I was wondering what I would need to change to get information from store 2 (which includes domain 2).

+4
source share
4 answers
 echo Mage::getBaseUrl (); 

will only return the store address, i.e. abc.com/store1.

To get the URL of the main repository (domain name), use the following code

 echo Mage::getBaseUrl (Mage_Core_Model_Store::URL_TYPE_WEB); 

OR

you can get the current domain with $_SERVER['HTTP_HOST'];

+14
source

First of all, $ _SERVER is not a function, but a predefined variable (associative array). After you access the site from domain 2, $ _SERVER ['SERVER_NAME'] will give you the right thing. It all depends on which domain you are accessing the server from. I am currently using this for a reseller website, I have many parked domains.

Hope this helps.

Hooray!

0
source

Keep in mind that $ _SERVER ['SERVER_NAME'] is not available in the tasks of the Magento (cron) scheduler (unless you have put any effort into it) - I just realized that today

0
source

If you have several domains, then, presumably, you have several stores. Instead of reading the domain to determine which storage you can just read the storage directly:

 $store = Mage::app()->getStore() 

$store , then you have all the necessary information. For example, to get the "repository code" that you set in using the administrator,

 $store->getCode() 

In addition to object-oriented and, therefore, easier to write, you benefit from the fact that the domains are fully customizable by the administrator, you will not need to rewrite your code every time there is a change.

-1
source

Source: https://habr.com/ru/post/1332083/


All Articles