protected function getContact()
 {
     // Create new temporary waContact object
     $contact = new waContact(wa()->getUser()->getId());
     // Assign address with the right extension, if no extension is set
     if ($this->form->fields('address.shipping') && !$contact->get('address.shipping') && ($addresses = $contact->get('address'))) {
         $contact->set('address.shipping', $addresses[0]);
     }
     if ($this->form->fields('address.billing') && !$contact->get('address.billing') && ($addresses = $contact->get('address.shipping'))) {
         $contact->set('address.billing', $addresses[0]);
     }
     return $contact;
 }
 /**
  * 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()
 {
     if ($shipping_id = waRequest::post('shipping_id')) {
         if ($data = waRequest::post('customer_' . $shipping_id)) {
             $settings = wa('shop')->getConfig()->getCheckoutSettings();
             if (!isset($settings['contactinfo']) || !isset($settings['contactinfo']['fields']['address.shipping']) && !isset($settings['contactinfo']['fields']['address'])) {
                 $settings = wa('shop')->getConfig()->getCheckoutSettings(true);
             }
             $plugin = shopShipping::getPlugin(null, $shipping_id);
             $form = $this->getAddressForm($shipping_id, $plugin, $settings, array(), true);
             if (!$form->isValid()) {
                 return false;
             }
             $contact = $this->getContact();
             if (!$contact) {
                 $contact = new waContact();
             }
             if ($data && is_array($data)) {
                 foreach ($data as $field => $value) {
                     if (is_array($value) && ($old = $contact->get($field))) {
                         if (isset($old[0]['data'])) {
                             foreach ($old[0]['data'] as $k => $v) {
                                 if (!isset($value[$k])) {
                                     $value[$k] = $v;
                                 }
                             }
                         }
                     }
                     $contact->set($field, $value);
                 }
                 if (wa()->getUser()->isAuth()) {
                     $contact->save();
                 } else {
                     $this->setSessionData('contact', $contact);
                 }
             }
         }
         $rates = waRequest::post('rate_id');
         $rate_id = isset($rates[$shipping_id]) ? $rates[$shipping_id] : null;
         $rate = $this->getRate($shipping_id, $rate_id);
         if (is_string($rate)) {
             $rate = false;
         }
         $this->setSessionData('shipping', array('id' => $shipping_id, 'rate_id' => $rate_id, 'name' => $rate ? $rate['name'] : '', 'plugin' => $rate ? $rate['plugin'] : ''));
         if (!$rate) {
             return false;
         }
         if ($comment = waRequest::post('comment')) {
             $this->setSessionData('comment', $comment);
         }
         if ($shipping_params = waRequest::post('shipping_' . $shipping_id)) {
             $params = $this->getSessionData('params', array());
             $params['shipping'] = $shipping_params;
             $this->setSessionData('params', $params);
         }
         return true;
     } else {
         return false;
     }
 }