diff --git a/resources/pot/retailcrm-ru_RU.pot b/resources/pot/retailcrm-ru_RU.pot index 7d974d4..6658a64 100644 --- a/resources/pot/retailcrm-ru_RU.pot +++ b/resources/pot/retailcrm-ru_RU.pot @@ -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 "Ошибка при получении данных. Попробуйте позже." diff --git a/src/include/class-wc-retailcrm-base.php b/src/include/class-wc-retailcrm-base.php index a605984..e535386 100644 --- a/src/include/class-wc-retailcrm-base.php +++ b/src/include/class-wc-retailcrm-base.php @@ -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 '

'. __('Error while retrieving data. Try again later.', 'retailcrm') . '

'; + } else { + echo $result; + } + + wp_die(); } /** diff --git a/src/include/class-wc-retailcrm-loyalty.php b/src/include/class-wc-retailcrm-loyalty.php index 77e7e2c..2cb0e20 100644 --- a/src/include/class-wc-retailcrm-loyalty.php +++ b/src/include/class-wc-retailcrm-loyalty.php @@ -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'); diff --git a/src/languages/retailcrm-ru_RU.mo b/src/languages/retailcrm-ru_RU.mo index 1604a87..4abcc17 100644 Binary files a/src/languages/retailcrm-ru_RU.mo and b/src/languages/retailcrm-ru_RU.mo differ