Exemplo n.º 1
0
 function register_validate()
 {
     $app = JFactory::getApplication();
     $user = JFactory::getUser();
     $session = JFactory::getSession();
     $view = $this->getThisView();
     if ($model = $this->getThisModel()) {
         // Push the model into the view (as default)
         $view->setModel($model, true);
     }
     $redirect_url = JRoute::_('index.php?option=com_j2store&view=checkout');
     $data = $app->input->getArray($_POST);
     $address_model = F0FModel::getTmpInstance('Addresses', 'J2StoreModel');
     $store_address = $store = J2Store::storeProfile();
     $userHelper = J2Store::user();
     $json = array();
     // Validate if customer is already logged out.
     if ($user->id) {
         $json['redirect'] = $redirect_url;
     }
     if (!$json) {
         $selectableBase = J2Store::getSelectableBase();
         $json = $selectableBase->validate($data, 'billing', 'address');
         //validate the password fields
         if (JString::strlen($app->input->post->get('password')) < 4) {
             $json['error']['password'] = JText::_('J2STORE_PASSWORD_REQUIRED');
         }
         if ($app->input->post->get('confirm') != $app->input->post->get('password')) {
             $json['error']['confirm'] = JText::_('J2STORE_PASSWORDS_DOESTNOT_MATCH');
         }
         //check email
         if (JString::strlen($app->input->post->get('email')) < 4) {
             $json['error']['email'] = JText::_('J2STORE_EMAIL_REQUIRED');
         }
         //check email
         if ($userHelper->emailExists($app->input->post->getString('email'))) {
             $json['error']['email'] = JText::_('J2STORE_EMAIL_EXISTS');
         }
     }
     J2Store::plugin()->event('CheckoutValidateRegister', array(&$json));
     if (!$json) {
         $post = $app->input->getArray($_POST);
         //now create the user
         // create the details array with new user info
         $details = array('email' => $app->input->getString('email'), 'name' => $app->input->getString('first_name') . ' ' . $app->input->getString('last_name'), 'username' => $app->input->getString('email'), 'password' => $app->input->getString('password'), 'password2' => $app->input->getString('confirm'));
         $msg = '';
         $user = $userHelper->createNewUser($details, $msg);
         $session->set('account', 'register', 'j2store');
         //now login the user
         if ($userHelper->login(array('username' => $user->username, 'password' => $details['password']))) {
             //$billing_address_id = $userHelper->addCustomer($post);
             $billing_address_id = $address_model->addAddress('billing');
             //check if we have a country and zone id's. If not use the store address
             $country_id = $app->input->post->getInt('country_id', '');
             if (empty($country_id)) {
                 $country_id = $store_address->get('country_id');
             }
             $zone_id = $app->input->post->getInt('zone_id', '');
             if (empty($zone_id)) {
                 $zone_id = $store_address->get('zone_id');
             }
             $postcode = $app->input->post->getString('zip');
             if (empty($postcode)) {
                 $postcode = $store_address->get('zip');
             }
             $session->set('billing_address_id', $billing_address_id, 'j2store');
             $session->set('billing_country_id', $country_id, 'j2store');
             $session->set('billing_zone_id', $zone_id, 'j2store');
             $session->set('billing_postcode', $postcode, 'j2store');
             $shipping_address = $app->input->post->get('shipping_address');
             if (!empty($shipping_address)) {
                 $session->set('shipping_address_id', $billing_address_id, 'j2store');
                 $session->set('shipping_country_id', $country_id, 'j2store');
                 $session->set('shipping_zone_id', $zone_id, 'j2store');
                 $session->set('shipping_postcode', $postcode, 'j2store');
             }
             if (!$json) {
                 $json = J2Store::plugin()->eventWithArray('CheckoutAfterRegister');
             }
         } else {
             $json['redirect'] = $redirect_url;
         }
         $session->clear('guest', 'j2store');
         $session->clear('shipping_method', 'j2store');
         $session->clear('shipping_methods', 'j2store');
         $session->clear('payment_method', 'j2store');
         $session->clear('payment_methods', 'j2store');
     }
     echo json_encode($json);
     $app->close();
 }
Exemplo n.º 2
0
 function validateEmailexists($new_email)
 {
     $json = array();
     $success = true;
     $model = $this->getThisModel();
     if (J2Store::user()->emailExists($new_email)) {
         $success = false;
         $json = array('msg' => JText::_('J2STORE_EMAIL_UPDATE_ERROR_WARNING'), 'msgType' => 'warning');
     }
     if ($success) {
         $json = array('redirect' => JUri::base() . 'index.php?option=com_j2store&view=customer&task=viewOrder&email_id=' . $new_email, 'msg' => JText::_('J2STORE_SUCCESS_SAVING_EMAIL'), 'msgType' => 'message');
         if (!$model->savenewEmail()) {
             $json = array('msg' => JText::_('J2STORE_ERROR_SAVING_EMAIL'), 'msgType' => 'warning');
         }
     }
     return $json;
 }