Skip to content

Commit

Permalink
Merge branch 'release-6.2.5' of github.com:mollie/PrestaShop into PIP…
Browse files Browse the repository at this point in the history
…RES-468/title-multilang
  • Loading branch information
GytisZum committed Dec 10, 2024
2 parents b0d8416 + 3a1627c commit 85aeeb5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
15 changes: 15 additions & 0 deletions mollie.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use Mollie\Repository\PaymentMethodRepositoryInterface;
use Mollie\Service\ExceptionService;
use Mollie\ServiceProvider\LeagueServiceContainerProvider;
use Mollie\Subscription\Config\Config as SubscriptionConfig;
use Mollie\Subscription\Handler\CustomerAddressUpdateHandler;
use Mollie\Subscription\Handler\UpdateSubscriptionCarrierHandler;
use Mollie\Subscription\Install\AttributeInstaller;
Expand Down Expand Up @@ -1124,6 +1125,20 @@ public function hookActionAjaxDieCartControllerDisplayAjaxUpdateBefore(array $pa
return;
}

$isSubscriptionEnabled = Configuration::get(Config::MOLLIE_SUBSCRIPTION_ENABLED);

$groups = Tools::getValue('group');
if (!(bool) $isSubscriptionEnabled || !is_array($groups)) {
return;
}

$subscriptionGroup = Configuration::get(SubscriptionConfig::SUBSCRIPTION_ATTRIBUTE_GROUP);

// Note: groups = ['attribute_group_id => 'attribute_id']
if (!array_key_exists($subscriptionGroup, $groups)) {
return;
}

$response = json_decode($params['value'], true);

$hasError = $response['hasError'] ?? false;
Expand Down
26 changes: 12 additions & 14 deletions src/Provider/PhoneNumberProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,34 +26,32 @@ public function getFromAddress(Address $address)
$phoneNumber = $this->getMobileOrPhone($address);

$phoneNumber = str_replace(' ', '', $phoneNumber);
$phoneNumber = str_replace('+', '', $phoneNumber);

if (empty($phoneNumber) || empty(str_replace(' ', '', $phoneNumber))) {
if (empty($phoneNumber)) {
return null;
}

while ('0' === $phoneNumber[0]) {
$phoneNumber = substr($phoneNumber, 1);

if (empty($phoneNumber) && $phoneNumber !== '0') {
// If the phone number starts with a '+', validate that it's in E.164 format
if ($phoneNumber[0] === '+') {
// E.164 format: +<country_code><number> and should be between 3 and 18 digits total
if (preg_match("/^\+\d{3,18}$/", $phoneNumber)) {
return $phoneNumber; // Return the number if it matches E.164 format
} else {
return null;
}
}

if ('+' !== $phoneNumber[0]) {
$phoneNumber = '+' . $phoneNumber;
}

$regex = "/^\+\d{3,18}$/";
if (1 == preg_match($regex, $phoneNumber)) {
return $phoneNumber;
} else {
// If the phone number starts with '0' (a local number), it's considered invalid in E.164 format
if ($phoneNumber[0] === '0') {
return null;
}

return null;
}

private function getMobileOrPhone(Address $address)
{
// Retrieve either the mobile or regular phone number based on the address format
$addressFormat = new AddressFormat((int) $address->id_country);

if (strpos($addressFormat->format, 'phone_mobile') !== false) {
Expand Down

0 comments on commit 85aeeb5

Please sign in to comment.