Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Admin Orders - Batch Action ( similar to print invoice/packingslip) to update order status
 
tegansnyder
Member
 
Avatar
Total Posts:  48
Joined:  2008-10-23
Saint Paul, MN
 

Ok I made some killer progress. I have the code that can set an order to be shipped. Now I just need to incorporate it into the code above so when you mark an order as complete it will both mark it as complete and shipped. Then I’m going to tie all this code into an Order Import script that takes a CSV and does this automatically.

This code will run outside of magento. I just made a test file called setShipped.php and uploaded it to my magento root folder.

<?php
require_once("app/Mage.php"); //REMOVE this to run inside of magento
Mage::app(); //REMOVE this to run inside of magento

$comment null;
$email false;
$includeComment false;
$orderIncrementId '100000002'//order ID that you want to be marked shipped!

$order Mage::getModel('sales/order')->loadByIncrementId($orderIncrementId);

$convertor Mage::getModel('sales/convert_order');
$shipment $convertor->toShipment($order);

foreach (
$order->getAllItems() as $orderItem{
    
    
if (!$orderItem->getQtyToShip()) {
        
continue;
    
}
    
if ($orderItem->getIsVirtual()) {
        
continue;
    
}
    
    $item 
$convertor->itemToShipmentItem($orderItem);

    
$qty $orderItem->getQtyToShip();

    
$item->setQty($qty);
    
$shipment->addItem($item);
}

$shipment
->register();
$shipment->addComment($comment$email && $includeComment);

if (
$email{
    $shipment
->setEmailSent(true);
}

$shipment
->getOrder()->setIsInProcess(true);


$transactionSave Mage::getModel('core/resource_transaction')
    ->
addObject($shipment)
    ->
addObject($shipment->getOrder())
    ->
save();

$shipment->sendEmail($email, ($includeComment $comment ''));

echo 
'success';

?>
 
Magento Community Magento Community
Magento Community
Magento Community
 
tegansnyder
Member
 
Avatar
Total Posts:  48
Joined:  2008-10-23
Saint Paul, MN
 

I having trouble updating the tracking numbers pragmatically based on the order Id. Does anybody have any ideas?

I see the function addTrack:

public function addTrack($shipmentIncrementId$carrier$title$trackNumber)
    
{
        $shipment 
Mage::getModel('sales/order_shipment')->loadByIncrementId($shipmentIncrementId);

        
/* @var $shipment Mage_Sales_Model_Order_Shipment */

        
if (!$shipment->getId()) {
            $this
->_fault('not_exists');
        
}

        $carriers 
$this->_getCarriers($shipment);

        if (!isset(
$carriers[$carrier])) {
            $this
->_fault('data_invalid'Mage::helper('sales')->__('Invalid carrier specified.'));
        
}

        $track 
Mage::getModel('sales/order_shipment_track')
                    ->
setNumber($trackNumber)
                    ->
setCarrierCode($carrier)
                    ->
setTitle($title);

        
$shipment->addTrack($track);

        try 
{
            $shipment
->save();
        
catch (Mage_Core_Exception $e{
            $this
->_fault('data_invalid'$e->getMessage());
        
}

        
return $track->getId();
    
}
 
Magento Community Magento Community
Magento Community
Magento Community
 
tegansnyder
Member
 
Avatar
Total Posts:  48
Joined:  2008-10-23
Saint Paul, MN
 

Here is how to mark an order as complete programatically and add a tracking code…

This code will run outside of Magento. Just call it test.php and place it in your magento root folder:

<?php
require_once("app/Mage.php");
Mage::app();

$comment null;
$email false;
$includeComment false;

$orderId '100000004';
$order Mage::getModel('sales/order')->loadByIncrementId($orderId);

$convertor Mage::getModel('sales/convert_order');
$shipment $convertor->toShipment($order);

foreach (
$order->getAllItems() as $orderItem{
    
    
if (!$orderItem->getQtyToShip()) {
        
continue;
    
}
    
if ($orderItem->getIsVirtual()) {
        
continue;
    
}
    
    $item 
$convertor->itemToShipmentItem($orderItem);

    
$qty $orderItem->getQtyToShip();

    
$item->setQty($qty);
    
$shipment->addItem($item);
}

$data 
= array();
$data['carrier_code''ups';
$data['title''United Parcel Service';
$data['number''test';

$track Mage::getModel('sales/order_shipment_track')->addData($data);
$shipment->addTrack($track);

Mage::register('current_shipment'$shipment);

$shipment->register();
$shipment->addComment($comment$email && $includeComment);
$shipment->setEmailSent(true);
$shipment->getOrder()->setIsInProcess(true);


$transactionSave Mage::getModel('core/resource_transaction')
    ->
addObject($shipment)
    ->
addObject($shipment->getOrder())
    ->
save();

$shipment->sendEmail($email, ($includeComment $comment ''));

?>

Step 1 complete.

My goal is to produce an order import script that can be run outside of magento and take records from a spreadsheet update their status and tracking code.

I’m surprised no body has even commented on my code yet. This could be a big thing. I haven’t been able to find an order import system.

 
Magento Community Magento Community
Magento Community
Magento Community
 
tegansnyder
Member
 
Avatar
Total Posts:  48
Joined:  2008-10-23
Saint Paul, MN
 

Update:

If anybody is interested in an order import script let me know. I have successfully developed a script which takes a CSV file full of order data and updates their tracking numbers and marks them as shipped.

My next step is to make it trigger the function to automatically produce packing slips and invoice statements.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Discovery
Enthusiast
 
Total Posts:  767
Joined:  2007-12-29
 

Glad to see some enthusiasm on the order processing optimisations, however, did you consider using the API:

http://www.magentocommerce.com/wiki/doc/webservices-api/api/sales_order_shipment#sales_order_shipment.addtrack

The API would be slower, only a problem with lots of orders grin

As for printing invoices and packing slips, you might want to borrow a tip or two from:

http://www.magentocommerce.com/wiki/automatically_printing_pdfs_for_invoice_and_delivery_notes?do=show

Here the server makes the invoices and parks them in a directory. Then an office PC checks that directory and prints anything new out. This sounds like it would be a bit flaky, but, with real orders the ‘delay’ waiting for the printer is not that long. You can also setup multiple copies so that the accounts always get a printed invoice coming out of their printer, the warehouse get the packing slip and so on…

 
Magento Community Magento Community
Magento Community
Magento Community
 
tegansnyder
Member
 
Avatar
Total Posts:  48
Joined:  2008-10-23
Saint Paul, MN
 

Discovery,

Yes I did consider using the web services API, but I haven’t been able to get soap to work correctly. It may be something with my server’s configuration.

Thanks for posting a link to that wiki. That is pretty slick.

Here is our current system:

I added some code to the Simple Order Export Extension. We now have an new drop down option to only export shipping information for UPS Worldship. The CSV is saved on a network drive and imported into Worldship.

Once orders are shipped the same CSV is imported back into magento with tracking numbers. Magento then sends out the confirmation of shipping emails.

Currently the customer runs the import/export process once in the morning and once before end of day. Ideally we would like to automate this with cron jobs in the future.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Discovery
Enthusiast
 
Total Posts:  767
Joined:  2007-12-29
 

@tegansnyder - last time I looked at this thread I was not interested in the UPS bit - how times change - we might be going to UPS.

Can I nobble that code off you, preferably ASAP? PM it to me if it has custom stuff in it and you don’t want to spend too long tidying up the code.

I like your workflow idea, not being familiar with UPS and seeing their tech guys tomorrow, I hope to get everything working sweetly (and with your script)…

 
Magento Community Magento Community
Magento Community
Magento Community
 
All About Doors and Windows
Member
 
Avatar
Total Posts:  51
Joined:  2008-10-13
Kansas City, MO USA
 

Great share tegansnyder. This is exactly what I am looking for. I already had an import script going and this will help me out a lot. Because of certain things, I am forced not to use the API right now. And the fact that this works outside of that really helps.

 
Magento Community Magento Community
Magento Community
Magento Community
 
royhayward
Jr. Member
 
Avatar
Total Posts:  12
Joined:  2010-03-14
Utah
 

Hey guys, I am trying tegansnyder\\\’s solution and getting this error:

Fatal error: Call to a member function getMethodInstance() on a non-object in /home/mycompany/domains/mycompany.com/public_html/magento/app/code/core/Mage/Payment/Model/Observer.php on line 46

Trying to dig through this but if anyone has hit this before I would appreciate any pointers. 

BTW, using Magento ver. 1.3.2.2.

Thanks

Roy

 
Magento Community Magento Community
Magento Community
Magento Community
 
royhayward
Jr. Member
 
Avatar
Total Posts:  12
Joined:  2010-03-14
Utah
 

ok, update on the error:

Fatal error: Call to a member function getMethodInstance() on a non-object in /home/mycompany/domains/mycompany.com/public_html/magento/app/code/core/Mage/Payment/Model/Observer.php on line 46

This is the line where the error happens:

$transactionSave Mage::getModel(\'core/resource_transaction\')
                        ->
addObject($shipment)
                        ->
addObject($shipment->getOrder())
                        ->
save();

Looking into what this is doing that observer.php doesn\’t like.

 
Magento Community Magento Community
Magento Community
Magento Community
 
royhayward
Jr. Member
 
Avatar
Total Posts:  12
Joined:  2010-03-14
Utah
 

For any poor souls that run into this as well.

I was passing in a order ID that didn’t match.

I have added this

if($order['increment_id'== "")
        
{
                
return "PO $orderId not found, please verify this PO Number is correct.";
        
}

right after this:

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

to prevent getting the error, and to return something meaningful to the caller of this page.

 
Magento Community Magento Community
Magento Community
Magento Community
 
plu_australia
Sr. Member
 
Total Posts:  132
Joined:  2010-04-20
 

Would anyone be so kind enough to upload the files from this thread which enable mass action against selected orders where status=processing . This would happen on the orders grid by first selecting orders set to ‘processing’ then the mass action ‘ship selected’ > on submit all orders are set to completed.

If this could go one step futher and print off the packaging slips that would be awesome.

 
Magento Community Magento Community
Magento Community
Magento Community
 
tegansnyder
Member
 
Avatar
Total Posts:  48
Joined:  2008-10-23
Saint Paul, MN
 

Here is an full blown import script from CSV example:
http://blog.tegdesign.com/2010/09/05/importing-orders-into-magento-from-a-csv-using-php/

 
Magento Community Magento Community
Magento Community
Magento Community
 
gkadmin
Member
 
Total Posts:  51
Joined:  2009-07-07
 

I tried Tegan’s script. It is working well.

Here is what I think this could do in combination with two other hacks I looked into. My intended workflow would be as follows:

1. http://www.webguys.de/magento/events-in-magento-export-bei-neuer-bestellung/
It’s in german. The small module generates an event whenever a order is checked out. This should trigger the following

2. order export to xml/csv
I downloaded and tried msn’s module @post #71 in this thread
http://www.magentocommerce.com/boards/viewthread/28679/P60/#
I also patched in the CSV-support you can find here:
http://www.magentocommerce.com/boards/viewthread/28679/P105/ @ #116

3. Automatically download the generated CSV to local machine (i.e. with something like http://www.sitedesigner.com/batchsync_secure.htm )

4. Import and process the CSV with MS Access.

5.
Export a new CSV that triggers your Order Import Script.

In theory this is very doable.
So far I see necessary modification at these steps:

@ 1.  Write an event that triggers the export module.
@ 2.  Automatically generate a CSV (so far only XML’s are put into folder - CSV’s have to be manually generated and downloaded)
@ 5.  Find a way to trigger the import whenever the import-csv is updated.

I think this would be a really good generic bridge to a wide range of order management applications.

Let me know what you think.
-g

 
Magento Community Magento Community
Magento Community
Magento Community
 
subhas
Jr. Member
 
Total Posts:  20
Joined:  2008-12-02
london
 

hi All.

My client is in need of a batch process all execute all orders. we can take upto 100 orders per day and manually going through each one is not an option.

we are currently using pre-authorisation(deferred payment) and i understand when you invoice a order, this then collects the full payment and does full authorisation. is this batch process do able within maganeto in a single hit, ie say select 500 orders that have been preauthorised and invoice, print packing slips etc and collect payment in one hit ?
if anyone can suggest ways of doing this, or has done this, i would like to share your knowledge.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top