From fad8a2539c35d3ab38088da8a5a81a526a59ddc4 Mon Sep 17 00:00:00 2001 From: Ivan Chaplygin Date: Fri, 17 May 2024 14:23:40 +0300 Subject: [PATCH] ref #72069 Changing the coupon output Edit text translations Creating separate methods with checks Fix check corporate person --- resources/pot/retailcrm-es_ES.pot | 4 ++-- resources/pot/retailcrm-ru_RU.pot | 4 ++-- src/include/class-wc-retailcrm-loyalty.php | 18 ++++-------------- src/include/class-wc-retailcrm-orders.php | 6 ++++-- src/include/functions.php | 10 ++++++++++ .../class-wc-retailcrm-loyalty-validator.php | 2 +- src/languages/retailcrm-es_ES.l10n.php | 2 +- src/languages/retailcrm-es_ES.mo | Bin 18277 -> 18284 bytes src/languages/retailcrm-ru_RU.l10n.php | 2 +- src/languages/retailcrm-ru_RU.mo | Bin 22511 -> 22526 bytes tests/datasets/data-loyalty-retailcrm.php | 8 ++++---- 11 files changed, 29 insertions(+), 27 deletions(-) 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_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vZOFgBnH*@5b$8?$j3RnQqP zpY-zYa0Tl(P~Trr>26^@?j~=>$MF=l;%(&8gl(Xm7g*@VHFzC0@-T@;UVu+w3##G| zkX^AUY{5IIjv5~}djdPK0mrco=dd2PtaZ0w0R800G05}nJ%X()jG{(#4+EIF&K+qK zHPQ-Zow0%GnCFnAuL3OZL5*yZ9m3&zP&+EgFoUToKHe% zQCyEZP#q8AlQ@A{_y8ZOpa?F*D%2LVA#a+!f@(d`KqgE@zL^eSy0q4t} z#l3g}b(-&B5#Gam%&B#6T#0q$d$1jo7{OW8-uw7auX6;c)rv8Sdr^%X!Hsybj`<%T zxaKX?vQfIhQPgYlIv&Qes6vAq%-+FL)T#d*HL)pF!BX7=sMl}^U&9I9hV}f)X#E(b;W^YH9mOSh5&5mL8Pwb3i@U#& zVJsn!U@5LgHLxEwsl+h?&V{{;%kVN5;C%ZdD#? zk5?f-ELNS2`d2PGPxKuB+V%hclDqs}&RFs*f1Wd%n(>c0&e`N(u+AAzeiN)L`PjQk zr?sE|5&nn0H8GjY4Xt%PNj?^OIdINfZ^KVh--mAJrlyu>rTO>u^c^Yg?CI<6dA>IF cQ~AFIshjbGX$#x>iaYyyzfQ5Zd27u152m!|Z2$lO 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 059386dbfffc5e4960bfef46bb57ee6a876817de..acd4ebf3f2a5c736dbb6e56f49e33059308c5c47 100644 GIT binary patch delta 1960 zcmX}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-Sm&44+kP*%Oo1-7?^?=Fb7jO8-KzK%qlcD450>EhWfunI1!iO46MO6 zOJoxU>0d1}f&7Kf)1O>y0$7W>u*PDW$!Tn7Kqp8b|CK(}OpLnYOi6jjM12hVe8$fmiT-43n-+coKJWe+kSJS<65#9>&|a6c5Zd z0sMe`CCyxR1Zt$0T(2N=$qm$%&wtvKB<7kx z_MHskOuY_A(8ori>@tR$>b&JVS@aorR#v^Y zk5kS3zT(&Kyqa~(@4S+qGr_Ya-o7>57;kTmH&r;T5noaAS~TFCj(&Mpc6VxEWN$b% TG_of(oI0C2Q{il_>$Ls_rEd}H 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 ], ]; }