On a large Magento project I am working on (inherited from a previous agency) the installation has 41 stores across 18 websites.

The site has 40k products and 5k categories - so as you can imagine the db is bloated beyond belief.

I would like to remove all but 2 websites and 2 store views (one per website), but using the GUI fails - on deleting store views the page goes blank. Although the db does remove the store from the core_store table, it feels flaky. I also cannot remove the default store view for its website - even when the website(s) in question are not the default for the installation.

Trying to delete a website gives a 'can not delete the website at this time, please try later'.

Is there a clean, safe way to remove all the superfluous store, their parent websites and all the data associated with them from the db directly?

Thank you.

有帮助吗?

解决方案 4

Thank you for the feedback.

I've played with various methods on our sandbox environment and deleting records from the core_store table does indeed cascade through, so this works well.

1 note for anyone else doing this; after you've removed all your stores, you wont be able to remove the superfluous core_websites records until you perform a complete reindex (FK constraint on pricing tables).

After trimming all but 2 stores and 2 websites the overall database has shed 30% of its size, with the biggest win in the core_url_rewrite table - down from 1.25 million records to a relatively lightweight 325k! Category page load times are now on average 2 seconds faster. Shed those superfluous Magento stores Mage People :)

Thanks again for your help.

其他提示

I'm facing this same task myself, on a legacy system that I inherited. My process for removing the actual store is very simple: just go into the database and delete the row from core_website. This will trigger a cascading delete which wipes out the corresponding records in core_store and the store_group, triggering another cascading deletion of any store/website scoped EAV values, and a variety of other things. You can find the full list by running this query (substitute your db name in place of your_magento_database):

SELECT table_name 
FROM   referential_constraints 
WHERE  constraint_schema = 'your_magento_database' 
       AND referenced_table_name IN( 'core_store', 'core_website' ) 
       AND delete_rule = 'CASCADE' 

Steve Robbins mentioned that even after deleting these things, you end up with lots of "orphaned" records which aren't removed by this cascading deletion. Below is a list of the things which I have been going through (mostly manually) to clean up, following the removal of a website/store.

  • customer groups (each customer group gets its own price index; causes HUGE database bloat)
  • products

    DELETE FROM catalog_product_entity WHERE entity_id NOT IN (SELECT product_id FROM catalog_product_website);

  • categories
  • catalog rules

    DELETE FROM catalogrule WHERE rule_id NOT IN (SELECT DISTINCT rule_id FROM catalogrule_website);

  • shopping cart price rules

    DELETE FROM salesrule WHERE (rule_id NOT IN (SELECT DISTINCT rule_id FROM salesrule_website));

  • config data (looks like Magento 1.9 deleted these automagically, but here's a query to confirm)

    SELECT * FROM core_config_data WHERE (scope="stores" AND scope_id NOT IN (SELECT store_id FROM core_store)) OR (scope="websites" AND scope_id NOT IN (SELECT website_id FROM core_website));

  • CMS pages

    DELETE FROM cms_page WHERE page_id NOT IN (SELECT DISTINCT page_id FROM cms_page_store);

  • Static blocks

    DELETE FROM cms_block WHERE block_id NOT IN (SELECT DISTINCT block_id FROM cms_block_store);

  • widget instances
  • flat category/product tables
  • email templates
  • tax rules, tax class, tax rate
  • admin users, admin roles
  • API users
  • Orders: I prefer to leave these, as the performance benefit is minimal, and you may want that data later on, but only you know what is best for your project.

    DELETE FROM sales_flat_order WHERE store_id IS NULL

I hope this will serve as useful information for anyone else doing a multi-store cleanup. I plan on updating this answer as I find more efficient ways of doing this cleanup.

Do it manually via the database. If you do this from the core_store table (i.e. Delete a store), I think it will ensure that any records in other tables related to the store are also deleted. This will be intensive on your DB and take a lot of time as most things in magento reference a store id and going by your numbers your gonna have a lot of data it needs to work out the relations too. Ensure you back up the db first before doing any of this, disable any indexes and stop any data being written too it whilst you perform these operations. I would advise doing one store at a time and checking the results and that you can still run indexes etc.

Other option is of course to start a new DB instance (i.e copy structure only to a new db) and transfer only the old data you want into the new one. Good luck. :-)

The "safest" way is to delete the store via System > Manage Stores. You're saying your getting a white page after a while. You might have ran out of memory or page execution time. Try checking your error logs and see if you can get past this.

Alternatively you can drop/delete tables/records in your database. After making a full backup, take a look in core_store with

show create table core_store

In the last few lines you should see something like

CONSTRAINT `FK_CORE_STORE_GROUP_ID_CORE_STORE_GROUP_GROUP_ID` FOREIGN KEY (`group_id`) REFERENCES `core_store_group` (`group_id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `FK_CORE_STORE_WEBSITE_ID_CORE_WEBSITE_WEBSITE_ID` FOREIGN KEY (`website_id`) REFERENCES `core_website` (`website_id`) ON DELETE CASCADE ON UPDATE CASCADE

The ON DELETE CASCADE means that it will go to those tables reference and delete the related records as well.

If you manually delete a row for core_store it's going to take other data with it. However, it's still missing a lot. You're likely to end up with orphaned data in CMS pages, blocks, products, categories, root catalogs, customers, orders, etc.

Remember to also get rid of the relevant category_flat and product_flat tables.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top