public function execute() { $id = (int) waRequest::get('id'); if ($id) { $this->form = shopHelper::getCustomerForm($id); } }
public function execute() { $form = shopHelper::getCustomerForm(); if ($form->post()) { $customer_validation_disabled = wa()->getSetting('disable_backend_customer_form_validation'); if ($customer_validation_disabled || $form->isValid()) { $c = new waContact(); if ($customer_validation_disabled) { $errors = array(); $c->save($form->post()); } else { $errors = $c->save($form->post(), true); } if (!$errors) { $scm = new shopCustomerModel(); $scm->createFromContact($c->getId()); echo '<script>$.customers.reloadSidebar(); window.location.hash = "#/id/' . $c->getId() . '"</script>'; exit; } // Show errors that waContact returned, e.g. email must be unique. foreach ($errors as $fld => $list) { foreach ($list as $err) { $form->errors($fld, $err); } } } } $this->view->assign('form', $form); $this->view->assign('customer_validation_disabled', wa()->getSetting('disable_backend_customer_form_validation')); }
protected function getForm() { $domain = wa()->getRouting()->getDomain(); $domain_config_path = wa()->getConfig()->getConfigPath('domains/' . $domain . '.php', true, 'site'); if (file_exists($domain_config_path)) { $domain_config = (include $domain_config_path); } else { $domain_config = array(); } if (!empty($domain_config['personal_fields'])) { return parent::getForm(); } return shopHelper::getCustomerForm(null, true); }
public function execute() { $order_id = waRequest::get('id', null, waRequest::TYPE_INT); $form = null; $order = array(); $shipping_address = array(); // Existing order? if ($order_id) { $order = $this->getOrder($order_id); $currency = $order['currency']; if ($order['contact_id']) { $has_contacts_rights = shopHelper::getContactRights($order['contact_id']); $shipping_address = shopHelper::getOrderAddress($order['params'], 'shipping'); if (!empty($order['contact_id'])) { try { $c = new waContact($order['contact_id']); if ($shipping_address) { $c['address.shipping'] = $shipping_address; } $form = shopHelper::getCustomerForm($c); } catch (waException $e) { // Contact does not exist; ignore. When $form is null, customer data saved in order is shown. } } } else { $has_contacts_rights = shopHelper::getContactRights(); } } else { $currency = $this->getConfig()->getCurrency(); $has_contacts_rights = shopHelper::getContactRights(); $form = shopHelper::getCustomerForm(); } $stock_model = new shopStockModel(); $stocks = $stock_model->getAll('id'); $tax_model = new shopTaxModel(); $taxes_count = $tax_model->countAll(); $count_new = $this->order_model->getStateCounters('new'); /** * Backend order edit page * @event backend_order_edit * @param array $order * @return array[string][string] $return[%plugin_id%] html output */ $this->view->assign('backend_order_edit', wa()->event('backend_order_edit', $order)); $this->view->assign(array('form' => $form, 'order' => $order, 'stocks' => $stocks, 'currency' => $currency, 'count_new' => $count_new, 'taxes_count' => $taxes_count, 'shipping_address' => $shipping_address, 'has_contacts_rights' => $has_contacts_rights, 'customer_validation_disabled' => wa()->getSetting('disable_backend_customer_form_validation'), 'ignore_stock_count' => wa()->getSetting('ignore_stock_count'))); }
/** * Execute step * * @return bool */ public function execute() { $contact = $this->getContact(); if (!$contact) { $contact = new waContact(); } $data = waRequest::post('customer'); if ($data && is_array($data)) { foreach ($data as $field => $value) { $contact->set($field, $value); } } $this->form = shopHelper::getCustomerForm(); if ($shipping = $this->getSessionData('shipping') && !waRequest::post('ignore_shipping_error')) { $shipping_step = new shopOnestepCheckoutShipping(); $rate = $shipping_step->getRate($shipping['id'], isset($shipping['rate_id']) ? $shipping['rate_id'] : null, $contact); if (!$rate || is_string($rate)) { // remove selected shipping method $this->setSessionData('shipping', null); /* $errors = array(); $errors['all'] = sprintf(_w('We cannot ship to the specified address via %s.'), $shipping['name']); if ($rate) { $errors['all'] .= '<br> <strong>'.$rate.'</strong><br>'; } $errors['all'] .= '<br> '._w('Please double-check the address above, or return to the shipping step and select another shipping option.'); $errors['all'] .= '<input type="hidden" name="ignore_shipping_error" value="1">'; wa()->getView()->assign('errors', $errors); return false; */ } } if (wa()->getUser()->isAuth()) { $contact->save(); } else { $errors = array(); if (waRequest::post('create_user')) { $login = waRequest::post('login'); if (!$login) { $errors['email'][] = _ws('Required'); } if (!waRequest::post('password')) { $errors['password'] = _ws('Required'); } $email_validator = new waEmailValidator(); if (!$email_validator->isValid($login)) { $errors['email'] = $email_validator->getErrors(); } if (!$errors) { $contact_model = new waContactModel(); if ($contact_model->getByEmail($login, true)) { $errors['email'][] = _w('Email already registered'); } } if (!$errors) { $contact->set('email', $login); $contact->set('password', waRequest::post('password')); } else { if (isset($errors['email'])) { $errors['email'] = implode(', ', $errors['email']); } wa()->getView()->assign('errors', $errors); return false; } } $this->setSessionData('contact', $contact); } if ($comment = waRequest::post('comment')) { $this->setSessionData('comment', $comment); } if (!$this->form->isValid($contact)) { return false; } return true; }
public function execute() { $id = waRequest::get('id', null, waRequest::TYPE_INT); // null - don't add/edit contact info // not zero numeric - edit existing contact // zero numeric - add contact $customer_id = waRequest::post('customer_id', null, waRequest::TYPE_INT); if ($customer_id && !shopHelper::getContactRights($customer_id)) { $customer_id = null; } if ($customer_id === null && !$id) { $customer_id = 0; } if ($customer_id !== null) { $contact = new waContact($customer_id); $form = shopHelper::getCustomerForm($customer_id); $customer_validation_disabled = wa()->getSetting('disable_backend_customer_form_validation'); if (!$customer_validation_disabled) { if (!$form->isValid($contact)) { $this->errors['customer']['html'] = $form->html(); } } } if ($data = $this->getData($id)) { $this->validate($data, $id); } if ($this->errors) { return; } $params_model = new shopOrderParamsModel(); $params = $params_model->get($id); if ($customer_id !== null) { foreach ((array) $form->post() as $fld_id => $fld_data) { if (!$fld_data) { continue; } if ($fld_id == 'address.shipping') { $this->shipping_address = $fld_data; $this->setAddress($contact, $params, 'shipping'); continue; } elseif ($fld_id == 'address.billing') { $this->billing_address = $fld_data; $this->setAddress($contact, $params, 'billing'); continue; } if (is_array($fld_data) && !empty($fld_data[0])) { $contact[$fld_id] = array(); foreach ($fld_data as $v) { $contact->set($fld_id, $v, true); } } else { $contact[$fld_id] = $fld_data; } } if ($customer_validation_disabled) { $contact->save(); } else { $errors = $contact->save(array(), true); if ($errors) { // Only consider errors from visible fields $errors = array_intersect_key($errors, $form->fields); if ($errors) { $this->errors['customer'] = $errors; return; } else { // No errors from visible fields: save anyway $contact->save(); } } } $data['contact'] = $contact; } $workflow = new shopWorkflow(); $this->getParams($data, $id); if (!$id) { $id = $workflow->getActionById('create')->run($data); } else { $data['id'] = $id; $workflow->getActionById('edit')->run($data); } $this->response['order'] = $this->workupOrder($this->getModel()->getOrder($id)); }