77
88namespace SwagMigrationAssistant \Profile \Shopware \Converter ;
99
10+ use Shopware \Core \Checkout \Customer \Aggregate \CustomerAddress \CustomerAddressDefinition ;
11+ use Shopware \Core \Checkout \Customer \CustomerDefinition ;
1012use Shopware \Core \Defaults ;
1113use Shopware \Core \Framework \Context ;
1214use Shopware \Core \Framework \DataAbstractionLayer \EntityRepository ;
@@ -107,17 +109,25 @@ public function convert(
107109 $ fields = $ this ->checkForEmptyRequiredDataFields ($ data , $ this ->requiredDataFieldKeys );
108110
109111 if (!empty ($ fields )) {
110- $ this ->loggingService ->addLogEntry ( // TODO: add optional fields
111- SwagMigrationLogBuilder::fromMigrationContext ($ migrationContext )
112+ $ this ->loggingService ->addLogForEach (
113+ $ fields ,
114+ fn (string $ key ) => SwagMigrationLogBuilder::fromMigrationContext ($ migrationContext )
115+ ->withEntityName (CustomerDefinition::ENTITY_NAME )
116+ ->withFieldSourcePath ($ key )
117+ ->withSourceData ($ data )
112118 ->build (EmptyNecessaryFieldRunLog::class)
113119 );
114120
115121 return new ConvertStruct (null , $ oldData );
116122 }
117123
118124 if (!$ this ->checkEmailValidity ($ data ['email ' ])) {
119- $ this ->loggingService ->addLogEntry ( // TODO: add optional fields
125+ $ this ->loggingService ->addLogEntry (
120126 SwagMigrationLogBuilder::fromMigrationContext ($ migrationContext )
127+ ->withEntityName (CustomerDefinition::ENTITY_NAME )
128+ ->withFieldName ('email ' )
129+ ->withFieldSourcePath ('email ' )
130+ ->withSourceData ($ data )
121131 ->build (InvalidEmailAddressLog::class)
122132 );
123133
@@ -227,8 +237,13 @@ public function convert(
227237 );
228238
229239 if ($ mapping === null ) {
230- $ this ->loggingService ->addLogEntry ( // TODO: add optional fields
240+ $ this ->loggingService ->addLogEntry (
231241 SwagMigrationLogBuilder::fromMigrationContext ($ migrationContext )
242+ ->withEntityName (CustomerDefinition::ENTITY_NAME )
243+ ->withFieldName ('defaultPaymentMethodId ' )
244+ ->withFieldSourcePath ('default_payment_method ' )
245+ ->withSourceData ($ data )
246+ ->withConvertedData ($ converted )
232247 ->build (EmptyNecessaryFieldRunLog::class)
233248 );
234249
@@ -284,11 +299,30 @@ public function convert(
284299 $ returnData = null ;
285300 }
286301
287- if (!isset ($ converted ['defaultBillingAddressId ' ], $ converted [ ' defaultShippingAddressId ' ] )) {
302+ if (!isset ($ converted ['defaultBillingAddressId ' ])) {
288303 $ this ->mappingService ->deleteMapping ($ converted ['id ' ], $ this ->connectionId , $ this ->context );
289304
290- $ this ->loggingService ->addLogEntry ( // TODO: add optional fields
305+ $ this ->loggingService ->addLogEntry (
291306 SwagMigrationLogBuilder::fromMigrationContext ($ migrationContext )
307+ ->withEntityName (CustomerDefinition::ENTITY_NAME )
308+ ->withFieldName ('defaultBillingAddressId ' )
309+ ->withFieldSourcePath ('default_billing_address_id ' )
310+ ->withSourceData ($ data )
311+ ->build (EmptyNecessaryFieldRunLog::class)
312+ );
313+
314+ return new ConvertStruct (null , $ oldData );
315+ }
316+
317+ if (!isset ($ converted ['defaultShippingAddressId ' ])) {
318+ $ this ->mappingService ->deleteMapping ($ converted ['id ' ], $ this ->connectionId , $ this ->context );
319+
320+ $ this ->loggingService ->addLogEntry (
321+ SwagMigrationLogBuilder::fromMigrationContext ($ migrationContext )
322+ ->withEntityName (CustomerDefinition::ENTITY_NAME )
323+ ->withFieldName ('defaultShippingAddressId ' )
324+ ->withFieldSourcePath ('default_shipping_address_id ' )
325+ ->withSourceData ($ data )
292326 ->build (EmptyNecessaryFieldRunLog::class)
293327 );
294328
@@ -332,8 +366,12 @@ protected function getDefaultPaymentMethod(array $originalData): ?string
332366 );
333367
334368 if ($ paymentMethodMapping === null ) {
335- $ this ->loggingService ->addLogEntry ( // TODO: add optional fields
369+ $ this ->loggingService ->addLogEntry (
336370 SwagMigrationLogBuilder::fromMigrationContext ($ this ->migrationContext )
371+ ->withEntityName (CustomerDefinition::ENTITY_NAME )
372+ ->withFieldName ('defaultPaymentMethodId ' )
373+ ->withFieldSourcePath ('default_payment_method ' )
374+ ->withSourceData ($ originalData )
337375 ->build (UnknownEntityLog::class)
338376 );
339377
@@ -357,8 +395,12 @@ protected function applyAddresses(array &$originalData, array &$converted, strin
357395
358396 $ fields = $ this ->checkForEmptyRequiredDataFields ($ address , $ this ->requiredAddressDataFieldKeys );
359397 if (!empty ($ fields )) {
360- $ this ->loggingService ->addLogEntry ( // TODO: add optional fields
361- SwagMigrationLogBuilder::fromMigrationContext ($ this ->migrationContext )
398+ $ this ->loggingService ->addLogForEach (
399+ $ fields ,
400+ fn (string $ key ) => SwagMigrationLogBuilder::fromMigrationContext ($ this ->migrationContext )
401+ ->withEntityName (CustomerAddressDefinition::ENTITY_NAME )
402+ ->withFieldSourcePath ($ key )
403+ ->withSourceData ($ address )
362404 ->build (EmptyNecessaryFieldRunLog::class)
363405 );
364406
@@ -539,8 +581,12 @@ protected function getCountryState(array $oldAddressData, string $newCountryId):
539581 $ state = ['countryId ' => $ newCountryId ];
540582
541583 if (!isset ($ oldAddressData ['state_id ' ], $ oldAddressData ['country ' ]['countryiso ' ], $ oldAddressData ['state ' ]['shortcode ' ])) {
542- $ this ->loggingService ->addLogEntry ( // TODO: add optional fields
584+ $ this ->loggingService ->addLogEntry (
543585 SwagMigrationLogBuilder::fromMigrationContext ($ this ->migrationContext )
586+ ->withEntityName (CustomerAddressDefinition::ENTITY_NAME )
587+ ->withFieldName ('stateId ' )
588+ ->withFieldSourcePath ('state_id ' )
589+ ->withSourceData ($ oldAddressData )
544590 ->build (UnknownEntityLog::class)
545591 );
546592
@@ -572,8 +618,12 @@ protected function getCountryState(array $oldAddressData, string $newCountryId):
572618 $ oldAddressData ['state ' ]['position ' ],
573619 $ oldAddressData ['state ' ]['active ' ]
574620 )) {
575- $ this ->loggingService ->addLogEntry ( // TODO: add optional fields
621+ $ this ->loggingService ->addLogEntry (
576622 SwagMigrationLogBuilder::fromMigrationContext ($ this ->migrationContext )
623+ ->withEntityName (CustomerAddressDefinition::ENTITY_NAME )
624+ ->withFieldName ('stateId ' )
625+ ->withFieldSourcePath ('state.name ' )
626+ ->withSourceData ($ oldAddressData ['state ' ])
577627 ->build (UnknownEntityLog::class)
578628 );
579629
@@ -643,8 +693,16 @@ protected function checkUnsetDefaultShippingAndDefaultBillingAddress(array &$ori
643693 $ converted ['defaultShippingAddressId ' ] = $ addresses [0 ]['id ' ];
644694 unset($ originalData ['default_billing_address_id ' ], $ originalData ['default_shipping_address_id ' ]);
645695
646- $ this ->loggingService ->addLogEntry ( // TODO: add optional fields
647- SwagMigrationLogBuilder::fromMigrationContext ($ this ->migrationContext )
696+ $ this ->loggingService ->addLogForEach (
697+ [
698+ 'defaultBillingAddressId ' => 'default_billing_address_id ' ,
699+ 'defaultShippingAddressId ' => 'default_shipping_address_id ' ,
700+ ],
701+ fn (string $ key , string $ value ) => SwagMigrationLogBuilder::fromMigrationContext ($ this ->migrationContext )
702+ ->withEntityName (CustomerAddressDefinition::ENTITY_NAME )
703+ ->withFieldName ($ key )
704+ ->withFieldSourcePath ($ value )
705+ ->withSourceData ($ originalData )
648706 ->build (FieldReassignedRunLog::class)
649707 );
650708 }
@@ -660,8 +718,12 @@ protected function checkUnsetDefaultShippingAddress(array &$originalData, array
660718 $ converted ['defaultShippingAddressId ' ] = $ converted ['defaultBillingAddressId ' ];
661719 unset($ originalData ['default_shipping_address_id ' ]);
662720
663- $ this ->loggingService ->addLogEntry ( // TODO: add optional fields
721+ $ this ->loggingService ->addLogEntry (
664722 SwagMigrationLogBuilder::fromMigrationContext ($ this ->migrationContext )
723+ ->withEntityName (CustomerAddressDefinition::ENTITY_NAME )
724+ ->withFieldName ('defaultShippingAddressId ' )
725+ ->withFieldSourcePath ('default_shipping_address_id ' )
726+ ->withSourceData ($ originalData )
665727 ->build (FieldReassignedRunLog::class)
666728 );
667729 }
@@ -677,8 +739,12 @@ protected function checkUnsetDefaultBillingAddress(array &$originalData, array &
677739 $ converted ['defaultBillingAddressId ' ] = $ converted ['defaultShippingAddressId ' ];
678740 unset($ originalData ['default_billing_address_id ' ]);
679741
680- $ this ->loggingService ->addLogEntry ( // TODO: add optional fields
742+ $ this ->loggingService ->addLogEntry (
681743 SwagMigrationLogBuilder::fromMigrationContext ($ this ->migrationContext )
744+ ->withEntityName (CustomerAddressDefinition::ENTITY_NAME )
745+ ->withFieldName ('defaultBillingAddressId ' )
746+ ->withFieldSourcePath ('default_billing_address_id ' )
747+ ->withSourceData ($ originalData )
682748 ->build (FieldReassignedRunLog::class)
683749 );
684750 }
@@ -694,8 +760,12 @@ protected function getSalutation(string $salutation): ?string
694760 );
695761
696762 if ($ mapping === null ) {
697- $ this ->loggingService ->addLogEntry ( // TODO: add optional fields
763+ $ this ->loggingService ->addLogEntry (
698764 SwagMigrationLogBuilder::fromMigrationContext ($ this ->migrationContext )
765+ ->withEntityName (CustomerDefinition::ENTITY_NAME )
766+ ->withFieldName ('salutationId ' )
767+ ->withFieldSourcePath ('salutation ' )
768+ ->withSourceData (['salutation ' => $ salutation ])
699769 ->build (UnknownEntityLog::class)
700770 );
701771
0 commit comments