Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Two responses?..one from each request
- $response = $service->findItemsAdvanced($request);
- // how to get compatibles from item id in request/response 1 ?//
- $response2 = $service-> /* ??? */ ($request2);
- // Iterate over the items returned in the response.
- foreach ($response->searchResult->item as $item) {
- //an easy var name for reference
- var mylistId = $item->itemId,
- // lets the see the ID's //
- printf(
- "(%s) %sn",
- $item->itemId,
- $item->title
- );
- //maybe the request and response is in the loop???
- // $requestTWO = get compatibles linked to mylistId
- // $responseTWO = return compatibles
- foreach ($responseTWO->searchResult->item as $compats) {
- // print new responses
- printf(
- "(%s) %sn",
- $compats->make,
- $compats->model,
- $compats->year
- );
- }
- <?php
- require __DIR__.'/vendor/autoload.php';
- use DTSeBaySDKSdk;
- use DTSeBaySDKConstants;
- use DTSeBaySDKFinding;
- use DTSeBaySDKShopping;
- $sdk = new Sdk([
- 'credentials' => [
- 'devId' => 'DEV ID',
- 'appId' => 'APP ID',
- 'certId' => 'CERT ID',
- ],
- 'globalId' => ConstantsGlobalIds::MOTORS
- ]);
- /**
- * Create the service objects.
- */
- $finding = $sdk->createFinding([
- 'apiVersion' => '1.13.0'
- ]);
- $shopping = $sdk->createShopping([
- 'apiVersion' => '981'
- ]);
- /**
- * Create the finding request.
- */
- $findingRequest = new FindingTypesFindItemsAdvancedRequest();
- /**
- * Ask for items from these sellers. You specify up to 100 sellers.
- */
- $itemFilter = new FindingTypesItemFilter();
- $itemFilter->name = 'Seller';
- $itemFilter->value = [
- 'brakemotive76',
- 'primechoiceautoparts'
- ];
- $findingRequest->itemFilter[] = $itemFilter;
- /**
- * You can optionally narrow the search down further by only requesting
- * listings that match keywords or categories.
- */
- //$request->keywords = 'Brake Pads';
- //$request->categoryId = ['33560', '33561'];
- /**
- * eBay can return more than one page of results.
- * So just start at page 1 to begin with.
- */
- $findingRequest->paginationInput = new FindingTypesPaginationInput();
- $pageNum = 1;
- do {
- $findingRequest->paginationInput->pageNumber = $pageNum;
- $findingResponse = $finding->findItemsAdvanced($findingRequest);
- // Handle any errors returned from the API.
- if (isset($findingResponse->errorMessage)) {
- foreach ($findingResponse->errorMessage->error as $error) {
- printf(
- "%s: %snn",
- $error->severity=== FindingEnumsErrorSeverity::C_ERROR ? 'Error' : 'Warning',
- $error->message
- );
- }
- }
- if ($findingResponse->ack !== 'Failure') {
- /**
- * For each item make a second request to the Shopping service to get the compatibility information.
- */
- foreach ($findingResponse->searchResult->item as $item) {
- $shoppingRequest = new ShoppingTypesGetSingleItemRequestType();
- $shoppingRequest->ItemID = $item->itemId;
- /**
- * We have to tell the Shopping service to return the comaptibility and item specifics information as
- * it will not by default.
- */
- $shoppingRequest->IncludeSelector = 'ItemSpecifics, Compatibility';
- $shoppingResponse = $shopping->getSingleItem($shoppingRequest);
- if (isset($shoppingResponse->Errors)) {
- foreach ($shoppingResponse->Errors as $error) {
- printf(
- "%s: %sn%snn",
- $error->SeverityCode === ShoppingEnumsSeverityCodeType::C_ERROR ? 'Error' : 'Warning',
- $error->ShortMessage,
- $error->LongMessage
- );
- }
- }
- if ($shoppingResponse->Ack !== 'Failure') {
- $item = $shoppingResponse->Item;
- print("n$item->Titlen");
- if (isset($item->ItemSpecifics)) {
- print("nThis item has the following item specifics:nn");
- foreach ($item->ItemSpecifics->NameValueList as $nameValues) {
- printf(
- "%s: %sn",
- $nameValues->Name,
- implode(', ', iterator_to_array($nameValues->Value))
- );
- }
- }
- if (isset($item->ItemCompatibilityCount)) {
- printf("nThis item is compatible with %s vehicles:nn", $item->ItemCompatibilityCount);
- foreach ($item->ItemCompatibilityList->Compatibility as $compatibility) {
- foreach ($compatibility->NameValueList as $nameValues) {
- if ($nameValues->Name != '') {
- printf(
- "%s: %sn",
- $nameValues->Name,
- implode(', ', iterator_to_array($nameValues->Value))
- );
- }
- }
- printf("Notes: %s n", $compatibility->CompatibilityNotes);
- }
- }
- }
- }
- }
- $pageNum += 1;
- } while ($pageNum <= $findingResponse->paginationOutput->totalPages);
Add Comment
Please, Sign In to add comment