Php 在magento中删除客户、地址和相关订单的代码

Php 在magento中删除客户、地址和相关订单的代码,php,magento,Php,Magento,在magento中,我们是否可以选择使用php代码删除客户及其地址和订单?如果是,我想知道php代码。我知道,从管理员,我们可以选择删除客户。但是我们需要php代码或查询来手动完成这个过程。提前谢谢 使用以下代码在magento根文件夹上创建标准脚本: <?php include_once('app/Mage.php'); Mage::app(); $customerId = 10; // Here you can specify customer ID Mage::register

在magento中,我们是否可以选择使用php代码删除客户及其地址和订单?如果是,我想知道php代码。我知道,从管理员,我们可以选择删除客户。但是我们需要php代码或查询来手动完成这个过程。提前谢谢

使用以下代码在magento根文件夹上创建标准脚本:

<?php
include_once('app/Mage.php');
Mage::app();

$customerId = 10;  // Here you can specify customer ID

Mage::register('isSecureArea', TRUE);

$orders = Mage::getModel('sales/order')->getCollection()->addFieldToFilter('customer_id', $customerId);

$orderIds = array();        
foreach($orders as $order) {
    $orderIds[] = $order->getId();      
}

foreach($orderIds as $id){
    try{
        Mage::getModel('sales/order')->load($id)->delete();
        echo "order #".$id." is Deleted <br>";
    }catch(Exception $e){
        echo "order #".$id." could not be Deleted: ".$e->getMessage() ."<br>";
    }
}

try{
    Mage::getModel("customer/customer")->load($customerId)->delete();
    echo "Customer #".$customerId." Deleted Successfully <br>";
}catch(Exception $e){
    echo "Customer #".$customerId." could not be Deleted: ".$e->getMessage() ."<br>";
}



Mage::unregister('isSecureArea');

die('Deletion DONE');