Overview

Packages

  • currencysymbol
  • MAbout
  • Mage
    • Admin
    • Adminhtml
    • AdminNotification
    • Api
    • Api2
    • Authorizenet
    • Backup
    • Bundle
    • Captcha
    • Catalog
    • CatalogIndex
    • CatalogInventory
    • CatalogRule
    • CatalogSearch
    • Centinel
    • Checkout
    • Cms
    • Compiler
    • Connect
    • Contacts
    • Core
    • Cron
    • CurrencySymbol
    • Customer
    • Dataflow
    • Directory
    • DirtectPost
    • Downloadable
    • Eav
    • GiftMessage
    • GoogleAnalytics
    • GoogleBase
    • GoogleCheckout
    • ImportExport
    • Index
    • Install
    • Log
    • Media
    • Newsletter
    • Oauth
    • Page
    • PageCache
    • Paygate
    • Payment
    • Paypal
    • PaypalUk
    • Persistent
    • Poll
    • ProductAlert
    • Rating
    • Reports
    • Review
    • Rss
    • Rule
    • Sales
    • SalesRule
    • Sedfriend
    • Sendfriend
    • Shipping
    • Sitemap
    • Tag
    • Tax
    • Usa
    • Weee
    • Widget
    • Wishlist
    • XmlConnect
  • None
  • Phoenix
    • Moneybookers
  • PHP
  • Zend
    • Date
    • Mime
    • XmlRpc

Classes

  • Mage
  • Mage_Adminhtml_Block_Html_Date
  • Mage_Adminhtml_Block_Html_Select
  • Mage_Api_Model_Wsdl_Config_Element
  • Mage_Captcha_Adminhtml_RefreshController
  • Mage_Captcha_RefreshController
  • Mage_Core_AjaxController
  • Mage_Core_Block_Abstract
  • Mage_Core_Block_Flush
  • Mage_Core_Block_Html_Calendar
  • Mage_Core_Block_Html_Date
  • Mage_Core_Block_Html_Link
  • Mage_Core_Block_Html_Select
  • Mage_Core_Block_Messages
  • Mage_Core_Block_Profiler
  • Mage_Core_Block_Store_Switcher
  • Mage_Core_Block_Template
  • Mage_Core_Block_Template_Facade
  • Mage_Core_Block_Template_Smarty
  • Mage_Core_Block_Template_Zend
  • Mage_Core_Block_Text
  • Mage_Core_Block_Text_List
  • Mage_Core_Block_Text_List_Item
  • Mage_Core_Block_Text_List_Link
  • Mage_Core_Block_Text_Tag
  • Mage_Core_Block_Text_Tag_Css
  • Mage_Core_Block_Text_Tag_Css_Admin
  • Mage_Core_Block_Text_Tag_Debug
  • Mage_Core_Block_Text_Tag_Js
  • Mage_Core_Block_Text_Tag_Meta
  • Mage_Core_Controller_Front_Action
  • Mage_Core_Controller_Front_Router
  • Mage_Core_Controller_Request_Http
  • Mage_Core_Controller_Response_Http
  • Mage_Core_Controller_Varien_Action
  • Mage_Core_Controller_Varien_Front
  • Mage_Core_Controller_Varien_Router_Abstract
  • Mage_Core_Controller_Varien_Router_Admin
  • Mage_Core_Controller_Varien_Router_Default
  • Mage_Core_Controller_Varien_Router_Standard
  • Mage_Core_Helper_Abstract
  • Mage_Core_Helper_Cookie
  • Mage_Core_Helper_Data
  • Mage_Core_Helper_File_Storage
  • Mage_Core_Helper_File_Storage_Database
  • Mage_Core_Helper_Hint
  • Mage_Core_Helper_Http
  • Mage_Core_Helper_Js
  • Mage_Core_Helper_String
  • Mage_Core_Helper_Translate
  • Mage_Core_Helper_Url
  • Mage_Core_Helper_Url_Rewrite
  • Mage_Core_IndexController
  • Mage_Core_Model_Abstract
  • Mage_Core_Model_App
  • Mage_Core_Model_App_Area
  • Mage_Core_Model_App_Emulation
  • Mage_Core_Model_Cache
  • Mage_Core_Model_Calculator
  • Mage_Core_Model_Config
  • Mage_Core_Model_Config_Base
  • Mage_Core_Model_Config_Data
  • Mage_Core_Model_Config_Element
  • Mage_Core_Model_Config_Options
  • Mage_Core_Model_Config_System
  • Mage_Core_Model_Cookie
  • Mage_Core_Model_Date
  • Mage_Core_Model_Design
  • Mage_Core_Model_Design_Package
  • Mage_Core_Model_Design_Source_Design
  • Mage_Core_Model_Email
  • Mage_Core_Model_Email_Info
  • Mage_Core_Model_Email_Template
  • Mage_Core_Model_Email_Template_Filter
  • Mage_Core_Model_Email_Template_Mailer
  • Mage_Core_Model_Email_Transport
  • Mage_Core_Model_Encryption
  • Mage_Core_Model_File_Storage
  • Mage_Core_Model_File_Storage_Abstract
  • Mage_Core_Model_File_Storage_Database
  • Mage_Core_Model_File_Storage_Database_Abstract
  • Mage_Core_Model_File_Storage_Directory_Database
  • Mage_Core_Model_File_Storage_File
  • Mage_Core_Model_File_Storage_Flag
  • Mage_Core_Model_File_Uploader
  • Mage_Core_Model_File_Validator_AvailablePath
  • Mage_Core_Model_File_Validator_NotProtectedExtension
  • Mage_Core_Model_Flag
  • Mage_Core_Model_Input_Filter
  • Mage_Core_Model_Input_Filter_MaliciousCode
  • Mage_Core_Model_Language
  • Mage_Core_Model_Layout
  • Mage_Core_Model_Layout_Data
  • Mage_Core_Model_Layout_Element
  • Mage_Core_Model_Layout_Update
  • Mage_Core_Model_Locale
  • Mage_Core_Model_Locale_Config
  • Mage_Core_Model_Log_Adapter
  • Mage_Core_Model_Magento_Api
  • Mage_Core_Model_Magento_Api_V2
  • Mage_Core_Model_Message
  • Mage_Core_Model_Message_Abstract
  • Mage_Core_Model_Message_Collection
  • Mage_Core_Model_Message_Error
  • Mage_Core_Model_Message_Notice
  • Mage_Core_Model_Message_Success
  • Mage_Core_Model_Message_Warning
  • Mage_Core_Model_Mysql4_Abstract
  • Mage_Core_Model_Mysql4_Cache
  • Mage_Core_Model_Mysql4_Collection_Abstract
  • Mage_Core_Model_Mysql4_Config
  • Mage_Core_Model_Mysql4_Config_Data
  • Mage_Core_Model_Mysql4_Config_Data_Collection
  • Mage_Core_Model_Mysql4_Design
  • Mage_Core_Model_Mysql4_Design_Collection
  • Mage_Core_Model_Mysql4_Design_Package_Collection
  • Mage_Core_Model_Mysql4_Design_Theme
  • Mage_Core_Model_Mysql4_Email_Template
  • Mage_Core_Model_Mysql4_Email_Template_Collection
  • Mage_Core_Model_Mysql4_File_Storage_Abstract
  • Mage_Core_Model_Mysql4_File_Storage_Database
  • Mage_Core_Model_Mysql4_File_Storage_Directory_Database
  • Mage_Core_Model_Mysql4_File_Storage_File
  • Mage_Core_Model_Mysql4_Flag
  • Mage_Core_Model_Mysql4_Language
  • Mage_Core_Model_Mysql4_Language_Collection
  • Mage_Core_Model_Mysql4_Layout
  • Mage_Core_Model_Mysql4_Resource
  • Mage_Core_Model_Mysql4_Session
  • Mage_Core_Model_Mysql4_Store
  • Mage_Core_Model_Mysql4_Store_Collection
  • Mage_Core_Model_Mysql4_Store_Group
  • Mage_Core_Model_Mysql4_Store_Group_Collection
  • Mage_Core_Model_Mysql4_Translate
  • Mage_Core_Model_Mysql4_Translate_String
  • Mage_Core_Model_Mysql4_Url_Rewrite
  • Mage_Core_Model_Mysql4_Url_Rewrite_Collection
  • Mage_Core_Model_Mysql4_Variable
  • Mage_Core_Model_Mysql4_Variable_Collection
  • Mage_Core_Model_Mysql4_Website
  • Mage_Core_Model_Mysql4_Website_Collection
  • Mage_Core_Model_Observer
  • Mage_Core_Model_Resource
  • Mage_Core_Model_Resource_Abstract
  • Mage_Core_Model_Resource_Cache
  • Mage_Core_Model_Resource_Config
  • Mage_Core_Model_Resource_Config_Data
  • Mage_Core_Model_Resource_Config_Data_Collection
  • Mage_Core_Model_Resource_Db_Abstract
  • Mage_Core_Model_Resource_Db_Collection_Abstract
  • Mage_Core_Model_Resource_Design
  • Mage_Core_Model_Resource_Design_Collection
  • Mage_Core_Model_Resource_Design_Package_Collection
  • Mage_Core_Model_Resource_Email_Template
  • Mage_Core_Model_Resource_Email_Template_Collection
  • Mage_Core_Model_Resource_Entity_Abstract
  • Mage_Core_Model_Resource_Entity_Table
  • Mage_Core_Model_Resource_File_Storage_Abstract
  • Mage_Core_Model_Resource_File_Storage_Database
  • Mage_Core_Model_Resource_File_Storage_Directory_Database
  • Mage_Core_Model_Resource_File_Storage_File
  • Mage_Core_Model_Resource_Flag
  • Mage_Core_Model_Resource_Helper_Abstract
  • Mage_Core_Model_Resource_Helper_Mysql4
  • Mage_Core_Model_Resource_Iterator
  • Mage_Core_Model_Resource_Language
  • Mage_Core_Model_Resource_Language_Collection
  • Mage_Core_Model_Resource_Layout
  • Mage_Core_Model_Resource_Resource
  • Mage_Core_Model_Resource_Session
  • Mage_Core_Model_Resource_Setup
  • Mage_Core_Model_Resource_Setup_Query_Modifier
  • Mage_Core_Model_Resource_Store
  • Mage_Core_Model_Resource_Store_Collection
  • Mage_Core_Model_Resource_Store_Group
  • Mage_Core_Model_Resource_Store_Group_Collection
  • Mage_Core_Model_Resource_Transaction
  • Mage_Core_Model_Resource_Translate
  • Mage_Core_Model_Resource_Translate_String
  • Mage_Core_Model_Resource_Type_Abstract
  • Mage_Core_Model_Resource_Type_Db
  • Mage_Core_Model_Resource_Type_Db_Mysqli
  • Mage_Core_Model_Resource_Type_Db_Mysqli_Setup
  • Mage_Core_Model_Resource_Type_Db_Pdo_Mysql
  • Mage_Core_Model_Resource_Url_Rewrite
  • Mage_Core_Model_Resource_Url_Rewrite_Collection
  • Mage_Core_Model_Resource_Variable
  • Mage_Core_Model_Resource_Variable_Collection
  • Mage_Core_Model_Resource_Website
  • Mage_Core_Model_Resource_Website_Collection
  • Mage_Core_Model_Session
  • Mage_Core_Model_Session_Abstract
  • Mage_Core_Model_Session_Abstract_Varien
  • Mage_Core_Model_Session_Abstract_Zend
  • Mage_Core_Model_Source_Email_Variables
  • Mage_Core_Model_Store
  • Mage_Core_Model_Store_Api
  • Mage_Core_Model_Store_Api_V2
  • Mage_Core_Model_Store_Group
  • Mage_Core_Model_Template
  • Mage_Core_Model_Translate
  • Mage_Core_Model_Translate_Expr
  • Mage_Core_Model_Translate_Inline
  • Mage_Core_Model_Translate_String
  • Mage_Core_Model_Url
  • Mage_Core_Model_Url_Rewrite
  • Mage_Core_Model_Url_Validator
  • Mage_Core_Model_Variable
  • Mage_Core_Model_Variable_Config
  • Mage_Core_Model_Variable_Observer
  • Mage_Core_Model_Website
  • Mage_Page_Block_Switch
  • Mage_Page_Block_Template_Container
  • Mage_Page_Block_Template_Links
  • Mage_Page_Block_Template_Links_Block
  • Mage_Sales_Model_Quote_Address_Total_Collector

Exceptions

  • Mage_Core_Controller_Varien_Exception
  • Mage_Core_Exception
  • Mage_Core_Model_Session_Exception
  • Mage_Core_Model_Store_Exception

Functions

  • destruct
  • is_dir_writeable
  • is_empty_date
  • mageCoreErrorHandler
  • mageDebugBacktrace
  • mageDelTree
  • mageFindClassFile
  • mageParseCsv
  • mageSendErrorFooter
  • mageSendErrorHeader
  • mageUndoMagicQuotes
  • now
  • sys_get_temp_dir
  • uc_words
  • Overview
  • Package
  • Class
  • Tree
   1: <?php
   2: /**
   3:  * Magento
   4:  *
   5:  * NOTICE OF LICENSE
   6:  *
   7:  * This source file is subject to the Open Software License (OSL 3.0)
   8:  * that is bundled with this package in the file LICENSE.txt.
   9:  * It is also available through the world-wide-web at this URL:
  10:  * http://opensource.org/licenses/osl-3.0.php
  11:  * If you did not receive a copy of the license and are unable to
  12:  * obtain it through the world-wide-web, please send an email
  13:  * to license@magentocommerce.com so we can send you a copy immediately.
  14:  *
  15:  * DISCLAIMER
  16:  *
  17:  * Do not edit or add to this file if you wish to upgrade Magento to newer
  18:  * versions in the future. If you wish to customize Magento for your
  19:  * needs please refer to http://www.magentocommerce.com for more information.
  20:  *
  21:  * @category    Mage
  22:  * @package     Mage_Core
  23:  * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
  24:  * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
  25:  */
  26: 
  27: /**
  28:  * Store model
  29:  *
  30:  * @method Mage_Core_Model_Resource_Store _getResource()
  31:  * @method Mage_Core_Model_Resource_Store getResource()
  32:  * @method Mage_Core_Model_Store setCode(string $value)
  33:  * @method Mage_Core_Model_Store setWebsiteId(int $value)
  34:  * @method Mage_Core_Model_Store setGroupId(int $value)
  35:  * @method Mage_Core_Model_Store setName(string $value)
  36:  * @method int getSortOrder()
  37:  * @method Mage_Core_Model_Store setSortOrder(int $value)
  38:  * @method Mage_Core_Model_Store setIsActive(int $value)
  39:  *
  40:  * @category    Mage
  41:  * @package     Mage_Core
  42:  * @author      Magento Core Team <core@magentocommerce.com>
  43:  */
  44: class Mage_Core_Model_Store extends Mage_Core_Model_Abstract
  45: {
  46:     /**
  47:      * Entity name
  48:      */
  49:     const ENTITY = 'core_store';
  50: 
  51:     /**
  52:      * Configuration pathes
  53:      */
  54:     const XML_PATH_STORE_STORE_NAME       = 'general/store_information/name';
  55:     const XML_PATH_STORE_STORE_PHONE      = 'general/store_information/phone';
  56:     const XML_PATH_STORE_IN_URL           = 'web/url/use_store';
  57:     const XML_PATH_USE_REWRITES           = 'web/seo/use_rewrites';
  58:     const XML_PATH_UNSECURE_BASE_URL      = 'web/unsecure/base_url';
  59:     const XML_PATH_SECURE_BASE_URL        = 'web/secure/base_url';
  60:     const XML_PATH_SECURE_IN_FRONTEND     = 'web/secure/use_in_frontend';
  61:     const XML_PATH_SECURE_IN_ADMINHTML    = 'web/secure/use_in_adminhtml';
  62:     const XML_PATH_SECURE_BASE_LINK_URL   = 'web/secure/base_link_url';
  63:     const XML_PATH_UNSECURE_BASE_LINK_URL = 'web/unsecure/base_link_url';
  64:     const XML_PATH_OFFLOADER_HEADER       = 'web/secure/offloader_header';
  65:     const XML_PATH_PRICE_SCOPE            = 'catalog/price/scope';
  66: 
  67:     /**
  68:      * Price scope constants
  69:      */
  70:     const PRICE_SCOPE_GLOBAL              = 0;
  71:     const PRICE_SCOPE_WEBSITE             = 1;
  72: 
  73:     /**
  74:      * Possible URL types
  75:      */
  76:     const URL_TYPE_LINK                   = 'link';
  77:     const URL_TYPE_DIRECT_LINK            = 'direct_link';
  78:     const URL_TYPE_WEB                    = 'web';
  79:     const URL_TYPE_SKIN                   = 'skin';
  80:     const URL_TYPE_JS                     = 'js';
  81:     const URL_TYPE_MEDIA                  = 'media';
  82: 
  83:     /**
  84:      * Code constants
  85:      */
  86:     const DEFAULT_CODE                    = 'default';
  87:     const ADMIN_CODE                      = 'admin';
  88: 
  89:     /**
  90:      * Cache tag
  91:      */
  92:     const CACHE_TAG                       = 'store';
  93: 
  94:     /**
  95:      * Cookie name
  96:      */
  97:     const COOKIE_NAME                     = 'store';
  98: 
  99:     /**
 100:      * Cookie currency key
 101:      */
 102:     const COOKIE_CURRENCY                 = 'currency';
 103: 
 104:     /**
 105:      * Script name, which returns all the images
 106:      */
 107:     const MEDIA_REWRITE_SCRIPT            = 'get.php/';
 108: 
 109:     /**
 110:      * Cache flag
 111:      *
 112:      * @var boolean
 113:      */
 114:     protected $_cacheTag    = true;
 115: 
 116:     /**
 117:      * Event prefix for model events
 118:      *
 119:      * @var string
 120:      */
 121:     protected $_eventPrefix = 'store';
 122: 
 123:     /**
 124:      * Event object name
 125:      *
 126:      * @var string
 127:      */
 128:     protected $_eventObject = 'store';
 129: 
 130:     /**
 131:      * Price filter
 132:      *
 133:      * @var Mage_Directory_Model_Currency_Filter
 134:      */
 135:     protected $_priceFilter;
 136: 
 137:     /**
 138:      * Website model
 139:      *
 140:      * @var Mage_Core_Model_Website
 141:      */
 142:     protected $_website;
 143: 
 144:     /**
 145:      * Group model
 146:      *
 147:      * @var Mage_Core_Model_Store_Group
 148:      */
 149:     protected $_group;
 150: 
 151:     /**
 152:      * Store configuration cache
 153:      *
 154:      * @var array|null
 155:      */
 156:     protected $_configCache = null;
 157: 
 158:     /**
 159:      * Base nodes of store configuration cache
 160:      *
 161:      * @var array
 162:      */
 163:     protected $_configCacheBaseNodes = array();
 164: 
 165:     /**
 166:      * Directory cache
 167:      *
 168:      * @var array
 169:      */
 170:     protected $_dirCache = array();
 171: 
 172:     /**
 173:      * URL cache
 174:      *
 175:      * @var array
 176:      */
 177:     protected $_urlCache = array();
 178: 
 179:     /**
 180:      * Base URL cache
 181:      *
 182:      * @var array
 183:      */
 184:     protected $_baseUrlCache = array();
 185: 
 186:     /**
 187:      * Session entity
 188:      *
 189:      * @var Mage_Core_Model_Session_Abstract
 190:      */
 191:     protected $_session;
 192: 
 193:     /**
 194:      * Flag that shows that backend URLs are secure
 195:      *
 196:      * @var boolean|null
 197:      */
 198:     protected $_isAdminSecure = null;
 199: 
 200:     /**
 201:      * Flag that shows that frontend URLs are secure
 202:      *
 203:      * @var boolean|null
 204:      */
 205:     protected $_isFrontSecure = null;
 206: 
 207:     /**
 208:      * Store frontend name
 209:      *
 210:      * @var string|null
 211:      */
 212:     protected $_frontendName = null;
 213: 
 214:     /**
 215:      * Readonly flag
 216:      *
 217:      * @var bool
 218:      */
 219:     private $_isReadOnly = false;
 220: 
 221:     /**
 222:      * Initialize object
 223:      */
 224:     protected function _construct()
 225:     {
 226:         $this->_init('core/store');
 227:         $this->_configCacheBaseNodes = array(
 228:             self::XML_PATH_PRICE_SCOPE,
 229:             self::XML_PATH_SECURE_BASE_URL,
 230:             self::XML_PATH_SECURE_IN_ADMINHTML,
 231:             self::XML_PATH_SECURE_IN_FRONTEND,
 232:             self::XML_PATH_STORE_IN_URL,
 233:             self::XML_PATH_UNSECURE_BASE_URL,
 234:             self::XML_PATH_USE_REWRITES,
 235:             self::XML_PATH_UNSECURE_BASE_LINK_URL,
 236:             self::XML_PATH_SECURE_BASE_LINK_URL,
 237:             'general/locale/code'
 238:         );
 239:     }
 240: 
 241:     /**
 242:      * Retrieve store session object
 243:      *
 244:      * @return Mage_Core_Model_Session_Abstract
 245:      */
 246:     protected function _getSession()
 247:     {
 248:         if (!$this->_session) {
 249:             $this->_session = Mage::getModel('core/session')
 250:                 ->init('store_'.$this->getCode());
 251:         }
 252:         return $this->_session;
 253:     }
 254: 
 255:     /**
 256:      * Loading store data
 257:      *
 258:      * @param   mixed $id
 259:      * @param   string $field
 260:      * @return  Mage_Core_Model_Store
 261:      */
 262:     public function load($id, $field=null)
 263:     {
 264:         if (!is_numeric($id) && is_null($field)) {
 265:             $this->_getResource()->load($this, $id, 'code');
 266:             return $this;
 267:         }
 268:         return parent::load($id, $field);
 269:     }
 270: 
 271:     /**
 272:      * Loading store configuration data
 273:      *
 274:      * @param   string $code
 275:      * @return  Mage_Core_Model_Store
 276:      */
 277:     public function loadConfig($code)
 278:     {
 279:         if (is_numeric($code)) {
 280:             foreach (Mage::getConfig()->getNode()->stores->children() as $storeCode => $store) {
 281:                 if ((int) $store->system->store->id == $code) {
 282:                     $code = $storeCode;
 283:                     break;
 284:                 }
 285:             }
 286:         } else {
 287:             $store = Mage::getConfig()->getNode()->stores->{$code};
 288:         }
 289:         if (!empty($store)) {
 290:             $this->setCode($code);
 291:             $id = (int) $store->system->store->id;
 292:             $this->setId($id)->setStoreId($id);
 293:             $this->setWebsiteId((int) $store->system->website->id);
 294:         }
 295:         return $this;
 296:     }
 297: 
 298:     /**
 299:      * Retrieve Store code
 300:      *
 301:      * @return string
 302:      */
 303:     public function getCode()
 304:     {
 305:         return $this->_getData('code');
 306:     }
 307: 
 308:     /**
 309:      * Retrieve store configuration data
 310:      *
 311:      * @param   string $path
 312:      * @return  string|null
 313:      */
 314:     public function getConfig($path)
 315:     {
 316:         if (isset($this->_configCache[$path])) {
 317:             return $this->_configCache[$path];
 318:         }
 319: 
 320:         $config = Mage::getConfig();
 321: 
 322:         $fullPath = 'stores/' . $this->getCode() . '/' . $path;
 323:         $data = $config->getNode($fullPath);
 324:         if (!$data && !Mage::isInstalled()) {
 325:             $data = $config->getNode('default/' . $path);
 326:         }
 327:         if (!$data) {
 328:             return null;
 329:         }
 330:         return $this->_processConfigValue($fullPath, $path, $data);
 331:     }
 332: 
 333:     /**
 334:      * Initialize base store configuration data
 335:      *
 336:      * Method provide cache configuration data without loading store config XML
 337:      *
 338:      * @return Mage_Core_Model_Config
 339:      */
 340:     public function initConfigCache()
 341:     {
 342:         /**
 343:          * Funtionality related with config separation
 344:          */
 345:         if ($this->_configCache === null) {
 346:             $code = $this->getCode();
 347:             if ($code) {
 348:                 if (Mage::app()->useCache('config')) {
 349:                     $cacheId = 'store_' . $code . '_config_cache';
 350:                     $data = Mage::app()->loadCache($cacheId);
 351:                     if ($data) {
 352:                         $data = unserialize($data);
 353:                     } else {
 354:                         $data = array();
 355:                         foreach ($this->_configCacheBaseNodes as $node) {
 356:                             $data[$node] = $this->getConfig($node);
 357:                         }
 358:                         Mage::app()->saveCache(serialize($data), $cacheId, array(
 359:                             self::CACHE_TAG,
 360:                             Mage_Core_Model_Config::CACHE_TAG
 361:                         ));
 362:                     }
 363:                     $this->_configCache = $data;
 364:                 }
 365:             }
 366:         }
 367:         return $this;
 368:     }
 369: 
 370:     /**
 371:      * Set config value for CURRENT model
 372:      *
 373:      * This value don't save in config
 374:      *
 375:      * @param string $path
 376:      * @param mixed $value
 377:      * @return Mage_Core_Model_Store
 378:      */
 379:     public function setConfig($path, $value)
 380:     {
 381:         if (isset($this->_configCache[$path])) {
 382:             $this->_configCache[$path] = $value;
 383:         }
 384:         $fullPath = 'stores/' . $this->getCode() . '/' . $path;
 385:         Mage::getConfig()->setNode($fullPath, $value);
 386: 
 387:         return $this;
 388:     }
 389: 
 390:     /**
 391:      * Set website model
 392:      *
 393:      * @param Mage_Core_Model_Website $website
 394:      */
 395:     public function setWebsite(Mage_Core_Model_Website $website)
 396:     {
 397:         $this->_website = $website;
 398:     }
 399: 
 400:     /**
 401:      * Retrieve store website
 402:      *
 403:      * @return Mage_Core_Model_Website
 404:      */
 405:     public function getWebsite()
 406:     {
 407:         if (is_null($this->getWebsiteId())) {
 408:             return false;
 409:         }
 410:         if (is_null($this->_website)) {
 411:             $this->_website = Mage::app()->getWebsite($this->getWebsiteId());
 412:         }
 413:         return $this->_website;
 414:     }
 415: 
 416:     /**
 417:      * Process config value
 418:      *
 419:      * @param string $fullPath
 420:      * @param string $path
 421:      * @param Varien_Simplexml_Element $node
 422:      * @return string
 423:      */
 424:     protected function _processConfigValue($fullPath, $path, $node)
 425:     {
 426:         if (isset($this->_configCache[$path])) {
 427:             return $this->_configCache[$path];
 428:         }
 429: 
 430:         if ($node->hasChildren()) {
 431:             $aValue = array();
 432:             foreach ($node->children() as $k => $v) {
 433:                 $aValue[$k] = $this->_processConfigValue($fullPath . '/' . $k, $path . '/' . $k, $v);
 434:             }
 435:             $this->_configCache[$path] = $aValue;
 436:             return $aValue;
 437:         }
 438: 
 439:         $sValue = (string) $node;
 440:         if (!empty($node['backend_model']) && !empty($sValue)) {
 441:             $backend = Mage::getModel((string) $node['backend_model']);
 442:             $backend->setPath($path)->setValue($sValue)->afterLoad();
 443:             $sValue = $backend->getValue();
 444:         }
 445: 
 446:         if (is_string($sValue) && strpos($sValue, '{{') !== false) {
 447:             if (strpos($sValue, '{{unsecure_base_url}}') !== false) {
 448:                 $unsecureBaseUrl = $this->getConfig(self::XML_PATH_UNSECURE_BASE_URL);
 449:                 $sValue = str_replace('{{unsecure_base_url}}', $unsecureBaseUrl, $sValue);
 450:             } elseif (strpos($sValue, '{{secure_base_url}}') !== false) {
 451:                 $secureBaseUrl = $this->getConfig(self::XML_PATH_SECURE_BASE_URL);
 452:                 $sValue = str_replace('{{secure_base_url}}', $secureBaseUrl, $sValue);
 453:             } elseif (strpos($sValue, '{{base_url}}') !== false) {
 454:                 $sValue = Mage::getConfig()->substDistroServerVars($sValue);
 455:             }
 456:         }
 457: 
 458:         $this->_configCache[$path] = $sValue;
 459: 
 460:         return $sValue;
 461:     }
 462: 
 463:     /**
 464:      * Convert config values for url pathes
 465:      *
 466:      * @deprecated after 1.4.2.0
 467:      * @param string $value
 468:      * @return string
 469:      */
 470:     public function processSubst($value)
 471:     {
 472:         if (!is_string($value)) {
 473:             return $value;
 474:         }
 475: 
 476:         if (strpos($value, '{{unsecure_base_url}}') !== false) {
 477:             $unsecureBaseUrl = $this->getConfig(self::XML_PATH_UNSECURE_BASE_URL);
 478:             $value = str_replace('{{unsecure_base_url}}', $unsecureBaseUrl, $value);
 479: 
 480:         } elseif (strpos($value, '{{secure_base_url}}') !== false) {
 481:             $secureBaseUrl = $this->getConfig(self::XML_PATH_SECURE_BASE_URL);
 482:             $value = str_replace('{{secure_base_url}}', $secureBaseUrl, $value);
 483:         } elseif (strpos($value, '{{') !== false && strpos($value, '{{base_url}}') === false) {
 484:             $value = Mage::getConfig()->substDistroServerVars($value);
 485:         }
 486:         return $value;
 487:     }
 488: 
 489:     /**
 490:      * Retrieve default base path
 491:      *
 492:      * @return string
 493:      */
 494:     public function getDefaultBasePath()
 495:     {
 496:         if (!isset($_SERVER['SCRIPT_NAME'])) {
 497:             return '/';
 498:         }
 499:         return rtrim(Mage::app()->getRequest()->getBasePath() . '/') . '/';
 500:     }
 501: 
 502:     /**
 503:      * Retrieve url using store configuration specific
 504:      *
 505:      * @param   string $route
 506:      * @param   array $params
 507:      * @return  string
 508:      */
 509:     public function getUrl($route = '', $params = array())
 510:     {
 511:         /** @var $url Mage_Core_Model_Url */
 512:         $url = Mage::getModel('core/url')
 513:             ->setStore($this);
 514:         if (Mage::app()->getStore()->getId() != $this->getId()) {
 515:             $params['_store_to_url'] = true;
 516:         }
 517: 
 518:         return $url->getUrl($route, $params);
 519:     }
 520: 
 521:     /**
 522:      * Retrieve base URL
 523:      *
 524:      * @param string $type
 525:      * @param boolean|null $secure
 526:      * @return string
 527:      */
 528:     public function getBaseUrl($type = self::URL_TYPE_LINK, $secure = null)
 529:     {
 530:         $cacheKey = $type . '/' . (is_null($secure) ? 'null' : ($secure ? 'true' : 'false'));
 531:         if (!isset($this->_baseUrlCache[$cacheKey])) {
 532:             switch ($type) {
 533:                 case self::URL_TYPE_WEB:
 534:                     $secure = is_null($secure) ? $this->isCurrentlySecure() : (bool)$secure;
 535:                     $url = $this->getConfig('web/' . ($secure ? 'secure' : 'unsecure') . '/base_url');
 536:                     break;
 537: 
 538:                 case self::URL_TYPE_LINK:
 539:                     $secure = (bool) $secure;
 540:                     $url = $this->getConfig('web/' . ($secure ? 'secure' : 'unsecure') . '/base_link_url');
 541:                     $url = $this->_updatePathUseRewrites($url);
 542:                     $url = $this->_updatePathUseStoreView($url);
 543:                     break;
 544: 
 545:                 case self::URL_TYPE_DIRECT_LINK:
 546:                     $secure = (bool) $secure;
 547:                     $url = $this->getConfig('web/' . ($secure ? 'secure' : 'unsecure') . '/base_link_url');
 548:                     $url = $this->_updatePathUseRewrites($url);
 549:                     break;
 550: 
 551:                 case self::URL_TYPE_SKIN:
 552:                 case self::URL_TYPE_JS:
 553:                     $secure = is_null($secure) ? $this->isCurrentlySecure() : (bool) $secure;
 554:                     $url = $this->getConfig('web/' . ($secure ? 'secure' : 'unsecure') . '/base_' . $type . '_url');
 555:                     break;
 556: 
 557:                 case self::URL_TYPE_MEDIA:
 558:                     $url = $this->_updateMediaPathUseRewrites($secure);
 559:                     break;
 560: 
 561:                 default:
 562:                     throw Mage::exception('Mage_Core', Mage::helper('core')->__('Invalid base url type'));
 563:             }
 564: 
 565:             if (false !== strpos($url, '{{base_url}}')) {
 566:                 $baseUrl = Mage::getConfig()->substDistroServerVars('{{base_url}}');
 567:                 $url = str_replace('{{base_url}}', $baseUrl, $url);
 568:             }
 569: 
 570:             $this->_baseUrlCache[$cacheKey] = rtrim($url, '/') . '/';
 571:         }
 572: 
 573:         return $this->_baseUrlCache[$cacheKey];
 574:     }
 575: 
 576:     /**
 577:      * Remove script file name from url in case when server rewrites are enabled
 578:      *
 579:      * @param   string $url
 580:      * @return  string
 581:      */
 582:     protected function _updatePathUseRewrites($url)
 583:     {
 584:         if ($this->isAdmin()
 585:             || !$this->getConfig(self::XML_PATH_USE_REWRITES)
 586:             || !Mage::isInstalled()
 587:         ) {
 588:             if ($this->_isCustomEntryPoint()) {
 589:                 $indexFileName = 'index.php';
 590:             } else {
 591:                 $indexFileName = basename($_SERVER['SCRIPT_FILENAME']);
 592:             }
 593:             $url .= $indexFileName . '/';
 594:         }
 595:         return $url;
 596:     }
 597: 
 598:     /**
 599:      * Check if used entry point is custom
 600:      *
 601:      * @return bool
 602:      */
 603:     protected function _isCustomEntryPoint()
 604:     {
 605:         return (bool)Mage::registry('custom_entry_point');
 606:     }
 607: 
 608:     /**
 609:      * Retrieve URL for media catalog
 610:      *
 611:      * If we use Database file storage and server doesn't support rewrites (.htaccess in media folder)
 612:      * we have to put name of fetching media script exactly into URL
 613:      *
 614:      * @param null|boolean $secure
 615:      * @param string $type
 616:      * @return string
 617:      */
 618:     protected function _updateMediaPathUseRewrites($secure = null, $type = self::URL_TYPE_MEDIA)
 619:     {
 620:         $secure = is_null($secure) ? $this->isCurrentlySecure() : (bool) $secure;
 621:         $secureStringFlag = $secure ? 'secure' : 'unsecure';
 622:         $url = $this->getConfig('web/' . $secureStringFlag . '/base_' . $type . '_url');
 623:         if (!$this->getConfig(self::XML_PATH_USE_REWRITES)
 624:             && Mage::helper('core/file_storage_database')->checkDbUsage()
 625:         ) {
 626:             $urlStart = $this->getConfig('web/' . $secureStringFlag . '/base_url');
 627:             $url = str_replace($urlStart, $urlStart . self::MEDIA_REWRITE_SCRIPT, $url);
 628:         }
 629:         return $url;
 630:     }
 631: 
 632:     /**
 633:      * Add store code to url in case if it is enabled in configuration
 634:      *
 635:      * @param   string $url
 636:      * @return  string
 637:      */
 638:     protected function _updatePathUseStoreView($url)
 639:     {
 640:         if ($this->getStoreInUrl()) {
 641:             $url .= $this->getCode() . '/';
 642:         }
 643:         return $url;
 644:     }
 645: 
 646:     /**
 647:      * Returns whether url forming scheme prepends url path with store view code
 648:      *
 649:      * @return bool
 650:      */
 651:     public function getStoreInUrl()
 652:     {
 653:         return Mage::isInstalled() && $this->getConfig(self::XML_PATH_STORE_IN_URL);
 654:     }
 655: 
 656:     /**
 657:      * Get store identifier
 658:      *
 659:      * @return  int
 660:      */
 661:     public function getId()
 662:     {
 663:         return $this->_getData('store_id');
 664:     }
 665: 
 666:     /**
 667:      * Check if store is admin store
 668:      *
 669:      * @return unknown
 670:      */
 671:     public function isAdmin()
 672:     {
 673:         return $this->getId() == Mage_Core_Model_App::ADMIN_STORE_ID;
 674:     }
 675: 
 676: 
 677:     /**
 678:      * Check if backend URLs should be secure
 679:      *
 680:      * @return boolean
 681:      */
 682:     public function isAdminUrlSecure()
 683:     {
 684:         if ($this->_isAdminSecure === null) {
 685:             $this->_isAdminSecure = (boolean) (int) (string) Mage::getConfig()
 686:                 ->getNode(Mage_Core_Model_Url::XML_PATH_SECURE_IN_ADMIN);
 687:         }
 688:         return $this->_isAdminSecure;
 689:     }
 690: 
 691:     /**
 692:      * Check if frontend URLs should be secure
 693:      *
 694:      * @return boolean
 695:      */
 696:     public function isFrontUrlSecure()
 697:     {
 698:         if ($this->_isFrontSecure === null) {
 699:             $this->_isFrontSecure = Mage::getStoreConfigFlag(Mage_Core_Model_Url::XML_PATH_SECURE_IN_FRONT,
 700:                 $this->getId());
 701:         }
 702:         return $this->_isFrontSecure;
 703:     }
 704: 
 705:     /**
 706:      * Check if request was secure
 707:      *
 708:      * @return boolean
 709:      */
 710:     public function isCurrentlySecure()
 711:     {
 712:         $standardRule = !empty($_SERVER['HTTPS']) && ('off' != $_SERVER['HTTPS']);
 713:         $offloaderHeader = trim((string) Mage::getConfig()->getNode(self::XML_PATH_OFFLOADER_HEADER, 'default'));
 714: 
 715:         if ((!empty($offloaderHeader) && !empty($_SERVER[$offloaderHeader])) || $standardRule) {
 716:             return true;
 717:         }
 718: 
 719:         if (Mage::isInstalled()) {
 720:             $secureBaseUrl = Mage::getStoreConfig(Mage_Core_Model_Url::XML_PATH_SECURE_URL);
 721: 
 722:             if (!$secureBaseUrl) {
 723:                 return false;
 724:             }
 725: 
 726:             $uri = Zend_Uri::factory($secureBaseUrl);
 727:             $port = $uri->getPort();
 728:             $isSecure = ($uri->getScheme() == 'https')
 729:                 && isset($_SERVER['SERVER_PORT'])
 730:                 && ($port == $_SERVER['SERVER_PORT']);
 731:             return $isSecure;
 732:         } else {
 733:             $isSecure = isset($_SERVER['SERVER_PORT']) && (443 == $_SERVER['SERVER_PORT']);
 734:             return $isSecure;
 735:         }
 736:     }
 737: 
 738:     /*************************************************************************************
 739:      * Store currency interface
 740:      */
 741: 
 742:     /**
 743:      * Retrieve store base currency code
 744:      *
 745:      * @return string
 746:      */
 747:     public function getBaseCurrencyCode()
 748:     {
 749:         $configValue = $this->getConfig(Mage_Core_Model_Store::XML_PATH_PRICE_SCOPE);
 750:         if ($configValue == Mage_Core_Model_Store::PRICE_SCOPE_GLOBAL) {
 751:             return Mage::app()->getBaseCurrencyCode();
 752:         } else {
 753:             return $this->getConfig(Mage_Directory_Model_Currency::XML_PATH_CURRENCY_BASE);
 754:         }
 755:     }
 756: 
 757:     /**
 758:      * Retrieve store base currency
 759:      *
 760:      * @return Mage_Directory_Model_Currency
 761:      */
 762:     public function getBaseCurrency()
 763:     {
 764:         $currency = $this->getData('base_currency');
 765:         if (is_null($currency)) {
 766:             $currency = Mage::getModel('directory/currency')->load($this->getBaseCurrencyCode());
 767:             $this->setData('base_currency', $currency);
 768:         }
 769:         return $currency;
 770:     }
 771: 
 772:     /**
 773:      * Get default store currency code
 774:      *
 775:      * @return string
 776:      */
 777:     public function getDefaultCurrencyCode()
 778:     {
 779:         $result = $this->getConfig(Mage_Directory_Model_Currency::XML_PATH_CURRENCY_DEFAULT);
 780:         return $result;
 781:     }
 782: 
 783:     /**
 784:      * Retrieve store default currency
 785:      *
 786:      * @return Mage_Directory_Model_Currency
 787:      */
 788:     public function getDefaultCurrency()
 789:     {
 790:         $currency = $this->getData('default_currency');
 791:         if (is_null($currency)) {
 792:             $currency = Mage::getModel('directory/currency')->load($this->getDefaultCurrencyCode());
 793:             $this->setData('default_currency', $currency);
 794:         }
 795:         return $currency;
 796:     }
 797: 
 798:     /**
 799:      * Set current store currency code
 800:      *
 801:      * @param   string $code
 802:      * @return  string
 803:      */
 804:     public function setCurrentCurrencyCode($code)
 805:     {
 806:         $code = strtoupper($code);
 807:         if (in_array($code, $this->getAvailableCurrencyCodes())) {
 808:             $this->_getSession()->setCurrencyCode($code);
 809:             if ($code == $this->getDefaultCurrency()) {
 810:                 Mage::app()->getCookie()->delete(self::COOKIE_CURRENCY, $code);
 811:             } else {
 812:                 Mage::app()->getCookie()->set(self::COOKIE_CURRENCY, $code);
 813:             }
 814:         }
 815:         return $this;
 816:     }
 817: 
 818:     /**
 819:      * Get current store currency code
 820:      *
 821:      * @return string
 822:      */
 823:     public function getCurrentCurrencyCode()
 824:     {
 825:         // try to get currently set code among allowed
 826:         $code = $this->_getSession()->getCurrencyCode();
 827:         if (empty($code)) {
 828:             $code = $this->getDefaultCurrencyCode();
 829:         }
 830:         if (in_array($code, $this->getAvailableCurrencyCodes(true))) {
 831:             return $code;
 832:         }
 833: 
 834:         // take first one of allowed codes
 835:         $codes = array_values($this->getAvailableCurrencyCodes(true));
 836:         if (empty($codes)) {
 837:             // return default code, if no codes specified at all
 838:             return $this->getDefaultCurrencyCode();
 839:         }
 840:         return array_shift($codes);
 841:     }
 842: 
 843:     /**
 844:      * Get allowed store currency codes
 845:      *
 846:      * If base currency is not allowed in current website config scope,
 847:      * then it can be disabled with $skipBaseNotAllowed
 848:      *
 849:      * @param bool $skipBaseNotAllowed
 850:      * @return array
 851:      */
 852:     public function getAvailableCurrencyCodes($skipBaseNotAllowed = false)
 853:     {
 854:         $codes = $this->getData('available_currency_codes');
 855:         if (is_null($codes)) {
 856:             $codes = explode(',', $this->getConfig(Mage_Directory_Model_Currency::XML_PATH_CURRENCY_ALLOW));
 857:             // add base currency, if it is not in allowed currencies
 858:             $baseCurrencyCode = $this->getBaseCurrencyCode();
 859:             if (!in_array($baseCurrencyCode, $codes)) {
 860:                 $codes[] = $baseCurrencyCode;
 861: 
 862:                 // save base currency code index for further usage
 863:                 $disallowedBaseCodeIndex = array_keys($codes);
 864:                 $disallowedBaseCodeIndex = array_pop($disallowedBaseCodeIndex);
 865:                 $this->setData('disallowed_base_currency_code_index', $disallowedBaseCodeIndex);
 866:             }
 867:             $this->setData('available_currency_codes', $codes);
 868:         }
 869: 
 870:         // remove base currency code, if it is not allowed by config (optional)
 871:         if ($skipBaseNotAllowed) {
 872:             $disallowedBaseCodeIndex = $this->getData('disallowed_base_currency_code_index');
 873:             if (null !== $disallowedBaseCodeIndex) {
 874:                 unset($codes[$disallowedBaseCodeIndex]);
 875:             }
 876:         }
 877:         return $codes;
 878:     }
 879: 
 880:     /**
 881:      * Retrieve store current currency
 882:      *
 883:      * @return Mage_Directory_Model_Currency
 884:      */
 885:     public function getCurrentCurrency()
 886:     {
 887:         $currency = $this->getData('current_currency');
 888: 
 889:         if (is_null($currency)) {
 890:             $currency     = Mage::getModel('directory/currency')->load($this->getCurrentCurrencyCode());
 891:             $baseCurrency = $this->getBaseCurrency();
 892: 
 893:             if (! $baseCurrency->getRate($currency)) {
 894:                 $currency = $baseCurrency;
 895:                 $this->setCurrentCurrencyCode($baseCurrency->getCode());
 896:             }
 897: 
 898:             $this->setData('current_currency', $currency);
 899:         }
 900: 
 901:         return $currency;
 902:     }
 903: 
 904:     /**
 905:      * Retrieve current currency rate
 906:      *
 907:      * @return float
 908:      */
 909:     public function getCurrentCurrencyRate()
 910:     {
 911:         return $this->getBaseCurrency()->getRate($this->getCurrentCurrency());
 912:     }
 913: 
 914:     /**
 915:      * Convert price from default currency to current currency
 916:      *
 917:      * @param   double $price
 918:      * @param   boolean $format             Format price to currency format
 919:      * @param   boolean $includeContainer   Enclose into <span class="price"><span>
 920:      * @return  double
 921:      */
 922:     public function convertPrice($price, $format = false, $includeContainer = true)
 923:     {
 924:         if ($this->getCurrentCurrency() && $this->getBaseCurrency()) {
 925:             $value = $this->getBaseCurrency()->convert($price, $this->getCurrentCurrency());
 926:         } else {
 927:             $value = $price;
 928:         }
 929: 
 930:         if ($this->getCurrentCurrency() && $format) {
 931:             $value = $this->formatPrice($value, $includeContainer);
 932:         }
 933:         return $value;
 934:     }
 935: 
 936:     /**
 937:      * Round price
 938:      *
 939:      * @param mixed $price
 940:      * @return double
 941:      */
 942:     public function roundPrice($price)
 943:     {
 944:         return round($price, 2);
 945:     }
 946: 
 947:     /**
 948:      * Format price with currency filter (taking rate into consideration)
 949:      *
 950:      * @param   double $price
 951:      * @param   bool $includeContainer
 952:      * @return  string
 953:      */
 954:     public function formatPrice($price, $includeContainer = true)
 955:     {
 956:         if ($this->getCurrentCurrency()) {
 957:             return $this->getCurrentCurrency()->format($price, array(), $includeContainer);
 958:         }
 959:         return $price;
 960:     }
 961: 
 962:     /**
 963:      * Get store price filter
 964:      *
 965:      * @return Varien_Filter_Sprintf
 966:      */
 967:     public function getPriceFilter()
 968:     {
 969:         if (!$this->_priceFilter) {
 970:             if ($this->getBaseCurrency() && $this->getCurrentCurrency()) {
 971:                 $this->_priceFilter = $this->getCurrentCurrency()->getFilter();
 972:                 $this->_priceFilter->setRate($this->getBaseCurrency()->getRate($this->getCurrentCurrency()));
 973:             }
 974:             elseif($this->getDefaultCurrency()) {
 975:                 $this->_priceFilter = $this->getDefaultCurrency()->getFilter();
 976:             }
 977:             else {
 978:                 $this->_priceFilter = new Varien_Filter_Sprintf('%s', 2);
 979:             }
 980:         }
 981:         return $this->_priceFilter;
 982:     }
 983: 
 984:     /**
 985:      * Retrieve root category identifier
 986:      *
 987:      * @return int
 988:      */
 989:     public function getRootCategoryId()
 990:     {
 991:         if (!$this->getGroup()) {
 992:             return 0;
 993:         }
 994:         return $this->getGroup()->getRootCategoryId();
 995:     }
 996: 
 997:     /**
 998:      * Set group model for store
 999:      *
1000:      * @param Mage_Core_Model_Store_Group $group
1001:      */
1002:     public function setGroup($group)
1003:     {
1004:         $this->_group = $group;
1005:     }
1006: 
1007:     /**
1008:      * Retrieve group model
1009:      *
1010:      * @return Mage_Core_Model_Store_Group
1011:      */
1012:     public function getGroup()
1013:     {
1014:         if (is_null($this->getGroupId())) {
1015:             return false;
1016:         }
1017:         if (is_null($this->_group)) {
1018:             $this->_group = Mage::getModel('core/store_group')->load($this->getGroupId());
1019:         }
1020:         return $this->_group;
1021:     }
1022: 
1023:     /**
1024:      * Retrieve website identifier
1025:      *
1026:      * @return string|int|null
1027:      */
1028:     public function getWebsiteId()
1029:     {
1030:         return $this->_getData('website_id');
1031:     }
1032: 
1033:     /**
1034:      * Retrieve group identifier
1035:      *
1036:      * @return string|int|null
1037:      */
1038:     public function getGroupId()
1039:     {
1040:         return $this->_getData('group_id');
1041:     }
1042: 
1043:     /**
1044:      * Retrieve default group identifier
1045:      *
1046:      * @return string|int|null
1047:      */
1048:     public function getDefaultGroupId()
1049:     {
1050:         return $this->_getData('default_group_id');
1051:     }
1052: 
1053:     /**
1054:      * Check if store can be deleted
1055:      *
1056:      * @return boolean
1057:      */
1058:     public function isCanDelete()
1059:     {
1060:         if (!$this->getId()) {
1061:             return false;
1062:         }
1063: 
1064:         return $this->getGroup()->getDefaultStoreId() != $this->getId();
1065:     }
1066: 
1067:     /**
1068:      * Retrieve current url for store
1069:      *
1070:      * @param bool|string $fromStore
1071:      * @return string
1072:      */
1073:     public function getCurrentUrl($fromStore = true)
1074:     {
1075:         $sidQueryParam = $this->_getSession()->getSessionIdQueryParam();
1076:         $requestString = Mage::getSingleton('core/url')->escape(
1077:             ltrim(Mage::app()->getRequest()->getRequestString(), '/'));
1078: 
1079:         $storeUrl = Mage::app()->getStore()->isCurrentlySecure()
1080:             ? $this->getUrl('', array('_secure' => true))
1081:             : $this->getUrl('');
1082:         $storeParsedUrl = parse_url($storeUrl);
1083: 
1084:         $storeParsedQuery = array();
1085:         if (isset($storeParsedUrl['query'])) {
1086:             parse_str($storeParsedUrl['query'], $storeParsedQuery);
1087:         }
1088: 
1089:         $currQuery = Mage::app()->getRequest()->getQuery();
1090:         if (isset($currQuery[$sidQueryParam]) && !empty($currQuery[$sidQueryParam])
1091:             && $this->_getSession()->getSessionIdForHost($storeUrl) != $currQuery[$sidQueryParam]
1092:         ) {
1093:             unset($currQuery[$sidQueryParam]);
1094:         }
1095: 
1096:         foreach ($currQuery as $k => $v) {
1097:             $storeParsedQuery[$k] = $v;
1098:         }
1099: 
1100:         if (!Mage::getStoreConfigFlag(Mage_Core_Model_Store::XML_PATH_STORE_IN_URL, $this->getCode())) {
1101:             $storeParsedQuery['___store'] = $this->getCode();
1102:         }
1103:         if ($fromStore !== false) {
1104:             $storeParsedQuery['___from_store'] = $fromStore === true ? Mage::app()->getStore()->getCode() : $fromStore;
1105:         }
1106: 
1107:         return $storeParsedUrl['scheme'] . '://' . $storeParsedUrl['host']
1108:             . (isset($storeParsedUrl['port']) ? ':' . $storeParsedUrl['port'] : '')
1109:             . $storeParsedUrl['path'] . $requestString
1110:             . ($storeParsedQuery ? '?'.http_build_query($storeParsedQuery, '', '&amp;') : '');
1111:     }
1112: 
1113:     /**
1114:      * Check if store is active
1115:      *
1116:      * @return boolean|null
1117:      */
1118:     public function getIsActive()
1119:     {
1120:         return $this->_getData('is_active');
1121:     }
1122: 
1123:     /**
1124:      * Retrieve store name
1125:      *
1126:      * @return string|null
1127:      */
1128:     public function getName()
1129:     {
1130:         return $this->_getData('name');
1131:     }
1132: 
1133:     /**
1134:      * Protect delete from non admin area
1135:      *
1136:      * Register indexing event before delete store
1137:      *
1138:      * @return Mage_Core_Model_Store
1139:      */
1140:     protected function _beforeDelete()
1141:     {
1142:         $this->_protectFromNonAdmin();
1143:         Mage::getSingleton('index/indexer')->logEvent($this, self::ENTITY, Mage_Index_Model_Event::TYPE_DELETE);
1144:         return parent::_beforeDelete();
1145:     }
1146: 
1147:     /**
1148:      * rewrite in order to clear configuration cache
1149:      *
1150:      * @return Mage_Core_Model_Store
1151:      */
1152:     protected function _afterDelete()
1153:     {
1154:         parent::_afterDelete();
1155:         Mage::getConfig()->removeCache();
1156:         return $this;
1157:     }
1158: 
1159:     /**
1160:      * Init indexing process after store delete commit
1161:      *
1162:      * @return Mage_Core_Model_Store
1163:      */
1164:     protected function _afterDeleteCommit()
1165:     {
1166:         parent::_afterDeleteCommit();
1167:         Mage::getSingleton('index/indexer')->indexEvents(self::ENTITY, Mage_Index_Model_Event::TYPE_DELETE);
1168:         return $this;
1169:     }
1170: 
1171:     /**
1172:      * Reinit and reset Config Data
1173:      *
1174:      * @return Mage_Core_Model_Store
1175:      */
1176:     public function resetConfig()
1177:     {
1178:         Mage::getConfig()->reinit();
1179:         $this->_dirCache        = array();
1180:         $this->_configCache     = array();
1181:         $this->_baseUrlCache    = array();
1182:         $this->_urlCache        = array();
1183: 
1184:         return $this;
1185:     }
1186: 
1187:     /**
1188:      * Get/Set isReadOnly flag
1189:      *
1190:      * @param bool $value
1191:      * @return bool
1192:      */
1193:     public function isReadOnly($value = null)
1194:     {
1195:         if (null !== $value) {
1196:             $this->_isReadOnly = (bool) $value;
1197:         }
1198:         return $this->_isReadOnly;
1199:     }
1200: 
1201:     /**
1202:      * Retrieve storegroup name
1203:      *
1204:      * @return string
1205:      */
1206:     public function getFrontendName()
1207:     {
1208:         if (is_null($this->_frontendName)) {
1209:             $storeGroupName = (string) Mage::getStoreConfig('general/store_information/name', $this);
1210:             $this->_frontendName = (!empty($storeGroupName)) ? $storeGroupName : $this->getGroup()->getName();
1211:         }
1212:         return $this->_frontendName;
1213:     }
1214: }
1215: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0