00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 class Mage_Core_Model_Store_Group extends Mage_Core_Model_Abstract
00036 {
00037 const CACHE_TAG = 'store_group';
00038
00039 protected $_cacheTag = true;
00040
00041
00042
00043
00044 protected $_eventPrefix = 'store_group';
00045
00046
00047
00048
00049 protected $_eventObject = 'store_group';
00050
00051
00052
00053
00054
00055
00056 protected $_stores;
00057
00058
00059
00060
00061
00062
00063 protected $_storeIds = array();
00064
00065
00066
00067
00068
00069
00070 protected $_storeCodes = array();
00071
00072
00073
00074
00075
00076
00077 protected $_storesCount = 0;
00078
00079
00080
00081
00082
00083
00084 protected $_defaultStore;
00085
00086
00087
00088
00089
00090
00091 protected $_website;
00092
00093
00094
00095
00096 private $_isReadOnly = false;
00097
00098
00099
00100
00101
00102 protected function _construct()
00103 {
00104 $this->_init('core/store_group');
00105 }
00106
00107
00108
00109
00110
00111 protected function _loadStores()
00112 {
00113 $this->_stores = array();
00114 $this->_storesCount = 0;
00115 foreach ($this->getStoreCollection() as $store) {
00116 $this->_stores[$store->getId()] = $store;
00117 $this->_storeIds[$store->getId()] = $store->getId();
00118 $this->_storeCodes[$store->getId()] = $store->getCode();
00119 if ($this->getDefaultStoreId() == $store->getId()) {
00120 $this->_defaultStore = $store;
00121 }
00122 $this->_storesCount ++;
00123 }
00124 }
00125
00126
00127
00128
00129
00130
00131 public function setStores($stores)
00132 {
00133 $this->_stores = array();
00134 $this->_storesCount = 0;
00135 foreach ($stores as $store) {
00136 $this->_stores[$store->getId()] = $store;
00137 $this->_storeIds[$store->getId()] = $store->getId();
00138 $this->_storeCodes[$store->getId()] = $store->getCode();
00139 if ($this->getDefaultStoreId() == $store->getId()) {
00140 $this->_defaultStore = $store;
00141 }
00142 $this->_storesCount ++;
00143 }
00144 }
00145
00146
00147
00148
00149
00150
00151 public function getStoreCollection()
00152 {
00153 return Mage::getModel('core/store')
00154 ->getCollection()
00155 ->addGroupFilter($this->getId());
00156 }
00157
00158
00159
00160
00161
00162
00163 public function getStores()
00164 {
00165 if (is_null($this->_stores)) {
00166 $this->_loadStores();
00167 }
00168 return $this->_stores;
00169 }
00170
00171
00172
00173
00174
00175
00176 public function getStoreIds()
00177 {
00178 if (is_null($this->_stores)) {
00179 $this->_loadStores();
00180 }
00181 return $this->_storeIds;
00182 }
00183
00184
00185
00186
00187
00188
00189 public function getStoreCodes()
00190 {
00191 if (is_null($this->_stores)) {
00192 $this->_loadStores();
00193 }
00194 return $this->_storeCodes;
00195 }
00196
00197 public function getStoresCount()
00198 {
00199 if (is_null($this->_stores)) {
00200 $this->_loadStores();
00201 }
00202 return $this->_storesCount;
00203 }
00204
00205
00206
00207
00208
00209
00210 public function getDefaultStore()
00211 {
00212 if (!$this->getDefaultStoreId()) {
00213 return false;
00214 }
00215 if (is_null($this->_stores)) {
00216 $this->_loadStores();
00217 }
00218 return $this->_defaultStore;
00219 }
00220
00221
00222
00223
00224
00225
00226 public function setWebsite(Mage_Core_Model_Website $website)
00227 {
00228 $this->_website = $website;
00229 }
00230
00231
00232
00233
00234
00235
00236 public function getWebsite()
00237 {
00238 if (is_null($this->getWebsiteId())) {
00239 return false;
00240 }
00241 if (is_null($this->_website)) {
00242 $this->_website = Mage::app()->getWebsite($this->getWebsiteId());
00243 }
00244 return $this->_website;
00245 }
00246
00247
00248
00249
00250
00251
00252 public function isCanDelete()
00253 {
00254 if (!$this->getId()) {
00255 return false;
00256 }
00257
00258 return $this->getWebsite()->getDefaultGroupId() != $this->getId();
00259 }
00260
00261 public function getDefaultStoreId()
00262 {
00263 return $this->_getData('default_store_id');
00264 }
00265
00266 public function getRootCategoryId()
00267 {
00268 return $this->_getData('root_category_id');
00269 }
00270
00271 public function getWebsiteId()
00272 {
00273 return $this->_getData('website_id');
00274 }
00275
00276 protected function _beforeDelete()
00277 {
00278 $this->_protectFromNonAdmin();
00279 return parent::_beforeDelete();
00280 }
00281
00282
00283
00284
00285
00286
00287
00288 public function isReadOnly($value = null)
00289 {
00290 if (null !== $value) {
00291 $this->_isReadOnly = (bool)$value;
00292 }
00293 return $this->_isReadOnly;
00294 }
00295 }