2017-03-16 127 views
0

到目前为止,我已经创建了两种获取销售订单对象的方法。一个是通过客户ID获取的,另一个是通过事务id或transId获取的。两种方法都返回销售订单,但itemList始终为空。当我登记NetSuite时,实际上有销售订单项目。PHP,NetSuite API,获取销售订单项目

我发现这个线程,提到确保bodyFieldsOnly设置为false。我不积极我正在设置这个属性,但我正在尝试这样做。

这里是我的两种方法,如果任何人有任何见解,我将不胜感激。我已经花了一段时间试图解决这个问题。

// Get sales order by tranId 
public function getSalesOrder($sales_order_trans_id) 
{ 

    $service = new NetSuiteService(self::_config); 
    $search = new TransactionSearchBasic(); 
    $searchStringField = array('searchValue' => $sales_order_trans_id, 
          'operator' => 'is'); 
    $search->tranId=$searchStringField; 
    $request = new SearchRequest(); 

    $searchPreferences = new SearchPreferences(); 
    $searchPreferences->bodyFieldsOnly = false; 
    $request->searchPreferences = $searchPreferences; 
    $request->searchRecord = $search; 
return $searchResponse = $service->search($request)->searchResult->recordList->record; 
} 

,并将所得销售订单的对象转换为数组,甩看起来像这样:

```array:1 [▼ 
    0 => SalesOrder {#175 ▼ 
    +createdDate: "2016-08-09T15:30:31.000-07:00" 
    +customForm: null 
    +entity: RecordRef {#176 ▶} 
    +job: null 
    +currency: null 
    +drAccount: null 
    +fxAccount: null 
    +tranDate: "2016-08-09T00:00:00.000-07:00" 
    +tranId: "SO4326" 
    +source: null 
    +createdFrom: null 
    +orderStatus: null 
    +opportunity: null 
    +salesRep: null 
    +contribPct: null 
    +partner: null 
    +salesGroup: null 
    +syncSalesTeams: false 
    +leadSource: RecordRef {#177 ▶} 
    +startDate: null 
    +endDate: null 
    +otherRefNum: null 
    +memo: null 
    +salesEffectiveDate: "2016-08-09T00:00:00.000-07:00" 
    +excludeCommission: null 
    +totalCostEstimate: null 
    +estGrossProfit: null 
    +estGrossProfitPercent: null 
    +exchangeRate: null 
    +promoCode: null 
    +currencyName: null 
    +discountItem: null 
    +discountRate: null 
    +isTaxable: null 
    +taxItem: null 
    +taxRate: null 
    +toBePrinted: false 
    +toBeEmailed: false 
    +email: "[email protected]" 
    +toBeFaxed: false 
    +fax: null 
    +messageSel: null 
    +message: null 
    +billingAddress: Address {#1 ▶} 
    +billAddressList: null 
    +shippingAddress: Address {#1 ▶} 
    +shipIsResidential: false 
    +shipAddressList: null 
    +fob: null 
    +shipDate: null 
    +actualShipDate: null 
    +shipMethod: null 
    +shippingCost: null 
    +shippingTax1Rate: null 
    +isMultiShipTo: null 
    +shippingTax2Rate: null 
    +shippingTaxCode: null 
    +handlingTaxCode: null 
    +handlingTax1Rate: null 
    +handlingTax2Rate: null 
    +handlingCost: null 
    +trackingNumbers: null 
    +linkedTrackingNumbers: null 
    +shipComplete: null 
    +paymentMethod: null 
    +shopperIpAddress: null 
    +saveOnAuthDecline: true 
    +creditCard: null 
    +revenueStatus: "_pending" 
    +recognizedRevenue: 0.0 
    +deferredRevenue: 0.0 
    +revRecOnRevCommitment: null 
    +revCommitStatus: null 
    +ccNumber: null 
    +ccExpireDate: null 
    +ccName: null 
    +ccStreet: null 
    +ccZipCode: null 
    +payPalStatus: null 
    +creditCardProcessor: null 
    +payPalTranId: null 
    +ccApproved: null 
    +getAuth: null 
    +authCode: null 
    +ccAvsStreetMatch: null 
    +ccAvsZipMatch: null 
    +isRecurringPayment: null 
    +ccSecurityCodeMatch: null 
    +altSalesTotal: null 
    +ignoreAvs: null 
    +paymentEventResult: null 
    +paymentEventHoldReason: null 
    +paymentEventType: null 
    +paymentEventDate: null 
    +paymentEventUpdatedBy: null 
    +subTotal: 444.99 
    +discountTotal: null 
    +taxTotal: null 
    +altShippingCost: null 
    +altHandlingCost: null 
    +total: 444.99 
    +revRecSchedule: null 
    +revRecStartDate: null 
    +revRecEndDate: null 
    +paypalAuthId: null 
    +balance: null 
    +paypalProcess: null 
    +billingSchedule: null 
    +ccSecurityCode: null 
    +threeDStatusCode: null 
    +class: null 
    +department: RecordRef {#1 ▶} 
    +subsidiary: RecordRef {#1 ▶} 
    +intercoTransaction: null 
    +intercoStatus: null 
    +debitCardIssueNo: null 
    +lastModifiedDate: "2016-08-09T15:30:31.000-07:00" 
    +location: null 
    +pnRefNum: null 
    +status: "Pending Approval" 
    +tax2Total: null 
    +terms: RecordRef {#182 ▶} 
    +validFrom: null 
    +vatRegNum: null 
    +giftCertApplied: null 
    +oneTime: null 
    +recurWeekly: null 
    +recurMonthly: null 
    +recurQuarterly: null 
    +recurAnnually: null 
    +tranIsVsoeBundle: null 
    +vsoeAutoCalc: null 
    +syncPartnerTeams: null 
    +salesTeamList: null 
    +partnersList: null 
    +giftCertRedemptionList: null 
    +promotionsList: null 
    +itemList: null 
    +shipGroupList: null 
    +accountingBookDetailList: null 
    +customFieldList: CustomFieldList {#183 ▶} 
    +internalId: "1" 
    +externalId: null 
    +nullFieldList: null 
    } 
]``` 

的另一种方法,通过客户ID获得客户的销售订单。

 public function getCustomerSalesOrders($customer_id) 
     { 

      $service = new NetSuiteService(self::_config); 
      $customerSearchBasic = new CustomerSearchBasic(); 

      $searchValue = new RecordRef(); 
      $searchValue->type = 'customer'; 
      $searchValue->internalId = $customer_id; 

      $searchMultiSelectField = new SearchMultiSelectField(); 
      setFields($searchMultiSelectField, array('operator' => 'anyOf', 'searchValue' => $searchValue)); 
      $customerSearchBasic->internalId = $searchMultiSelectField; 

      $transactionSearchBasic = new TransactionSearchBasic(); 

      $prefs = new Preferences(); 
      $service->preferences = $prefs; 
      $searchPreferences = new SearchPreferences(); 
      $searchPreferences->bodyFieldsOnly = false; 
      $service->searchPreferences = $searchPreferences; 

      $searchMultiSelectEnumField = new SearchEnumMultiSelectField(); 
      setFields($searchMultiSelectEnumField, array('operator' => 'anyOf', 'searchValue' => "_salesOrder")); 

      $transactionSearchBasic->type = $searchMultiSelectEnumField; 
      $transactionSearch = new TransactionSearch(); 
      $transactionSearch->basic = $transactionSearchBasic; 
      $transactionSearch->customerJoin = $customerSearchBasic; 

      $request = new SearchRequest(); 
      $request->searchRecord = $transactionSearch; 
      $searchResponse = $service->search($request); 

      return $searchResponse->searchResult->recordList->record; 

    } 

回答

2

您正在使用搜索。改为:

$service = new NetSuiteService(); 
$request = new GetRequest(); 
$request->baseRef = new RecordRef(); 
$request->baseRef->internalId = 123456; //<< REPLACE THIS WITH YOUR INTERNAL ID 
$request->baseRef->type = 'salesOrder'; 
$getResponse = $service->get($request); 
+0

非常感谢你,那正是我所需要的。 –

相关问题