Clear drupal commerce database.
<?php
//==============================================
$order_ids = db_select('commerce_order', 'n')
->fields('n', array('order_id'))
->execute()
->fetchCol();
$i = 0;
$delete_ids = array();
$operations = array();
$end_key = end(array_keys($transaction_ids));
foreach ($order_ids as $order_id) {
$i++;
$delete_ids[] = $order_id;
if ($i == 100 || $key == $end_key) {
$operations[] = array('commerce_order_delete_multiple', array($delete_ids));
$i = 0;
$delete_ids = array();
}
}
$batch = array(
'title' => t('Deleting orders'),
'operations' => $operations
);
batch_set($batch);
//=================================
$return_ids = db_select('commerce_return', 'n')
->fields('n', array('return_id'))
->execute()
->fetchCol();
$i = 0;
$delete_ids = array();
$operations = array();
$end_key = end(array_keys($transaction_ids));
foreach ($return_ids as $return_id) {
$i++;
$delete_ids[] = $return_id;
if ($i == 100 || $key == $end_key) {
$operations[] = array('commerce_return_delete_multiple', array($delete_ids));
$i = 0;
$delete_ids = array();
}
}
$batch = array(
'title' => t('Deleting return'),
'operations' => $operations
);
batch_set($batch);
//=================================
$transaction_ids = db_select('commerce_payment_transaction', 'n')
->fields('n', array('transaction_id'))
->execute()
->fetchCol();
$i = 0;
$delete_ids = array();
$operations = array();
$end_key = end(array_keys($transaction_ids));
foreach ($transaction_ids as $transaction_id) {
$i++;
$delete_ids[] = $transaction_id;
if ($i == 100 || $key == $end_key) {
$operations[] = array('commerce_payment_transaction_delete_multiple', array($delete_ids));
$i = 0;
$delete_ids = array();
}
}
$batch = array(
'title' => t('Deleting refund'),
'operations' => $operations
);
batch_set($batch);
//==================================
$profile_ids = db_select('commerce_customer_profile', 'n')
->fields('n', array('profile_id'))
->execute()
->fetchCol();
$i = 0;
$delete_ids = array();
$operations = array();
$end_key = end(array_keys($transaction_ids));
foreach ($profile_ids as $profile_id) {
$i++;
$delete_ids[] = $profile_id;
if ($i == 100 || $key == $end_key) {
$operations[] = array('commerce_customer_profile_delete_multiple', array($delete_ids));
$i = 0;
$delete_ids = array();
}
}
$batch = array(
'title' => t('Deleting refund'),
'operations' => $operations
);
batch_set($batch);
//==================================
$line_item_ids = db_select('commerce_line_item', 'n')
->fields('n', array('line_item_id'))
->execute()
->fetchCol();
$i = 0;
$delete_ids = array();
$operations = array();
$end_key = end(array_keys($transaction_ids));
foreach ($line_item_ids as $line_item_id) {
$i++;
$delete_ids[] = $line_item_id;
if ($i == 100 || $key == $end_key) {
$operations[] = array('commerce_line_item_delete_multiple', array($delete_ids));
$i = 0;
$delete_ids = array();
}
}
$batch = array(
'title' => t('Deleting refund'),
'operations' => $operations
);
batch_set($batch);
//==================================