diff --git a/resources/pot/retailcrm-es_ES.pot b/resources/pot/retailcrm-es_ES.pot
index 2dc4ce0..356d5f0 100644
--- a/resources/pot/retailcrm-es_ES.pot
+++ b/resources/pot/retailcrm-es_ES.pot
@@ -586,5 +586,5 @@ msgstr "Es posible debitar"
msgid "bonuses"
msgstr "bonos"
-msgid "Your coupon:"
-msgstr "Tu cupón:"
+msgid "Use coupon:"
+msgstr "Utiliza el cupón:"
diff --git a/resources/pot/retailcrm-ru_RU.pot b/resources/pot/retailcrm-ru_RU.pot
index 40d8bd7..193c76e 100644
--- a/resources/pot/retailcrm-ru_RU.pot
+++ b/resources/pot/retailcrm-ru_RU.pot
@@ -595,5 +595,5 @@ msgstr "Возможно списать"
msgid "bonuses"
msgstr "бонусов"
-msgid "Your coupon:"
-msgstr "Ваш купон:"
+msgid "Use coupon:"
+msgstr "Используйте купон:"
diff --git a/src/include/class-wc-retailcrm-loyalty.php b/src/include/class-wc-retailcrm-loyalty.php
index b3dfce5..92aeda4 100644
--- a/src/include/class-wc-retailcrm-loyalty.php
+++ b/src/include/class-wc-retailcrm-loyalty.php
@@ -37,7 +37,7 @@ if (!class_exists('WC_Retailcrm_Loyalty')) :
$this->loyaltyForm = new WC_Retailcrm_Loyalty_Form();
$this->validator = new WC_Retailcrm_Loyalty_Validator(
$this->apiClient,
- $this->settings['corporate_enabled'] ?? WC_Retailcrm_Base::NO
+ isCorporateUserActivate($this->settings)
);
}
@@ -272,9 +272,8 @@ if (!class_exists('WC_Retailcrm_Loyalty')) :
return $resultString;
}
- $resultString .= '
' . __('It is possible to write off', 'retailcrm') . ' ' . $lpDiscountSum . ' ' . __('bonuses', 'retailcrm') . '
';
-
- return $resultString . '' . __('Your coupon:', 'retailcrm') . ' ' . $coupon->get_code() . '
';
+ $resultString .= ' ' . __('It is possible to write off', 'retailcrm') . ' ' . $lpDiscountSum . ' ' . __('bonuses', 'retailcrm') . '
';
+ return $resultString. '' . __('Use coupon:', 'retailcrm') . ' ' . $coupon->get_code() . '
';
}
public function clearLoyaltyCoupon()
@@ -349,16 +348,7 @@ if (!class_exists('WC_Retailcrm_Loyalty')) :
public function isValidOrder($wcUser, $wcOrder)
{
- return !(!$wcUser
- || (
- isset($this->settings['corporate_enabled'])
- && $this->settings['corporate_enabled'] === WC_Retailcrm_Base::YES
- && (
- !empty($wcUser->get_billing_company())
- || !empty($wcOrder->get_billing_company())
- )
- ))
- ;
+ return !(!$wcUser || (isCorporateUserActivate($this->settings) && isCorporateOrder($wcUser, $wcOrder)));
}
public function applyLoyaltyDiscount($wcOrder, $discountLp, $createdOrder)
diff --git a/src/include/class-wc-retailcrm-orders.php b/src/include/class-wc-retailcrm-orders.php
index d1b6ea7..6bfe6ec 100644
--- a/src/include/class-wc-retailcrm-orders.php
+++ b/src/include/class-wc-retailcrm-orders.php
@@ -100,8 +100,10 @@ if (!class_exists('WC_Retailcrm_Orders')) :
$discountLp = $this->loyalty->deleteLoyaltyCouponInOrder($wcOrder);
$wcUser = $wcOrder->get_user();
- if (!$this->loyalty->isValidOrder($wcUser, $wcOrder) && $discountLp > 0) {
- writeBaseLogs('The user does not meet the requirements for working with the loyalty program. Order Id: ' . $orderId);
+ if (!$this->loyalty->isValidOrder($wcUser, $wcOrder)) {
+ if ($discountLp > 0) {
+ writeBaseLogs('The user does not meet the requirements for working with the loyalty program. Order Id: ' . $orderId);
+ }
$discountLp = 0;
} else {
diff --git a/src/include/functions.php b/src/include/functions.php
index 87f1fa8..b1afd25 100644
--- a/src/include/functions.php
+++ b/src/include/functions.php
@@ -207,3 +207,13 @@ function isLoyaltyActivate($settings)
{
return isset($settings['loyalty']) && $settings['loyalty'] === WC_Retailcrm_Base::YES;
}
+
+function isCorporateUserActivate($settings)
+{
+ return isset($settings['corporate_enabled']) && $settings['corporate_enabled'] === WC_Retailcrm_Base::YES;
+}
+
+function isCorporateOrder($wcUser, $wcOrder)
+{
+ return !empty($wcUser->get_billing_company()) || !empty($wcOrder->get_billing_company());
+}
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 17a8731..2e08d09 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
@@ -59,7 +59,7 @@ if (!class_exists('WC_Retailcrm_Loyalty_Validator')) :
$customer = new WC_Customer($userId);
- if ($this->isActiveCorp === WC_Retailcrm_Base::YES && !empty($customer->get_billing_company())) {
+ if ($this->isActiveCorp && !empty($customer->get_billing_company())) {
throw new ValidatorException($this->isCorporateUser, 400);
}
diff --git a/src/languages/retailcrm-es_ES.l10n.php b/src/languages/retailcrm-es_ES.l10n.php
index ad61403..7a6b3e6 100644
--- a/src/languages/retailcrm-es_ES.l10n.php
+++ b/src/languages/retailcrm-es_ES.l10n.php
@@ -246,7 +246,7 @@ return [
"This user is a corporate person" => "Este usuario es una persona jurídica",
"It is possible to write off" => "Es posible debitar",
"bonuses" => "bonificaciones",
- "Your coupon:" => "Tu cupón:",
+ "Use coupon:" => "Utiliza el cupón:",
],
"language" => "es",
"x-generator" => "GlotPress/2.4.0-alpha",
diff --git a/src/languages/retailcrm-es_ES.mo b/src/languages/retailcrm-es_ES.mo
index 3da7bc5..43567c3 100644
Binary files a/src/languages/retailcrm-es_ES.mo and b/src/languages/retailcrm-es_ES.mo differ
diff --git a/src/languages/retailcrm-ru_RU.l10n.php b/src/languages/retailcrm-ru_RU.l10n.php
index 9312170..514c7e5 100644
--- a/src/languages/retailcrm-ru_RU.l10n.php
+++ b/src/languages/retailcrm-ru_RU.l10n.php
@@ -245,7 +245,7 @@ return [
"This user is a corporate person" => "Этот пользователь является корпоративным лицом",
"It is possible to write off" => "Возможно списать",
"bonuses" => "бонусов",
- "Your coupon:" => "Ваш купон:",
+ "Use coupon:" => "Используйте купон:",
],
"language" => "ru",
"x-generator" => "GlotPress/2.4.0-alpha",
diff --git a/src/languages/retailcrm-ru_RU.mo b/src/languages/retailcrm-ru_RU.mo
index 059386d..acd4ebf 100644
Binary files a/src/languages/retailcrm-ru_RU.mo and b/src/languages/retailcrm-ru_RU.mo differ
diff --git a/tests/datasets/data-loyalty-retailcrm.php b/tests/datasets/data-loyalty-retailcrm.php
index 082ccb3..6793410 100644
--- a/tests/datasets/data-loyalty-retailcrm.php
+++ b/tests/datasets/data-loyalty-retailcrm.php
@@ -78,25 +78,25 @@ class DataLoyaltyRetailCrm
'responseApiMethod' => [],
'wcUserType' => 'individual',
'throwMessage' => 'User not found in the system',
- 'isCorpActive' => 'no'
+ 'isCorpActive' => false
],
[
'responseApiMethod' => ['customer' => ['id' => 1]],
'wcUserType' => 'corp',
'throwMessage' => 'This user is a corporate person',
- 'isCorpActive' => 'yes',
+ 'isCorpActive' => true
],
[
'responseApiMethod' => ['customer' => ['id' => 1]],
'wcUserType' => 'corp',
'throwMessage' => null,
- 'isCorpActive' => 'no',
+ 'isCorpActive' => false
],
[
'responseApiMethod' => ['customer' => ['id' => 1]],
'wcUserType' => 'individual',
'throwMessage' => null,
- 'isCorpActive' => 'yes',
+ 'isCorpActive' => true
],
];
}