tags:

views:

138

answers:

1

I know there is a way to programmatically invoice, ship, and set state on an order (http://www.magentocommerce.com/boards/viewthread/74072/), but I actually need to drill down even deeper to the item level of an order. We have a situation where, depending on item type, two different items can be processed in two different locations (from the same order). I can go into the Magento back-end and "ship" one item without "shipping" the other and append comments to that one item, but I'm looking for a way to do this programmatically. Thank you in advance for your help!

Update: Here is the code I ended up using to accomplish this:

$client = new SoapClient('http://somesite.domain/magento/index.php/api/?wsdl');
$session = $client->login('username', 'password');

function extract_item_id($items, $sku ){
    foreach($items as $item ){
        if ($item["sku"]==$sku) {
            return $item["item_id"];
        }
    }
}

$orderNum = "200000052";

$oderInfo = $client->call($session, "sales_order.info", $orderNum );

$item_id = extract_item_id($oderInfo["items"], "someSKU") ;
$itemsQty = array( $item_id => "1" ); 
$shipment = array(
    $orderNum,
    $itemsQty,
    "Comment associated with item shipped.",
    true,
    true
);

var_dump($shipment);

$nship = $client->call($session, 'sales_order_shipment.create', $shipment);
+1  A: 

I've never done it, but it looks like the SOAP API supports creating individual shipment items. That'd be the first thing I'd check.

If that doesn't work, I'd examine the source code the the Magento admin and reverse engineer what its doing with to create a single item shipment. Specifically, start tracing at the saveAction of the admin's Shipment Controller

app/code/core/Mage/Adminhtml/controllers/Sales/Order/ShipmentController.php

The order/shipment/invoice section of Magento codebase is one of the most volatile/iterative sections, with the core objects/methods/dependencies changing subtly between versions. Finding one "right" answer for this will prove difficult, if not impossible.

Alan Storm
Thank you very much for the response. It looks like the SOAP API is definitely the right direction. The strange thing is that I used the sales_order_shipment.create method, and it only invoiced the item instead of shipping it. I wonder if I'm just missing something. Anyway, thank you for getting me on the right track.
chrisSC
What version of Magento are you using? There was a recent Community Edition release that had an API bug that sounds like the behavior you're describing.http://magebase.com/magento-tutorials/shipment-api-in-magento-1-4-1-broken/
Alan Storm
I'm using Magento Professional. (Ver. 1.8.0.0)
chrisSC
Yep, just fixed the bug and it's working perfectly now! Thanks again!
chrisSC