我正在为Netsuite进行集成。当我返回保存的搜索时,为searchRowBasic
属性返回了300多个字段。我将在下面添加一个var_dump。
我的源代码来自Magento 2,因此工厂方法不在范围内,但是您可以假定它们创建了该类的新实例(我会注意)。
我还使用composer package for netsuite来利用名称空间,而不是Netsuite的官方软件包,后者是一个文件,具有1600个类,没有名称空间(严重)。
/** @var Netsuite\Classes\ItemSearchAdvanced $searchRecord */
$searchRecord = $this->itemSearchAdvancedFactory->create();
/** @var Netsuite\Classes\SearchRow $searchRow */
$searchRow = $this->itemSearchRowFactory->create();
/** @var Netsuite\Classes\SearchRowBasic $searchRowBasic */
$searchRowBasic = $this->itemSearchRowBasicFactory->create();
/** @var Netsuite\Classes\SearchRequest */
$request = $this->searchRequestFactory->create();
$searchRecord->savedSearchId = 190;
$request->searchRecord = $searchRecord;
/** @var Netsuite\NetsuiteService $netsuiteService */
// Loaded with authentication values.
$netsuiteService = $this->getNetsuiteService();
$netsuiteService->setSearchPreferences(false, 1000);
// Submit the request - returns successful response.
$searchResponse = $netsuiteService->search($request);
我的请求返回成功的响应(:thumbsup:)
问题是我想在整个响应中使用4个变量,但是数组中有数百个未使用的索引。我最担心的是Netsuite在响应期间查询这些信息,我的次要关注是返回多个KB的数据,这些数据不会在响应中用于较大的请求。
我已经尝试过这样做,以取消设置参数,希望如果我不声明它们,Netsuite将在响应中忽略它们,但是我没有运气。
protected function getSearchRecord(): ItemSearchAdvanced
{
$searchRecord = $this->itemSearchAdvancedFactory->create();
$searchRow = $this->itemSearchRowFactory->create();
$searchRowBasic = $this->itemSearchRowBasicFactory->create();
$i = 0;
$fields = $searchRowBasic::$paramtypesmap;
foreach ($fields as $name => $type) {
// use only the first 10 just to see if only these 10 will be used.
// no such luck.
if ($i > 10) {
unset($searchRowBasic::$paramtypesmap[$name]);
unset($searchRowBasic->$name);
}
$i++;
}
$searchRow->basic = $searchRowBasic;
$searchRecord->columns = $searchRow;
return $searchRecord;
}
在提出请求之前,我知道要返回的字段。如何指定这些字段以仅返回所需的数据,而不是所有可用数据?
这是响应的var_dump以查看格式。我将数据截断了很多,如果有人需要,我可以轻松地提供它,但是我认为当前提供的信息足够。
class NetSuite\Classes\SearchResponse#2452 (1) {
public $searchResult =>
class NetSuite\Classes\SearchResult#2449 (8) {
public $status =>
class NetSuite\Classes\Status#2447 (2) {
public $statusDetail =>
NULL
public $isSuccess =>
bool(true)
}
public $totalRecords =>
int(1)
public $pageSize =>
int(1000)
public $totalPages =>
int(1)
public $pageIndex =>
int(1)
public $searchId =>
string(60) "<requst_id_with_personal_data>"
public $recordList =>
NULL
public $searchRowList =>
class NetSuite\Classes\SearchRowList#2475 (1) {
public $searchRow =>
array(1) {
[0] =>
class NetSuite\Classes\ItemSearchRow#2476 (23) {
public $basic =>
class NetSuite\Classes\ItemSearchRowBasic#2477 (322) {
public $accBookRevRecForecastRule =>
NULL
public $accountingBook =>
NULL
public $accountingBookAmortization =>
NULL
public $accountingBookCreatePlansOn =>
NULL
public $accountingBookRevRecRule =>
NULL
public $accountingBookRevRecSchedule =>
NULL
public $allowedShippingMethod =>
NULL
public $alternateDemandSourceItem =>
NULL
public $assetAccount =>
NULL
public $atpLeadTime =>
NULL
(more elements)...
}
public $assemblyItemBillOfMaterialsJoin =>
NULL
public $binNumberJoin =>
NULL
public $binOnHandJoin =>
NULL
public $correlatedItemJoin =>
NULL
public $effectiveRevisionJoin =>
NULL
public $fileJoin =>
NULL
public $inventoryDetailJoin =>
NULL
public $inventoryLocationJoin =>
NULL
public $inventoryNumberJoin =>
NULL
(more elements)...
}
}
}
}
}
答案 0 :(得分:0)
在搜索了来自服务器的XML响应之后,Netsuite似乎仅在需要时用保存的搜索中声明的列进行响应。初始化响应对象时,我收到的其他空值被初始化为默认值。