/** * add customers to group */ public function addCustomersToGroup($group_id, $group_ids_remove) { require_once 'models/client/client_group.php'; require_once 'models/client/client_customer.php'; $ClientGroup = new client_group(); $Customer = new client_customer(); //force cache even for back office user $Customer->setCacheable(true); if ($group_filter = $this->getGroupFilter($group_id)) { $customer_list = $Customer->getClientList(0, $group_filter); $list_count = count($customer_list); if ($Customer->addCustomersToGroupFromList($customer_list, $group_id, $group_ids_remove)) { msg("All {$list_count} customers were added to group ID {$group_id}"); //flush cache as we are using forced cache for client_customer in backoffice $Customer->flushCache(); } else { msg("Cannot add {$list_count} customers to group ID {$group_id}", 'error'); return false; } } else { return false; } }
/** * main action */ public function mainAction() { require_once 'models/client/client_customer.php'; require_once 'models/client/client_customer_taxonomy.php'; $Customer = new client_customer(); $Taxonomy = new client_customer_taxonomy(); //force cache even for back office user $Customer->setCacheable(true); /** * Filtering */ /** * Get the list */ $customer_filter = $_SESSION['bo']['customer-filter']; // account_type is integer, but we also allow in UI to use it for backoffice users if ($customer_filter['account_type'] == 'backoffice') { $customer_filter['backoffice_role_only'] = 1; } // get the list $customer_list = $Customer->getClientList(0, $customer_filter); if (is_array($customer_list) && count($customer_list) > 0) { /** * Sorting */ if ($this->GET['customer-list-sort-by']) { $_SESSION['bo']['customer-list-sort-by'] = $this->GET['customer-list-sort-by']; } if ($this->GET['customer-list-sort-direction']) { $_SESSION['bo']['customer-list-sort-direction'] = $this->GET['customer-list-sort-direction']; } if ($_SESSION['bo']['customer-list-sort-by']) { $sortby = $_SESSION['bo']['customer-list-sort-by']; } else { $sortby = "id"; } if ($_SESSION['bo']['customer-list-sort-direction']) { $direction = $_SESSION['bo']['customer-list-sort-direction']; } else { $direction = "DESC"; } //msg("Sorted by $sortby $direction"); switch ($sortby) { default: case 'id': $customer_list = php_multisort($customer_list, array(array('key' => 'customer_id', 'sort' => $direction), array('key' => 'customer_id', 'type' => 'numeric'))); foreach ($customer_list as $item) { $p[] = $item; } $customer_list = $p; break; case 'last_order': $customer_list = php_multisort($customer_list, array(array('key' => 'last_order', 'sort' => $direction), array('key' => 'customer_id', 'type' => 'numeric'))); foreach ($customer_list as $item) { $p[] = $item; } $customer_list = $p; break; case 'goods_net': $customer_list = php_multisort($customer_list, array(array('key' => 'goods_net', 'sort' => $direction), array('key' => 'customer_id', 'type' => 'numeric'))); foreach ($customer_list as $item) { $p[] = $item; } $customer_list = $p; break; case 'count_baskets': $customer_list = php_multisort($customer_list, array(array('key' => 'count_baskets', 'sort' => $direction), array('key' => 'customer_id', 'type' => 'numeric'))); foreach ($customer_list as $item) { $p[] = $item; } $customer_list = $p; break; case 'count_orders': $customer_list = php_multisort($customer_list, array(array('key' => 'count_orders', 'sort' => $direction), array('key' => 'customer_id', 'type' => 'numeric'))); foreach ($customer_list as $item) { $p[] = $item; } $customer_list = $p; break; case 'count_items': $customer_list = php_multisort($customer_list, array(array('key' => 'count_items', 'sort' => $direction), array('key' => 'customer_id', 'type' => 'numeric'))); foreach ($customer_list as $item) { $p[] = $item; } $customer_list = $p; break; } /** * Initialize pagination variables */ if (is_numeric($this->GET['limit_from'])) { $from = $this->GET['limit_from']; } else { $from = 0; } if (is_numeric($this->GET['limit_per_page'])) { $per_page = $this->GET['limit_per_page']; } else { $per_page = 25; } $limit = "{$from},{$per_page}"; /** * Display pagination */ //$link = "/page/" . $_SESSION['active_pages'][0]; $count = count($customer_list); $_Onxshop_Request = new Onxshop_Request("component/pagination~limit_from={$from}:limit_per_page={$per_page}:count={$count}~"); $this->tpl->assign('PAGINATION', $_Onxshop_Request->getContent()); /** * Display items * Implemented pagination */ foreach ($customer_list as $i => $customer) { if ($i >= $from && $i < $from + $per_page) { $even_odd = 'odd' != $even_odd ? 'odd' : 'even'; $item['even_odd'] = $even_odd; $taxonomy = $Taxonomy->getRelationsToCustomer($customer['customer_id']); foreach ($taxonomy as $t) { $customer['class'] .= "t{$t} "; } $role_ids = $Customer->getRoleIds($customer['customer_id']); foreach ($role_ids as $r) { $customer['class'] .= "role_{$r} "; } $this->tpl->assign('ITEM', $customer); $this->tpl->parse('content.list.item'); } } $this->tpl->parse('content.list'); } else { msg("No user found", 'error'); } return true; }