1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26:
27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43:
44: class Mage_Core_Model_Store extends Mage_Core_Model_Abstract
45: {
46: 47: 48:
49: const ENTITY = 'core_store';
50:
51: 52: 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 = 'web/secure/offloader_header';
65: const XML_PATH_PRICE_SCOPE = 'catalog/price/scope';
66:
67: 68: 69:
70: const PRICE_SCOPE_GLOBAL = 0;
71: const PRICE_SCOPE_WEBSITE = 1;
72:
73: 74: 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: 85:
86: const DEFAULT_CODE = 'default';
87: const ADMIN_CODE = 'admin';
88:
89: 90: 91:
92: const CACHE_TAG = 'store';
93:
94: 95: 96:
97: const COOKIE_NAME = 'store';
98:
99: 100: 101:
102: const COOKIE_CURRENCY = 'currency';
103:
104: 105: 106:
107: const MEDIA_REWRITE_SCRIPT = 'get.php/';
108:
109: 110: 111: 112: 113:
114: protected $_cacheTag = true;
115:
116: 117: 118: 119: 120:
121: protected $_eventPrefix = 'store';
122:
123: 124: 125: 126: 127:
128: protected $_eventObject = 'store';
129:
130: 131: 132: 133: 134:
135: protected $_priceFilter;
136:
137: 138: 139: 140: 141:
142: protected $_website;
143:
144: 145: 146: 147: 148:
149: protected $_group;
150:
151: 152: 153: 154: 155:
156: protected $_configCache = null;
157:
158: 159: 160: 161: 162:
163: protected $_configCacheBaseNodes = array();
164:
165: 166: 167: 168: 169:
170: protected $_dirCache = array();
171:
172: 173: 174: 175: 176:
177: protected $_urlCache = array();
178:
179: 180: 181: 182: 183:
184: protected $_baseUrlCache = array();
185:
186: 187: 188: 189: 190:
191: protected $_session;
192:
193: 194: 195: 196: 197:
198: protected $_isAdminSecure = null;
199:
200: 201: 202: 203: 204:
205: protected $_isFrontSecure = null;
206:
207: 208: 209: 210: 211:
212: protected $_frontendName = null;
213:
214: 215: 216: 217: 218:
219: private $_isReadOnly = false;
220:
221: 222: 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: 243: 244: 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: 257: 258: 259: 260: 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: 273: 274: 275: 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: 300: 301: 302:
303: public function getCode()
304: {
305: return $this->_getData('code');
306: }
307:
308: 309: 310: 311: 312: 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: 335: 336: 337: 338: 339:
340: public function initConfigCache()
341: {
342: 343: 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: 372: 373: 374: 375: 376: 377: 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: 392: 393: 394:
395: public function setWebsite(Mage_Core_Model_Website $website)
396: {
397: $this->_website = $website;
398: }
399:
400: 401: 402: 403: 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: 418: 419: 420: 421: 422: 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: 465: 466: 467: 468: 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: 491: 492: 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: 504: 505: 506: 507: 508:
509: public function getUrl($route = '', $params = array())
510: {
511:
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: 523: 524: 525: 526: 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: 578: 579: 580: 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: 600: 601: 602:
603: protected function _isCustomEntryPoint()
604: {
605: return (bool)Mage::registry('custom_entry_point');
606: }
607:
608: 609: 610: 611: 612: 613: 614: 615: 616: 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: 634: 635: 636: 637:
638: protected function _updatePathUseStoreView($url)
639: {
640: if ($this->getStoreInUrl()) {
641: $url .= $this->getCode() . '/';
642: }
643: return $url;
644: }
645:
646: 647: 648: 649: 650:
651: public function getStoreInUrl()
652: {
653: return Mage::isInstalled() && $this->getConfig(self::XML_PATH_STORE_IN_URL);
654: }
655:
656: 657: 658: 659: 660:
661: public function getId()
662: {
663: return $this->_getData('store_id');
664: }
665:
666: 667: 668: 669: 670:
671: public function isAdmin()
672: {
673: return $this->getId() == Mage_Core_Model_App::ADMIN_STORE_ID;
674: }
675:
676:
677: 678: 679: 680: 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: 693: 694: 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: 707: 708: 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: 740:
741:
742: 743: 744: 745: 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: 759: 760: 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: 774: 775: 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: 785: 786: 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: 800: 801: 802: 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: 820: 821: 822:
823: public function getCurrentCurrencyCode()
824: {
825:
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:
835: $codes = array_values($this->getAvailableCurrencyCodes(true));
836: if (empty($codes)) {
837:
838: return $this->getDefaultCurrencyCode();
839: }
840: return array_shift($codes);
841: }
842:
843: 844: 845: 846: 847: 848: 849: 850: 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:
858: $baseCurrencyCode = $this->getBaseCurrencyCode();
859: if (!in_array($baseCurrencyCode, $codes)) {
860: $codes[] = $baseCurrencyCode;
861:
862:
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:
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: 882: 883: 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: 906: 907: 908:
909: public function getCurrentCurrencyRate()
910: {
911: return $this->getBaseCurrency()->getRate($this->getCurrentCurrency());
912: }
913:
914: 915: 916: 917: 918: 919: 920: 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: 938: 939: 940: 941:
942: public function roundPrice($price)
943: {
944: return round($price, 2);
945: }
946:
947: 948: 949: 950: 951: 952: 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: 964: 965: 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: 986: 987: 988:
989: public function getRootCategoryId()
990: {
991: if (!$this->getGroup()) {
992: return 0;
993: }
994: return $this->getGroup()->getRootCategoryId();
995: }
996:
997: 998: 999: 1000: 1001:
1002: public function setGroup($group)
1003: {
1004: $this->_group = $group;
1005: }
1006:
1007: 1008: 1009: 1010: 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: 1025: 1026: 1027:
1028: public function getWebsiteId()
1029: {
1030: return $this->_getData('website_id');
1031: }
1032:
1033: 1034: 1035: 1036: 1037:
1038: public function getGroupId()
1039: {
1040: return $this->_getData('group_id');
1041: }
1042:
1043: 1044: 1045: 1046: 1047:
1048: public function getDefaultGroupId()
1049: {
1050: return $this->_getData('default_group_id');
1051: }
1052:
1053: 1054: 1055: 1056: 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: 1069: 1070: 1071: 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, '', '&') : '');
1111: }
1112:
1113: 1114: 1115: 1116: 1117:
1118: public function getIsActive()
1119: {
1120: return $this->_getData('is_active');
1121: }
1122:
1123: 1124: 1125: 1126: 1127:
1128: public function getName()
1129: {
1130: return $this->_getData('name');
1131: }
1132:
1133: 1134: 1135: 1136: 1137: 1138: 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: 1149: 1150: 1151:
1152: protected function _afterDelete()
1153: {
1154: parent::_afterDelete();
1155: Mage::getConfig()->removeCache();
1156: return $this;
1157: }
1158:
1159: 1160: 1161: 1162: 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: 1173: 1174: 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: 1189: 1190: 1191: 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: 1203: 1204: 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: