Guest User

Untitled

a guest
May 26th, 2018
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.27 KB | None | 0 0
  1. //Two responses?..one from each request
  2. $response = $service->findItemsAdvanced($request);
  3.  
  4. // how to get compatibles from item id in request/response 1 ?//
  5. $response2 = $service-> /* ??? */ ($request2);
  6.  
  7.  
  8. // Iterate over the items returned in the response.
  9. foreach ($response->searchResult->item as $item) {
  10. //an easy var name for reference
  11. var mylistId = $item->itemId,
  12. // lets the see the ID's //
  13. printf(
  14. "(%s) %sn",
  15. $item->itemId,
  16. $item->title
  17. );
  18.  
  19. //maybe the request and response is in the loop???
  20. // $requestTWO = get compatibles linked to mylistId
  21. // $responseTWO = return compatibles
  22. foreach ($responseTWO->searchResult->item as $compats) {
  23. // print new responses
  24. printf(
  25. "(%s) %sn",
  26. $compats->make,
  27. $compats->model,
  28. $compats->year
  29. );
  30. }
  31.  
  32. <?php
  33. require __DIR__.'/vendor/autoload.php';
  34.  
  35. use DTSeBaySDKSdk;
  36. use DTSeBaySDKConstants;
  37. use DTSeBaySDKFinding;
  38. use DTSeBaySDKShopping;
  39.  
  40. $sdk = new Sdk([
  41. 'credentials' => [
  42. 'devId' => 'DEV ID',
  43. 'appId' => 'APP ID',
  44. 'certId' => 'CERT ID',
  45. ],
  46. 'globalId' => ConstantsGlobalIds::MOTORS
  47. ]);
  48.  
  49. /**
  50. * Create the service objects.
  51. */
  52. $finding = $sdk->createFinding([
  53. 'apiVersion' => '1.13.0'
  54. ]);
  55.  
  56. $shopping = $sdk->createShopping([
  57. 'apiVersion' => '981'
  58. ]);
  59.  
  60. /**
  61. * Create the finding request.
  62. */
  63. $findingRequest = new FindingTypesFindItemsAdvancedRequest();
  64. /**
  65. * Ask for items from these sellers. You specify up to 100 sellers.
  66. */
  67. $itemFilter = new FindingTypesItemFilter();
  68. $itemFilter->name = 'Seller';
  69. $itemFilter->value = [
  70. 'brakemotive76',
  71. 'primechoiceautoparts'
  72. ];
  73. $findingRequest->itemFilter[] = $itemFilter;
  74. /**
  75. * You can optionally narrow the search down further by only requesting
  76. * listings that match keywords or categories.
  77. */
  78. //$request->keywords = 'Brake Pads';
  79. //$request->categoryId = ['33560', '33561'];
  80.  
  81. /**
  82. * eBay can return more than one page of results.
  83. * So just start at page 1 to begin with.
  84. */
  85. $findingRequest->paginationInput = new FindingTypesPaginationInput();
  86. $pageNum = 1;
  87.  
  88. do {
  89. $findingRequest->paginationInput->pageNumber = $pageNum;
  90.  
  91. $findingResponse = $finding->findItemsAdvanced($findingRequest);
  92.  
  93. // Handle any errors returned from the API.
  94. if (isset($findingResponse->errorMessage)) {
  95. foreach ($findingResponse->errorMessage->error as $error) {
  96. printf(
  97. "%s: %snn",
  98. $error->severity=== FindingEnumsErrorSeverity::C_ERROR ? 'Error' : 'Warning',
  99. $error->message
  100. );
  101. }
  102. }
  103.  
  104. if ($findingResponse->ack !== 'Failure') {
  105. /**
  106. * For each item make a second request to the Shopping service to get the compatibility information.
  107. */
  108. foreach ($findingResponse->searchResult->item as $item) {
  109. $shoppingRequest = new ShoppingTypesGetSingleItemRequestType();
  110. $shoppingRequest->ItemID = $item->itemId;
  111. /**
  112. * We have to tell the Shopping service to return the comaptibility and item specifics information as
  113. * it will not by default.
  114. */
  115. $shoppingRequest->IncludeSelector = 'ItemSpecifics, Compatibility';
  116.  
  117. $shoppingResponse = $shopping->getSingleItem($shoppingRequest);
  118.  
  119. if (isset($shoppingResponse->Errors)) {
  120. foreach ($shoppingResponse->Errors as $error) {
  121. printf(
  122. "%s: %sn%snn",
  123. $error->SeverityCode === ShoppingEnumsSeverityCodeType::C_ERROR ? 'Error' : 'Warning',
  124. $error->ShortMessage,
  125. $error->LongMessage
  126. );
  127. }
  128. }
  129.  
  130. if ($shoppingResponse->Ack !== 'Failure') {
  131. $item = $shoppingResponse->Item;
  132.  
  133. print("n$item->Titlen");
  134.  
  135. if (isset($item->ItemSpecifics)) {
  136. print("nThis item has the following item specifics:nn");
  137. foreach ($item->ItemSpecifics->NameValueList as $nameValues) {
  138. printf(
  139. "%s: %sn",
  140. $nameValues->Name,
  141. implode(', ', iterator_to_array($nameValues->Value))
  142. );
  143. }
  144. }
  145.  
  146. if (isset($item->ItemCompatibilityCount)) {
  147. printf("nThis item is compatible with %s vehicles:nn", $item->ItemCompatibilityCount);
  148.  
  149. foreach ($item->ItemCompatibilityList->Compatibility as $compatibility) {
  150. foreach ($compatibility->NameValueList as $nameValues) {
  151. if ($nameValues->Name != '') {
  152. printf(
  153. "%s: %sn",
  154. $nameValues->Name,
  155. implode(', ', iterator_to_array($nameValues->Value))
  156. );
  157. }
  158. }
  159. printf("Notes: %s n", $compatibility->CompatibilityNotes);
  160. }
  161. }
  162. }
  163. }
  164. }
  165.  
  166. $pageNum += 1;
  167.  
  168. } while ($pageNum <= $findingResponse->paginationOutput->totalPages);
Add Comment
Please, Sign In to add comment