parent
7a7a2dec91
commit
159e459e7e
4 changed files with 44 additions and 12 deletions
|
@ -538,8 +538,14 @@ msgstr "Акционные товары"
|
|||
msgid "bonus for every"
|
||||
msgstr "бонус за каждые"
|
||||
|
||||
msgid "bonuses"
|
||||
msgstr "бонусов"
|
||||
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 "Ошибка при получении данных. Попробуйте позже."
|
||||
|
|
|
@ -647,10 +647,9 @@ if (!class_exists('WC_Retailcrm_Base')) {
|
|||
echo json_encode(['error' => __('Error while registering in the loyalty program. Try again later.', 'retailcrm')]);
|
||||
}
|
||||
|
||||
$response = $this->loyalty->registerCustomer($userId, $phone, $site);
|
||||
$isSuccessful = $this->loyalty->registerCustomer($userId, $phone, $site);
|
||||
|
||||
if (!$response->isSuccessful()) {
|
||||
writeBaseLogs('Error while registering in the loyalty program: ' . $response->getRawResponse());
|
||||
if (!$isSuccessful) {
|
||||
echo json_encode(['error' => __('Error while registering in the loyalty program. Try again later.', 'retailcrm')]);
|
||||
}
|
||||
|
||||
|
@ -882,7 +881,15 @@ if (!class_exists('WC_Retailcrm_Base')) {
|
|||
wp_localize_script($jsScript, 'LoyaltyUrl', $loyaltyUrl);
|
||||
wp_localize_script($jsScript, 'customerId', $userId);
|
||||
|
||||
echo $this->loyalty->getForm($userId);
|
||||
$result = $this->loyalty->getForm($userId);
|
||||
|
||||
if (!isset($result)) {
|
||||
echo '<p style="color: red">'. __('Error while retrieving data. Try again later.', 'retailcrm') . '</p>';
|
||||
} else {
|
||||
echo $result;
|
||||
}
|
||||
|
||||
wp_die();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -29,7 +29,7 @@ if (!class_exists('WC_Retailcrm_Loyalty')) :
|
|||
|
||||
public function getForm(int $userId)
|
||||
{
|
||||
$result = '';
|
||||
$result = null;
|
||||
|
||||
$response = $this->apiClient->customersGet($userId);
|
||||
|
||||
|
@ -38,7 +38,14 @@ if (!class_exists('WC_Retailcrm_Loyalty')) :
|
|||
}
|
||||
|
||||
$filter['customerId'] = $response['customer']['id'];
|
||||
$response = $this->apiClient->getLoyaltyAccountList($filter);
|
||||
|
||||
try {
|
||||
$response = $this->apiClient->getLoyaltyAccountList($filter);
|
||||
} catch (Throwable $exception) {
|
||||
writeBaseLogs('Exception get loyalty accounts: ' . $exception->getMessage());
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
if (!$response->isSuccessful() || !$response->offsetExists('loyaltyAccounts')) {
|
||||
return $result;
|
||||
|
@ -85,7 +92,7 @@ if (!class_exists('WC_Retailcrm_Loyalty')) :
|
|||
return $result;
|
||||
}
|
||||
|
||||
public function registerCustomer(int $userId, string $phone, string $site): WC_Retailcrm_Response
|
||||
public function registerCustomer(int $userId, string $phone, string $site): bool
|
||||
{
|
||||
$parameters = [
|
||||
'phoneNumber' => $phone,
|
||||
|
@ -94,7 +101,19 @@ if (!class_exists('WC_Retailcrm_Loyalty')) :
|
|||
]
|
||||
];
|
||||
|
||||
return $this->apiClient->createLoyaltyAccount($parameters, $site);
|
||||
try {
|
||||
$response = $this->apiClient->createLoyaltyAccount($parameters, $site);
|
||||
|
||||
if (!$response->isSuccessful()) {
|
||||
writeBaseLogs('Error while registering in the loyalty program: ' . $response->getRawResponse());
|
||||
}
|
||||
|
||||
return $response->isSuccessful();
|
||||
} catch (Throwable $exception) {
|
||||
writeBaseLogs('Exception while registering in the loyalty program: ' . $exception->getMessage());
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private function getLoyaltyInfo(array $loyaltyAccount)
|
||||
|
@ -117,8 +136,8 @@ if (!class_exists('WC_Retailcrm_Loyalty')) :
|
|||
$data[] = __('Promotional products', 'retailcrm') . ': 1 ' . __('bonus for every', 'retailcrm') . ' '. $loyaltyAccount['level']['privilegeSizePromo'];
|
||||
break;
|
||||
case 'bonus_percent':
|
||||
$data[] = __('Ordinary goods', 'retailcrm') . ': ' . $loyaltyAccount['level']['privilegeSize'] . '% ' . __('bonuses', 'retailcrm');
|
||||
$data[] = __('Promotional products', 'retailcrm') . ': ' . $loyaltyAccount['level']['privilegeSizePromo'] . '% ' . __('bonuses', 'retailcrm');
|
||||
$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');
|
||||
|
|
Binary file not shown.
Loading…
Add table
Reference in a new issue