Magento Model – Playing with Mage_Core_Model_Store
14 July 2010
726 views
No Comment
API Doc – The Store Model
Located in /Core/Model/Store.php (line 35)
Varien_Object
|
--Mage_Core_Model_Abstract
|
--Mage_Core_Model_Store
How to gather info about stores ?
In our example, we have 1 website which contains 1 store with 3 store views : (1) Default Store View, (2) Debug Store View, (3) US Store View.
With Php Script :
<?php
require_once('app/Mage.php');
Mage::app();
// fetch stores collection
$stores = Mage::getModel('core/store')
->getCollection();
// parse stores;
foreach($stores as $store) {
printf("%s\n", str_repeat('-', 50));
$data = $store->getData();
foreach($data as $key => $item) {
printf("%-30s: %s\n", $key, $item);
}
}
/*
OUTPUT :
--------------------------------------------------
store_id : 2
code : debug
website_id : 1
group_id : 1
name : Debug Store View
sort_order : 0
is_active : 1
--------------------------------------------------
store_id : 1
code : default
website_id : 1
group_id : 1
name : Default Store View
sort_order : 0
is_active : 1
--------------------------------------------------
store_id : 3
code : us
website_id : 1
group_id : 1
name : US Store View
sort_order : 0
is_active : 1
*/
?>
With SQL :
SELECT
`main_table`.*
FROM `core_store` AS `main_table`
WHERE (main_table.store_id>0)
ORDER BY
CASE WHEN main_table.store_id = 0 THEN 0 ELSE 1 END ASC,
main_table.sort_order ASC,
main_table.name ASC;










