public function action_customers() { $customer_search = new Beans_Customer_Search($this->_beans_data_auth((object) array('page_size' => 5, 'sort_by' => 'newest'))); $customer_search_result = $customer_search->execute(); if ($this->_beans_result_check($customer_search_result)) { $this->_view->customer_search_result = $customer_search_result; } }
public function action_customersloadmore() { $last_customer_id = $this->request->post('last_customer_id'); $last_page = $this->request->post('last_page'); $search_terms = $this->request->post('search_terms'); $count = $this->request->post('count'); if (!$last_page) { $last_page = 0; } if (!$count) { $count = 20; } $this->_return_object->data->customers = array(); $search_parameters = new stdClass(); $search_parameters->sort_by = 'newest'; $search_parameters->page = $last_page; if ($search_terms) { $search_parameters->search_email = $search_terms; $search_parameters->search_name = $search_terms; $search_parameters->search_number = $search_terms; } do { $customer_search = new Beans_Customer_Search($this->_beans_data_auth($search_parameters)); $customer_search_result = $customer_search->execute(); if (!$customer_search_result->success) { return $this->_return_error("An unexpected error occurred: " . $this->_beans_result_get_error($customer_search_result)); } $this->_return_object->data->last_page = $customer_search_result->data->page; foreach ($customer_search_result->data->customers as $customer) { if ($customer->id < $last_customer_id or !$last_customer_id) { $html = new View_Partials_Customers_Customer_Customer(); $html->customer = $customer; $customer->html = $html->render(); $this->_return_object->data->customers[] = $customer; } if (count($this->_return_object->data->customers) >= $count) { return; } } $search_parameters->page++; } while ($search_parameters->page < $customer_search_result->data->pages and count($this->_return_object->data->customers) < $count); }