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 $installer = $this;
00028
00029
00030 $installer->startSetup();
00031
00032 $installer->run("
00033 DROP TABLE IF EXISTS {$this->getTable('core_store_group')};
00034 CREATE TABLE {$this->getTable('core_store_group')} (
00035 `group_id` smallint(5) unsigned NOT NULL auto_increment,
00036 `website_id` smallint(5) unsigned NOT NULL default '0',
00037 `name` varchar(32) NOT NULL default '',
00038 `root_category_id` int(10) unsigned NOT NULL default '0',
00039 `default_store_id` smallint(5) unsigned NOT NULL default '0',
00040 PRIMARY KEY (`group_id`),
00041 KEY `FK_STORE_GROUP_WEBSITE` (`website_id`),
00042 KEY (`default_store_id`),
00043 CONSTRAINT `FK_STORE_GROUP_WEBSITE` FOREIGN KEY (`website_id`) REFERENCES {$this->getTable('core_website')} (`website_id`) ON DELETE CASCADE ON UPDATE CASCADE
00044 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
00045 INSERT INTO {$this->getTable('core_store_group')} VALUES (0,0,'Default',0,0);
00046 ALTER TABLE {$this->getTable('core_store')}
00047 DROP FOREIGN KEY `FK_STORE_LANGUAGE`;
00048 ALTER TABLE {$this->getTable('core_store')}
00049 DROP INDEX `FK_STORE_LANGUAGE`;
00050 DROP TABLE IF EXISTS {$this->getTable('core_language')};
00051 ALTER TABLE {$this->getTable('core_store')}
00052 DROP `language_code`;
00053 ALTER TABLE {$this->getTable('core_store')}
00054 ADD `group_id` smallint(5) unsigned NOT NULL AFTER `website_id`;
00055 ALTER TABLE {$this->getTable('core_store')}
00056 ADD INDEX `FK_STORE_GROUP` (`group_id`);
00057 ALTER TABLE {$this->getTable('core_store')}
00058 ADD CONSTRAINT `FK_STORE_GROUP_STORE` FOREIGN KEY (`group_id`)
00059 REFERENCES {$this->getTable('core_store_group')} (`group_id`)
00060 ON DELETE CASCADE
00061 ON UPDATE CASCADE;
00062 ALTER TABLE {$this->getTable('core_website')}
00063 DROP INDEX `is_active`,
00064 ADD INDEX (`sort_order`);
00065 ALTER TABLE {$this->getTable('core_website')}
00066 DROP `is_active`;
00067 ALTER TABLE {$this->getTable('core_website')}
00068 ADD `default_group_id` smallint(5) unsigned NOT NULL default '0';
00069 ALTER TABLE {$this->getTable('core_website')}
00070 ADD INDEX (`default_group_id`);
00071 UPDATE {$this->getTable('core_website')}
00072 SET `default_group_id`='0'
00073 WHERE `website_id`=0;
00074 ");
00075
00076 $websiteRows = $installer->getConnection()
00077 ->fetchAll($installer->getConnection()
00078 ->select()
00079 ->from($this->getTable('core_website'))
00080 ->where($installer->getConnection()->quoteInto('website_id>?', 0)));
00081
00082 $rows = $installer->getConnection()
00083 ->fetchAll($installer->getConnection()
00084 ->select()
00085 ->from($this->getTable('core_config_data'))
00086 ->where($installer->getConnection()->quoteInto('path LIKE ?', 'catalog/category/root_id')));
00087 $rootCategoryIds = array();
00088 foreach ($rows as $row) {
00089 $rootCategoryIds[$row['scope']][$row['scope_id']] = $row['value'];
00090 }
00091
00092 foreach ($websiteRows as $websiteRow) {
00093 $rootCategoryId = 2;
00094 if (isset($rootCategoryIds['website'][$websiteRow['website_id']])) {
00095 $rootCategoryId = $rootCategoryIds['website'][$websiteRow['website_id']];
00096 }
00097 elseif (isset($rootCategoryIds['default'][0])) {
00098 $rootCategoryId = $rootCategoryIds['default'][0];
00099 }
00100 $defaultStoreId = (int)$installer->getConnection()
00101 ->fetchOne($installer->getConnection()
00102 ->select()
00103 ->from($this->getTable('core_store'))
00104 ->where($installer->getConnection()->quoteInto('website_id=?', $websiteRow['website_id']))
00105 ->limit(0, 1), 'store_id');
00106
00107
00108 $installer->getConnection()->insert($this->getTable('core_store_group'), array(
00109 'website_id' => $websiteRow['website_id'],
00110 'name' => $websiteRow['name'] . ' Store',
00111 'root_category_id' => $rootCategoryId,
00112 'default_store_id' => $defaultStoreId
00113 ));
00114 $groupId = $installer->getConnection()->lastInsertId();
00115
00116 $installer->getConnection()
00117 ->update($this->getTable('core_store'),
00118 array('group_id'=>$groupId),
00119 $installer->getConnection()->quoteInto('website_id=?', $websiteRow['website_id'])
00120 );
00121
00122 $installer->getConnection()
00123 ->update($this->getTable('core_website'),
00124 array('default_group_id'=>$groupId),
00125 $installer->getConnection()->quoteInto('website_id=?', $websiteRow['website_id'])
00126 );
00127 }
00128
00129 $installer->endSetup();