PHP,NetSuite API,获取销售订单项目

时间:2017-03-16 17:39:32

标签: php netsuite

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

我找到了这个帖子,提到确保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;
}

生成的Sales Order对象转换为数组,dumped如下所示:

```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: "jondoe@example.com"
    +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;

    }

1 个答案:

答案 0 :(得分:3)

您正在使用搜索。请改用:

$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);