string(53) "/2010/07/09/magento-diagram-website-store-store-view/"
Home » Magento Diagram

Magento Diagram – Website / Store / Store View

9 July 2010 6,134 views No Comment

How does Magento handles multiples stores ? What are store code and store id ? Have a look at the database diagram below to know more about Magento’s SQL tables. Note this is only a small part of the whole database diagram (!).

Magento Multiple Stores Diagram (Magento Version 1.4.1.0)

Magento Diagram - Website, Store, Store View

Discussion

To understand how Magento manages multiple websites and stores, we dump the queries executed on MySQL server while running the single instruction Mage::app() which is responsible for launching Magento application (see index.php and app/Mage.php) in your magento base installation directory).

Php Standalone Script

All the table relations displayed into the above diagram are demonstrated with this very simple script.

<?php
require_once('app/Mage.php');
Mage::app();
?>

SQL Queries

Here, you will find the queries performed on the MySQL server while running the simple script above. Execute the queries on your Magento Test Server to have details of the output.


SET NAMES utf8;
#
# query core_website
#
SELECT website_id, code, name FROM core_website;

#
# query core_store
#
SELECT store_id, code, name, website_id FROM core_store ORDER BY sort_order ASC;

#
# query core_config_data
#
SELECT scope, scope_id, path, value FROM core_config_data;

#
# query core_store (again)
#
SELECT `main_table`.* FROM `core_store` AS `main_table` ORDER BY CASE WHEN main_table.store_id = 0 THEN 0 ELSE 1 END ASC, main_table.sort_order ASC, main_table.name ASC;

#
# query core_website (again)
#
SELECT `main_table`.* FROM `core_website` AS `main_table` ORDER BY main_table.sort_order ASC, main_table.name ASC;

#
# query core_store_group
#
SELECT `main_table`.* FROM `core_store_group` AS `main_table` ORDER BY main_table.name ASC;

How to fetch store code and store id ?

Here, we fetch the store code and the store id. No parameter is passed to the Mage::app() method, therefore Magento will return the 'default' store.

<?php
require_once('app/Mage.php');

// launch Magento (no parameter => default store view)
Mage::app();

// get store code
$code = Mage::app()->getStore()->getCode();
var_dump($code);

// get store id
$id = Mage::app()->getStore()->getId();
var_dump($id);
?>

This script will output :

string(7) "default"
string(1) "1"

If you pass as parameter an unknown store code to Mage->app(), Magento will throw an Exception (Mage_Core_Model_Store_Exception).

How to gather info about Magento configuration ?

This SQL query outputs all the configuration variables available. See table core_config_data for more info.

mysql> select path from core_config_data;
+-----------------------------------------------+
| path                                          |
+-----------------------------------------------+
| catalog/category/root_id                      |
| currency/options/allow                        |
| currency/options/base                         |
| currency/options/default                      |
| design/footer/absolute_footer                 |
| design/footer/copyright                       |
| design/head/default_description               |
| design/head/default_keywords                  |
| design/head/default_robots                    |
| design/head/default_title                     |
| design/head/demonotice                        |
| design/head/includes                          |
| design/head/title_prefix                      |
| design/head/title_suffix                      |
| design/header/logo_alt                        |
| design/header/logo_src                        |
| design/header/welcome                         |
| design/package/name                           |
| design/package/ua_regexp                      |
| design/pagination/anchor_text_for_next        |
| design/pagination/anchor_text_for_previous    |
| design/pagination/pagination_frame            |
| design/pagination/pagination_frame_skip       |
| design/theme/default                          |
| design/theme/default_ua_regexp                |
| design/theme/layout                           |
| design/theme/layout_ua_regexp                 |
| design/theme/locale                           |
| design/theme/skin                             |
| design/theme/skin_ua_regexp                   |
| design/theme/template                         |
| design/theme/template_ua_regexp               |
| design/watermark/image_imageOpacity           |
| design/watermark/image_position               |
| design/watermark/image_size                   |
| design/watermark/small_image_imageOpacity     |
| design/watermark/small_image_position         |
| design/watermark/small_image_size             |
| design/watermark/thumbnail_imageOpacity       |
| design/watermark/thumbnail_position           |
| design/watermark/thumbnail_size               |
| general/country/allow                         |
| general/country/default                       |
| general/country/optional_zip_countries        |
| general/locale/code                           |
| general/locale/firstday                       |
| general/locale/timezone                       |
| general/locale/weekend                        |
| general/store_information/address             |
| general/store_information/name                |
| general/store_information/phone               |
| shipping/option/checkout_multiple             |
| shipping/option/checkout_multiple_maximum_qty |
| shipping/origin/city                          |
| shipping/origin/country_id                    |
| shipping/origin/postcode                      |
| shipping/origin/region_id                     |
| tax/calculation/algorithm                     |
| tax/calculation/apply_after_discount          |
| tax/calculation/apply_tax_on                  |
| tax/calculation/based_on                      |
| tax/calculation/discount_tax                  |
| tax/calculation/price_includes_tax            |
| tax/calculation/shipping_includes_tax         |
| tax/cart_display/full_summary                 |
| tax/cart_display/grandtotal                   |
| tax/cart_display/price                        |
| tax/cart_display/shipping                     |
| tax/cart_display/subtotal                     |
| tax/cart_display/zero_tax                     |
| tax/classes/shipping_tax_class                |
| tax/defaults/country                          |
| tax/defaults/postcode                         |
| tax/defaults/region                           |
| tax/display/shipping                          |
| tax/display/type                              |
| tax/sales_display/full_summary                |
| tax/sales_display/grandtotal                  |
| tax/sales_display/price                       |
| tax/sales_display/shipping                    |
| tax/sales_display/subtotal                    |
| tax/sales_display/zero_tax                    |
| tax/weee/apply_vat                            |
| tax/weee/discount                             |
| tax/weee/display                              |
| tax/weee/display_email                        |
| tax/weee/display_list                         |
| tax/weee/display_sales                        |
| tax/weee/enable                               |
| tax/weee/include_in_subtotal                  |
| web/secure/base_url                           |
| web/seo/use_rewrites                          |
| web/unsecure/base_url                         |
| dev/debug/template_hints                      |
| dev/debug/template_hints_blocks               |
| design/header/welcome                         |
| general/country/default                       |
| general/locale/code                           |
+-----------------------------------------------+
98 rows in set (0.00 sec)

With PHP :

<?php
require_once('app/Mage.php');

// launch Magento (no parameter => default store view)
Mage::app();

// get core config data : catalog category root id
$res = Mage::getStoreConfig('catalog/category/root_id');
var_dump($res);

// get core config data : web base url
$res = Mage::getStoreConfig('web/unsecure/base_url');
var_dump($res);

?>

This script will output :

string(1) "2"
string(26) "http://www.yourmagento.com"

API Doc – The Store Model

API Doc – docs.magentocommerce.com

Located in /Core/Model/Store.php  (line 35)

Varien_Object
   |
   --Mage_Core_Model_Abstract
      |
      --Mage_Core_Model_Store

API Doc – The Website Model


Located in /Core/Model/Website.php (line 35)

Varien_Object
   |
   --Mage_Core_Model_Abstract
      |
      --Mage_Core_Model_Website

Comments are closed.

Google