/** * Process website info * * @param Mage_Core_Model_System_Store $storeModel * @param Mage_Core_Model_Website $website * @param string $section * @param string $curStore * @param string $curWebsite * @param array $options * @return array */ protected function _processWebsite(Mage_Core_Model_System_Store $storeModel, Mage_Core_Model_Website $website, $section, $curStore, $curWebsite, array $options) { $websiteShow = false; foreach ($storeModel->getGroupCollection() as $group) { if ($group->getWebsiteId() != $website->getId()) { continue; } $groupShow = false; foreach ($storeModel->getStoreCollection() as $store) { if ($store->getGroupId() != $group->getId()) { continue; } if (!$websiteShow) { $websiteShow = true; $options['website_' . $website->getCode()] = array('label' => $website->getName(), 'url' => $this->getUrl('*/*/*', array('section' => $section, 'website' => $website->getCode())), 'selected' => !$curStore && $curWebsite == $website->getCode(), 'style' => 'padding-left:16px; background:#DDD; font-weight:bold;'); } if (!$groupShow) { $groupShow = true; $options['group_' . $group->getId() . '_open'] = array('is_group' => true, 'is_close' => false, 'label' => $group->getName(), 'style' => 'padding-left:32px;'); } $options['store_' . $store->getCode()] = array('label' => $store->getName(), 'url' => $this->getUrl('*/*/*', array('section' => $section, 'website' => $website->getCode(), 'store' => $store->getCode())), 'selected' => $curStore == $store->getCode(), 'style' => ''); } if ($groupShow) { $options['group_' . $group->getId() . '_close'] = array('is_group' => true, 'is_close' => true); } } return $options; }
public function testLoad() { /* Test loading by id */ $this->assertEquals(1, $this->_model->getId()); $this->assertEquals('base', $this->_model->getCode()); $this->assertEquals('Main Website', $this->_model->getName()); /* Test loading by code */ $this->_model->load('admin'); $this->assertEquals(0, $this->_model->getId()); $this->assertEquals('admin', $this->_model->getCode()); $this->assertEquals('Admin', $this->_model->getName()); }
/** * Initialize currently ran store * * @param string $scopeCode code of default scope (website/store_group/store code) * @param string $scopeType type of default scope (website/group/store) * @return unknown_type */ protected function _initCurrentStore($scopeCode, $scopeType) { Varien_Profiler::start('mage::app::init::stores'); $this->_initStores(); Varien_Profiler::stop('mage::app::init::stores'); if (empty($scopeCode) && !is_null($this->_website)) { $scopeCode = $this->_website->getCode(); $scopeType = 'website'; } switch ($scopeType) { case 'store': $this->_currentStore = $scopeCode; break; case 'group': $this->_currentStore = $this->_getStoreByGroup($scopeCode); break; case 'website': $this->_currentStore = $this->_getStoreByWebsite($scopeCode); break; default: $this->throwStoreException(); } if (!empty($this->_currentStore)) { $this->_checkCookieStore($scopeType); $this->_checkGetStore($scopeType); } $this->_useSessionInUrl = $this->getStore()->getConfig(Mage_Core_Model_Session_Abstract::XML_PATH_USE_FRONTEND_SID); return $this; }
/** * Initialize currently ran store * * @param string $scopeCode code of default scope (website/store_group/store code) * @param string $scopeType type of default scope (website/group/store) * @return unknown_type */ protected function _initCurrentStore($scopeCode, $scopeType) { Varien_Profiler::start('mage::app::init::stores'); $this->_initStores(); Varien_Profiler::stop('mage::app::init::stores'); if (empty($scopeCode) && !is_null($this->_website)) { $scopeCode = $this->_website->getCode(); $scopeType = 'website'; } switch ($scopeType) { case 'store': $this->_currentStore = $scopeCode; break; case 'group': $this->_currentStore = $this->_getStoreByGroup($scopeCode); break; case 'website': $this->_currentStore = $this->_getStoreByWebsite($scopeCode); break; default: $this->throwStoreException(); } if (!empty($this->_currentStore)) { $this->_checkCookieStore($scopeType); $this->_checkGetStore($scopeType); } return $this; }
/** * Initialize application * * @param string|array $code * @param string $type * @param string $etcDir * @return Mage_Core_Model_App */ public function init($code, $type = null, $options = array()) { $this->setErrorHandler(self::DEFAULT_ERROR_HANDLER); date_default_timezone_set(Mage_Core_Model_Locale::DEFAULT_TIMEZONE); if (is_string($options)) { $options = array('etc_dir' => $options); } if (VPROF) { Varien_Profiler::start('mage::app::init::config'); } $this->_config = AO::getConfig(); $this->_config->init($options); if (VPROF) { Varien_Profiler::stop('mage::app::init::config'); } if (AO::isInstalled($options)) { if (VPROF) { Varien_Profiler::start('mage::app::init::stores'); } $this->_initStores(); if (VPROF) { Varien_Profiler::stop('mage::app::init::stores'); } if (empty($code) && !is_null($this->_website)) { $code = $this->_website->getCode(); $type = 'website'; } switch ($type) { case 'store': $this->_currentStore = $code; break; case 'group': $this->_currentStore = $this->_getStoreByGroup($code); break; case 'website': $this->_currentStore = $this->_getStoreByWebsite($code); break; default: $this->throwStoreException(); } if (!empty($this->_currentStore)) { $this->_checkCookieStore($type); $this->_checkGetStore($type); } $this->getRequest()->setPathInfo(); } $this->_initFrontController(); return $this; }
private function _saveWebsiteConfigItems(array $configs, Mage_Core_Model_Website $website) { try { if (!$website->getId()) { throw new Exception($this->__('Website does not exist')); } if (!empty($configs)) { foreach ($configs as $config) { if (isset($config['encrypted']) && $config['encrypted'] == 1) { $config['value'] = Mage::helper('core')->encrypt($config['value']); } // Save config $this->_checkAndSaveConfig($config['path'], $config['value'], 'websites', $website->getId(), $website->getCode()); } } } catch (Exception $e) { $this->log($e->getMessage()); } }
/** * Method add website fieldset to the form. * @param Mage_Core_Model_Website $website */ private function _addWebsiteFieldset($website, $form) { $prefixWeb = 'website-' . $website->getCode(); /* make fieldset */ $layoutFieldset = $form->addFieldset($prefixWeb . '_fieldset', array('legend' => Mage::helper('mturbo')->__($website->getName() . ' settings'), 'class' => 'fieldset')); /* add extra user control */ $layoutFieldset->addType('html_element', Artio_MTurbo_Helper_Data::FORM_HTML); $layoutFieldset->addType('widget_button', Artio_MTurbo_Helper_Data::FORM_WIDGET_BUTTON); /* indicator whether website is enabled */ $layoutFieldset->addField($prefixWeb . '-enabled', 'select', array('name' => $prefixWeb . '-enabled', 'label' => Mage::helper('mturbo')->__('Enable website') . ':', 'value' => '1', 'options' => array(0 => Mage::helper('mturbo')->__('No'), 1 => Mage::helper('mturbo')->__('Yes')))); /* add field for turbopath */ $layoutFieldset->addField($prefixWeb . '-base_dir', 'text', array('name' => $prefixWeb . '-base_dir', 'value' => Mage::getBaseDir(), 'label' => Mage::helper('mturbo')->__('Base directory') . ':')); /* add field for server name */ $layoutFieldset->addField($prefixWeb . '-server_name', 'text', array('name' => $prefixWeb . '-server_name', 'value' => Mage::helper('mturbo/website')->getServerName($website->getDefaultStore()->getCode()), 'label' => Mage::helper('mturbo')->__('Server name') . ':')); /* every store has one select determines whether enabled is */ foreach ($website->getStores() as $store) { if ($store->getIsActive()) { $layoutFieldset->addField($prefixWeb . '-store-' . $store->getCode(), 'select', array('name' => $prefixWeb . '-store-' . $store->getCode(), 'label' => $store->getGroup()->getName() . '<br />' . $store->getName(), 'value' => '1', 'options' => array(0 => Mage::helper('mturbo')->__('No'), 1 => Mage::helper('mturbo')->__('Yes')))); } } }
/** * Method add website fieldset to the form. * @param Mage_Core_Model_Website $website */ private function _addWebsiteFieldset($website) { $prefixWeb = 'website-' . $website->getCode(); /* make fieldset */ $layoutFieldset = $this->form->addFieldset($prefixWeb . '_fieldset', array('legend' => $this->getMyHelper()->__($website->getName() . ' settings'), 'class' => 'fieldset')); /* add extra user control */ $layoutFieldset->addType('html_element', Artio_MTurbo_Helper_Data::FORM_HTML); $layoutFieldset->addType('widget_button', Artio_MTurbo_Helper_Data::FORM_WIDGET_BUTTON); /* indicator whether website is enabled */ $layoutFieldset->addField($prefixWeb . '-enabled', 'select', array('name' => $prefixWeb . '-enabled', 'label' => $this->getMyHelper()->__('Enable website') . ':', 'options' => array(0 => $this->getMyHelper()->__('No'), 1 => $this->getMyHelper()->__('Yes')))); /* add field for base dir */ $layoutFieldset->addField($prefixWeb . '-base_dir', 'text', array('name' => $prefixWeb . '-base_dir', 'label' => $this->getMyHelper()->__('Base directory') . ':')); /* add field for server name */ $layoutFieldset->addField($prefixWeb . '-server_name', 'text', array('name' => $prefixWeb . '-server_name', 'label' => $this->getMyHelper()->__('Server name') . ':')); $layoutFieldset->addField($prefixWeb . '_dec1', 'html_element', array('label' => '<h4>' . $this->getMyHelper()->__('Enable/Disable Storeview') . '</h4>', 'code' => '<div style="height:10px;border-bottom:1px solid #808080"></div>')); /* every store has one select determines whether enabled is */ foreach ($website->getStores() as $store) { if ($store->getIsActive()) { $layoutFieldset->addField($prefixWeb . '-store-' . $store->getCode(), 'select', array('name' => $prefixWeb . '-store-' . $store->getCode(), 'label' => $store->getGroup()->getName() . '<br />' . $store->getName(), 'options' => array(0 => $this->getMyHelper()->__('No'), 1 => $this->getMyHelper()->__('Yes')))); } } $layoutFieldset->addField($prefixWeb . '_dec2', 'html_element', array('label' => '<h4>' . $this->getMyHelper()->__('Htaccess settings') . '</h4>', 'code' => '<div style="height:10px;border-bottom:1px solid #808080"></div>')); /* get htaccess state and set color by it */ $htaccess = Mage::getModel('mturbo/htaccess')->setWebsiteCode($website->getCode()); $state = ''; $pathToHtaccess = $htaccess->getPathToBaseHtaccess(); $color = Mage::helper('mturbo/functions')->get_file_state($pathToHtaccess, $state, 'ew') ? 'green' : 'red'; $layoutFieldset->addField($prefixWeb . '_dec3', 'html_element', array('label' => $this->getMyHelper()->__('File .htaccess path'), 'code' => '<span>' . $pathToHtaccess . '</span>')); $edit = $htaccess->isEditedByMTurbo() ? 'yes' : 'no'; $layoutFieldset->addField($prefixWeb . '_dec5', 'html_element', array('label' => $this->getMyHelper()->__('Edited by MTurbo'), 'code' => '<span><b>' . $this->getMyHelper()->__($edit) . '</b></span>')); $layoutFieldset->addField($prefixWeb . '_dec4', 'html_element', array('label' => $this->getMyHelper()->__('File .htaccess state'), 'code' => '<span style="color:' . $color . '">' . $this->getMyHelper()->__($state) . '</span>')); /* button 'rebuild' show only if htaccess is ready */ if ($color == 'green') { $layoutFieldset->addField($prefixWeb . '_htaccess_button', 'widget_button', array('name' => $prefixWeb . '_htaccess_button', 'label' => $this->getMyHelper()->__('Rebuild .htaccess for this website'), 'onclick' => "setLocation('" . Mage::helper('adminhtml')->getUrl('*/*/htaccessbuild', array('websitecode' => $website->getCode())) . "')")); } $layoutFieldset->addField($prefixWeb . '_urllist_button', 'widget_button', array('name' => $prefixWeb . '_urllist_button', 'label' => $this->getMyHelper()->__('Generate URL list for this website'), 'onclick' => "setLocation('" . Mage::helper('adminhtml')->getUrl('*/*/generateurllist', array('websitecode' => $website->getCode())) . "')")); }
/** * Make sure website is set * * @throws Mage_Core_Exception */ protected function _ensureWebsite() { if (!$this->_website || !$this->_website->getCode()) { Mage::throwException(Mage::helper('enterprise_staging')->__('Website code is not defined.')); } }
/** * Initialize currently ran store * * @param string $scopeCode code of default scope (website/store_group/store code) * @param string $scopeType type of default scope (website/group/store) * @return Mage_Core_Model_App * @throws Mage_Core_Model_Store_Exception */ protected function _initCurrentStore($scopeCode, $scopeType) { Magento_Profiler::start('init_stores'); $this->_initStores(); Magento_Profiler::stop('init_stores'); if (empty($scopeCode) && !is_null($this->_website)) { $scopeCode = $this->_website->getCode(); $scopeType = 'website'; } switch ($scopeType) { case Mage_Core_Model_App_Options::APP_RUN_TYPE_STORE: $this->_currentStore = $scopeCode; break; case Mage_Core_Model_App_Options::APP_RUN_TYPE_GROUP: $this->_currentStore = $this->_getStoreByGroup($scopeCode); break; case Mage_Core_Model_App_Options::APP_RUN_TYPE_WEBSITE: $this->_currentStore = $this->_getStoreByWebsite($scopeCode); break; default: $this->throwStoreException(); } if (!empty($this->_currentStore)) { $this->_checkCookieStore($scopeType); $this->_checkGetStore($scopeType); } $this->_useSessionInUrl = $this->getStore()->getConfig(Mage_Core_Model_Session_Abstract::XML_PATH_USE_FRONTEND_SID); Mage::dispatchEvent('core_app_init_current_store_after'); return $this; }