/** * 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; }