Close

February 21, 2019

Magento 1 – Unship an Order

We started seeing weird issues recently where a label provider (ShipStation) was running into issues with the WAF firewall Incapsula.

The label would print in ShipStation, but ShipStation’s subsequent call back to Magento would set the order as “Complete” and all items shipped, despite the actual shipment details being present.


The issue actually was sporadic too, so it was not affecting shipping, but we still needed a way to manually “unship” the order so that staff could add in shipping manually.

We came up with the following quick script that “unships” the order and allows you hit the “Ship” button again to start from scratch. Note, the order id is hard-coded on purpose, so you have to physically want to change the order (safeguard).

We hope you find this useful.

ignore_user_abort(true);
set_time_limit(0);
error_reporting(E_ALL);
ini_set('display_errors', '1');
 
require_once('/var/www/vhosts/thecpapshop.com/public_html/app/Mage.php');
Mage::app();
 
 
 
 
 
 
$id=643348;
$objOrder	= Mage::getModel('sales/order')->load(643348);
 
// check if has shipments
#if(!$objOrder->hasShipments()){
#    die('No Shipments');
#}

 $items = $objOrder->getAllItems();
    $orderquanty=0;
    $skip_found=false;
    foreach($items as $orderItem):
 
		if($orderItem->getLockedDoShip()){
			print "\n ITEM IS LOCKED...unlocking";
			$orderItem->setLockedDoShip(false);
		}else{
			print "\n NOT LOCKED";
		}
	if($orderItem->getQtyShipped()>=1){
		print "\n SHipped..going to unship it: ".$orderItem->getQtyShipped();
		$orderItem->setQtyShipped(0.00);
		$orderItem->save();
	}else{
		print "\n Qty Shippied not greater than one: ".$orderItem->getQtyShipped();
	}
 
 if ($orderItem->getQtyToShip()>0){
 	print "\n ** Good Ship";
 }else{
 	print "\n BAD No QTY ship";
 } 
 
		print "\n\n";
    endforeach;
    $objOrder->save();