custom/plugins/UandiEfbErpSynchronization/src/Service/Document/Lists/DeclarationOfConformity.php line 40

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Uandi\UandiEfbErpSynchronization\Service\Document\Lists;
  3. use Monolog\Logger;
  4. use Shopware\Core\System\SalesChannel\SalesChannelContext;
  5. use Uandi\UandiEfbErpSynchronization\Service\ApiConnectionServiceInterface;
  6. class DeclarationOfConformity
  7. {
  8.     const REQUEST_NAME 'DocumentListRequest';
  9.     const DOCUMENT_TYPE '6000';
  10.     private ApiConnectionServiceInterface $soapService;
  11.     private Logger $logger;
  12.     public function __construct(
  13.         ApiConnectionServiceInterface $soapService,
  14.         Logger $logger
  15.     ) {
  16.         $this->soapService $soapService;
  17.         $this->logger $logger;
  18.     }
  19.     /**
  20.      * Get relevant information for the pdf generation of declaration of conformity.
  21.      * Input: customer number, product numbers.
  22.      * Output: attributes ROHS, EMV, NSR; list of products with rough descriptions
  23.      *
  24.      * @param string $customerNumber
  25.      * @param array $productNumbers
  26.      * @param SalesChannelContext $context
  27.      * @return array
  28.      */
  29.     public function getConformityDeclarationAttributes(
  30.         string $customerNumber,
  31.         array $productNumbers,
  32.         SalesChannelContext $context
  33.     ): array {
  34.         $response $this->soapService->execute(
  35.             $this->generateErpRequest($customerNumber$productNumbers),
  36.             self::REQUEST_NAME,
  37.             $context->getSalesChannelId()
  38.         );
  39.         if ($response === [] || !array_key_exists('document_list'$response)) {
  40.             $this->logger->error(
  41.                 sprintf(
  42.                     'API Response empty, did you supply a customer number? Customer: %s, products: %s',
  43.                     $customerNumber,
  44.                     implode('|'$productNumbers)
  45.                 )
  46.             );
  47.             return [];
  48.         }
  49.         if (array_key_exists('error'$response)) {
  50.             $this->logger->error('API Response: ' $response['error']['error_text']);
  51.             return [];
  52.         }
  53.         return $response['document_list'][0];
  54.     }
  55.     private function generateErpRequest(string $customerNumber, array $productNumbers): array
  56.     {
  57.         return [
  58.             "customer_number" => $customerNumber,
  59.             "document_type" => self::DOCUMENT_TYPE,
  60.             "source" => "EFB",
  61.             "language" => "de",
  62.             "product_list" => $productNumbers
  63.         ];
  64.     }
  65. }