web-services - 添加 Netsuite 销售订单项目

标签 web-services add netsuite

我遇到这种类型的错误:

=> 我在集成 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;
    }
    +

最佳答案

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;
        } 

        ?>

关于web-services - 添加 Netsuite 销售订单项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17547850/

相关文章:

c# - 如何解析从文件加载的 soap 消息?

xcode - 通过 Applescript 将文件添加到 Xcode 项目目标

android - 将项目永久添加到现有的警报对话框?

c# - 调用 HTTPClient.PostAsync 时设置授权/内容类型 header

javascript - 向包含document.write的脚本中添加脚本不会执行

java - (Java) 在运行时动态创建新的 REST Web 服务

web-services - 玩!框架异步调用修改数据库的相同对象

ios - 添加一个 UIView 到另一个

api - 如何在 netsuite 1.0 搜索过滤器上使用子列表项?我尝试执行 item.fieldname 但它导致错误

asp.net - ASSX 处理程序返回 500 内部服务器错误