Skip to content

Commit

Permalink
MOL-1287: do not overwrite exisisting technical name (#678)
Browse files Browse the repository at this point in the history
* MOL-1287: do not overwrite exisisting technical name

* MOL-1287: technical name in 6.5.7

* MOL-1287: cs and stan fix

---------

Co-authored-by: Vitalij Mik <[email protected]>
  • Loading branch information
BlackScorp and Vitalij Mik authored Jan 10, 2024
1 parent 37d176b commit 1491af3
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions src/Service/PaymentMethodService.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ public function addPaymentMethods(array $paymentMethods, Context $context): void
$existingPaymentMethod = null;
}

$technicalName = '';

if ($existingPaymentMethod instanceof PaymentMethodEntity) {

Expand All @@ -183,19 +184,17 @@ public function addPaymentMethods(array $paymentMethods, Context $context): void
'name' => $existingPaymentMethod->getName(),
];

# starting with Shopware 6.5.7.0 this has to be filled out
# so that you can still save the payment method in the administration
if ($this->versionCompare->gte('6.5.7.0')) {
$paymentMethodData['technicalName'] = self::TECHNICAL_NAME_PREFIX . $mollieName;
# we do a string cast here, since getTechnicalName will be not nullable in the future
$technicalName = (string)$existingPaymentMethod->getTechnicalName(); /** @phpstan-ignore-line */
}

$upsertData[] = $paymentMethodData;
} else {
# let's create a full parameter list of everything
# that our new payment method needs to have

$mollieName = $paymentMethod['description'];


$paymentMethodData = [
'handlerIdentifier' => $paymentMethod['handler'],
'pluginId' => $pluginId,
Expand All @@ -209,15 +208,19 @@ public function addPaymentMethods(array $paymentMethods, Context $context): void
'mollie_payment_method_name' => $mollieName
],
];
}

# starting with Shopware 6.5.7.0 this has to be filled out
# so that you can still save the payment method in the administration
if ($this->versionCompare->gte('6.5.7.0')) {
$paymentMethodData['technicalName'] = self::TECHNICAL_NAME_PREFIX . $mollieName;
}
if (mb_strlen($technicalName) > 0) {
$technicalName = self::TECHNICAL_NAME_PREFIX . $mollieName;
}

$upsertData[] = $paymentMethodData;
# starting with Shopware 6.5.7.0 this has to be filled out
# so that you can still save the payment method in the administration
if ($this->versionCompare->gte('6.5.7.0')) {
$paymentMethodData['technicalName'] = $technicalName;
}

$upsertData[] = $paymentMethodData;
}

if (count($upsertData) > 0) {
Expand Down

0 comments on commit 1491af3

Please sign in to comment.