Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/DependencyInjection/shopware.xml
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@
<argument type="service" id="SwagMigrationAssistant\Migration\Media\MediaFileService"/>
<argument type="service" id="SwagMigrationAssistant\Migration\Mapping\Lookup\MediaDefaultFolderLookup"/>
<argument type="service" id="SwagMigrationAssistant\Migration\Mapping\Lookup\DocumentTypeLookup"/>
<argument type="service" id="SwagMigrationAssistant\Migration\Mapping\Lookup\GlobalDocumentBaseConfigLookup"/>
</service>

<service id="SwagMigrationAssistant\Profile\Shopware\Converter\CustomerGroupAttributeConverter"
Expand Down
21 changes: 20 additions & 1 deletion src/Migration/Mapping/Lookup/GlobalDocumentBaseConfigLookup.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
class GlobalDocumentBaseConfigLookup implements ResetInterface
{
/**
* @var array<string, string|null>
* @var array<string, array<string, mixed>|string|null>
*/
private array $cache = [];

Expand All @@ -36,7 +36,7 @@
public function get(string $documentTypeId, Context $context): ?string
{
if (\array_key_exists($documentTypeId, $this->cache)) {
return $this->cache[$documentTypeId];

Check failure on line 39 in src/Migration/Mapping/Lookup/GlobalDocumentBaseConfigLookup.php

View workflow job for this annotation

GitHub Actions / phpstan

Method SwagMigrationAssistant\Migration\Mapping\Lookup\GlobalDocumentBaseConfigLookup::get() should return string|null but returns array<string, mixed>|string|null.
}

$criteria = new Criteria();
Expand All @@ -51,6 +51,25 @@
return $baseConfigId;
}

/**
* @return array<string, mixed>|null
*/
public function getBaseConfig(string $baseConfigId, Context $context): ?array
{
if (\array_key_exists($baseConfigId, $this->cache)) {
return $this->cache[$baseConfigId];

Check failure on line 60 in src/Migration/Mapping/Lookup/GlobalDocumentBaseConfigLookup.php

View workflow job for this annotation

GitHub Actions / phpstan

Method SwagMigrationAssistant\Migration\Mapping\Lookup\GlobalDocumentBaseConfigLookup::getBaseConfig() should return array<string, mixed>|null but returns array<string, mixed>|string|null.
}

$criteria = new Criteria([$baseConfigId]);

$baseConfig = $this->documentBaseConfigRepository->search($criteria, $context)->first();

$config = $baseConfig?->getConfig();
$this->cache[$baseConfigId] = $config;

return $config;
}

public function reset(): void
{
$this->cache = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public function process(
if ($currentDataSet === null) {
try {
$currentDataSet = $this->dataSetRegistry->getDataSet($migrationContext, $mediaFile['entity']);
$migrationContext->setDataset($currentDataSet);
} catch (DataSetNotFoundException $e) {
$this->logDataSetNotFoundException($migrationContext, $mediaFile);

Expand Down
2 changes: 2 additions & 0 deletions src/Migration/MigrationContextInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,6 @@ public function getLimit(): int;
public function getGateway(): GatewayInterface;

public function setGateway(GatewayInterface $gateway): void;

public function setDataset(DataSet $dataSet): void;
}
30 changes: 24 additions & 6 deletions src/Profile/Shopware/Converter/OrderDocumentConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use SwagMigrationAssistant\Migration\Logging\Log\EmptyNecessaryFieldRunLog;
use SwagMigrationAssistant\Migration\Logging\LoggingServiceInterface;
use SwagMigrationAssistant\Migration\Mapping\Lookup\DocumentTypeLookup;
use SwagMigrationAssistant\Migration\Mapping\Lookup\GlobalDocumentBaseConfigLookup;
use SwagMigrationAssistant\Migration\Mapping\Lookup\MediaDefaultFolderLookup;
use SwagMigrationAssistant\Migration\Mapping\MappingServiceInterface;
use SwagMigrationAssistant\Migration\Media\MediaFileServiceInterface;
Expand All @@ -45,6 +46,7 @@
protected MediaFileServiceInterface $mediaFileService,
protected readonly MediaDefaultFolderLookup $mediaFolderLookup,
protected readonly DocumentTypeLookup $documentTypeLookup,
protected readonly GlobalDocumentBaseConfigLookup $globalDocumentBaseConfigLookup,
) {
parent::__construct($mappingService, $loggingService);
}
Expand Down Expand Up @@ -143,22 +145,23 @@
$converted['fileType'] = FileTypes::PDF;
$converted['static'] = true;
$converted['deepLinkCode'] = Random::getAlphanumericString(32);
$converted['config'] = [];

$documentType = $this->getDocumentType($data['documenttype']);

$converted['documentType'] = $documentType;
unset($data['documenttype']);

$converted['config'] = $this->getBaseDocumentTypeConfig($documentType['id'], $context);
if (isset($data['docID'])) {
$converted['config']['documentNumber'] = $data['docID'];

if (isset($data['documenttype']['key']) && $data['documenttype']['key'] === 'invoice') {

Check failure on line 158 in src/Profile/Shopware/Converter/OrderDocumentConverter.php

View workflow job for this annotation

GitHub Actions / phpstan

Result of && is always false.

Check failure on line 158 in src/Profile/Shopware/Converter/OrderDocumentConverter.php

View workflow job for this annotation

GitHub Actions / phpstan

Offset 'documenttype' on non-empty-array<mixed, mixed> in isset() does not exist.
$converted['config']['custom']['invoiceNumber'] = $data['docID'];
}

unset($data['docID']);
}

$documentType = $this->getDocumentType($data['documenttype']);

$converted['documentType'] = $documentType;
unset($data['documenttype']);

if (isset($data['attributes'])) {
$converted['customFields'] = $this->getAttributes($data['attributes'], DefaultEntities::ORDER_DOCUMENT, $this->connectionName, ['id', 'documentID'], $this->context);
}
Expand Down Expand Up @@ -223,6 +226,21 @@
return $documentType;
}

protected function getBaseDocumentTypeConfig(string $documentTypeId, Context $context): array

Check failure on line 229 in src/Profile/Shopware/Converter/OrderDocumentConverter.php

View workflow job for this annotation

GitHub Actions / phpstan

Method SwagMigrationAssistant\Profile\Shopware\Converter\OrderDocumentConverter::getBaseDocumentTypeConfig() return type has no value type specified in iterable type array.
{
$documentConfigId = $this->globalDocumentBaseConfigLookup->get($documentTypeId, $context);
if ($documentConfigId === null) {
return [];
}

$documentConfig = $this->globalDocumentBaseConfigLookup->getBaseConfig($documentConfigId, $context);
if ($documentConfig === null) {
return [];
}

return $documentConfig;
}

/**
* @param array<mixed> $data
*
Expand Down
Loading