Example #1
0
 public function getManyProducts(array $ids, $countryShortName = 'US')
 {
     if (count($ids) > 20) {
         throw new BadRequest('products count is more than 20');
     }
     $request = new Request($this->httpClient, $this->keys);
     $responses = $request->performParallel(['with_description' => ['url' => self::SHOPPING_URL, 'params' => ['callname' => 'GetMultipleItems', 'responseencoding' => 'XML', 'appid' => '%APP_ID%', 'siteid' => $this->getCountryCodeByShortName($countryShortName), 'version' => self::SHOPPING_API_VERSION, 'ItemID' => implode(',', $ids), 'IncludeSelector' => implode(',', array_merge(['Description'], $this->defaultProductSelectors))]], 'with_text_description' => ['url' => self::SHOPPING_URL, 'params' => ['callname' => 'GetMultipleItems', 'responseencoding' => 'XML', 'appid' => '%APP_ID%', 'siteid' => $this->getCountryCodeByShortName($countryShortName), 'version' => self::SHOPPING_API_VERSION, 'ItemID' => implode(',', $ids), 'IncludeSelector' => 'TextDescription']]]);
     $responseWithDescription = $this->decode($responses['with_description']);
     $responseWithTextDescription = $this->decode($responses['with_text_description']);
     if (!isset($responseWithDescription['Item']) || !isset($responseWithTextDescription['Item'])) {
         throw new EmptyRequest('Response is empty.');
     }
     $productList = new ProductList($responseWithDescription, $responseWithTextDescription);
     return $productList->toObjects();
 }