Created
May 31, 2022 17:51
-
-
Save guifavere/339ce62b1306b8f8053ae58e83f16ddc to your computer and use it in GitHub Desktop.
Flush magento 1.9 database
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
include_once('app/Mage.php'); | |
// customers | |
function destroyAllCustomers() { | |
function destroyCustomer($customerId) { | |
Mage::getModel("customer/customer")->load($customerId)->delete(); | |
} | |
$customers = Mage::getModel('customer/customer')->getCollection(); | |
foreach ($customers as $customer) { | |
destroyCustomer($customer->getId()); | |
} | |
} | |
// products | |
function destroyAllProducts() { | |
function destroyProduct($productId) { | |
Mage::getModel('catalog/product')->load($productId)->delete(); | |
} | |
$products = Mage::getResourceModel('catalog/product_collection'); | |
foreach ($products as $product) { | |
destroyProduct($product->getId()); | |
} | |
} | |
// product categories | |
function destroyAllProductCategories() { | |
function destroyProductCategory($categoryId) { | |
Mage::getModel('catalog/category')->load($categoryId)->delete(); | |
} | |
$productCategories = Mage::getResourceModel('catalog/category_collection'); | |
foreach ($productCategories as $productCategory) { | |
destroyProductCategory($productCategory->getId()); | |
} | |
} | |
// sale orders | |
function destroyAllSaleOrders() { | |
function destroySaleOrder($saleOrderId) { | |
Mage::getModel('sales/order')->load($saleOrderId)->delete(); | |
} | |
$saleOrders = Mage::getModel('sales/order')->getCollection(); | |
foreach ($saleOrders as $saleOrder) { | |
destroySaleOrder($saleOrder->getId()); | |
} | |
} | |
Mage::app(); | |
Mage::register('isSecureArea', TRUE); | |
destroyAllSaleOrders(); | |
destroyAllCustomers(); | |
destroyAllProducts(); | |
destroyAllProductCategories(); | |
Mage::unregister('isSecureArea'); | |
die('done'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment