diff --git a/CHANGELOG.md b/CHANGELOG.md index 43c32d3..62aaa59 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 2020-08-08 4.1.1 +* Добавлена настройка выбора ролей клиентов для выгрузки в retailCRM + ## 2020-08-05 4.1.0 * Добавлена возможность подключения Онлайн-консультанта diff --git a/VERSION b/VERSION index ee74734..627a3f4 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -4.1.0 +4.1.1 diff --git a/resources/pot/retailcrm-es_ES.pot b/resources/pot/retailcrm-es_ES.pot index 9c5141c..0ba0ccb 100644 --- a/resources/pot/retailcrm-es_ES.pot +++ b/resources/pot/retailcrm-es_ES.pot @@ -136,6 +136,15 @@ msgstr "Métodos de pago" msgid "Delivery types" msgstr "Métodos de envío" +msgid "Select client roles which will be uploaded from website to retailCRM" +msgstr "Seleccione los roles del cliente que se cargarán desde el sitio web a retailCRM" + +msgid "Client roles available for uploading to retailCRM" +msgstr "Roles del cliente disponibles para cargar en retailCRM" + +msgid "Client roles" +msgstr "Roles del cliente" + msgid "Select order methods which will be uploaded from retailCRM to the website" msgstr "Elige el método de formalización de los pedidos que se van a subir desde retailCRM a la página web" diff --git a/resources/pot/retailcrm-ru_RU.pot b/resources/pot/retailcrm-ru_RU.pot index ad1975e..a476eac 100644 --- a/resources/pot/retailcrm-ru_RU.pot +++ b/resources/pot/retailcrm-ru_RU.pot @@ -145,6 +145,15 @@ msgstr "Способы оплаты" msgid "Delivery types" msgstr "Способы доставки" +msgid "Select client roles which will be uploaded from website to retailCRM" +msgstr "Выберите роли клиентов, которые будут выгружаться в retailCRM" + +msgid "Client roles available for uploading to retailCRM" +msgstr "Роли клиентов, доступные для выгрузки в retailCRM" + +msgid "Client roles" +msgstr "Роли клиентов" + msgid "Select order methods which will be uploaded from retailCRM to the website" msgstr "Выберите способы оформления заказов, которые будут выгружаться из retailCRM на сайт" diff --git a/src/include/abstracts/class-wc-retailcrm-abstracts-settings.php b/src/include/abstracts/class-wc-retailcrm-abstracts-settings.php index 41ee36e..4ab0689 100644 --- a/src/include/abstracts/class-wc-retailcrm-abstracts-settings.php +++ b/src/include/abstracts/class-wc-retailcrm-abstracts-settings.php @@ -178,6 +178,36 @@ abstract class WC_Retailcrm_Abstracts_Settings extends WC_Integration ) { add_action('admin_print_footer_scripts', array($this, 'show_blocks'), 99); + /** + * Client roles options + */ + $client_roles_option = array(); + $client_roles_list = wp_roles()->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 retailCRM', 'retailcrm'), + 'class' => '', + 'type' => 'multiselect', + 'description' => __('Select client roles which will be uploaded from website to retailCRM', '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 981b921..1248af4 100644 --- a/src/include/class-wc-retailcrm-customers.php +++ b/src/include/class-wc-retailcrm-customers.php @@ -1,4 +1,5 @@ isCustomer($user)) { continue; } @@ -149,7 +150,7 @@ if (!class_exists('WC_Retailcrm_Customers')) : return null; } - if (self::isCustomer($customer)) { + if ($this->isCustomer($customer)) { $this->processCustomer($customer, $order); $response = $this->retailcrm->customersCreate($this->customer); @@ -177,7 +178,7 @@ if (!class_exists('WC_Retailcrm_Customers')) : $customer = $this->wcCustomerGet($customer_id); - if (self::isCustomer($customer)) { + if ($this->isCustomer($customer)) { $this->processCustomer($customer); $this->retailcrm->customersEdit($this->customer); } @@ -202,7 +203,7 @@ if (!class_exists('WC_Retailcrm_Customers')) : $customer = $this->wcCustomerGet($customer_id); - if (self::isCustomer($customer)) { + if ($this->isCustomer($customer)) { $this->processCustomer($customer); $this->customer['id'] = $crmCustomerId; $this->retailcrm->customersEdit($this->customer, 'id'); @@ -235,7 +236,7 @@ if (!class_exists('WC_Retailcrm_Customers')) : return null; } - if (self::isCustomer($customer)) { + if ($this->isCustomer($customer)) { $this->processCorporateCustomer($crmCustomerId, $customer, $order); $response = $this->retailcrm->customersCorporateCreate($this->customerCorporate); @@ -493,7 +494,7 @@ if (!class_exists('WC_Retailcrm_Customers')) : if (empty($search['customers'])) { return false; } - + if (isset($filter['email']) && count($filter) == 1) { foreach ($search['customers'] as $finding) { if (isset($finding['email']) && $finding['email'] == $filter['email']) { @@ -547,7 +548,7 @@ if (!class_exists('WC_Retailcrm_Customers')) : */ public function searchCorporateCustomer($filter, $returnGroup = false) { - $search = $this->retailcrm->customersCorporateList($filter); + $search = $this->retailcrm->customersCorporateList($filter); if (!empty($search) && $search->isSuccessful()) { if (isset($search['customersCorporate'])) { @@ -619,16 +620,34 @@ if (!class_exists('WC_Retailcrm_Customers')) : * * @return bool */ - public static function isCustomer($user) + public function isCustomer($user) { - if ($user instanceof WC_Customer) { - return $user->get_role() == self::CUSTOMER_ROLE || $user->get_role() == self::ADMIN_ROLE; - } elseif ($user instanceof WP_User) { - return in_array(self::CUSTOMER_ROLE, $user->roles) - || in_array(self::ADMIN_ROLE, $user->roles); + $retailcrmSettings = array(); + + if (!empty($this->retailcrm_settings) && array_key_exists('client_roles', $this->retailcrm_settings)) { + $retailcrmSettings = $this->retailcrm_settings['client_roles']; } - return false; + if (empty($retailcrmSettings)) { + $selectedRoles = array(self::CUSTOMER_ROLE, self::ADMIN_ROLE); + } else { + $selectedRoles = $retailcrmSettings; + } + + if ($user instanceof WP_User) { + $userRoles = $user->roles; + } elseif ($user instanceof WC_Customer) { + $wpUser = get_user_by('id', $user->get_id()); + $userRoles = ($wpUser) ? $wpUser->roles : array($user->get_role()); + } else { + return false; + } + + $result = array_filter($userRoles, function ($userRole) use ($selectedRoles) { + return in_array($userRole, $selectedRoles); + }); + + return !empty($result); } } endif; diff --git a/src/include/class-wc-retailcrm-orders.php b/src/include/class-wc-retailcrm-orders.php index f96e3e1..6c39b82 100644 --- a/src/include/class-wc-retailcrm-orders.php +++ b/src/include/class-wc-retailcrm-orders.php @@ -171,7 +171,7 @@ if ( ! class_exists( 'WC_Retailcrm_Orders' ) ) : } if ($wpUser instanceof WP_User) { - if (!WC_Retailcrm_Customers::isCustomer($wpUser)) { + if (!$this->customers->isCustomer($wpUser)) { return false; } @@ -369,7 +369,7 @@ if ( ! class_exists( 'WC_Retailcrm_Orders' ) ) : $order_data = $this->orders->build($order)->get_data(); if ($order->get_items('shipping')) { - $shippings = $order->get_items( 'shipping' ); + $shippings = $order->get_items('shipping'); $shipping = reset($shippings); $shipping_code = explode(':', $shipping['method_id']); diff --git a/src/readme.txt b/src/readme.txt index 65bfbb5..27dbb43 100644 --- a/src/readme.txt +++ b/src/readme.txt @@ -45,6 +45,9 @@ API-ключ должен быть для отдельного магазина 2. В появившихся списках справочников настройте соответствие способов доставки и оплаты, а так же статусов заказов. Отметьте галочку "Выгружать остатки", если хотите выгружать остатки из Retailcrm в магазин (подробнее смотрите в описании). == Changelog == += 4.1.1 = +* Добавлена настройка выбора ролей клиентов для выгрузки в retailCRM + = 4.1.0 = * Добавлена возможность подключения Онлайн-консультанта diff --git a/src/retailcrm.php b/src/retailcrm.php index 5202acd..2b927b3 100644 --- a/src/retailcrm.php +++ b/src/retailcrm.php @@ -1,6 +1,6 @@