Skip to content
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
d6f73ba
Merge branch 'trunk' of github.com:shopware/SwagMigrationAssistant in…
DennisGarding Sep 23, 2025
3cf6d32
Merge branch 'feature/migration-logging-refactor' of github.com:shopw…
DennisGarding Sep 24, 2025
5ad6e0a
Merge branch 'feature/migration-logging-refactor' of github.com:shopw…
DennisGarding Oct 23, 2025
0bc9d86
Merge branch 'feature/migration-logging-refactor' of github.com:shopw…
DennisGarding Oct 28, 2025
b028a3b
chore: remove validation from converter
DennisGarding Oct 30, 2025
e00d8dd
Merge branch 'feature/migration-logging-refactor' of github.com:shopw…
DennisGarding Oct 31, 2025
0ed185f
Fix cs
DennisGarding Oct 31, 2025
3b6460f
Fix phpstan issues
DennisGarding Oct 31, 2025
ab6740a
Fix cs
DennisGarding Oct 31, 2025
6e56dbd
Fix test
DennisGarding Oct 31, 2025
dd94888
Fix test
DennisGarding Oct 31, 2025
4e77b2f
Fix test
DennisGarding Oct 31, 2025
9c7a195
Remove comment
DennisGarding Oct 31, 2025
9c5961e
Merge branch 'feature/migration-logging-refactor' of github.com:shopw…
DennisGarding Nov 3, 2025
3c94193
Fix issues
DennisGarding Nov 3, 2025
92419d8
Merge branch 'feature/migration-logging-refactor' of github.com:shopw…
DennisGarding Nov 11, 2025
302c381
Change
DennisGarding Nov 11, 2025
7447c4f
Fix test
DennisGarding Nov 11, 2025
fbb83e2
Fix test
DennisGarding Nov 11, 2025
408ad3a
Add keys to dataprovider
DennisGarding Nov 12, 2025
9ff744f
Fix cs
DennisGarding Nov 12, 2025
7d5a29e
Fix comments
DennisGarding Nov 12, 2025
b8af7d3
Fix comments
DennisGarding Nov 12, 2025
fbe3e52
Fix tests
DennisGarding Nov 13, 2025
da4ff75
Merge branch 'feature/migration-logging-refactor' of github.com:shopw…
DennisGarding Nov 24, 2025
a1f6d55
Early return (null) in converter
DennisGarding Nov 24, 2025
3a53195
Merge branch 'feature/migration-logging-refactor' of github.com:shopw…
DennisGarding Dec 1, 2025
2893e6a
fix code style
DennisGarding Dec 1, 2025
adeb9bb
fix cs and tests
DennisGarding Dec 2, 2025
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: 0 additions & 1 deletion src/DependencyInjection/shopware.xml
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,6 @@

<service id="SwagMigrationAssistant\Profile\Shopware\Converter\LanguageConverter"
parent="SwagMigrationAssistant\Profile\Shopware\Converter\ShopwareConverter" abstract="true">
<argument type="service" id="SwagMigrationAssistant\Migration\Mapping\Lookup\LanguageLookup"/>
<argument type="service" id="SwagMigrationAssistant\Migration\Mapping\Lookup\LocaleLookup"/>
</service>

Expand Down
1 change: 1 addition & 0 deletions src/DependencyInjection/shopware6.xml
Original file line number Diff line number Diff line change
Expand Up @@ -972,6 +972,7 @@
parent="SwagMigrationAssistant\Migration\Writer\AbstractWriter">
<argument type="service" id="Shopware\Core\Framework\DataAbstractionLayer\Write\EntityWriter"/>
<argument type="service" id="Shopware\Core\Content\Product\SalesChannel\Sorting\ProductSortingDefinition"/>
<argument type="service" id="SwagMigrationAssistant\Migration\Mapping\Lookup\ProductSortingLookup"/>
<tag name="shopware.migration.writer"/>
</service>

Expand Down
1 change: 1 addition & 0 deletions src/DependencyInjection/writer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
parent="SwagMigrationAssistant\Migration\Writer\AbstractWriter">
<argument type="service" id="Shopware\Core\Framework\DataAbstractionLayer\Write\EntityWriter"/>
<argument type="service" id="Shopware\Core\System\Language\LanguageDefinition"/>
<argument type="service" id="SwagMigrationAssistant\Migration\Mapping\Lookup\LanguageLookup"/>
<tag name="shopware.migration.writer"/>
</service>

Expand Down
28 changes: 28 additions & 0 deletions src/Migration/Writer/LanguageWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,42 @@

namespace SwagMigrationAssistant\Migration\Writer;

use Shopware\Core\Framework\Context;
use Shopware\Core\Framework\DataAbstractionLayer\EntityDefinition;
use Shopware\Core\Framework\DataAbstractionLayer\EntityWriteResult;
use Shopware\Core\Framework\DataAbstractionLayer\Write\EntityWriterInterface;
use Shopware\Core\Framework\Log\Package;
use SwagMigrationAssistant\Migration\DataSelection\DefaultEntities;
use SwagMigrationAssistant\Migration\Mapping\Lookup\LanguageLookup;

#[Package('fundamentals@after-sales')]
class LanguageWriter extends AbstractWriter
{
public function __construct(
protected EntityWriterInterface $entityWriter,
protected EntityDefinition $definition,
protected readonly LanguageLookup $languageLookup,
) {
parent::__construct($this->entityWriter, $this->definition);
}

public function supports(): string
{
return DefaultEntities::LANGUAGE;
}

/**
* @param array<mixed> $data
*
* @return array<string, array<EntityWriteResult>>
*/
public function writeData(array $data, Context $context): array
{
// do not create languages which already exists
$data = array_filter($data, function ($value) use ($context) {
return $this->languageLookup->get($value['locale'], $context) === null;
});

return parent::writeData($data, $context);
}
}
5 changes: 5 additions & 0 deletions src/Migration/Writer/SeoUrlWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ public function supports(): string
*/
public function writeData(array $data, Context $context): array
{
// only modified should be written
$data = \array_filter($data, static function ($value) {
return !(isset($value['isModified']) && $value['isModified'] === false);
});

$writeResults = [];

$context->addExtension(
Expand Down
33 changes: 13 additions & 20 deletions src/Profile/Shopware/Converter/CategoryConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
use SwagMigrationAssistant\Exception\MigrationException;
use SwagMigrationAssistant\Migration\Converter\ConvertStruct;
use SwagMigrationAssistant\Migration\DataSelection\DefaultEntities;
use SwagMigrationAssistant\Migration\Logging\Log\Builder\SwagMigrationLogBuilder;
use SwagMigrationAssistant\Migration\Logging\Log\EmptyNecessaryFieldRunLog;
use SwagMigrationAssistant\Migration\Logging\LoggingServiceInterface;
use SwagMigrationAssistant\Migration\Mapping\Lookup\DefaultCmsPageLookup;
use SwagMigrationAssistant\Migration\Mapping\Lookup\LanguageLookup;
Expand All @@ -37,7 +35,7 @@ abstract class CategoryConverter extends ShopwareConverter

protected string $oldCategoryId;

protected string $locale;
protected ?string $locale = null;

protected string $runId;

Expand Down Expand Up @@ -84,19 +82,13 @@ public function convert(
$this->connectionId = $connection->getId();
$this->connectionName = $connection->getName();

if (!isset($data['_locale'])) {
$this->loggingService->addLogEntry(
SwagMigrationLogBuilder::fromMigrationContext($migrationContext)
->withEntityName(CategoryDefinition::ENTITY_NAME)
->withFieldSourcePath('_locale')
->withSourceData($data)
->build(EmptyNecessaryFieldRunLog::class)
);
$converted = [];

return new ConvertStruct(null, $data);
if (isset($data['_locale'])) {
$this->locale = $data['_locale'];
} else {
$this->locale = null;
}
$this->locale = $data['_locale'];
$converted = [];

$cmsPageUuid = $this->defaultCmsPageLookup->get($context);
if ($cmsPageUuid !== null) {
Expand Down Expand Up @@ -244,8 +236,7 @@ protected function setGivenCategoryTranslation(array &$data, array &$converted):
}

$locale = $language->getLocale();

if ($locale === null || $locale->getCode() === $data['_locale']) {
if (!isset($data['_locale']) || $locale?->getCode() === $data['_locale']) {
return;
}

Expand Down Expand Up @@ -364,10 +355,12 @@ protected function addMediaTranslation(array &$media, array $data): void
$localeTranslation['id'] = $mapping['entityId'];
$this->mappingIds[] = $mapping['id'];

$languageUuid = $this->languageLookup->get($this->locale, $this->context);
if ($languageUuid !== null) {
$localeTranslation['languageId'] = $languageUuid;
$media['translations'][$languageUuid] = $localeTranslation;
if ($this->locale !== null) {
$languageUuid = $this->languageLookup->get($this->locale, $this->context);
if ($languageUuid !== null) {
$localeTranslation['languageId'] = $languageUuid;
$media['translations'][$languageUuid] = $localeTranslation;
}
}
}
}
43 changes: 10 additions & 33 deletions src/Profile/Shopware/Converter/CrossSellingConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,10 @@

namespace SwagMigrationAssistant\Profile\Shopware\Converter;

use Shopware\Core\Content\Product\Aggregate\ProductCrossSelling\ProductCrossSellingDefinition;
use Shopware\Core\Framework\Context;
use Shopware\Core\Framework\Log\Package;
use SwagMigrationAssistant\Migration\Converter\ConvertStruct;
use SwagMigrationAssistant\Migration\DataSelection\DefaultEntities;
use SwagMigrationAssistant\Migration\Logging\Log\AssociationRequiredMissingLog;
use SwagMigrationAssistant\Migration\Logging\Log\Builder\SwagMigrationLogBuilder;
use SwagMigrationAssistant\Migration\MigrationContextInterface;

#[Package('fundamentals@after-sales')]
Expand Down Expand Up @@ -59,36 +56,14 @@ public function convert(array $data, Context $context, MigrationContextInterface
$converted['id'] = $crossSellingMapping['entityId'];

$sourceProductMapping = $this->getProductMapping($data['articleID']);
if ($sourceProductMapping === null) {
$this->loggingService->addLogEntry(
SwagMigrationLogBuilder::fromMigrationContext($migrationContext)
->withEntityName(ProductCrossSellingDefinition::ENTITY_NAME)
->withFieldName('id')
->withFieldSourcePath('articleID')
->withSourceData($data)
->withConvertedData($converted)
->build(AssociationRequiredMissingLog::class)
);

return new ConvertStruct(null, $data);
if ($sourceProductMapping !== null) {
$this->mappingIds[] = $sourceProductMapping['id'];
}
$this->mappingIds[] = $sourceProductMapping['id'];

$relatedProductMapping = $this->getProductMapping($data['relatedarticle']);
if ($relatedProductMapping === null) {
$this->loggingService->addLogEntry(
SwagMigrationLogBuilder::fromMigrationContext($migrationContext)
->withEntityName(ProductCrossSellingDefinition::ENTITY_NAME)
->withFieldName('id')
->withFieldSourcePath('relatedarticle')
->withSourceData($data)
->withConvertedData($converted)
->build(AssociationRequiredMissingLog::class)
);

return new ConvertStruct(null, $data);
if ($relatedProductMapping !== null) {
$this->mappingIds[] = $relatedProductMapping['id'];
}
$this->mappingIds[] = $relatedProductMapping['id'];

if ($data['type'] === DefaultEntities::CROSS_SELLING_SIMILAR) {
$converted['name'] = 'Similar Items';
Expand All @@ -105,15 +80,17 @@ public function convert(array $data, Context $context, MigrationContextInterface

$converted['type'] = 'productList';
$converted['active'] = true;
$converted['productId'] = $sourceProductMapping['entityId'];
$converted['assignedProducts'] = [
[
'id' => $relationMapping['entityId'],
'position' => $data['position'],
'productId' => $relatedProductMapping['entityId'],
'id' => $relationMapping['entityId'] ?? null,
'position' => $data['position'] ?? null,
'productId' => $relatedProductMapping['entityId'] ?? null,
],
];

if (isset($sourceProductMapping['entityId'])) {
$converted['productId'] = $sourceProductMapping['entityId'];
}
unset(
$data['type'],
$data['id'],
Expand Down
17 changes: 0 additions & 17 deletions src/Profile/Shopware/Converter/CurrencyConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,23 +49,6 @@ public function convert(array $data, Context $context, MigrationContextInterface
$connection = $migrationContext->getConnection();
$this->connectionId = $connection->getId();

$currencyUuid = $this->currencyLookup->get($data['currency'], $context);
if ($currencyUuid !== null) {
$currencyMapping = $this->mappingService->getMapping($this->connectionId, DefaultEntities::CURRENCY, $data['currency'], $context);
if ($currencyMapping === null) {
$this->mappingService->createMapping(
$this->connectionId,
DefaultEntities::CURRENCY,
$data['currency'],
$this->checksum,
null,
$currencyUuid
);
}

return new ConvertStruct(null, $data);
}

$converted = [];
$this->mainMapping = $this->mappingService->getOrCreateMapping(
$this->connectionId,
Expand Down
53 changes: 18 additions & 35 deletions src/Profile/Shopware/Converter/CustomerConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
use SwagMigrationAssistant\Migration\MigrationContextInterface;
use SwagMigrationAssistant\Profile\Shopware\Premapping\PaymentMethodReader;
use SwagMigrationAssistant\Profile\Shopware\Premapping\SalutationReader;
use Symfony\Component\Validator\Constraints\Email;
use Symfony\Component\Validator\Validator\ValidatorInterface;

#[Package('fundamentals@after-sales')]
Expand Down Expand Up @@ -165,19 +164,18 @@ public function convert(
$converted['customerNumber'] = 'number-' . $this->oldCustomerId;
}

$mapping = $this->mappingService->getMapping(
$this->connectionId,
DefaultEntities::CUSTOMER_GROUP,
$data['customerGroupId'] ?? '',
$context
);

if (\is_array($mapping) && \array_key_exists('entityId', $mapping)) {
$converted['groupId'] = $mapping['entityId'];
$this->mappingIds[] = $mapping['id'];
if (isset($data['customerGroupId'])) {
$mapping = $this->mappingService->getMapping(
$this->connectionId,
DefaultEntities::CUSTOMER_GROUP,
$data['customerGroupId'],
$context
);
if ($mapping !== null) {
$converted['groupId'] = $mapping['entityId'];
$this->mappingIds[] = $mapping['id'];
}
unset($data['customerGroupId'], $data['customergroup']);
} else {
$converted['groupId'] = null;
}

if (isset($data['defaultpayment']['id'])) {
Expand All @@ -198,19 +196,15 @@ public function convert(
$this->context
);

if (\is_array($mapping) && \array_key_exists('entityId', $mapping)) {
if ($mapping !== null) {
$converted['defaultPaymentMethodId'] = $mapping['entityId'];
$this->mappingIds[] = $mapping['id'];
} else {
$converted['defaultPaymentMethodId'] = null;
}
}

$salutationUuid = $this->getSalutation($data['salutation']);
if ($salutationUuid !== null) {
$converted['salutationId'] = $salutationUuid;
} else {
$converted['salutationId'] = null;
}

if (isset($data['addresses']) && isset($this->mainMapping['entityId'])) {
Expand Down Expand Up @@ -404,13 +398,13 @@ protected function applyAddresses(array &$originalData, array &$converted, strin
$converted['addresses'] = $addresses;

// No valid default billing and shipping address was converted, so use the first valid one as default
$this->checkUnsetDefaultShippingAndDefaultBillingAddress($originalData, $converted, $customerUuid, $addresses);
$this->checkUnsetDefaultShippingAndDefaultBillingAddress($originalData, $converted, $addresses);

// No valid default shipping address was converted, but the default billing address is valid
$this->checkUnsetDefaultShippingAddress($originalData, $converted, $customerUuid);
$this->checkUnsetDefaultShippingAddress($originalData, $converted);

// No valid default billing address was converted, but the default shipping address is valid
$this->checkUnsetDefaultBillingAddress($originalData, $converted, $customerUuid);
$this->checkUnsetDefaultBillingAddress($originalData, $converted);
}

/**
Expand Down Expand Up @@ -610,7 +604,7 @@ protected function applyCountryStateTranslation(array &$state, array $data): voi
* @param array<string, mixed> $converted
* @param array<int, array<string, mixed>> $addresses
*/
protected function checkUnsetDefaultShippingAndDefaultBillingAddress(array &$originalData, array &$converted, string $customerUuid, array $addresses): void
protected function checkUnsetDefaultShippingAndDefaultBillingAddress(array &$originalData, array &$converted, array $addresses): void
{
if (!isset($converted['defaultBillingAddressId']) && !isset($converted['defaultShippingAddressId'])) {
$converted['defaultBillingAddressId'] = $addresses[0]['id'];
Expand All @@ -636,7 +630,7 @@ protected function checkUnsetDefaultShippingAndDefaultBillingAddress(array &$ori
* @param array<string, mixed> $originalData
* @param array<string, mixed> $converted
*/
protected function checkUnsetDefaultShippingAddress(array &$originalData, array &$converted, string $customerUuid): void
protected function checkUnsetDefaultShippingAddress(array &$originalData, array &$converted): void
{
if (!isset($converted['defaultShippingAddressId']) && isset($converted['defaultBillingAddressId'])) {
$converted['defaultShippingAddressId'] = $converted['defaultBillingAddressId'];
Expand All @@ -657,7 +651,7 @@ protected function checkUnsetDefaultShippingAddress(array &$originalData, array
* @param array<string, mixed> $originalData
* @param array<string, mixed> $converted
*/
protected function checkUnsetDefaultBillingAddress(array &$originalData, array &$converted, string $customerUuid): void
protected function checkUnsetDefaultBillingAddress(array &$originalData, array &$converted): void
{
if (!isset($converted['defaultBillingAddressId']) && isset($converted['defaultShippingAddressId'])) {
$converted['defaultBillingAddressId'] = $converted['defaultShippingAddressId'];
Expand Down Expand Up @@ -700,17 +694,6 @@ protected function getSalutation(string $salutation): ?string
return $mapping['entityId'];
}

protected function checkEmailValidity(string $email): bool
{
$constraint = new Email();
$errors = $this->validator->validate(
$email,
$constraint
);

return \count($errors) === 0;
}

/**
* If the customer's default billing address or default shipping address contains a company,
* the account type is business, else private.
Expand Down
Loading
Loading