1
0
mirror of synced 2025-03-20 23:24:02 +03:00

Add selection of client roles (#148)

This commit is contained in:
max-baranikov 2020-08-18 16:22:26 +03:00 committed by GitHub
parent e1a22abab0
commit 6f9ce78d50
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 93 additions and 20 deletions

View File

@ -1,3 +1,6 @@
## 2020-08-08 4.1.1
* Добавлена настройка выбора ролей клиентов для выгрузки в retailCRM
## 2020-08-05 4.1.0
* Добавлена возможность подключения Онлайн-консультанта

View File

@ -1 +1 @@
4.1.0
4.1.1

View File

@ -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"

View File

@ -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 на сайт"

View File

@ -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
*/

View File

@ -1,4 +1,5 @@
<?php
/**
* RetailCRM Integration.
*
@ -24,7 +25,7 @@ if (!class_exists('WC_Retailcrm_Customers')) :
*/
const CUSTOMER_ROLE = 'customer';
/** @var bool | WC_Retailcrm_Proxy | \WC_Retailcrm_Client_V5 */
/** @var bool | WC_Retailcrm_Proxy | \WC_Retailcrm_Client_V5 */
protected $retailcrm;
/** @var array */
@ -106,7 +107,7 @@ if (!class_exists('WC_Retailcrm_Customers')) :
$data_customers = array();
foreach ($users as $user) {
if (!static::isCustomer($user)) {
if (!$this->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;

View File

@ -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']);

View File

@ -45,6 +45,9 @@ API-ключ должен быть для отдельного магазина
2. В появившихся списках справочников настройте соответствие способов доставки и оплаты, а так же статусов заказов. Отметьте галочку "Выгружать остатки", если хотите выгружать остатки из Retailcrm в магазин (подробнее смотрите в описании).
== Changelog ==
= 4.1.1 =
* Добавлена настройка выбора ролей клиентов для выгрузки в retailCRM
= 4.1.0 =
* Добавлена возможность подключения Онлайн-консультанта

View File

@ -1,6 +1,6 @@
<?php
/**
* Version: 4.1.0
* Version: 4.1.1
* WC requires at least: 3.0
* WC tested up to: 3.9.3
* Plugin Name: WooCommerce retailCRM

View File

@ -15,7 +15,7 @@
*
*
* @link https://wordpress.org/plugins/woo-retailcrm/
* @version 4.1.0
* @version 4.1.1
*
* @package RetailCRM
*/