00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 class Mage_Core_Block_Store_Switcher extends Mage_Core_Block_Template
00035 {
00036 protected $_groups = array();
00037 protected $_stores = array();
00038 protected $_loaded = false;
00039
00040 public function __construct()
00041 {
00042 $this->_loadData();
00043 $this->setStores(array());
00044 $this->setLanguages(array());
00045 return parent::__construct();
00046 }
00047
00048 protected function _loadData()
00049 {
00050 if ($this->_loaded) {
00051 return $this;
00052 }
00053
00054 $websiteId = Mage::app()->getStore()->getWebsiteId();
00055 $storeCollection = Mage::getModel('core/store')
00056 ->getCollection()
00057 ->addWebsiteFilter($websiteId);
00058 $groupCollection = Mage::getModel('core/store_group')
00059 ->getCollection()
00060 ->addWebsiteFilter($websiteId);
00061 foreach ($groupCollection as $group) {
00062 $this->_groups[$group->getId()] = $group;
00063 }
00064 foreach ($storeCollection as $store) {
00065 if (!$store->getIsActive()) {
00066 continue;
00067 }
00068 $store->setLocaleCode(Mage::getStoreConfig('general/locale/code', $store->getId()));
00069 $this->_stores[$store->getGroupId()][$store->getId()] = $store;
00070 }
00071
00072 $this->_loaded = true;
00073
00074 return $this;
00075 }
00076
00077 public function getStoreCount()
00078 {
00079 $stores = array();
00080 $localeCode = Mage::getStoreConfig('general/locale/code');
00081 foreach ($this->_groups as $group) {
00082 if (!isset($this->_stores[$group->getId()])) {
00083 continue;
00084 }
00085 $useStore = false;
00086 foreach ($this->_stores[$group->getId()] as $store) {
00087 if ($store->getLocaleCode() == $localeCode) {
00088 $useStore = true;
00089 $stores[] = $store;
00090 }
00091 }
00092 if (!$useStore && isset($this->_stores[$group->getId()][$group->getDefaultStoreId()])) {
00093 $stores[] = $this->_stores[$group->getId()][$group->getDefaultStoreId()];
00094 }
00095 }
00096
00097 $this->setStores($stores);
00098 return count($this->getStores());
00099 }
00100
00101 public function getLanguageCount()
00102 {
00103 $groupId = Mage::app()->getStore()->getGroupId();
00104 if (!isset($this->_stores[$groupId])) {
00105 $this->setLanguages(array());
00106 return 0;
00107 }
00108 $this->setLanguages($this->_stores[$groupId]);
00109 return count($this->getLanguages());
00110 }
00111
00112 public function getCurrentStoreId()
00113 {
00114 return Mage::app()->getStore()->getId();
00115 }
00116
00117 public function getCurrentStoreCode()
00118 {
00119 return Mage::app()->getStore()->getCode();
00120 }
00121 }