2

I want to get store name by using multiple store ids in magento. like:

<?php $store_ids= array(1,2,3);

Now how to get store names of these store ids.

2 Answers 2

4

Simplest way I can think is:

Mage::getModel('core/store')->load($storeId);

So use :

$store_ids= array(1,2,3);
foreach($store_ids as $storeId){
$store = Mage::getModel('core/store')->load($storeId);
$name = $store->getName();
}

That's what else you can have from object $store:

        [code] => 
        [website_id] => 
        [group_id] => 
        [name] => 
        [sort_order] => 
        [is_active] => 
2
  • Thankyou vbak. its working for me.
    – India
    Aug 1, 2015 at 12:50
  • @vbak How can we do the same in magento 2?
    – manini
    Jul 20, 2018 at 6:49
0

Use below:

$store_ids= array(1,2,3); $stores=Mage::getModel('core/store')->getCollection()
->addFieldToFilter('store_id',array('in'=>$store_ids))->addFieldToSelect('name');

foreach( $stores as $eachStore){

echo $eachStore->getName();

}

As you want to only store name of multiple stores that why i am suggest to use store collection and filter them by store_id instead of use store model(Mage::getModel('core/store')) and load them one by one.

It is better for coding.

  • In magento,you can get store collection by below code:

Mage::getModel('core/store')->getCollection()

  • Now you nee filter the collection by store_id and with in array conditions:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.