Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.1.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [4.0.5](https://github.com/unzerdev/magento2/compare/4.0.4..4.0.5)
### Fixed
* Fix customerId assignment for guest customers in UPL payment methods
* Fix and improve salutation handling logic

## [4.0.4](https://github.com/unzerdev/magento2/compare/4.0.3..4.0.4)
### Fixed
* Resolve issue with customer company information mapping
Expand Down
53 changes: 40 additions & 13 deletions Helper/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,11 @@ public function createCustomerFromQuote(Quote $quote, string $email, bool $creat
->setFirstname($billingAddress->getFirstname())
->setLastname($billingAddress->getLastname());

$customer->setSalutation($this->getSalutationFromQuote($quote));
$customer->setSalutation(
$this->getSalutationFromPrefix($billingAddress->getPrefix())
?? $this->getSalutationFromQuote($quote)
);

$customer->setEmail($email);
$customer->setPhone($billingAddress->getTelephone());
$customer->setBirthDate($quote->getCustomer()->getDob());
Expand Down Expand Up @@ -419,12 +423,12 @@ public function createCustomerFromOrder(
$customer->setCompany($company);
}

$gender = $order->getCustomerGender();
if ($gender) {
$customer->setSalutation($this->getSalutationFromGender($gender));
} else {
$customer->setSalutation($this->getSalutationFromPayment($order->getPayment()));
}
$customer->setSalutation(
$this->getSalutationFromPrefix($billingAddress->getPrefix())
?? $this->getSalutationFromGender($order->getCustomerGender())
?? $this->getSalutationFromPayment($order->getPayment())
);

$birthDate = $this->getBirthdateFromPayment($order->getPayment());
if ($birthDate) {
$customer->setBirthDate($birthDate);
Expand Down Expand Up @@ -500,7 +504,7 @@ private function updateGatewayAddressFromMagento(
): void {
$street = $this->convertStreetLinesToString($magentoAddress->getStreet());

$gatewayAddress->setName($magentoAddress->getName());
$gatewayAddress->setName($magentoAddress->getFirstname() . ' ' . $magentoAddress->getLastname());
$gatewayAddress->setCity($magentoAddress->getCity());
$gatewayAddress->setCountry($magentoAddress->getCountryId());
$gatewayAddress->setStreet($street);
Expand Down Expand Up @@ -571,6 +575,11 @@ public function updateGatewayCustomerFromOrder(OrderModel $order, Customer $gate
$gatewayCustomer->setFirstname($billingAddress->getFirstname());
$gatewayCustomer->setLastname($billingAddress->getLastname());

$gatewayCustomer->setSalutation(
$this->getSalutationFromPrefix($billingAddress->getPrefix())
?? Salutations::UNKNOWN
);

$gatewayCustomer->setCompany($billingAddress->getCompany());
$gatewayCustomer->setEmail($billingAddress->getEmail());

Expand Down Expand Up @@ -659,9 +668,9 @@ private function validateGatewayAddressAgainstOrderAddress(
*
* @param Quote $quote
*
* @return string
* @return ?string
*/
protected function getSalutationFromQuote(Quote $quote): string
protected function getSalutationFromQuote(Quote $quote): ?string
{
return $this->getSalutationFromGender($quote->getCustomer()->getGender());
}
Expand All @@ -671,9 +680,9 @@ protected function getSalutationFromQuote(Quote $quote): string
*
* @param float|int $gender
*
* @return string
* @return ?string
*/
protected function getSalutationFromGender($gender): string
protected function getSalutationFromGender($gender): ?string
{
switch ($gender) {
case self::GENDER_MALE:
Expand All @@ -683,7 +692,7 @@ protected function getSalutationFromGender($gender): string
$salutation = Salutations::MRS;
break;
default:
$salutation = Salutations::UNKNOWN;
$salutation = null;
}
return $salutation;
}
Expand All @@ -700,6 +709,24 @@ protected function getSalutationFromPayment(InfoInterface $payment): ?string
return $payment->getAdditionalInformation('salutation');
}

/**
* @param ?string $prefix
*
* @return ?string
*/
protected function getSalutationFromPrefix(?string $prefix): ?string
{
$prefix = strtolower(trim($prefix ?? ''));
if (str_starts_with($prefix, 'mrs') || str_starts_with($prefix, 'ms') || str_starts_with($prefix, 'mis')) {
return Salutations::MRS;
}
if (str_starts_with($prefix, 'mr')) {
return Salutations::MR;
}

return null;
}

/**
* Get Birthdate from Payment
*
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "unzerdev/magento2",
"description": "This extension for Magento 2 provides a direct integration of the Unzer payment types to your Magento 2 shop via the Unzer Payment API (PAPI).",
"type": "magento2-module",
"version": "4.0.4",
"version": "4.0.5",
"license": "Apache-2.0",
"require": {
"php": "~7.4.0|~8.1.0|~8.2.0|~8.3.0|~8.4.0",
Expand Down
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Unzer_PAPI" setup_version="4.0.4">
<module name="Unzer_PAPI" setup_version="4.0.5">
<sequence>
<module name="Magento_Checkout"/>
<module name="Magento_Config" />
Expand Down
18 changes: 17 additions & 1 deletion view/frontend/web/js/view/payment/method-renderer/basev2.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,17 +274,33 @@ define(
const shipping = quote.shippingAddress();

const customerId = window.checkoutConfig?.customerData.id || '';
const uniqueCustomerId = `${customerId}_${email}_${shop}`;
const uniqueCustomerId = !quote.guestEmail && customerId ? `${customerId}_${email}_${shop}` : '';

if (unzerCustomerId) {
this.customer = unzerCustomerId;
}

const mapSalutation = (prefix) => {
if (!prefix) return "unknown";

const normalized = prefix.toLowerCase().trim();

if (normalized.startsWith('mrs') || normalized.startsWith('ms') || normalized.startsWith('mis')) {
return 'mrs';
}
if (normalized.startsWith('mr')) {
return 'mr';
}

return "unknown";
};

const customer = {
id: unzerCustomerId || '',
customerId: uniqueCustomerId,
firstname: billing ? billing.firstname : '',
lastname: billing ? billing.lastname : '',
salutation: billing ? mapSalutation(billing.prefix) : 'unknown',
email: email,
...(customerData?.dob ? {birthDate: customerData.dob.split('T')[0]} : {}),
billingAddress: billing ? {
Expand Down
Loading