2013-07-09 145 views
2

我得到这种类型的错误:添加Netsuite销售订单项目

=>我在网络集成的错误。

在销售订单中添加netsuite中的项目所以有一些错误是在上面的代码段中定义我的代码是下面请看代码添加如何解决这个问题。

[code] => USER_ERROR 
    [message] => You must enter at least one line item for this transaction. 
    [type] => ERRORi am gatting this type of error please help me 
    [code] => USER_ERROR 
    [message] => You must enter at least one line item for this transaction. 
    [type] => ERROR 

我的代码是

include('NetSuiteService.php'); 

    $service = new NetSuiteService(); 
    if($order_items->netsuitid > 0){ 
     $internal_Id = $order_items->netsuitid; 
     $emailCustomer = $order_items->user_email; 
    } 
    else{ 
     $customer_Info = $order->get_customer_info($order->user_id); 
     $customer_information = array(); 
     foreach($customer_Info as $customer_key => $customer_value){ 
      if($customer_value->meta_key == 'first_name'){ 
       $customer_information['first_name'] = $customer_value->meta_value; 
      } 
      if($customer_value->meta_key == 'last_name'){ 
       $customer_information['last_name'] = $customer_value->meta_value; 
      } 
     } 

     $customer_information['email'] = $customer_Info->user_email; 


     //Add customer into net suit integration 
     $service = new NetSuiteService(); 

     $customer = new Customer(); 
     $customer->lastName = $customer_information['last_name']; 
     $customer->firstName = $customer_information['first_name']; 
     $customer->companyName = 'Company Name'; 
     $customer->phone = '2222222222'; 
     $customer->email = $customer_information['email']; 
     $emailCustomer = $customer_information['email']; 
     $request = new AddRequest(); 
     $request->record = $customer; 

     $addResponse = $service->add($request); 
     if (!$addResponse->writeResponse->status->isSuccess) { 
      echo "You are already Registered with Netsuit."; 
     } 
     else { 
      $internal_Id = $addResponse->writeResponse->baseRef->internalId; 
      $order->insert_Customer($internal_Id,$order->user_id); 
     } 
     //End customer into net suit integration 
    } 

    //Add Product Information 
    /*$items = array(); 

    foreach ($order_items as $item_id => $item) { 
     $itemRef = new nsRecordRef(array('internalId'=>$internal_Id)); 
     $qty = $item['qty']; 
     if($item['type'] == 'line_item'){ 
      $salesOrderItemFieldArray = array(
       "item" => $itemRef, 
       "quantity" => $qty 

      ); 
     } 
     if($item['type'] == 'fee'){ 
      $salesOrderItemFieldArray = array(
       "item" => $itemRef, 
       "quantity" => $qty 
      ); 
     } 
     $SalesOrderItem->setFields($salesOrderItemFieldArray); 
     $items[] = $SalesOrderItem; 
    } 

    $salesOrderItemList = new nsComplexObject("SalesOrderItemList"); 
    $salesOrderItemList->setFields(array(
     "item" => $items 
    )); 

    $salesOrderFields = array(
     "orderStatus" => $order->status, 
     "entity" => '', 
     "getAuth" => true, 
     "shippingCost" => $order->order_shipping, 
     "shipMethod" => $order->payment_method, 
     "toBeEmailed" => true, 
     "email" => $emailCustomer, 
     "itemList" => $salesOrderItemList 
    );*/ 

    $so = new SalesOrder(); 
    //created Date 
    //$so->createdDate = $order->order_date; 
    //entity 
    $so->entity = new RecordRef(); 
    $so->entity->internalId = $internal_Id; 
    $so->entity->name = $order->order_custom_fields['_billing_company'][0]; 

    //Transaction Id 
    //$so->tranId = $order->order_custom_fields['Transaction ID'][0]; 

    //Transaction Paid Date 
    //$so->tranDate = $order->order_custom_fields['_paid_date'][0]; 

    //Source 
    $so->source = 'littlecrate'; 

    //Created From 
    $so->createdFrom = 'littlecrate.com'; 

    //Currency Name 
    require_once('geoplugin.class.php'); 
    $geoplugin = new geoPlugin(); 

    $geoplugin->currency = $order->order_custom_fields['_order_currency']; 

    $so->currencyName = $geoplugin->countryName; 
    $so->currency = $order->order_custom_fields['_order_currency'][0]; 

    //Discount 
    $so->discountRate = $order->order_custom_fields['_order_discount'][0]; 

    //Tax 
    $so->taxRate = $order->order_custom_fields['_order_tax'][0]; 

    //email 
    $so->email = $order->billing_email; 

    //Status 
    //$so->orderStatus = $order->status; 

    //Billing Address 
    $so->billAddressList = array(
    'billFirstname' => $order->order_custom_fields['_billing_first_name'][0], 
    'lastname' => $order->order_custom_fields['_billing_last_name'][0], 
    'billAddressee' => $order->order_custom_fields['_billing_address_1'][0], 
    'billAddr1' => $order->order_custom_fields['_billing_address_2'][0], 
    'billCountry' => $order->order_custom_fields['_billing_country'][0], 
    'billState' => $order->order_custom_fields['_billing_state'][0], 
    'billZip' => $order->order_custom_fields['_billing_postcode'][0], 
    'billPhone' => $order->order_custom_fields['_billing_phone'][0], 
    'billEmail' => $order->order_custom_fields['_billing_email'][0]); 

    //Shipping Address 
    $so->shipAddressList = array(
    'shipFirstname' => $order->order_custom_fields['_shipping_first_name'][0], 
    'shipLastname' => $order->order_custom_fields['_shipping_last_name'][0], 
    'shipAddressee' => $order->order_custom_fields['_shipping_address_1'][0], 
    'shipAddr1' => $order->order_custom_fields['_shipping_address_2'][0], 
    'shipCity' => $order->order_custom_fields['_shipping_city'][0], 
    'shipState' => $order->order_custom_fields['_shipping_state'][0], 
    'shipZip' => $order->order_custom_fields['_shipping_postcode'][0], 
    'shiplPhone' => $order->order_custom_fields['_billing_phone'][0], 
    'shipEmail' => $order->order_custom_fields['_billing_email'][0]); 

    //Ship Date 
    //$so->shipDate = $order->order_custom_fields['Transaction ID'][0]; 

    //Shipping Method 
    $so->shipMethod = $order->shipping_method; 

    //Shipping Charges 
    $so->shippingCost = $order->order_shipping; 

    //Shipping Tax Rate 
    $so->shippingTax1Rate = $order->order_shipping_tax; 

    //Payment Method 
    $so->paymentMethod = $order->payment_method; 

    //Sub Total 
    //$so->subTotal = $order->order_total; 

    //Discount Total(Cart Total) 
    //$so->discountTotal = $order->cart_discount; 

    //Tax Total 
    //$so->taxTotal = $order->order_tax; 

    //Total 
    //$so->total = $order->order_total; 

    //Product Listing 
    $arrItemsList = array(); 
    $i = 0; 
    foreach($order_items_product as $keyProduct =>$valueProduct){ 
     if($valueProduct['type'] == 'line_item'){ 
     //$arrItemsList[$i]['item']['internalId'] = $valueProduct['product_id']; 
     //$arrItemsList[$i]['item']['externalId'] = $keyProduct; 
     $arrItemsList[$i]['item']['name']   = $valueProduct['name']; 
     $arrItemsList[$i]['item']['quantity']  = $valueProduct['qty']; 
     $arrItemsList[$i]['item']['description'] = $valueProduct['type']; 
     $arrItemsList[$i]['item']['amount']   = $valueProduct['line_total']; 
     } 
     if($valueProduct['type'] == 'fee'){ 
     //$arrItemsList[$i]['item']['internalId'] = $valueProduct['product_id']; 
     //$arrItemsList[$i]['item']['externalId'] = $keyProduct; 
     $arrItemsList[$i]['item']['name']   = $valueProduct['name']; 
     $arrItemsList[$i]['item']['quantity']  = $valueProduct['qty']; 
     $arrItemsList[$i]['item']['description'] = $valueProduct['type']; 
     $arrItemsList[$i]['item']['amount']   = $valueProduct['line_total']; 
     } 
     $i++; 
    } 

    //print_r($arrItemsList); 

    $so->itemList->item = $arrItemsList; 

    /*$so->itemList = new SalesOrderItemList(); 
    $soi = new SalesOrderItem(); 
    $soi->item = new RecordRef(); 
    $soi->item->internalId = 15; 
    $soi->quantity = 3; 
    $soi->price = new RecordRef(); 
    $soi->price->internalId = $id; 
    $soi->amount = 55.3; 
    $so->itemList->item = array($soi);*/ 

    $request = new AddRequest(); 
    $request->record = $so; 
    //print_r($request); 

    $addResponse = $service->add($request); 
    print_r($addResponse); 
    exit; 
    if (!$addResponse->writeResponse->status->isSuccess) { 
     echo "ADD ERROR"; 
    } else { 
     echo "ADD SUCCESS, id " . $addResponse->writeResponse->baseRef->internalId; 
    } 
    + 

回答

4
I Complited Using The Help Of Saqib, 

http://stackoverflow.com/users/810555/saqib 

He is The Great Developer And Regarding Netsuite Information Please Contact To Saqib Thanks Man U Just Do It. 

<?php 
    $order_date = date('Y-m-d H:i:s'); 

     // create array of fields 
     $itemArr = array(); 
     $i = 0; 
     foreach($order_items_product as $keyProduct =>$valueProduct){ 
      //if you not have internal id of item in netsuuite then please add the item in the netsuite and try. 
      $netsuiteItemId = 'Your Item Internal id Which is in the Netsuite Item'; 

      $itemArr[$i]['item']['internalId'] = $netsuiteItemId; 
      $itemArr[$i]['quantity'] = $valueProduct['qty']; 
      $i++; 
     } 

     if (!define('LF', "\n")) { 
      define('LF', "\n"); 
     } 

     /* for use in formatting custom addresses since NetSuite converts to <br> */ 
     //Billing Address Information 
     /* this example has the customer address info in a db record, just pulled into $row */ 
     $billAddress = stripslashes($order->order_custom_fields['_billing_first_name'][0]) . ' ' . $order->order_custom_fields['_billing_last_name'][0] . LF; 
     $billAddress .= stripslashes($order->order_custom_fields['_billing_address_1'][0]).LF; 
     $billAddress .= stripslashes($order->order_custom_fields['_billing_address_2'][0]).LF; 
     $billAddress .= stripslashes($order->order_custom_fields['_billing_country'][0]).LF; 
     $billAddress .= stripslashes($order->order_custom_fields['_billing_state'][0]) . ' - ' . $order->order_custom_fields['_billing_postcode'][0] . ', ' . LF; 
     $billAddress .= $order->order_custom_fields['_billing_phone'][0] . ', ' . $order->order_custom_fields['_billing_email'][0]; 

     //Shipping Address Information 
     $shipAddress = stripslashes($order->order_custom_fields['_shipping_first_name'][0]) . ' ' . $order->order_custom_fields['_shipping_last_name'][0] . LF; 
     $shipAddress .= stripslashes($order->order_custom_fields['_shipping_address_1'][0]).LF; 
     $shipAddress .= stripslashes($order->order_custom_fields['_shipping_address_2'][0]).LF; 
     $shipAddress .= stripslashes($order->order_custom_fields['_shipping_city'][0]).LF; 
     $shipAddress .= stripslashes($order->order_custom_fields['_shipping_state'][0]) . ', ' . $order->order_custom_fields['_shipping_postcode'][0] . ', ' . LF; 
     $shipAddress .= $order->order_custom_fields['_billing_phone'][0] .', '. $order->order_custom_fields['_billing_email'][0]; 


     $purchaseOrderFields = array (
          'entity' => array ('internalId' => $internal_Id, 'type' => 'customer'), 
          'shippingCost' => $order->order_shipping, 
          'shipMethod' => $order->payment_method, 
          'toBeEmailed' => true, 
          //'tranId' => $order->order_custom_fields['Transaction ID'][0], 
          //'tranDate' => date('Y-m-d H:i:s'), 
          'source' => 'littlecrate', 
          'createdFrom' => 'littlecrate.com', 
          'discountRate' => $order->order_custom_fields['_order_discount'][0], 
          'taxRate' => $order->order_custom_fields['_order_tax'][0], 
          'email' => $order->billing_email, 
          //'shipDate' => date('Y-m-d H:i:s'), 
          'shipMethod' => $order->shipping_method, 
          'shippingCost' => $order->order_shipping, 
          'shippingTax1Rate' => $order->order_shipping_tax, 
          'paymentMethod' => $order->payment_method, 
          //'taxTotal' => $order->order_tax, 
          //'total' => $order->order_total, 
          'billAddress' => $billAddress, 
          'shipAddress' => $shipAddress, 
          'itemList' => array (
                'item' => $itemArr 
               ) 
            ); 

     $salesOrder = new nsComplexObject('SalesOrder'); 

     $salesOrder ->setFields($purchaseOrderFields); 

     $addResponse = $myNSclient->add($salesOrder); 
     if (!$addResponse->isSuccess) { 
      echo "Order Information is Not Inserted Into The Netsuite. Please Contact to Administration."; 
      exit; 
     } 

     ?> 
2

您的项目列表对象似乎不正确的格式。您的代码应该是这样的

$itemArr = array(); 
foreach($order_items_product as $keyProduct =>$valueProduct){ 
    $item = new SalesOrderItem(); 
    $item->item = $valueProduct['product_id']; 
    $item->quantity = $valueProduct['qty']; 
    $itemArr[] = $item; 
} 

$itemList = new SalesOrderItemList(); 
$itemList->item = $itemArr; 

$so->itemList->item = $itemList; 
+0

您好Saqib,感谢您的回复,u能送我的如何添加销售产品净套房 –

+0

指如何添加的销售订单 –

+0

垫的孔代码的代码看起来很好。只需插入我的代码段,它应该可以工作。 – Saqib

相关问题