Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magento - Fetch current domain and not base domain

Tags:

php

magento

We are running one Magento install over multiple domains and are using a script to fetch information from the database to help users filter the products.

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

like image 617
Vince P Avatar asked Dec 14 '10 09:12

Vince P


2 Answers

echo Mage::getBaseUrl (); 

will return the Store url only i.e. abc.com/store1.

In order to get the Main store URL (domain name), use the following code

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

OR

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

like image 185
Shakti Singh Avatar answered Sep 23 '22 04:09

Shakti Singh


Be aware that $_SERVER['SERVER_NAME'] is not available on Magento scheduler (cron) tasks (unless you put some effort on it) - just realised that today

like image 38
Eugene Lycenok Avatar answered Sep 20 '22 04:09

Eugene Lycenok