<?php
namespace Uandi\UandiEfbErpSynchronization\Service\Document\Lists;
use Monolog\Logger;
use Shopware\Core\System\SalesChannel\SalesChannelContext;
use Uandi\UandiEfbErpSynchronization\Service\ApiConnectionServiceInterface;
class UkcaDeclaration
{
const REQUEST_NAME = 'DocumentListRequest';
const DOCUMENT_TYPE = '7000';
private ApiConnectionServiceInterface $soapService;
private Logger $logger;
public function __construct(
ApiConnectionServiceInterface $soapService,
Logger $logger
) {
$this->soapService = $soapService;
$this->logger = $logger;
}
/**
* Get relevant information for the pdf generation of UKCA declaration of conformity.
* Input: customer number, product numbers.
* Output: attributes ROHS, EMV, NSR; list of products with rough descriptions
*
* @param string $customerNumber
* @param array $productNumbers
* @param SalesChannelContext $context
* @return array
*/
public function getUkcaAttributes(
string $customerNumber,
array $productNumbers,
SalesChannelContext $context
): array {
$response = $this->soapService->execute(
$this->generateErpRequest($customerNumber, $productNumbers),
self::REQUEST_NAME,
$context->getSalesChannelId()
);
if ($response === [] || !array_key_exists('document_list', $response)) {
$this->logger->error(
sprintf(
'API Response empty, did you supply a customer number? Customer: %s, products: %s',
$customerNumber,
implode('|', $productNumbers)
)
);
return [];
}
if (array_key_exists('error', $response)) {
$this->logger->error('API Response: ' . $response['error']['error_text']);
return [];
}
return $response['document_list'][0];
}
private function generateErpRequest(string $customerNumber, array $productNumbers): array
{
return [
"customer_number" => $customerNumber,
"document_type" => self::DOCUMENT_TYPE,
"source" => "EFB",
"language" => "de",
"product_list" => $productNumbers
];
}
}