Commit d8f9e97d authored by Ivan Ruzak's avatar Ivan Ruzak Committed by Jakub Piasecki
Browse files

Issue #3311833 by teodorakis, zaporylie: Make "FullName" mapping conditional...

Issue #3311833 by teodorakis, zaporylie: Make "FullName" mapping conditional so we don't end up we duplicate names for private customers
parent cf0fdf8c
Loading
Loading
Loading
Loading
+11 −1
Original line number Diff line number Diff line
@@ -373,7 +373,6 @@ class SveaCheckout extends OffsitePaymentGatewayBase implements SveaCheckoutInte
   */
  protected function populateProfile(ProfileInterface $profile, array $address) {
    $mapping = [
      // For B2B customers "FullName" field contains the company name.
      'FullName' => 'organization',
      'FirstName' => 'given_name',
      'LastName' => 'family_name',
@@ -383,6 +382,17 @@ class SveaCheckout extends OffsitePaymentGatewayBase implements SveaCheckoutInte
      'StreetAddress' => 'address_line1',
      'StreetAddress2' => 'address_line2',
    ];

    // For B2B customers "FullName" field contains the company name, in other
    // cases it will just create duplicated data for first/last names in
    // billing/shipping profiles. Omit such cases.
    if ($address['FirstName'] || $address['LastName']) {
      $full_name = implode(' ', [$address['FirstName'], $address['LastName']]);
      if ($full_name == $address['FullName']) {
        unset($mapping['FullName']);
      }
    }

    foreach ($address as $key => $value) {
      if (isset($mapping[$key])) {
        $profile->address->{$mapping[$key]} = $value;