Como apagar todos pedidos, clientes e produtos do Magento 1
Estava procurando um artigo que pudesse me ajudar a zerar, deletar ou apagar todos os pedidos, clientes e produtos do Magento 1 e não consegui encontrar um completo, por isso resolvi compartilhar aqui. Eu precisei fazer uma migração de banco de dados de magento para magento.
A versão do Magento que estou utilizando é a 1.9.3.3, pelas pesquisas que fiz os comandos abaixo funcionam também desde a versão 1.7.0.2.
A forma mais simples, rápida e confiável é realizar esses procedimentos diretamente em seu banco de dados (Magento utiliza MySQL), por isso pode ser realizado pelo phpMyAdmin, Navicat, Sequel Pro, MySQL Workbench ou qualquer outro.
Obs: Recomento que antes de executar qualquer comando faça BACKUP;
Bom depois de todas as explicações, vamos agora para a prática.
1. Remover todos os produtos;
SET FOREIGN_KEY_CHECKS = 0; TRUNCATE TABLE `catalog_product_bundle_option`; TRUNCATE TABLE `catalog_product_bundle_option_value`; TRUNCATE TABLE `catalog_product_bundle_selection`; TRUNCATE TABLE `catalog_product_entity_datetime`; TRUNCATE TABLE `catalog_product_entity_decimal`; TRUNCATE TABLE `catalog_product_entity_gallery`; TRUNCATE TABLE `catalog_product_entity_int`; TRUNCATE TABLE `catalog_product_entity_media_gallery`; TRUNCATE TABLE `catalog_product_entity_media_gallery_value`; TRUNCATE TABLE `catalog_product_entity_text`; TRUNCATE TABLE `catalog_product_entity_tier_price`; TRUNCATE TABLE `catalog_product_entity_varchar`; TRUNCATE TABLE `catalog_product_link`; TRUNCATE TABLE `catalog_product_link_attribute`; TRUNCATE TABLE `catalog_product_link_attribute_decimal`; TRUNCATE TABLE `catalog_product_link_attribute_int`; TRUNCATE TABLE `catalog_product_link_attribute_varchar`; TRUNCATE TABLE `catalog_product_link_type`; TRUNCATE TABLE `catalog_product_option`; TRUNCATE TABLE `catalog_product_option_price`; TRUNCATE TABLE `catalog_product_option_title`; TRUNCATE TABLE `catalog_product_option_type_price`; TRUNCATE TABLE `catalog_product_option_type_title`; TRUNCATE TABLE `catalog_product_option_type_value`; TRUNCATE TABLE `catalog_product_super_attribute_label`; TRUNCATE TABLE `catalog_product_super_attribute_pricing`; TRUNCATE TABLE `catalog_product_super_attribute`; TRUNCATE TABLE `catalog_product_super_link`; TRUNCATE TABLE `catalog_product_enabled_index`; TRUNCATE TABLE `catalog_product_website`; TRUNCATE TABLE `catalog_category_product_index`; TRUNCATE TABLE `catalog_category_product`; TRUNCATE TABLE `cataloginventory_stock_item`; TRUNCATE TABLE `cataloginventory_stock_status`; TRUNCATE TABLE `cataloginventory_stock`; TRUNCATE TABLE `catalog_product_entity`; TRUNCATE TABLE `catalog_product_flat_1`; INSERT INTO `catalog_product_link_type`(`link_type_id`,`code`) VALUES (1,'relation'),(2,'bundle'),(3,'super'),(4,'up_sell'),(5,'cross_sell'); INSERT INTO `catalog_product_link_attribute`(`product_link_attribute_id`,`link_type_id`,`product_link_attribute_code`,`data_type`) VALUES (1,2,'qty','decimal'),(2,1,'position','int'),(3,4,'position','int'),(4,5,'position','int'),(6,1,'qty','decimal'),(7,3,'position','int'),(8,3,'qty','decimal'); INSERT INTO `cataloginventory_stock`(`stock_id`,`stock_name`) VALUES (1,'Default'); SET FOREIGN_KEY_CHECKS = 1;
Depois que executar o script acima e ter apagado todos os produtos do seu banco de dados com sucesso, agora você precisa apagar todas as pastas do diretório “media/catalog/product” que é onde são salvas todas as imagens dos produtos.
2. Remover todas as categorias;
SET FOREIGN_KEY_CHECKS = 0; TRUNCATE TABLE `catalog_category_flat_store_1`; TRUNCATE TABLE `catalog_category_entity`; TRUNCATE TABLE `catalog_category_entity_datetime`; TRUNCATE TABLE `catalog_category_entity_decimal`; TRUNCATE TABLE `catalog_category_entity_int`; TRUNCATE TABLE `catalog_category_entity_text`; TRUNCATE TABLE `catalog_category_entity_varchar`; TRUNCATE TABLE `catalog_category_product`; TRUNCATE TABLE `catalog_category_product_index`; SET FOREIGN_KEY_CHECKS = 1; INSERT INTO `catalog_category_entity`(`entity_id`,`entity_type_id`,`attribute_set_id`,`parent_id`,`created_at`,`updated_at`,`path`,`POSITION`,`level`,`children_count`) VALUES (1,3,0,0,'2019-09-27 00:00:00','2009-02-20 00:25:34','1',1,0,1),(2,3,3,0,'2009-02-20 00:25:34','2009-02-20 00:25:34','1/2',1,1,0); INSERT INTO `catalog_category_entity_int`(`value_id`,`entity_type_id`,`attribute_id`,`store_id`,`entity_id`,`value`) VALUES (1,3,32,0,2,1),(2,3,32,1,2,1); INSERT INTO `catalog_category_entity_varchar`(`value_id`,`entity_type_id`,`attribute_id`,`store_id`,`entity_id`,`value`) VALUES (1,3,31,0,1,'Root Catalog'),(2,3,33,0,1,'root-catalog'),(3,3,31,0,2,'Default Category'),(4,3,39,0,2,'PRODUCTS'),(5,3,33,0,2,'default-category');
3. Remover todos os clientes;
SET FOREIGN_KEY_CHECKS=0; -- reset customers TRUNCATE customer_address_entity; TRUNCATE customer_address_entity_datetime; TRUNCATE customer_address_entity_decimal; TRUNCATE customer_address_entity_int; TRUNCATE customer_address_entity_text; TRUNCATE customer_address_entity_varchar; TRUNCATE customer_entity; TRUNCATE customer_entity_datetime; TRUNCATE customer_entity_decimal; TRUNCATE customer_entity_int; TRUNCATE customer_entity_text; TRUNCATE customer_entity_varchar; TRUNCATE log_customer; TRUNCATE log_visitor; TRUNCATE log_visitor_info; SET FOREIGN_KEY_CHECKS=1;
4. Remover todos os pedidos;
SET FOREIGN_KEY_CHECKS=0; 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_payment_transaction`; TRUNCATE `sales_order_aggregated_created`; TRUNCATE `sales_order_tax`; TRUNCATE `sales_order_tax_item`; TRUNCATE `sendfriend_log`; TRUNCATE `tag`; TRUNCATE `tag_relation`; TRUNCATE `tag_summary`; TRUNCATE `wishlist`; TRUNCATE `log_quote`; TRUNCATE `report_event`; TRUNCATE `eav_entity_store`; SET FOREIGN_KEY_CHECKS=1;
Depois de executar todos esses scripts, seu Magento estará zerado (produtos, categorias, clientes e pedidos).
PS: Se estiver realizando esse procedimento no windows, favor verificar as aspas.
Dúvidas? Me deixem saber!
É isso aí! Espero que esses comandos possam de ajudar a como apagar todos pedidos, clientes e produtos do Magento 1.9. Como sempre, se você achou esta postagem útil, inscreva-se em nossa newsletter gratuita ou siga-nos no Instagram @douglasvillar, conecte comigo no Linkedin e curta nossa página no Facebook.