From eb95f3e37566a4bf87e28bbd79bfcea3f5548b6a Mon Sep 17 00:00:00 2001 From: Dima Uryvskiy Date: Tue, 3 Aug 2021 18:26:55 +0300 Subject: [PATCH] Update logic client roles. Delete setting role --- doc/1.Setup/Settings .md | 3 ++ doc/1.Setup/User roles.md | 33 ++++++++++++++++++ doc/README.md | 1 + resources/pot/retailcrm-es_ES.pot | 9 ----- resources/pot/retailcrm-ru_RU.pot | 9 ----- .../class-wc-retailcrm-abstracts-settings.php | 30 ---------------- src/include/class-wc-retailcrm-customers.php | 25 ++++--------- src/languages/retailcrm-es_ES.mo | Bin 8751 -> 8417 bytes src/languages/retailcrm-ru_RU.mo | Bin 10734 -> 10339 bytes 9 files changed, 43 insertions(+), 67 deletions(-) create mode 100644 doc/1.Setup/Settings .md create mode 100644 doc/1.Setup/User roles.md create mode 100644 doc/README.md diff --git a/doc/1.Setup/Settings .md b/doc/1.Setup/Settings .md new file mode 100644 index 0000000..0bf7e32 --- /dev/null +++ b/doc/1.Setup/Settings .md @@ -0,0 +1,3 @@ + +# Settings + diff --git a/doc/1.Setup/User roles.md b/doc/1.Setup/User roles.md new file mode 100644 index 0000000..78e90dd --- /dev/null +++ b/doc/1.Setup/User roles.md @@ -0,0 +1,33 @@ +# User roles + +С версии `4.3.7` опция `"Роли клиентов"` была удалена из настроек модуля. Сейчас выгружаются пользователи со всеми доступными ролями в CMS. +Добавили фильтр `retailcrm_customer_roles` для корректировки выгружаемых пользователей. + +## Пример работы фильтра +В приведенном ниже примере показано, как возможно корректировать роли выгружаемых пользователей: + +```php +get_names(); - - if (!empty($client_roles_list)) { - foreach ($client_roles_list as $code => $name) { - $client_roles_option[$code] = $name; - } - - $this->form_fields[] = array( - 'title' => __('Client roles', 'retailcrm'), - 'type' => 'heading', - 'description' => '', - 'id' => 'client_roles_options' - ); - - $this->form_fields['client_roles'] = array( - 'label' => ' ', - 'title' => __('Client roles available for uploading to Simla.com', 'retailcrm'), - 'class' => '', - 'type' => 'multiselect', - 'description' => __('Select client roles which will be uploaded from website to Simla.com', 'retailcrm'), - 'options' => $client_roles_option, - 'css' => 'min-height:100px;', - 'select_buttons' => true - ); - } - /** * Order methods options */ diff --git a/src/include/class-wc-retailcrm-customers.php b/src/include/class-wc-retailcrm-customers.php index 6ff9b2c..bc12a4c 100644 --- a/src/include/class-wc-retailcrm-customers.php +++ b/src/include/class-wc-retailcrm-customers.php @@ -599,32 +599,19 @@ if (!class_exists('WC_Retailcrm_Customers')) : */ public function isCustomer($user) { - $retailcrmSettings = array(); - - if (!empty($this->retailcrm_settings) && array_key_exists('client_roles', $this->retailcrm_settings)) { - $retailcrmSettings = $this->retailcrm_settings['client_roles']; - } - - if (empty($retailcrmSettings)) { - $selectedRoles = array(self::CUSTOMER_ROLE, self::ADMIN_ROLE); - } else { - $selectedRoles = $retailcrmSettings; - } + $clientRoles = wp_roles()->get_names(); + $clientRoles = apply_filters('retailcrm_customer_roles', WC_Retailcrm_Plugin::clearArray($clientRoles)); if ($user instanceof WP_User) { - $userRoles = $user->roles; + $userRole = !empty($user->roles[0]) ? $user->roles[0] : null; } elseif ($user instanceof WC_Customer) { - $wpUser = get_user_by('id', $user->get_id()); - $userRoles = ($wpUser) ? $wpUser->roles : array($user->get_role()); + $role = $user->get_role(); + $userRole = !empty($role) ? $role : null; } else { return false; } - $result = array_filter($userRoles, function ($userRole) use ($selectedRoles) { - return in_array($userRole, $selectedRoles); - }); - - return !empty($result); + return array_key_exists($userRole, $clientRoles); } } endif; diff --git a/src/languages/retailcrm-es_ES.mo b/src/languages/retailcrm-es_ES.mo index 0eeef134dba04376086c1680d57f030e1e1aaf61..0af69857184e0fc054d14dae903c854c4a58477b 100644 GIT binary patch delta 1986 zcmYk+T};nW9LMo*ibRrBBvC0(JxCsU(1ViXsXvOaF*6Z1rqPAruRGRNYc{r+7;bE| zzlXK%Y|YGEG!t5$W@F|?xNt%9{``KYt+W66z0UdlfB)Y(=X<{Af3NCOMeu!G#3iHb zq|T-ejWY{k=XfrZ%aL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jT@8DAW6cyNa zScX?|72d@Aa4}zMz7Q&q2sYs{JgB9<&!CYD^(==)ST6=~AL@als6fVX6MlxhcpIy+ zhv*ex6c=F{7vqb_$Bz5wCsFsG#ryF~3@X)sFlff*{8|s{!S$FxJ~qxl4>;@lv44FM zLtMXtG1~wtfHZEzQ`nA|QO~JlmA%-BBq?iS z479?x^B3#`)QY~w{rET5;$AA0IV^+9*cd9{asPY@RaC!X1WP#auphMrAE93FN!0VE za@X1a-x;X7XOOH}fTyV#>rih)BPxXYBBQ^D!=(wm{8 zQh`=aoCvfPR43wIa@eI)2`^*Y|2ui@g+(j?S{$ z$|K%jCO+)BJML^O+Y;#BqZ!?hmvH&tc=o?5ZYZ8PoJz(Ab?4z|I_hH4^nqyFdC57? zJ-BSVB+}<4yjU!rN_sAl%H+eHJGp!AdCz4$e}d27O7dl9$a6fN_~I!?pe{OR*3uQ1 Gi~j|)QTw<6 diff --git a/src/languages/retailcrm-ru_RU.mo b/src/languages/retailcrm-ru_RU.mo index bd1945464dc0be34d3a002647779288b60d8be18..9496683f35fc672a79103bfad4c47f75a78c01fc 100644 GIT binary patch delta 2034 zcmYk-YiL(x90%~Td6`pdHqB{j&P$ooP3K)(&NQuQGfi{q5F#t7z_JW_)t|lE3%ih& z7KlX`D2$>;FT#STD6{AS3KbHDLX;2%j)(~QeE<6^KKy^@^PIDDp3Cof&eIg+P1g1>P*`zz;l!;0bx=My-N&78_L zT*~`+D_`ZPboHmol`d4(dWa3o1M}&IVhhv3E?&hRrh`MwfZpci{D4z-}bK=On(uYJNOQ{$;cH)CIrdTZf@M&8+pW9Ls78p3IDABip!yJ7~ zGM_uSlLz?-|K&73sId&}SuW=%T*fLJBJH=8RB~e{bK@SS!nVj+`>jm!)WGE4IY_wzWHafgdp`xj_##Sx~zFIb!R|D4Kb7y6maRBNZj zam);6Favmq_wo>vu|Znd$2Rux7?ZiRUWIBtO531#j26w3rlcYOqHb!I@&lM?)g=H<5qrvdi;o4iVYNWBdARHdXcY*7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