Mage_Core_Model_Website Class Reference

Inheritance diagram for Mage_Core_Model_Website:

Mage_Core_Model_Abstract Varien_Object

List of all members.

Public Member Functions

 load ($id, $field=null)
 loadConfig ($code)
 getConfig ($path)
 setGroups ($groups)
 getGroupCollection ()
 getGroups ()
 getGroupIds ()
 getGroupsCount ()
 getDefaultGroup ()
 setStores ($stores)
 getStoreCollection ()
 getStores ()
 getStoreIds ()
 getStoreCodes ()
 getStoresCount ()
 isCanDelete ()
 getWebsiteGroupStore ()
 getDefaultGroupId ()
 getCode ()
 getBaseCurrencyCode ()
 getBaseCurrency ()
 getDefaultStore ()
 getDefaultStoresSelect ($withDefault=false)
 isReadOnly ($value=null)

Public Attributes

const CACHE_TAG = 'website'

Protected Member Functions

 _construct ()
 _loadGroups ()
 _loadStores ()
 _beforeDelete ()
 _afterDelete ()

Protected Attributes

 $_cacheTag = true
 $_eventPrefix = 'website'
 $_eventObject = 'website'
 $_configCache = array()
 $_groups
 $_groupIds = array()
 $_groupsCount
 $_stores
 $_storeIds = array()
 $_storeCodes = array()
 $_storesCount = 0
 $_defaultGroup
 $_defaultStore
 $_isCanDelete


Detailed Description

Definition at line 35 of file Website.php.


Member Function Documentation

_afterDelete (  )  [protected]

rewrite in order to clear configuration cache

Returns:
Mage_Core_Model_Website

Reimplemented from Mage_Core_Model_Abstract.

Definition at line 469 of file Website.php.

00470     {
00471         parent::_afterDelete();
00472         Mage::getConfig()->removeCache();
00473         return $this;
00474     }

_beforeDelete (  )  [protected]

Processing object before delete data

Returns:
Mage_Core_Model_Abstract

Reimplemented from Mage_Core_Model_Abstract.

Definition at line 458 of file Website.php.

00459     {
00460         $this->_protectFromNonAdmin();
00461         return parent::_beforeDelete();
00462     }

_construct (  )  [protected]

init model

Reimplemented from Varien_Object.

Definition at line 136 of file Website.php.

00137     {
00138         $this->_init('core/website');
00139     }

_loadGroups (  )  [protected]

Load group collection and set internal data

Definition at line 217 of file Website.php.

00218     {
00219         $this->_groups = array();
00220         $this->_groupsCount = 0;
00221         foreach ($this->getGroupCollection() as $group) {
00222             $this->_groups[$group->getId()] = $group;
00223             $this->_groupIds[$group->getId()] = $group->getId();
00224             if ($this->getDefaultGroupId() == $group->getId()) {
00225                 $this->_defaultGroup = $group;
00226             }
00227             $this->_groupsCount ++;
00228         }
00229     }

_loadStores (  )  [protected]

Load store collection and set internal data

Definition at line 322 of file Website.php.

00323     {
00324         $this->_stores = array();
00325         $this->_storesCount = 0;
00326         foreach ($this->getStoreCollection() as $store) {
00327             $this->_stores[$store->getId()] = $store;
00328             $this->_storeIds[$store->getId()] = $store->getId();
00329             $this->_storeCodes[$store->getId()] = $store->getCode();
00330             if ($this->getDefaultGroup() && $this->getDefaultGroup()->getDefaultStoreId() == $store->getId()) {
00331                 $this->_defaultStore = $store;
00332             }
00333             $this->_storesCount ++;
00334         }
00335     }

getBaseCurrency (  ) 

Retrieve website base currency

Returns:
Mage_Directory_Model_Currency

Definition at line 495 of file Website.php.

00496     {
00497         $currency = $this->getData('base_currency');
00498         if (is_null($currency)) {
00499             $currency = Mage::getModel('directory/currency')->load($this->getBaseCurrencyCode());
00500             $this->setData('base_currency', $currency);
00501         }
00502         return $currency;
00503     }

getBaseCurrencyCode (  ) 

Retrieve website base currency code

Returns:
string

Definition at line 481 of file Website.php.

00482     {
00483         if ($this->getConfig(Mage_Core_Model_Store::XML_PATH_PRICE_SCOPE) == Mage_Core_Model_Store::PRICE_SCOPE_GLOBAL) {
00484             return Mage::app()->getBaseCurrencyCode();
00485         } else {
00486             return $this->getConfig(Mage_Directory_Model_Currency::XML_PATH_CURRENCY_BASE);
00487         }
00488     }

getCode (  ) 

Definition at line 453 of file Website.php.

00454     {
00455         return $this->_getData('code');
00456     }

getConfig ( path  ) 

Get website config data

Parameters:
string $path
Returns:
mixed

Definition at line 192 of file Website.php.

00192                                      {
00193         if (!isset($this->_configCache[$path])) {
00194 
00195             $config = Mage::getConfig()->getNode('websites/'.$this->getCode().'/'.$path);
00196             if (!$config) {
00197                 return false;
00198                 #throw Mage::exception('Mage_Core', Mage::helper('core')->__('Invalid websites configuration path: %s', $path));
00199             }
00200             if ($config->hasChildren()) {
00201                 $value = array();
00202                 foreach ($config->children() as $k=>$v) {
00203                     $value[$k] = $v;
00204                 }
00205             } else {
00206                 $value = (string)$config;
00207             }
00208             $this->_configCache[$path] = $value;
00209         }
00210         return $this->_configCache[$path];
00211     }

getDefaultGroup (  ) 

Retrieve default group model

Returns:
Mage_Core_Model_Store_Group

Definition at line 307 of file Website.php.

00308     {
00309         if (!$this->getDefaultGroupId()) {
00310             return false;
00311         }
00312         if (is_null($this->_groups)) {
00313             $this->_loadGroups();
00314         }
00315         return $this->_defaultGroup;
00316     }

getDefaultGroupId (  ) 

Definition at line 448 of file Website.php.

00449     {
00450         return $this->_getData('default_group_id');
00451     }

getDefaultStore (  ) 

Retrieve Default Website Store or null

Returns:
Mage_Core_Model_Store

Definition at line 510 of file Website.php.

00511     {
00512         // init stores if not loaded
00513         $this->getStores();
00514         return $this->_defaultStore;
00515     }

getDefaultStoresSelect ( withDefault = false  ) 

Retrieve default stores select object Select fields website_id, store_id

Parameters:
$withDefault include/exclude default admin website
Returns:
Varien_Db_Select

Definition at line 524 of file Website.php.

00525     {
00526         return $this->getResource()->getDefaultStoresSelect($withDefault);
00527     }

getGroupCollection (  ) 

Retrieve new (not loaded) Group collection object with website filter

Returns:
Mage_Core_Model_Mysql4_Store_Group_Collection

Definition at line 256 of file Website.php.

00257     {
00258         return Mage::getModel('core/store_group')
00259             ->getCollection()
00260             ->addWebsiteFilter($this->getId());
00261     }

getGroupIds (  ) 

Retrieve website group ids

Returns:
array

Definition at line 281 of file Website.php.

00282     {
00283         if (is_null($this->_groups)) {
00284             $this->_loadGroups();
00285         }
00286         return $this->_groupIds;
00287     }

getGroups (  ) 

Retrieve website groups

Returns:
array

Definition at line 268 of file Website.php.

00269     {
00270         if (is_null($this->_groups)) {
00271             $this->_loadGroups();
00272         }
00273         return $this->_groups;
00274     }

getGroupsCount (  ) 

Retrieve number groups in a website

Returns:
int

Definition at line 294 of file Website.php.

00295     {
00296         if (is_null($this->_groups)) {
00297             $this->_loadGroups();
00298         }
00299         return $this->_groupsCount;
00300     }

getStoreCodes (  ) 

Retrieve website store codes

Returns:
array

Definition at line 400 of file Website.php.

00401     {
00402         if (is_null($this->_stores)) {
00403             $this->_loadStores();
00404         }
00405         return $this->_storeCodes;
00406     }

getStoreCollection (  ) 

Retrieve new (not loaded) Store collection object with website filter

Returns:
Mage_Core_Model_Mysql4_Store_Collection

Definition at line 362 of file Website.php.

00363     {
00364         return Mage::getModel('core/store')
00365             ->getCollection()
00366             ->addWebsiteFilter($this->getId());
00367     }

getStoreIds (  ) 

Retrieve website store ids

Returns:
array

Definition at line 387 of file Website.php.

00388     {
00389         if (is_null($this->_stores)) {
00390             $this->_loadStores();
00391         }
00392         return $this->_storeIds;
00393     }

getStores (  ) 

Retrieve wersite store objects

Returns:
array

Definition at line 374 of file Website.php.

00375     {
00376         if (is_null($this->_stores)) {
00377             $this->_loadStores();
00378         }
00379         return $this->_stores;
00380     }

getStoresCount (  ) 

Retrieve number stores in a website

Returns:
int

Definition at line 413 of file Website.php.

00414     {
00415         if (is_null($this->_stores)) {
00416             $this->_loadStores();
00417         }
00418         return $this->_storesCount;
00419     }

getWebsiteGroupStore (  ) 

Retrieve unique website-group-store key for collection with groups and stores

Returns:
string

Definition at line 443 of file Website.php.

00444     {
00445         return join('-', array($this->getWebsiteId(), $this->getGroupId(), $this->getStoreId()));
00446     }

isCanDelete (  ) 

is can delete website

Returns:
bool

Definition at line 426 of file Website.php.

00427     {
00428         if ($this->_isReadOnly || !$this->getId()) {
00429             return false;
00430         }
00431         if (is_null($this->_isCanDelete)) {
00432             $this->_isCanDelete = (Mage::getModel('core/website')->getCollection()->getSize() > 2)
00433                 && !$this->getIsDefault();
00434         }
00435         return $this->_isCanDelete;
00436     }

isReadOnly ( value = null  ) 

Get/Set isReadOnly flag

Parameters:
bool $value
Returns:
bool

Definition at line 535 of file Website.php.

00536     {
00537         if (null !== $value) {
00538             $this->_isReadOnly = (bool)$value;
00539         }
00540         return $this->_isReadOnly;
00541     }

load ( id,
field = null 
)

Custom load

Parameters:
int|string $id
string $field
Returns:
Mage_Core_Model_Website

Reimplemented from Mage_Core_Model_Abstract.

Definition at line 148 of file Website.php.

00149     {
00150         if (!is_numeric($id) && is_null($field)) {
00151             $this->_getResource()->load($this, $id, 'code');
00152             return $this;
00153         }
00154         return parent::load($id, $field);
00155     }

loadConfig ( code  ) 

Load website configuration

Parameters:
string $code
Returns:
Mage_Core_Model_Website

Definition at line 163 of file Website.php.

00164     {
00165         if (!Mage::getConfig()->getNode('websites')) {
00166             return $this;
00167         }
00168         if (is_numeric($code)) {
00169             foreach (Mage::getConfig()->getNode('websites')->children() as $websiteCode=>$website) {
00170                 if ((int)$website->system->website->id==$code) {
00171                     $code = $websiteCode;
00172                     break;
00173                 }
00174             }
00175         } else {
00176             $website = Mage::getConfig()->getNode('websites/'.$code);
00177         }
00178         if (!empty($website)) {
00179             $this->setCode($code);
00180             $id = (int)$website->system->website->id;
00181             $this->setId($id)->setStoreId($id);
00182         }
00183         return $this;
00184     }

setGroups ( groups  ) 

Set website groups

Parameters:
array $groups

Definition at line 236 of file Website.php.

00237     {
00238         $this->_groups = array();
00239         $this->_groupsCount = 0;
00240         foreach ($groups as $group) {
00241             $this->_groups[$group->getId()] = $group;
00242             $this->_groupIds[$group->getId()] = $group->getId();
00243             if ($this->getDefaultGroupId() == $group->getId()) {
00244                 $this->_defaultGroup = $group;
00245             }
00246             $this->_groupsCount ++;
00247         }
00248         return $this;
00249     }

setStores ( stores  ) 

Set website stores

Parameters:
array $stores

Definition at line 342 of file Website.php.

00343     {
00344         $this->_stores = array();
00345         $this->_storesCount = 0;
00346         foreach ($stores as $store) {
00347             $this->_stores[$store->getId()] = $store;
00348             $this->_storeIds[$store->getId()] = $store->getId();
00349             $this->_storeCodes[$store->getId()] = $store->getCode();
00350             if ($this->getDefaultGroup() && $this->getDefaultGroup()->getDefaultStoreId() == $store->getId()) {
00351                 $this->_defaultStore = $store;
00352             }
00353             $this->_storesCount ++;
00354         }
00355     }


Member Data Documentation

$_cacheTag = true [protected]

Reimplemented from Mage_Core_Model_Abstract.

Definition at line 38 of file Website.php.

$_configCache = array() [protected]

Definition at line 55 of file Website.php.

$_defaultGroup [protected]

Definition at line 111 of file Website.php.

$_defaultStore [protected]

Definition at line 118 of file Website.php.

$_eventObject = 'website' [protected]

Reimplemented from Mage_Core_Model_Abstract.

Definition at line 48 of file Website.php.

$_eventPrefix = 'website' [protected]

Reimplemented from Mage_Core_Model_Abstract.

Definition at line 43 of file Website.php.

$_groupIds = array() [protected]

Definition at line 69 of file Website.php.

$_groups [protected]

Definition at line 62 of file Website.php.

$_groupsCount [protected]

Definition at line 76 of file Website.php.

$_isCanDelete [protected]

Definition at line 125 of file Website.php.

$_storeCodes = array() [protected]

Definition at line 97 of file Website.php.

$_storeIds = array() [protected]

Definition at line 90 of file Website.php.

$_stores [protected]

Definition at line 83 of file Website.php.

$_storesCount = 0 [protected]

Definition at line 104 of file Website.php.

const CACHE_TAG = 'website'

Definition at line 37 of file Website.php.


The documentation for this class was generated from the following file:

Generated on Sat Jul 4 17:24:01 2009 for Magento by  doxygen 1.5.8