/** * register customer with extended validation (valid password, address check and notification sent) * * @param array $customer_data * information about customer * * @param array $address_data * information about customer's address * * @param array $company_data * information about customer's company * * @return integer * customer ID or false if not saved */ function registerCustomer($customer_data, $address_data = null, $company_data = null) { /** * check address is valid */ if (is_array($address_data)) { require_once 'models/client/client_address.php'; $Address = new client_address(); $address_data['delivery']['customer_id'] = 0; $Address->setAll($address_data['delivery']); if (!$Address->getValid()) { msg('Not a valid address', 'error'); msg($address_data); return false; } } /** * insert customer */ if ($customer_data = $this->prepareToRegister($customer_data)) { $id = $this->insertCustomer($customer_data); if ($id) { $customer_data['id'] = $id; /** * insert company and update customer data */ if (strlen(trim($company_data['name']))) { require_once 'models/client/client_company.php'; $company_data['customer_id'] = $customer_data['id']; $Company = new client_company($company_data); if ($company_id = $Company->insert($company_data)) { $customer_data['company_id'] = $company_id; $this->update($customer_data); } } if ($customer_data['status'] != 5 && $this->conf['registration_mail_send_to_customer'] == 1) { /** * send notification email */ require_once 'models/common/common_email.php'; $EmailForm = new common_email(); //this allows use customer data and company data in the mail template //is passed as DATA to template in common_email->_format $GLOBALS['common_email']['customer'] = $customer_data; $GLOBALS['common_email']['company'] = $company_data; if (!$EmailForm->sendEmail('registration', 'n/a', $customer_data['email'], $customer_data['first_name'] . " " . $customer_data['last_name'])) { msg('New customer email sending failed.', 'error'); } //send it to the customer registration admin email /* if ($GLOBALS['onxshop_conf']['global']['admin_email'] != $this->conf['registration_mail_to_address']) { if (!$EmailForm->sendEmail('registration', 'n/a', $this->conf['registration_mail_to_address'], $this->conf['registration_mail_to_name'])) { msg('New customer email sending failed.', 'error'); } }*/ //send notification to admin if (!$EmailForm->sendEmail('registration_notify', 'n/a', $this->conf['registration_mail_to_address'], $this->conf['registration_mail_to_name'])) { msg('Admin notification email sending failed.', 'error'); } } /** * insert address and update customer data */ $this->insertCustomerAddress($customer_data, $address_data); /** * return customer ID */ msg("client_customer.registerCustomer() of customer ID {$id} was successful.", 'ok', 1); return $id; } else { return false; } } }