コード例 #1
0
ファイル: checkout.php プロジェクト: ForAEdesWeb/AEW4
 function register_validate()
 {
     $app = JFactory::getApplication();
     $user = JFactory::getUser();
     $model = $this->getModel('checkout');
     $redirect_url = JRoute::_('index.php?option=com_j2store&view=checkout');
     $data = $app->input->getArray($_POST);
     $address_model = $this->getModel('address');
     $store_address = J2StoreHelperCart::getStoreAddress();
     require_once JPATH_ADMINISTRATOR . '/components/com_j2store/library/user.php';
     $userHelper = new J2StoreHelperUser();
     $json = array();
     // Validate if customer is already logged out.
     if ($user->id) {
         $json['redirect'] = $redirect_url;
     }
     // Validate cart has products and has stock.
     if (!J2StoreHelperCart::hasProducts()) {
         $json['redirect'] = $redirect_url;
     }
     if (!$json) {
         $selectableBase = J2StoreFactory::getSelectableBase();
         $json = $selectableBase->validate($data, 'register', '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 ($userHelper->emailExists($app->input->post->getString('email'))) {
             $json['error']['email'] = JText::_('J2STORE_EMAIL_EXISTS');
         }
     }
     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);
         $this->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->country_id;
             }
             $zone_id = $app->input->post->getInt('zone_id', '');
             if (empty($zone_id)) {
                 $zone_id = $store_address->zone_id;
             }
             $postcode = $app->input->post->getString('zip');
             if (empty($postcode)) {
                 $postcode = $store_address->store_zip;
             }
             $this->session->set('billing_address_id', $billing_address_id, 'j2store');
             $this->session->set('billing_country_id', $country_id, 'j2store');
             $this->session->set('billing_zone_id', $zone_id, 'j2store');
             $shipping_address = $app->input->post->get('shipping_address');
             if (!empty($shipping_address)) {
                 $this->session->set('shipping_address_id', $billing_address_id, 'j2store');
                 $this->session->set('shipping_country_id', $country_id, 'j2store');
                 $this->session->set('shipping_zone_id', $zone_id, 'j2store');
                 $this->session->set('shipping_postcode', $postcode, 'j2store');
             }
         } else {
             $json['redirect'] = $redirect_url;
         }
         $this->session->clear('guest', 'j2store');
         $this->session->clear('shipping_method', 'j2store');
         $this->session->clear('shipping_methods', 'j2store');
         $this->session->clear('payment_method', 'j2store');
         $this->session->clear('payment_methods', 'j2store');
     }
     echo json_encode($json);
     $app->close();
 }