searchEngine = $searchEngine; $this->barcode = $barcode; } public function getName(): string { return 'SearchJob'; } protected function handle(ImportJobResult $result): ImportJobResult { $result->addLog(sprintf('[%s] querying providers for barcode %s.', $this->getName(), $this->barcode)); $searchRequest = new SearchRequest($this->barcode, 1, 0); $searchResult = $this->searchEngine->search($searchRequest); $items = $searchResult->getItems(); if (empty($items)) { throw new ImportException('No search results found for identifier: ' . $this->barcode); } $product = reset($items); if (! $product instanceof ProductDTO) { throw new ImportException('Search result did not return a ProductDTO instance.'); } $result->setProduct($product); $result->addLog(sprintf('[%s] found product %s.', $this->getName(), $product->getName())); return $result; } }