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 0eeef13..0af6985 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.mo b/src/languages/retailcrm-ru_RU.mo index bd19454..9496683 100644 Binary files a/src/languages/retailcrm-ru_RU.mo and b/src/languages/retailcrm-ru_RU.mo differ