From 13d592af5a59d00b7d6750227f5a348de1ec52d5 Mon Sep 17 00:00:00 2001 From: Ivan Chaplygin Date: Wed, 24 Apr 2024 19:09:03 +0300 Subject: [PATCH] ref #95034 Checking the existence of a corporate person Adding translations --- resources/pot/retailcrm-es_ES.pot | 24 +++++++++++++++++++ resources/pot/retailcrm-ru_RU.pot | 24 +++++++++++++++++++ .../class-wc-retailcrm-loyalty-constraint.php | 2 ++ .../class-wc-retailcrm-loyalty-validator.php | 10 ++++++-- 4 files changed, 58 insertions(+), 2 deletions(-) diff --git a/resources/pot/retailcrm-es_ES.pot b/resources/pot/retailcrm-es_ES.pot index e859fd0..b794686 100644 --- a/resources/pot/retailcrm-es_ES.pot +++ b/resources/pot/retailcrm-es_ES.pot @@ -474,3 +474,27 @@ msgstr "Descarga de servicios" msgid "Goods with the 'virtual' option enabled will be uploaded to Simla as services" msgstr "Los bienes con la opción 'virtual' activada se cargarán en Simla como servicios" + +msgid "User not found in the system" +msgstr "Usuario no encontrado en el sistema" + +msgid "Error when searching for participation in loyalty programs" +msgstr "Error al buscar la participación en programas de fidelización" + +msgid "No active participation in the loyalty program was detected" +msgstr "No se detectó ninguna participación activa en el programa de fidelización" + +msgid "No bonuses for debiting" +msgstr "Sin bonificaciones por adeudo" + +msgid "Loyalty program not found" +msgstr "Programa de fidelización no encontrado" + +msgid "Loyalty program is not active" +msgstr "El programa de fidelización no está activo" + +msgid "Loyalty program blocked" +msgstr "Programa de fidelización bloqueado" + +msgid "This user is a corporate person" +msgstr "Este usuario es una persona jurídica" diff --git a/resources/pot/retailcrm-ru_RU.pot b/resources/pot/retailcrm-ru_RU.pot index 0547a62..a719296 100644 --- a/resources/pot/retailcrm-ru_RU.pot +++ b/resources/pot/retailcrm-ru_RU.pot @@ -669,3 +669,27 @@ msgstr "Обычные товары: %s%% скидка" msgid "Promotional products: %s%% discount" msgstr "Акционные товары: %s%% скидка" + +msgid "User not found in the system" +msgstr "Пользователь не найден в системе" + +msgid "Error when searching for participation in loyalty programs" +msgstr "Ошибка при поиске участия в программах лояльности" + +msgid "No active participation in the loyalty program was detected" +msgstr "Активного участия в программе лояльности не обнаружено" + +msgid "No bonuses for debiting" +msgstr "Бонусы на списание отсутствуют" + +msgid "Loyalty program not found" +msgstr "Программа лояльности не найдена" + +msgid "Loyalty program is not active" +msgstr "Программа лояльности не активна" + +msgid "Loyalty program blocked" +msgstr "Программа лояльности заблокирована" + +msgid "This user is a corporate person" +msgstr "Данный пользователь является корпоратиным лицом" diff --git a/src/include/validators/loyalty-validator/class-wc-retailcrm-loyalty-constraint.php b/src/include/validators/loyalty-validator/class-wc-retailcrm-loyalty-constraint.php index 2521be3..838bae9 100644 --- a/src/include/validators/loyalty-validator/class-wc-retailcrm-loyalty-constraint.php +++ b/src/include/validators/loyalty-validator/class-wc-retailcrm-loyalty-constraint.php @@ -27,5 +27,7 @@ if (!class_exists('WC_Retailcrm_Loyalty_Constraint')) : public $loyaltyInactive = 'Loyalty program is not active'; public $loyaltyBlocked = 'Loyalty program blocked'; + + public $isCorporateUser = 'This user is a corporate person'; } endif; diff --git a/src/include/validators/loyalty-validator/class-wc-retailcrm-loyalty-validator.php b/src/include/validators/loyalty-validator/class-wc-retailcrm-loyalty-validator.php index c7ba0a8..542ff3c 100644 --- a/src/include/validators/loyalty-validator/class-wc-retailcrm-loyalty-validator.php +++ b/src/include/validators/loyalty-validator/class-wc-retailcrm-loyalty-validator.php @@ -30,7 +30,7 @@ if (!class_exists('WC_Retailcrm_Loyalty_Validator')) : $result = false; try { - $crmUser = $this->getUser($userId); + $crmUser = $this->checkUser($userId); //add check customer corporate $actualAccount = $this->getLoyaltyAccount($crmUser['id']); $this->checkActiveLoyalty($actualAccount['loyalty']['id']); @@ -47,7 +47,7 @@ if (!class_exists('WC_Retailcrm_Loyalty_Validator')) : /** * @throws ValidatorException */ - private function getUser($userId) + private function checkUser($userId) { $responseUser = $this->apiClient->customersGet($userId); @@ -55,6 +55,12 @@ if (!class_exists('WC_Retailcrm_Loyalty_Validator')) : throw new ValidatorException($this->notFoundCrmUser, 400); } + $customer = new WC_Customer($userId); + + if (!empty($customer->get_shipping_company())) { + throw new ValidatorException($this->isCorporateUser, 400); + } + return $responseUser['customer']; }