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( '

%s

-

%s%s.

-

%s%s.

-

+ %s + %s +

', __('To register in the loyalty program, fill in the form:', 'retailcrm'), - __(' I agree with ', 'retailcrm'), - __('loyalty program terms', 'retailcrm'), - __(' I agree with ', 'retailcrm'), - __('terms of personal data processing', 'retailcrm'), + $htmlLoyaltyTerms, + $htmlLoyaltyPersonal, __('Phone', 'retailcrm'), + $phone, __('Send', 'retailcrm'), __('Close', 'retailcrm') ); diff --git a/src/readme.txt b/src/readme.txt index 4aa72dd..8936352 100644 --- a/src/readme.txt +++ b/src/readme.txt @@ -5,7 +5,7 @@ Tags: Интеграция, Simla.com, simla Requires PHP: 7.1 Requires at least: 5.3 Tested up to: 6.5 -Stable tag: 4.8.8 +Stable tag: 4.8.9 License: GPLv1 or later License URI: http://www.gnu.org/licenses/gpl-1.0.html @@ -82,6 +82,9 @@ Asegúrate de tener una clave API específica para cada tienda. Las siguientes i == Changelog == += 4.8.9 = +* Improvement of customer registration form in loyalty program + = 4.8.8 = * Fix tests svn externals definitions error diff --git a/src/retailcrm.php b/src/retailcrm.php index 2e63dbe..1bce89f 100644 --- a/src/retailcrm.php +++ b/src/retailcrm.php @@ -5,7 +5,7 @@ * Description: Integration plugin for WooCommerce & Simla.com * Author: RetailDriver LLC * Author URI: http://retailcrm.pro/ - * Version: 4.8.8 + * Version: 4.8.9 * Tested up to: 6.5 * Requires Plugins: woocommerce * WC requires at least: 5.4 diff --git a/src/uninstall.php b/src/uninstall.php index 40530c2..8275ed6 100644 --- a/src/uninstall.php +++ b/src/uninstall.php @@ -16,7 +16,7 @@ * * @link https://wordpress.org/plugins/woo-retailcrm/ * - * @version 4.8.8 + * @version 4.8.9 * * @package RetailCRM */