*/ class Mage_Adminhtml_Block_Store_Switcher extends Mage_Adminhtml_Block_Template { /** * Key in config for store switcher hint */ const XPATH_HINT_KEY = 'store_switcher'; /** * @var array */ protected $_storeIds; /** * Name of store variable * * @var string */ protected $_storeVarName = 'store'; /** * Url for store switcher hint * * @var string */ protected $_hintUrl; /** * @var bool */ protected $_hasDefaultOption = true; public function __construct() { parent::__construct(); $this->setTemplate('store/switcher.phtml'); $this->setUseConfirm(true); $this->setUseAjax(true); $this->setDefaultStoreName($this->__('All Store Views')); } /** * Deprecated */ public function getWebsiteCollection() { $collection = Mage::getModel('core/website')->getResourceCollection(); $websiteIds = $this->getWebsiteIds(); if (!is_null($websiteIds)) { $collection->addIdFilter($this->getWebsiteIds()); } return $collection->load(); } /** * Get websites * * @return array */ public function getWebsites() { $websites = Mage::app()->getWebsites(); if ($websiteIds = $this->getWebsiteIds()) { foreach ($websites as $websiteId => $website) { if (!in_array($websiteId, $websiteIds)) { unset($websites[$websiteId]); } } } return $websites; } /** * Deprecated */ public function getGroupCollection($website) { if (!$website instanceof Mage_Core_Model_Website) { $website = Mage::getModel('core/website')->load($website); } return $website->getGroupCollection(); } /** * Get store groups for specified website * * @param Mage_Core_Model_Website $website * @return array */ public function getStoreGroups($website) { if (!$website instanceof Mage_Core_Model_Website) { $website = Mage::app()->getWebsite($website); } return $website->getGroups(); } /** * Deprecated */ public function getStoreCollection($group) { if (!$group instanceof Mage_Core_Model_Store_Group) { $group = Mage::getModel('core/store_group')->load($group); } $stores = $group->getStoreCollection(); $_storeIds = $this->getStoreIds(); if (!empty($_storeIds)) { $stores->addIdFilter($_storeIds); } return $stores; } /** * Get store views for specified store group * * @param Mage_Core_Model_Store_Group $group * @return array */ public function getStores($group) { if (!$group instanceof Mage_Core_Model_Store_Group) { $group = Mage::app()->getGroup($group); } $stores = $group->getStores(); if ($storeIds = $this->getStoreIds()) { foreach ($stores as $storeId => $store) { if (!in_array($storeId, $storeIds)) { unset($stores[$storeId]); } } } return $stores; } public function getSwitchUrl() { if ($url = $this->getData('switch_url')) { return $url; } return $this->getUrl('*/*/*', array('_current' => true, $this->_storeVarName => null)); } public function setStoreVarName($varName) { $this->_storeVarName = $varName; return $this; } public function getStoreId() { return $this->getRequest()->getParam($this->_storeVarName); } public function setStoreIds($storeIds) { $this->_storeIds = $storeIds; return $this; } public function getStoreIds() { return $this->_storeIds; } public function isShow() { return !Mage::app()->isSingleStoreMode(); } protected function _toHtml() { if (!Mage::app()->isSingleStoreMode()) { return parent::_toHtml(); } return ''; } /** * Set/Get whether the switcher should show default option * * @param bool $hasDefaultOption * @return bool */ public function hasDefaultOption($hasDefaultOption = null) { if (null !== $hasDefaultOption) { $this->_hasDefaultOption = $hasDefaultOption; } return $this->_hasDefaultOption; } /** * Return url for store switcher hint * * @return string */ public function getHintUrl() { if (null === $this->_hintUrl) { $this->_hintUrl = Mage::helper('core/hint')->getHintByCode(self::XPATH_HINT_KEY); } return $this->_hintUrl; } /** * Return store switcher hint html * * @return string */ public function getHintHtml() { $html = ''; $url = $this->getHintUrl(); if ($url) { $html = '' . $this->__('What is this?') . ''; } return $html; } }