*/ class Fishpig_Bolt_Helper_Data extends Mage_Core_Helper_Abstract { /** * Store the current store ID/code in the session * * @param Mage_Core_Mode_Store|null $store * @return $this */ public function setSessionData($store = null) { if (is_null($store)) { $store = Mage::app()->getStore(); } Mage::getSingleton('core/session') ->setWebsiteId($store->getWebsiteId()) ->setWebsiteCode($store->getWebsite()->getCode()) ->setStoreGroupId($store->getGroupId()) ->setStoreCode($store->getCode()) ->setStoreId($store->getId()) ->setCurrencyCode($store->getCurrencyCode()) ->setCartItemCount( Mage::getSingleton('checkout/cart')->getItemsCount() ); return $this; } /** * Refresh the cache files for the given store/url combinations * * @param array $urlsByStore * @return $this */ public function refreshCache(array $urlsByStore) { Fishpig_Bolt_Cache::setCachePath( Mage::getStoreConfig('bolt/cache_file/path', 0) ); foreach($urlsByStore as $storeId => $urls) { $currencies = explode(',', Mage::getStoreConfig('currency/options/allow', $storeId)); foreach($urls as $url) { Fishpig_Bolt_Cache::deleteById(Fishpig_Bolt::createCacheId($url, $storeId)); foreach($currencies as $currency) { Fishpig_Bolt_Cache::deleteById(Fishpig_Bolt::createCacheId($url, $storeId, $currency)); } } } return $this; } /** * Refresh the config file * * @return array|false */ public function refreshConfig() { $file = Mage::getBaseDir('etc') . DS . 'bolt.config'; if (Mage::app()->useCache('bolt')) { $container = array( 'websites' => array(), 'admin_route' => (string)Mage::getConfig()->getNode('admin/routers/adminhtml/args/frontName'), 'use_cache' => (int)Mage::app()->useCache('bolt'), ); $defaults = (array)Mage::app()->getConfig()->getNode('default/bolt')->asArray(); $websites = Mage::getResourceModel('core/website_collection')->load(); foreach($websites as $website) { $isDefaultStore = false; if (count(($groups = $website->getGroups())) > 0) { $container['websites'][$website->getId()] = array( 'code' => $website->getCode(), 'default_group_id' => $website->getDefaultGroupId(), 'is_default' => $website->getIsDefault(), 'groups' => array(), ); if ($website->getIsDefault()) { $container['default_website_code'] = $website->getCode(); $container['default_website_id'] = $website->getId(); } foreach($groups as $group) { $stores = Mage::getResourceModel('core/store_collection') ->addFieldToFilter('group_id', $group->getId()) ->setOrder('sort_order', 'ASC') ->load(); if (count($stores) > 0) { $container['websites'][$website->getId()]['groups'][$group->getId()] = array( 'default_store_id' => $group->getDefaultStoreId(), 'stores' => array(), ); foreach($stores as $store) { $buffer = array( 'website_id' => $website->getId(), 'website_code' => $website->getCode(), 'store_group_id' => $group->getId(), 'store_id' => $store->getId(), 'store_code' => $store->getCode(), 'base_url' => Mage::getUrl('', array('_store' => $store->getCode())), 'currency_code' => $store->getCurrentCurrencyCode(), 'is_default' => $group->getDefaultStoreId() === $store->getId(), ); foreach($defaults as $area => $values) { foreach($values as $field => $value) { if (($configValue = trim(Mage::getStoreConfig('bolt/' . $area . '/' . $field, $store))) !== '') { $buffer[$area][$field] = $configValue; } } } if (isset($buffer['exclude']['uris'])) { $uris = array(); foreach(unserialize($buffer['exclude']['uris']) as $uri) { $uris[] = array_shift($uri); } $buffer['exclude']['uris'] = serialize($uris); } $container['websites'][$website->getId()]['groups'][$group->getId()]['stores'][$store->getId()] = $buffer; } } } if (count($container['websites'][$website->getId()]['groups']) === 0) { unset($container['websites'][$website->getId()]); } } } @file_put_contents($file, serialize($container)); return $container; } else { @unlink($file); } return false; } /** * Retrieve the config file name and path * * @return string */ public function getConfigFile() { return Mage::getBaseDir('etc') . DS . 'bolt.config'; } /** * Determine whether the config file exists * * @return bool */ public function configFileExists() { return is_file($this->getConfigFile()); } }