diff --git a/CHANGELOG.md b/CHANGELOG.md index d415f0c..7083fbb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 2024-09-30 4.8.9 +* Improvement of customer registration form in loyalty program + ## 2024-09-30 4.8.8 * Fix tests svn externals definitions error diff --git a/VERSION b/VERSION index fd8ccaa..34d6b60 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -4.8.8 +4.8.9 diff --git a/src/include/class-wc-retailcrm-base.php b/src/include/class-wc-retailcrm-base.php index 5d05161..52b8e45 100644 --- a/src/include/class-wc-retailcrm-base.php +++ b/src/include/class-wc-retailcrm-base.php @@ -1167,17 +1167,20 @@ if (!class_exists('WC_Retailcrm_Base')) { $cssPath = plugins_url() . self::ASSETS_DIR . '/css/'; $messagePhone = __('Enter the correct phone number', 'retailcrm'); + $loyaltyTemrs = $this->settings['loyalty_terms'] ?? ''; + $loyaltyPersonal = $this->settings['loyalty_personal'] ?? ''; + wp_register_script($jsScript, $jsScriptsPath . $jsScript . '.js', false, '0.1'); wp_enqueue_script($jsScript, $jsScriptsPath . $jsScript . '.js', '', '', true); wp_localize_script($jsScript, 'loyaltyUrl', $loyaltyUrl); wp_localize_script($jsScript, 'customerId', $userId); wp_localize_script($jsScript, 'messagePhone', $messagePhone); - wp_localize_script($jsScript, 'termsLoyalty', $this->settings['loyalty_terms']); - wp_localize_script($jsScript, 'privacyLoyalty', $this->settings['loyalty_personal']); + wp_localize_script($jsScript, 'termsLoyalty', $loyaltyTemrs); + wp_localize_script($jsScript, 'privacyLoyalty', $loyaltyPersonal); wp_register_style('retailcrm-loyalty-style', $cssPath . 'retailcrm-loyalty-style.css', false, '0.1'); wp_enqueue_style('retailcrm-loyalty-style'); - $result = $this->loyalty->getForm($userId); + $result = $this->loyalty->getForm($userId, $loyaltyTemrs, $loyaltyPersonal); if ([] === $result) { echo '
'. __('Error while retrieving data. Try again later', 'retailcrm') . '
'; diff --git a/src/include/class-wc-retailcrm-loyalty.php b/src/include/class-wc-retailcrm-loyalty.php index ca4ee50..30b22b2 100644 --- a/src/include/class-wc-retailcrm-loyalty.php +++ b/src/include/class-wc-retailcrm-loyalty.php @@ -41,9 +41,16 @@ if (!class_exists('WC_Retailcrm_Loyalty')) : ); } - public function getForm(int $userId) + public function getForm(int $userId, $loyaltyTerms = '', $loyaltyPersonal = '') { $result = []; + $phone = ''; + + $wcCustomer = new WC_Customer($userId); + + if ($wcCustomer instanceof WC_Customer) { + $phone = $wcCustomer->get_billing_phone(); + } try { $response = $this->getLoyaltyAccounts($userId); @@ -68,7 +75,7 @@ if (!class_exists('WC_Retailcrm_Loyalty')) : $result['loyaltyId'] = $loyaltyAccount['id']; } } else { - $result['form'] = $this->loyaltyForm->getRegistrationForm(); + $result['form'] = $this->loyaltyForm->getRegistrationForm($phone, $loyaltyTerms, $loyaltyPersonal); } return $result; @@ -84,6 +91,17 @@ if (!class_exists('WC_Retailcrm_Loyalty')) : ]; try { + $wcCustomer = new WC_Customer($userId); + + if ($wcCustomer instanceof WC_Customer) { + $currentPhone = $wcCustomer->get_billing_phone(); + + if (empty($currentPhone) && $phone !== '') { + $wcCustomer->set_billing_phone($phone); + $wcCustomer->save(); + } + } + $response = $this->apiClient->createLoyaltyAccount($parameters, $site); if (!$response->isSuccessful()) { diff --git a/src/include/components/class-wc-retailcrm-loyalty-form.php b/src/include/components/class-wc-retailcrm-loyalty-form.php index 0e600db..d919aa1 100644 --- a/src/include/components/class-wc-retailcrm-loyalty-form.php +++ b/src/include/components/class-wc-retailcrm-loyalty-form.php @@ -5,15 +5,34 @@ if (!class_exists('WC_Retailcrm_Loyalty')) : class WC_Retailcrm_Loyalty_Form { - public function getRegistrationForm() + public function getRegistrationForm($phone = '', $loyaltyTerms = '', $loyaltyPersonal = '') { + $htmlLoyaltyTerms = $loyaltyTerms !== '' + ? sprintf( + '%s%s.
', + __(' I agree with ', 'retailcrm'), + __('loyalty program terms', 'retailcrm') + ) + : '' + ; + + $htmlLoyaltyPersonal = $loyaltyPersonal !== '' + ? sprintf( + '%s%s.
', + __(' I agree with ', 'retailcrm'), + __('terms of personal data processing', 'retailcrm') + ) + : '' + ; + + return sprintf( '