Showing posts with label delete order and customer record table. Show all posts
Showing posts with label delete order and customer record table. Show all posts

delete all orders and customers magento

I am magento developer and i know when we worked on test site than there is lot of dummy order and customer created on magento website . We used our local DB to live site db when we will go for live magento website. but before we can't delete dummy order or customer record in data base table. now i wrote a very easy script to delete all orders and customers in magento.

One More Important Thing for we don't need to open phpmyadmin for delete all orders and customers in magento

Note :- Please take a Data Base backup before run this script  .

Step1:-  Create a deleteCustomerAndOrder.php file in root folder

Step2:-  paste below code and save the file.


<?php

require_once ("app/Mage.php");
$app = Mage::app('default');

$config  = Mage::getConfig()->getResourceConnectionConfig("default_setup");

$dbinfo = array("host" => $config->host,
            "user" => $config->username,
            "pass" => $config->password,
            "dbname" => $config->dbname
);

$hostname = $dbinfo["host"];
$user = $dbinfo["user"];
$password = $dbinfo["pass"];
$dbname = $dbinfo["dbname"];
$con = mysql_select_db($dbname,mysql_connect($hostname,$user,$password)) ;
$tablePrefix = (string) Mage::getConfig()->getTablePrefix();


// For Delete orders tables

$orderTableName = array (
    'sales_flat_order',
    'sales_flat_order_address',
    'sales_flat_order_grid',
    'sales_flat_order_item',
    'sales_flat_order_status_history',
    'sales_flat_quote',
    'sales_flat_quote_address',
    'sales_flat_quote_address_item',
    'sales_flat_quote_item',
    'sales_flat_quote_item_option',
    'sales_flat_order_payment',
    'sales_flat_quote_payment',
    'sales_flat_shipment',
    'sales_flat_shipment_item',
    'sales_flat_shipment_grid',
    'sales_flat_invoice',
    'sales_flat_invoice_grid',
    'sales_flat_invoice_item',
    'sendfriend_log',
    'tag',
    'tag_relation',
    'tag_summary',
    'wishlist',
    'log_quote',
    'report_event'
    );
mysql_query('SET FOREIGN_KEY_CHECKS=0');
for($ga=0;$ga<=(count($orderTableName)-1);$ga++){

  mysql_query('TRUNCATE  `'.$tablePrefix.$orderTableName[$ga].'`');
  mysql_query('ALTER TABLE  `'.$tablePrefix.$orderTableName[$ga].'` AUTO_INCREMENT=1');


}
// For Delete customer tables

$customerTableName = array (
    'customer_address_entity',
    'customer_address_entity_datetime',
    'customer_address_entity_decimal',
    'customer_address_entity_int',
    'customer_address_entity_text',
    'customer_address_entity_text',
    'customer_address_entity_varchar',
    'customer_entity',
    'customer_entity_datetime',
    'customer_entity_decimal',
    'customer_entity_int',
    'customer_entity_text',
    'customer_entity_varchar',
    'log_customer',
    'log_visitor',
    'log_visitor_info',
    'log_visitor_info',
'eav_entity_store');


for($gau=0;$gau<=(count($customerTableName)-1);$gau++){

  mysql_query('TRUNCATE  `'.$tablePrefix.$customerTableName[$gau].'`');
  mysql_query('ALTER TABLE  `'.$tablePrefix.$customerTableName[$gau].'` AUTO_INCREMENT=1 ');

}

mysql_query('SET FOREIGN_KEY_CHECKS=1');

?>


Step3:- run this script on your browser.
http://yoursiteurl.com/deleteCustomerAndOrder.php

Guys I am always try to learn new things and  post on my blog for our magento developers . Please give me your valuable feedback for encourage me to write more programming solutions.
Thanks
GA





get table prefix in magento

when we will work on Data Base table with custom Query . than it is very important to know what is the table prefix of the magento data base table. This magento blog or magento tutorial will tell you how to get the table Prefix in magento.

In 2 ways you will get data base table prefix.

1) echo $tablePrefix = (string) Mage::getConfig()->getTablePrefix();

2) Go to app/etc/local.xml open local.xml file. and see

                <db>
                <table_prefix><![CDATA['SEE YOUR TABLE PREFIX HERE ']]></table_prefix>
               </db>