1
0
Fork 0
mirror of synced 2025-04-06 07:13:33 +03:00
Small corrections
Added possibility to modify loyalty program forms
This commit is contained in:
Ivan Chaplygin 2024-04-11 17:55:44 +03:00
parent aa33cb6ef1
commit 7c84f365f0
6 changed files with 143 additions and 121 deletions

View file

@ -481,26 +481,26 @@ msgstr "Для активации программы лояльности нео
msgid "Bonus account"
msgstr "Бонусный счёт"
msgid "Participation ID"
msgstr "ID участия"
msgid "Participation ID: "
msgstr "ID участия: "
msgid "Current level"
msgstr "Текущий уровень"
msgid "Current level: "
msgstr "Текущий уровень: "
msgid "Bonuses on the account"
msgstr "Бонусов на счёте"
msgid "Bonuses on the account: "
msgstr "Бонусов на счёте: "
msgid "Bonus card number"
msgstr "Номер бонусной карты"
msgid "Bonus card number: "
msgstr "Номер бонусной карты: "
msgid "Date of registration"
msgstr "Дата регистрации"
msgid "Date of registration: "
msgstr "Дата регистрации: "
msgid "Current level rules"
msgstr "Правила текущего уровня"
msgid "Required amount of purchases to move to the next level"
msgstr "Необходимая сумма покупок для перехода на следующий уровень"
msgid "Required amount of purchases to move to the next level: "
msgstr "Необходимая сумма покупок для перехода на следующий уровень: "
msgid "Activate participation in the loyalty program"
msgstr "Активировать участие в программе лояльности"
@ -529,24 +529,6 @@ msgstr "Ошибка при регистрации в программе лоя
msgid "The card is not linked"
msgstr "Карта не привязана"
msgid "Ordinary goods"
msgstr "Обычные товары"
msgid "Promotional products"
msgstr "Акционные товары"
msgid "accrual of 1 bonus for each"
msgstr "начисление 1 бонуса за каждые"
msgid "of the purchase amount"
msgstr "от суммы покупки"
msgid "bonus accrual in the amount of"
msgstr "начисление бонусов в размере"
msgid "discount"
msgstr "скидка"
msgid "Error while retrieving data. Try again later"
msgstr "Ошибка при получении данных. Попробуйте позже"
@ -558,3 +540,21 @@ msgstr "Введите корректный номер телефона"
msgid "Close"
msgstr "Закрыть"
msgid "Ordinary products: accrual of 1 bonus for each %s %s"
msgstr "Обычные товары: начисление 1 бонуса за каждые %s %s"
msgid "Promotional products: accrual of 1 bonus for each %s %s"
msgstr "Акционные товары: начисление 1 бонуса за каждые %s %s"
msgid "Ordinary products: bonus accrual in the amount of %s% of the purchase amount"
msgstr "Обычные товары: начисление бонусов в размере %s% от суммы покупки"
msgid "Promotional products: bonus accrual in the amount of %s% of the purchase amount"
msgstr "Акционные товары: начисление бонусов в размере %s% от суммы покупки"
msgid "Ordinary products: %s% discount"
msgstr "Обычные товары: %s% скидка"
msgid "Promotional products: %s% discount"
msgstr "Акционные товары: %s% скидка"

View file

@ -100,7 +100,7 @@ jQuery(function() {
});
jQuery(document).keydown(function(e) {
if (e.keyCode === 27) {
if (e.keyCode === 27) { // Key Escape
e.stopPropagation();
jQuery('.popup-fade-loyalty').fadeOut();
}

View file

@ -636,22 +636,17 @@ if (!class_exists('WC_Retailcrm_Base')) {
{
$phone = filter_input(INPUT_POST, 'phone');
$userId = filter_input(INPUT_POST, 'userId');
$site = $this->apiClient->getSingleSiteForKey();
$isSuccessful = false;
if (empty($site)) {
writeBaseLogs('Error with CRM credentials: need an valid apiKey assigned to one certain site');
echo json_encode(['error' => __('Error while registering in the loyalty program. Try again later', 'retailcrm')]);
if (!empty($site) && $userId && $phone) {
$isSuccessful = $this->loyalty->registerCustomer($userId, $phone, $site);
}
if (!$userId || !$phone) {
writeBaseLogs('Errors when registering a loyalty program. Passed parameters: userId = ' . ($userId ?? 'NULL') . ' phone = ' . ($phone ?? 'NULL'));
echo json_encode(['error' => __('Error while registering in the loyalty program. Try again later', 'retailcrm')]);
}
$isSuccessful = $this->loyalty->registerCustomer($userId, $phone, $site);
if (!$isSuccessful) {
writeBaseLogs('Errors when registering a loyalty program. Passed parameters: ' .
json_encode(['site' => $site, 'userId' => $userId, 'phone' => $phone])
);
echo json_encode(['error' => __('Error while registering in the loyalty program. Try again later', 'retailcrm')]);
} else {
echo json_encode(['isSuccessful' => true]);
@ -663,15 +658,14 @@ if (!class_exists('WC_Retailcrm_Base')) {
public function activate_customer_loyalty()
{
$loyaltyId = filter_input(INPUT_POST, 'loyaltyId');
$isSuccessful = false;
if (!$loyaltyId) {
writeBaseLogs('Errors when activate loyalty program. loyaltyId is missing');
echo json_encode(['error' => __('Error when activating the loyalty program. Try again later', 'retailcrm')]);
if ($loyaltyId) {
$isSuccessful = $this->loyalty->activateLoyaltyCustomer($loyaltyId);
}
$isSuccessful = $this->loyalty->activateLoyaltyCustomer($loyaltyId);
if (!$isSuccessful) {
writeBaseLogs('Errors when activate loyalty program. Passed parameters: ' . json_encode(['loyaltyId' => $loyaltyId]));
echo json_encode(['error' => __('Error when activating the loyalty program. Try again later', 'retailcrm')]);
} else {
echo json_encode(['isSuccessful' => true]);

View file

@ -1,6 +1,9 @@
<?php
if (!class_exists('WC_Retailcrm_Loyalty')) :
if (!class_exists('WC_Retailcrm_Loyalty_Form')) {
include_once(WC_Integration_Retailcrm::checkCustomFile('include/components/class-wc-retailcrm-loyalty-form.php'));
}
/**
* PHP version 7.0
*
@ -16,15 +19,20 @@ if (!class_exists('WC_Retailcrm_Loyalty')) :
{
/** @var WC_Retailcrm_Client_V5 */
protected $apiClient;
protected $dateFormat;
protected $settings;
/** @var WC_Retailcrm_Loyalty_Form */
protected $loyaltyForm;
public function __construct($apiClient, $settings)
{
$this->apiClient = $apiClient;
$this->settings = $settings;
$this->dateFormat = 'Y-m-d H:i:sP';
$this->loyaltyForm = new WC_Retailcrm_Loyalty_Form();
}
public function getForm(int $userId)
@ -55,47 +63,14 @@ if (!class_exists('WC_Retailcrm_Loyalty')) :
if ($loyaltyAccount && (int) $loyaltyAccount['customer']['externalId'] === $userId) {
if ($loyaltyAccount['active'] === true) {
$result['form'] = $this->getLoyaltyInfo($loyaltyAccount);
$result['form'] = $this->loyaltyForm->getInfoLoyalty($loyaltyAccount);
} else {
$result['form'] = sprintf(
'
<form id="loyaltyActivateForm" method="post">
<p><input type="checkbox" id="loyaltyActiveCheckbox" name="loyaltyCheckbox" required> %s</p>
<input type="submit" value="%s">
</form>',
__('Activate participation in the loyalty program', 'retailcrm'),
__('Send', 'retailcrm')
);
$result['form'] = $this->loyaltyForm->getActivationForm();
$result['loyaltyId'] = $loyaltyAccount['id'];
}
} else {
$result['form'] = 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>
<p><input type="submit" value="%s"></p>
</form>
<div class="popup-fade-loyalty">
<div class="popup-loyalty">
<a class="popup-close-loyalty" href="#">%s</a>
<br>
<div id="popup-loyalty-text"></div>
</div>
</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'),
__('Phone', 'retailcrm'),
__('Send', 'retailcrm'),
__('Close', 'retailcrm')
);
$result['form'] = $this->loyaltyForm->getRegistrationForm();
}
return $result;
@ -141,44 +116,6 @@ if (!class_exists('WC_Retailcrm_Loyalty')) :
return false;
}
}
private function getLoyaltyInfo(array $loyaltyAccount)
{
$data = [
'<b>' . __('Bonus account', 'retailcrm') . '</b>',
__('Participation ID', 'retailcrm') . ': ' . $loyaltyAccount['id'],
__('Current level', 'retailcrm') . ': ' . $loyaltyAccount['level']['name'],
__('Bonuses on the account', 'retailcrm') . ': ' . $loyaltyAccount['amount'],
__('Bonus card number' , 'retailcrm') . ': ' . ($loyaltyAccount['cardNumber'] ?? __('The card is not linked', 'retailcrm')),
__('Date of registration', 'retailcrm') . ': ' . $loyaltyAccount['activatedAt'],
'<br>',
'<b>' . __('Current level rules', 'retailcrm') . '</b>',
__('Required amount of purchases to move to the next level', 'retailcrm') . ': ' . $loyaltyAccount['nextLevelSum'],
];
switch ($loyaltyAccount['level']['type']) {
case 'bonus_converting':
$data[] = __('Ordinary goods', 'retailcrm') . ': ' . __('accrual of 1 bonus for each', 'retailcrm') . ' '. $loyaltyAccount['level']['privilegeSize'] . ' ' . $loyaltyAccount['loyalty']['currency'];
$data[] = __('Promotional products', 'retailcrm') . ': ' . __('accrual of 1 bonus for each', 'retailcrm') . ' '. $loyaltyAccount['level']['privilegeSizePromo']. ' ' . $loyaltyAccount['loyalty']['currency'];
break;
case 'bonus_percent':
$data[] = __('Ordinary goods', 'retailcrm') . ': ' . __('bonus accrual in the amount of', 'retailcrm'). ' ' . $loyaltyAccount['level']['privilegeSize'] . '% ' . __('of the purchase amount', 'retailcrm');
$data[] = __('Promotional products', 'retailcrm') . ': ' . __('bonus accrual in the amount of', 'retailcrm'). ' ' . $loyaltyAccount['level']['privilegeSizePromo'] . '% ' . __('of the purchase amount', 'retailcrm');
break;
case 'discount':
$data[] = __('Ordinary goods', 'retailcrm') . ': ' . $loyaltyAccount['level']['privilegeSize'] . '% ' . __('discount', 'retailcrm');
$data[] = __('Promotional products', 'retailcrm') . ': ' . $loyaltyAccount['level']['privilegeSizePromo'] . '% ' . __('discount', 'retailcrm');
break;
}
$result = '';
foreach ($data as $line) {
$result .= "<p style='line-height: 1'>$line</p>";
}
return $result;
}
}
endif;

View file

@ -0,0 +1,90 @@
<?php
if (!class_exists('WC_Retailcrm_Loyalty')) :
class WC_Retailcrm_Loyalty_Form
{
public function getRegistrationForm()
{
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>
<p><input type="submit" value="%s"></p>
</form>
<div class="popup-fade-loyalty">
<div class="popup-loyalty">
<a class="popup-close-loyalty" href="#">%s</a>
<br>
<div id="popup-loyalty-text"></div>
</div>
</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'),
__('Phone', 'retailcrm'),
__('Send', 'retailcrm'),
__('Close', 'retailcrm')
);
}
public function getActivationForm()
{
return sprintf('
<form id="loyaltyActivateForm" method="post">
<p><input type="checkbox" id="loyaltyActiveCheckbox" name="loyaltyCheckbox" required> %s</p>
<input type="submit" value="%s">
</form>',
__('Activate participation in the loyalty program', 'retailcrm'),
__('Send', 'retailcrm')
);
}
public function getInfoLoyalty(array $loyaltyAccount)
{
$data = [
'<b>' . __('Bonus account', 'retailcrm') . '</b>',
__('Participation ID: ', 'retailcrm') . $loyaltyAccount['id'],
__('Current level: ', 'retailcrm') . $loyaltyAccount['level']['name'],
__('Bonuses on the account: ', 'retailcrm') . $loyaltyAccount['amount'],
__('Bonus card number: ' , 'retailcrm') . ($loyaltyAccount['cardNumber'] ?? __('The card is not linked', 'retailcrm')),
__('Date of registration: ', 'retailcrm') . $loyaltyAccount['activatedAt'],
'<br>',
'<b>' . __('Current level rules', 'retailcrm') . '</b>',
__('Required amount of purchases to move to the next level: ', 'retailcrm') . $loyaltyAccount['nextLevelSum'] . ' ' . $loyaltyAccount['loyalty']['currency']
];
switch ($loyaltyAccount['level']['type']) {
case 'bonus_converting':
$data[] = sprintf(__('Ordinary products: accrual of 1 bonus for each %s %s', 'retailcrm'), $loyaltyAccount['level']['privilegeSize'], $loyaltyAccount['loyalty']['currency']);
$data[] = sprintf(__('Promotional products: accrual of 1 bonus for each %s %s', 'retailcrm'), $loyaltyAccount['level']['privilegeSizePromo'], $loyaltyAccount['loyalty']['currency']);
break;
case 'bonus_percent':
$data[] = sprintf(__('Ordinary products: bonus accrual in the amount of %s% of the purchase amount', 'retailcrm'), $loyaltyAccount['level']['privilegeSize']);
$data[] = sprintf(__('Promotional products: bonus accrual in the amount of %s% of the purchase amount', 'retailcrm'), $loyaltyAccount['level']['privilegeSizePromo']);
break;
case 'discount':
$data[] = sprintf(__('Ordinary products: %s% discount', 'retailcrm'), $loyaltyAccount['level']['privilegeSize']);
$data[] = sprintf(__('Promotional products: %s% discount', 'retailcrm'), $loyaltyAccount['level']['privilegeSizePromo']);
break;
}
$result = '';
foreach ($data as $line) {
$result .= "<p style='line-height: 1'>$line</p>";
}
return $result;
}
}
endif;

View file

@ -132,6 +132,7 @@ if (!class_exists( 'WC_Integration_Retailcrm')) :
require_once(self::checkCustomFile('include/validators/url-validator/class-wc-retailcrm-url-constraint.php'));
require_once(self::checkCustomFile('include/validators/url-validator/class-wc-retailcrm-url-validator.php'));
require_once(self::checkCustomFile('include/validators/class-wc-retailcrm-validator-exception.php'));
require_once(self::checkCustomFile('include/components/class-wc-retailcrm-loyalty-form.php'));
}
/**