Netsuite Webservices and Multiple Item Sales Orders

By request, here is a post on creating a sales order record with Netsuite PHPToolkit with more than one item:

$items = array();
foreach ($mycartitems as $item) {
    $itemRef = new nsRecordRef(array('internalId'=>$item->getNetsuiteID()));
    $qty = $item->getQuantity();
    $SalesOrderItem = new nsComplexObject("SalesOrderItem");
    $salesOrderItemFieldArray = array(
         "item" => $itemRef,
         "quantity" => $qty
    );
    $SalesOrderItem->setFields($salesOrderItemFieldArray);
    $items[] = $SalesOrderItem;
}
$salesOrderItemList = new nsComplexObject("SalesOrderItemList");
$salesOrderItemList->setFields(array(
     "item" => $items
));
$salesOrderFields = array(
    "orderStatus" => "_pendingFulfillment",
    "entity" => $custRef,
    "getAuth" => true,
    "shippingCost" => $shipCost,
    "shipMethod" => $shipRef,
    "toBeEmailed" => true,
    "email" => $emailList,
    "itemList" => $salesOrderItemList
);

Its not all that intuitive, but that’s Netsuite Web-services for you…

This entry was posted in Netsuite PHPToolkit, PHP and tagged , , , , . Bookmark the permalink.

3 Responses to Netsuite Webservices and Multiple Item Sales Orders

  1. Denny says:

    Hi Daniel,
    It’s me again, i’ve been using your code above for my SO( Sales Order) implementation.
    It’s working perfectly.

    I have problem now on how to add the custom Shipping and billing address in SO.
    But i don’t want the address to be added to the customer record, i just want it to be a custom data in the particular Sales Order
    Do you have sample script to achieve this ?

    I can only find an example in SuiteScript, but cannot find how to do in SuiteTalk.

    • daniel says:

      I haven’t tried to do that before. I have always added the address to the customer. If you can’t find a way to do what you want, a work around might be adding it to the customer and then removing after the order completes.

  2. Denny says:

    Hi Daniel,
    Based on this article the item is referred by internalID
    $itemRef = new nsRecordRef(array(‘internalId’=>$item->getNetsuiteID()));

    Is there any way to refer the item by itemId ?

    I tried
    $itemRef = new nsRecordRef(array(‘itemId’=>’SKU123456′);
    but it’s not working

    Thanks

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>