FOL9000

Magento: Alle Bestellungen löschen

von | 13 Kommentare

Auf Testsystemen häufen sich schnell Bestellungen an, die irgendwann stören. Besonders das Übertragen der Datenbank auf andere Systeme ist dann zwar noch möglich, aber man hat den Test-Müll dann auch auf dem neuen System. Weil Magento keine Funktion hat, um Bestellungen zu löschen, hilft das folgende Script: Es versetzt die Datenbank wieder in einen vorzeigbaren und brauchbaren Zustand.

Das kurze SQL-Script löscht den beim Testen anfallenden Bestellungs-Müll. Alles, was beim Testen so anfällt, was man aber nicht auf andere Systeme übertragen möchte, wird komplett entfernt. Danach dürfte die Datenbank in einem sauberen Zustand sein, sodass man ein Datenbank-Export problemlos auf einem anderen System einsetzen kann.

Die Datenbankstruktur von Magento ist nicht gerade einfach und zwischen den Versionen auch manchmal leicht unterschiedlich. Ich habs unter 1.7.0.2 ausprobiert und es funktionierte problemlos. Trotzdem: Anwendung auf eigene Gefahr, und vorher ein Backup machen! (Kleines Update: Auch unter 1.9.0.1 funktioniert es.)

Das Script setzt nicht den Counter für die Bestell-Nummern zurück. Hat man zehn Bestellungen gelöscht bekommt trotz des Löschens die nächste Bestellung die Nummer elf. Dies lässt sich mit Anweisungen zum Setzen des Increment-Counters lösen, die ich ebendort beschrieben habe.

Vor dem Ausführen muss natürlich noch im USE-Statement der richtige Datenbank-Name eingesetzt werden.

Und noch etwas: Obwohl der folgende SQL-Code an Einfachheit kaum zu überbieten sein dürfte: Er ist nicht von mir, ich weiß aber auch nicht mehr, woher er ist.

-- Reset Magento Test Data
-- Checked with 1.7.0.2
USE `magento_databse`;
SET FOREIGN_KEY_CHECKS=0;
-- reset dashboard search queries
TRUNCATE `catalogsearch_query`;
ALTER TABLE `catalogsearch_query` AUTO_INCREMENT=1;
-- reset sales order info
TRUNCATE `sales_flat_creditmemo`;
TRUNCATE `sales_flat_creditmemo_comment`;
TRUNCATE `sales_flat_creditmemo_grid`;
TRUNCATE `sales_flat_creditmemo_item`;
TRUNCATE `sales_flat_invoice`;
TRUNCATE `sales_flat_invoice_comment`;
TRUNCATE `sales_flat_invoice_grid`;
TRUNCATE `sales_flat_invoice_item`;
TRUNCATE `sales_flat_order`;
TRUNCATE `sales_flat_order_address`;
TRUNCATE `sales_flat_order_grid`;
TRUNCATE `sales_flat_order_item`;
TRUNCATE `sales_flat_order_payment`;
TRUNCATE `sales_flat_order_status_history`;
TRUNCATE `sales_flat_quote`;
TRUNCATE `sales_flat_quote_address`;
TRUNCATE `sales_flat_quote_address_item`;
TRUNCATE `sales_flat_quote_item`;
TRUNCATE `sales_flat_quote_item_option`;
TRUNCATE `sales_flat_quote_payment`;
TRUNCATE `sales_flat_quote_shipping_rate`;
TRUNCATE `sales_flat_shipment`;
TRUNCATE `sales_flat_shipment_comment`;
TRUNCATE `sales_flat_shipment_grid`;
TRUNCATE `sales_flat_shipment_item`;
TRUNCATE `sales_flat_shipment_track`;
TRUNCATE `sales_invoiced_aggregated`;
TRUNCATE `sales_invoiced_aggregated_order`;
TRUNCATE `sales_order_aggregated_created`;
TRUNCATE `sendfriend_log`;
TRUNCATE `tag`;
TRUNCATE `tag_relation`;
TRUNCATE `tag_summary`;
TRUNCATE `wishlist`;
TRUNCATE `log_quote`;
TRUNCATE `report_event`;
ALTER TABLE `sales_flat_creditmemo` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_creditmemo_comment` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_creditmemo_grid` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_creditmemo_item` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_invoice` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_invoice_comment` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_invoice_grid` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_invoice_item` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_order` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_order_address` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_order_grid` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_order_item` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_order_payment` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_order_status_history` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_address` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_address_item` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_item` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_item_option` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_payment` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_shipping_rate` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_shipment` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_shipment_comment` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_shipment_grid` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_shipment_item` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_shipment_track` AUTO_INCREMENT=1;
ALTER TABLE `sales_invoiced_aggregated` AUTO_INCREMENT=1;
ALTER TABLE `sales_invoiced_aggregated_order` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_aggregated_created` AUTO_INCREMENT=1;
ALTER TABLE `sendfriend_log` AUTO_INCREMENT=1;
ALTER TABLE `tag` AUTO_INCREMENT=1;
ALTER TABLE `tag_relation` AUTO_INCREMENT=1;
ALTER TABLE `tag_summary` AUTO_INCREMENT=1;
ALTER TABLE `wishlist` AUTO_INCREMENT=1;
ALTER TABLE `log_quote` AUTO_INCREMENT=1;
ALTER TABLE `report_event` AUTO_INCREMENT=1;
SET FOREIGN_KEY_CHECKS=1;

13 Kommentare

  1. At this time it seems like Movable Type is the best blogging platform available right now. from what I’ve read Is that what you are using on your blog?

  2. At this time it seems like Movable Type is the best blogging platform available right now. from what I’ve read Is that what you are using on your blog?

  3. At this time it seems like Movable Type is the best blogging platform available right now. from what I’ve read Is that what you are using on your blog?

  4. you may have an important weblog here! would you prefer to make some invite posts on my blog?

  5. you may have an important weblog here! would you prefer to make some invite posts on my blog?

  6. I think you have remarked some very interesting points , appreciate it for the post.

  7. I think you have remarked some very interesting points , appreciate it for the post.

  8. I think you have remarked some very interesting points , appreciate it for the post.

  9. I keep listening to the news update lecture about receiving boundless online grant applications so I have been looking around for the top site to get one. Could you advise me please, where could i acquire some?

  10. I keep listening to the news update lecture about receiving boundless online grant applications so I have been looking around for the top site to get one. Could you advise me please, where could i acquire some?

  11. I got what you intend, thankyou for putting up.Woh I am glad to find this website through google. It is a very hard undertaking to seek to please everybody. by Publilius Syrus.

  12. I got what you intend, thankyou for putting up.Woh I am glad to find this website through google. It is a very hard undertaking to seek to please everybody. by Publilius Syrus.

  13. I got what you intend, thankyou for putting up.Woh I am glad to find this website through google. It is a very hard undertaking to seek to please everybody. by Publilius Syrus.

Schreibe einen Kommentar

Pflichtfelder sind mit * markiert.