How to create a new AssemblyItem in Netsuite PHP toolkit? - php

I am trying to send the order info from Woocommerce into Netsuite as a sale order, when creating a new order. In order to create a new sale order by PHP toolkit, it is necessary for me to create Assembly Items first.
Is there a way to create a new Item using PHP-toolkit?
Here is a PHP code snippet for creating a new Item myself.
$service = new NetSuiteService();
$ai = new AssemblyItem();
// Rustica Group Item Form - 20
$ai->customForm = new RecordRef();
$ai->customForm->internalId = 20;
$ai->memberList = new ItemMemberList();
$item_member = array();
$itemMember = new ItemMember();
$itemMember->internalId = 186625;
$item_member[] = $itemMember;
$ai->memberList->itemMember = $item_member;
$ai->itemId = 'Hardware' . $data['itemId'];
$ai->displayName = $data['displayName'];
$ai->vendorName = '';
$ai->cost = $data['price'];
$ai->isTaxable = $data['taxable'];
$ai->description = $data['description'];
$request = new AddRequest();
$request->record = $ai;
$addResponse = $service->add($request);
print_r($addResponse);
if (!$addResponse->writeResponse->status->isSuccess) {
return "ADD ERROR";
} else {
return $addResponse->writeResponse->baseRef->internalId;
}

There is no internalid field for ItemMember. Look at the schema
Should look like this...
$itemMember = new ItemMember();
$itemMember->item = new RecordRef();
$itemMember->item->internalId = 186625;
You're missing taxSchedule too..not sure if you are confusing that with isTaxable
$ai->taxSchedule = new RecordRef();
$ai->taxSchedule->internalId = 1; //whatever tax schedule you're using

You should pre-store the item of the product before saving the product that you want to send from Woocommerce into Netsuite.
If you store the item on netsuite, they will return the internal_id of the item.
Then, you can save the item with internal id that they return.

Related

PHP NetSuite - Advanced Search with criterion

I have PHP code for Advanced Search items in NetSuite,
but I don't know how I can combine to my search - filtering by item name.
My code is:
$service = new NetSuiteService($config);
$service->setSearchPreferences(true, $page_size, true);
$savedSearchId = '###';
$searchAdvanced = new ItemSearchAdvanced();
setFields($searchAdvanced, array('savedSearchScriptId'=>$savedSearchId));
$request = new SearchRequest();
$request->searchRecord = $searchAdvanced;
$results = $service->search($request);
I want to combine a criteria
Here's sample code I found to get inventory details using Item internal id as a filter. You can reference Suite Answer 90401, 37585, and 25066.
<?php
require_once '../PHPToolkit/NetSuiteService.php';
$service = new NetSuiteService();
// formulate the criteria
$itemRecord = new RecordRef();
$itemRecord--->internalId = 140;
$itemMultiSelect = new SearchMultiSelectField();
$itemMultiSelect->operator = 'anyOf';
$itemMultiSelect->searchValue = $itemRecord;
$itemSearchBasic = new ItemSearchBasic();
$itemSearchBasic->internalId = $itemMultiSelect;
$criteria = new ItemSearch();
$criteria->basic = $itemSearchBasic;
// formulate the resulting columns
$searchRowBasic = new ItemSearchRowBasic();
$searchRowBasic->itemId = new SearchColumnStringField(); // Item Name/Number in UI
$searchRowBasic->internalId = new SearchColumnSelectField(); // Internal ID in UI
$searchRowBasic->location = new SearchColumnSelectField(); // Location (Main section of Inventory Item) in UI
$searchRowBasic->inventoryLocation = new SearchColumnSelectField(); // Location column in Locations tab (Inventory Item) in UI
$searchRowBasic->locationQuantityOnHand = new SearchColumnDoubleField();// Quantity on Hand column in Locations tab (Inventory Item) in UI
$columns = new ItemSearchRow();
$columns->basic = $searchRowBasic;
// item search advanced
$search = new ItemSearchAdvanced();
$search->criteria = $criteria;
$search->columns = $columns;
$request = new SearchRequest();
$request->searchRecord = $search;
$searchResponse = $service->search($request);
if (!$searchResponse->searchResult->status->isSuccess) {
echo "SEARCH ERROR";
} else {
echo "SEARCH SUCCESS, records found: " . $searchResponse->searchResult->totalRecords ;
}
?>

How do I get the serialized inventory item by the inventory id in NetSuite api with PHP?

Here is the situation, I'm trying to get the Serialized Inventory Item based on the id (https://xxx.app.netsuite.com/app/common/item/item.nl?id=522216), however, when I tried the following code:
$search = new TransactionSearchBasic();
$type = new SearchEnumMultiSelectField();
$type->operator = 'anyOf';
$type->searchValue = array('serializedInventoryItem');
$search->type = $type;
$invetoryRef = new RecordRef();
$invetoryRef->internalId = '522216';
$params = new SearchMultiSelectField();
$params->operator = 'anyOf';
$params->searchValue = array($invetoryRef);
$search->serializedInventoryItem = $params;
$request = new SearchRequest();
$request->searchRecord = $search;
$searchResponse = $service->search($request);
However, the response that I'm getting the following error:
The field type's enum value is invalid for this search.
Why would I be getting that error message?
Thank you,
Kevin Davis

Netsuite Item Fulfillment Invalid Line Items

I'm trying to set a SalesOrder to fulfilled using the PHP Netsuite Api but I keep getting the following error:
VALID_LINE_ITEM_REQD - You must have at least one valid line item for
this transaction.
I'm using the https://github.com/ryanwinchester/netsuite-php library.
I have the following so far. I've tried using the Initialise methods as well that I've seen in some examples, but they all seem to give the same error. We're using Advanced Inventory Management if that helps.
$itemFulfillment = new ItemFulfillment();
// Sales Order
$itemFulfillment->createdFrom = new RecordRef();
$itemFulfillment->createdFrom->internalId = <SALES_ORDER_ID>;
$itemFulfillment->shipStatus = ItemFulfillmentShipStatus::_shipped;
// Customer
$itemFulfillment->entity = new RecordRef();
$itemFulfillment->entity->internalId = <CUSTOMER_ID>;
// List
$fullfillmentList = new ItemFulfillmentItemList();
$fullfillmentList->replaceAll = true;
foreach($salesOrder->itemList->item as $saleItem) {
$item = new ItemFulfillmentItem();
$item->location = new RecordRef();
$item->location->internalId = 4;
$item->item = new RecordRef();
$item->item->internalId = $saleItem->item->internalId;
$item->itemIsFulfilled = true;
$item->itemReceive = true;
$item->quantity = $saleItem->quantity;
$item->orderLine = $saleItem->line;
// Department Reference
$departmentRec = new RecordRef();
$departmentRec->internalId = 5;
$item->department = $departmentRec;
$fullfillmentList->item[] = $item;
}
$itemFulfillment->itemList = $fullfillmentList;
$request = new AddRequest();
$request->record = $itemFulfillment;
$client->add($request);
Any help would be great. :)
Transforming a Sales Order to a
Cross-Subsidiary Item Fulfillment Record will return a
"VALID_LINE_ITEM_REQD >
You must have at least one valid line item for this transaction" error if we did not specify an inventoryLocation in the defaultValue parameter.
function createIF(soId, invLocation) {
var itemFulfillment = record.transform({
fromType: record.Type.SALES_ORDER,
fromId: soId,
toType: record.Type.ITEM_FULFILLMENT,
defaultValues: {
inventorylocation: invLocation
}
});
/**
* You can insert other script logic here
*/
var ifID = itemFulfillment.save();
return ifID;
}
make sure the item is in inventory
make sure the item is available to your subsidiary
make sure you are committing sublists correctly, if applicable
dump $saleItem to see whats in it to make sure noting is null

Adding Sales Order to Netsuite using PHP toolkit amount error

I'm getting an error when trying to add a sales order to netsuite via PHP toolkit
My code:
<?php
require_once '../PHPToolkit/NetSuiteService.php';
$service = new NetSuiteService();
$so->itemList = new SalesOrderItemList();
$item = new SalesOrderItem();
$so = new SalesOrder();
$entityRR = new RecordRef();
$entityRR->internalId = 10731;
$entityRR->recordType = "customer";
$so->entity = $entityRR ;
$so->currency->internalId = 1;
$so->itemList = new SalesOrderItemList();
$soi = new SalesOrderItem();
$soi->item = new RecordRef();
$soi->item->internalId = 2551;
$soi->quantity = 1;
$pricelevelRR = new RecordRef();
$pricelevelRR->internalId = -1;
$pricelevelRR->recordType = "priceLevel";
$soi->price = $pricelevelRR;
$soi->rate = 55.3;
$so->itemList->item = $soi;
$so->subsidiary->internalId = 5;
$so->location->internalId = 9;
$shipAddress = "123 the street Hampton NY 11937 United States";
$billAddress = "123 The street Hampton NY 11937 United States";
$so->shippingAddress1 = $shipAddress;
$so->billingAddress = $billAddress;
$arr = get_defined_vars();
print_r($arr["so"]);
$request = new AddRequest();
$request->record = $so;
$addResponse = $service->add($request);
if (!$addResponse->writeResponse->status->isSuccess) {
echo "ADD ERROR";
exit();
} else {
echo "ADD SUCCESS, id " . $addResponse->writeResponse->baseRef->internalId;
}
?>
I get the add response of this
<platformCore:code>USER_ERROR</platformCore:code>
<platformCore:message>Could not calculate cost for the selected Realtime rate. Missing/Illegal
ShipTo/Address/StateProvinceCode</platformCore:message>
</platformCore:statusDetail></platformCore:status></writeResponse>
</addResponse></soapenv:Body></soapenv:Envelope>
I'm not quite sure why it would not be able to calculate the cost and also say shipping address is missing
I noticed that you are entering the shipping address as one whole text. Have you tried entering it per the address fields. NetSuite has fields of each part of the address: address1, address2, city, state and zip code.
It might be looking that those fields which is why it is returning an error.
This is an old question but for those who are searching, this is an issue with pricing groups, to add a custom amount you need to match this with a pricing group in NetSuite.

Sending WooCommerce order to NetSuite

I'm attempting to take an order from WooCommerce using the Rest API, and add that information into NetSuite as a Sales Order. I can successfully grab the order information from WooCommerce, but I am unsuccessful when adding the order into NetSuite using the PHPToolkit. Here is what I have so far:
<?php
/*
* Add a customer to Netsuite.
*
* paramtypesmap
*
*/
require_once 'includes/functions.php';
// create array of fields
$itemArr = array();
$i = 0;
$service = new NetSuiteService();
$salesOrder = new SalesOrder();
$salesOrder->entity = new RecordRef();
$salesOrder->entity->internalId = 512;
$salesOrder->entity->type = 'customer';
$salesOrder->shipDate = formatDate('2014-10-06T07:12:57.000-07:00');
$service = new NetSuiteService();
$service->setSearchPreferences(false, 1000);
$siteCategory = new SearchMultiSelectField();
$siteCategory->operator = "anyOf";
$siteCategory->searchValue = array('internalId' => 512);
$search = new ItemSearchBasic();
$search->internalId = $siteCategory;
$request = new SearchRequest();
$request->searchRecord = $search;
$searchResponse = $service->search($request);
$products = $searchResponse->searchResult->recordList->record;
$salesOrder->itemList = new SalesOrderItemList();
$item = new SalesOrderItem();
$item->item = new RecordRef();
$item->item->internalId = 531;
$item->quantity = 1;
//removeEmpty($item->item);
//removeEmpty($item);
$item->price = new RecordRef();
$item->price->internalId = 1;
$item->amount = 55.3;
$salesOrder->itemList->item=array(0=>$item);
//Equivalent too print_r
pr($item);
//Equivalent too print_r
pr($salesOrder);
removeEmpty($salesOrder);
$request = new AddRequest();
$request->record = $salesOrder;
//$service->setFields($purchaseOrderFields);
$response = $service->add($request);
if (!$response->writeResponse->status->isSuccess) {
echo getErrors($response->writeResponse);
} else {
echo success($response->writeResponse->baseRef->internalId);
}
?>
I'm just trying to work from the ground up to see what fields are required and how to build them, however I keep getting this error when ran:
Please choose a child matrix item
I have spent the last couple of days attempting to try some Google Fu on the problem, but with my luck found nothing. Can anyone help me with this?
Based from the error message, you are trying to submit a Parent Matrix Item instead of the child. Verify it by checking the Item Record with internal id 531.
The best way to achieve correct internal ids is to import Matrix Items directly from NetSuite into WooCommerce as variable products. Assigning the internal id to each variation.

Categories