简体   繁体   中英

How to delete a shipment from Magento that was created accidentally?

How can I remove a shipment that was created accidentally? I know there is no way to do it through the admin, but I'm trying to figure out what I need to do to revert an order back to a status of "Processing" along with all the old shipment information so it can be shipped at a later time. I'm hoping this can be done programmatically via PHP or even just directly in MySQL.

FYI, I'm using Magento version 1.1.8.

Try

require_once  'app/Mage.php';

Varien_Profiler::enable();
Mage::setIsDeveloperMode(true);
ini_set('display_errors', 1);
umask(0);
Mage::app('default');
Mage::register('isSecureArea', 1);


//Update Order id
$orderId = xyz;


$order = Mage::getModel('sales/order')->load($orderId);

// check if has shipments
if(!$order->hasShipments()){
    die('No Shipments');
}

//delete shipment
$shipments = $order->getShipmentsCollection();
foreach ($shipments as $shipment){
    $shipment->delete();
}

// Reset item shipment qty
// see Mage_Sales_Model_Order_Item::getSimpleQtyToShip()
$items = $order->getAllVisibleItems();
foreach($items as $i){
   $i->setQtyShipped(0);
   $i->save();
}

//Reset order state
$order->setState(Mage_Sales_Model_Order::STATE_PROCESSING, true, 'Undo Shipment');
$order->save();

echo 'Done';
$shipment = Mage::getModel('sales/order_shipment')->load($shippingOrderId);
$shipment->delete();

I assume this works. I haven't tried it.

I ended up purchasing the extension below which did the trick beautifully. Even though it doesn't say it supports versions prior to 1.3, it worked flawlessly on my setup of v1.1.8.

http://www.magentocommerce.com/magento-connect/delete-shipment-6498.html

Say you shipped an order in its entirety and didn't mean to. Just delete the INVOICE. It will remove the invoice and any of the shipments...SHIPMENTS plural!

So you have to be careful, if you have other shipments you will need to recreate them. Then invoice it again. Then it will be just like you never shipped anything and you can then SHIP whatever quantity you originally required.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM