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

Issue #3319472 by teodorakis: "FullName" might be stored as vice-versed...

Issue #3319472 by teodorakis: "FullName" might be stored as vice-versed combination of first/last name
parent c2834d34
Loading
Loading
Loading
Loading
+21 −2
Original line number Diff line number Diff line
@@ -388,8 +388,14 @@ class SveaCheckout extends OffsitePaymentGatewayBase implements SveaCheckoutInte
    // 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']) {
      // There might be cases when Svea saves name parts vice versa for some
      // reasons. So check both of possible combinations.
      $name_parts = [$address['FirstName'], $address['LastName']];
      $separator = '';
      if (in_array($this->removeSpaces($address['FullName']), [
        $this->removeSpaces(implode($separator, $name_parts)),
        $this->removeSpaces(implode($separator, array_reverse($name_parts))),
      ])) {
        unset($mapping['FullName']);
      }
    }
@@ -401,6 +407,19 @@ class SveaCheckout extends OffsitePaymentGatewayBase implements SveaCheckoutInte
    }
  }

  /**
   * Removes spaces from the string.
   *
   * @param string $string
   *   String.
   *
   * @return string
   *   String without spaces.
   */
  protected function removeSpaces(string $string): string {
    return preg_replace('/\s+/', '', $string);
  }

  /**
   * {@inheritdoc}
   */