Improvement of customer registration form in Loyalty program (#349)
This commit is contained in:
parent
b00ff321ab
commit
b195d169e1
@ -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
|
||||
|
||||
|
@ -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 '<p style="color: red">'. __('Error while retrieving data. Try again later', 'retailcrm') . '</p>';
|
||||
|
@ -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()) {
|
||||
|
@ -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(
|
||||
'<p><input type="checkbox" name="terms" id="termsLoyalty" required>%s<a id="terms-popup" class="popup-open-loyalty" href="#">%s</a>.</p>',
|
||||
__(' I agree with ', 'retailcrm'),
|
||||
__('loyalty program terms', 'retailcrm')
|
||||
)
|
||||
: ''
|
||||
;
|
||||
|
||||
$htmlLoyaltyPersonal = $loyaltyPersonal !== ''
|
||||
? sprintf(
|
||||
'<p><input type="checkbox" name="privacy" id="privacyLoyalty" required>%s<a id="privacy-popup" class="popup-open-loyalty" href="#">%s</a>.</p>',
|
||||
__(' I agree with ', 'retailcrm'),
|
||||
__('terms of personal data processing', 'retailcrm')
|
||||
)
|
||||
: ''
|
||||
;
|
||||
|
||||
|
||||
return sprintf(
|
||||
'
|
||||
<form id="loyaltyRegisterForm" method="post">
|
||||
<p>%s</p>
|
||||
<p><input type="checkbox" name="terms" id="termsLoyalty" required>%s<a id="terms-popup" class="popup-open-loyalty" href="#">%s</a>.</p>
|
||||
<p><input type="checkbox" name="privacy" id="privacyLoyalty" required>%s<a id="privacy-popup" class="popup-open-loyalty" href="#">%s</a>.</p>
|
||||
<p><input type="text" name="phone" id="phoneLoyalty" placeholder="%s" required></p>
|
||||
%s
|
||||
%s
|
||||
<p><input type="text" name="phone" id="phoneLoyalty" placeholder="%s" value="%s" required></p>
|
||||
<p><input type="submit" value="%s"></p>
|
||||
</form>
|
||||
<div class="popup-fade-loyalty">
|
||||
@ -25,11 +44,10 @@ if (!class_exists('WC_Retailcrm_Loyalty')) :
|
||||
</div>
|
||||
',
|
||||
__('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')
|
||||
);
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -16,7 +16,7 @@
|
||||
*
|
||||
* @link https://wordpress.org/plugins/woo-retailcrm/
|
||||
*
|
||||
* @version 4.8.8
|
||||
* @version 4.8.9
|
||||
*
|
||||
* @package RetailCRM
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user