Ejemplo n.º 1
0
 /**
  * Check validation
  *
  * @param   string  $users_info_id  not used
  *
  * @return bool
  */
 public function chkvalidation($users_info_id)
 {
     $model = $this->getModel('checkout');
     $billingaddresses = $model->billingaddresses();
     $shippingaddresses = $model->shipaddress($users_info_id);
     $extra_field = new extra_field();
     $extrafield_name = '';
     $return = 0;
     if (!$billingaddresses->is_company) {
         if ($billingaddresses->firstname == '') {
             $return = 1;
             $msg = JText::_('COM_REDSHOP_PLEASE_ENTER_FIRST_NAME');
             JError::raiseWarning('', $msg);
             return $return;
         } elseif ($billingaddresses->lastname == '') {
             $return = 1;
             $msg = JText::_('COM_REDSHOP_PLEASE_ENTER_LAST_NAME');
             JError::raiseWarning('', $msg);
             return $return;
         }
     } else {
         if ($billingaddresses->company_name == '') {
             $return = 1;
             $msg = JText::_('COM_REDSHOP_PLEASE_ENTER_COMPANY_NAME');
             JError::raiseWarning('', $msg);
             return $return;
         }
         if ($billingaddresses->firstname == '') {
             $return = 1;
             $msg = JText::_('COM_REDSHOP_PLEASE_ENTER_FIRST_NAME');
             JError::raiseWarning('', $msg);
             return $return;
         } elseif ($billingaddresses->lastname == '') {
             $return = 1;
             $msg = JText::_('COM_REDSHOP_PLEASE_ENTER_LAST_NAME');
             JError::raiseWarning('', $msg);
             return $return;
         } elseif (ECONOMIC_INTEGRATION == 1 && trim($billingaddresses->ean_number) != '') {
             $economic = new economic();
             $debtorHandle = $economic->createUserInEconomic($billingaddresses);
             if (JError::isError(JError::getError())) {
                 $return = 1;
                 $error = JError::getError();
                 $msg = $error->message;
                 JError::raiseWarning('', $msg);
                 return $return;
             }
         }
     }
     if (!trim($billingaddresses->address)) {
         $return = 1;
         $msg = JText::_('COM_REDSHOP_PLEASE_ENTER_ADDRESS');
         JError::raiseWarning('', $msg);
         return $return;
     } elseif (!$billingaddresses->country_code) {
         $return = 1;
         $msg = JText::_('COM_REDSHOP_PLEASE_SELECT_COUNTRY');
         JError::raiseWarning('', $msg);
         return $return;
     } elseif (!$billingaddresses->zipcode) {
         $return = 1;
         $msg = JText::_('COM_REDSHOP_PLEASE_ENTER_ZIPCODE');
         JError::raiseWarning('', $msg);
         return $return;
     } elseif (!$billingaddresses->phone) {
         $return = 1;
         $msg = JText::_('COM_REDSHOP_PLEASE_ENTER_PHONE');
         JError::raiseWarning('', $msg);
         return $return;
     }
     if ($billingaddresses->is_company == 1) {
         $extrafield_name = $extra_field->chk_extrafieldValidation(8, $billingaddresses->users_info_id);
         if (!empty($extrafield_name)) {
             $return = 1;
             $msg = $extrafield_name . JText::_('COM_REDSHOP_IS_REQUIRED');
             JError::raiseWarning('', $msg);
             return $return;
         }
     } else {
         $extrafield_name = $extra_field->chk_extrafieldValidation(7, $billingaddresses->users_info_id);
         if (!empty($extrafield_name)) {
             $return = 1;
             $msg = $extrafield_name . JText::_('COM_REDSHOP_IS_REQUIRED');
             JError::raiseWarning('', $msg);
             return $return;
         }
     }
     if (SHIPPING_METHOD_ENABLE && $users_info_id != $billingaddresses->users_info_id) {
         if ($billingaddresses->is_company == 1) {
             $extrafield_name = $extra_field->chk_extrafieldValidation(15, $users_info_id);
             if (!empty($extrafield_name)) {
                 $return = 2;
                 $msg = $extrafield_name . JText::_('COM_REDSHOP_IS_REQUIRED');
                 JError::raiseWarning('', $msg);
                 return $return;
             }
         } else {
             $extrafield_name = $extra_field->chk_extrafieldValidation(14, $users_info_id);
             if (!empty($extrafield_name)) {
                 $return = 2;
                 $msg = $extrafield_name . JText::_('COM_REDSHOP_IS_REQUIRED');
                 JError::raiseWarning('', $msg);
                 return $return;
             }
         }
     }
     return $return;
 }
Ejemplo n.º 2
0
 public function storeRedshopUser($data, $user_id = 0, $admin = 0)
 {
     $redshopMail = new redshopMail();
     $extra_field = new extra_field();
     $helper = new redhelper();
     $data['user_email'] = $data['email'] = $data['email1'];
     $data['name'] = $name = $data['firstname'];
     $data['address_type'] = 'BT';
     $row = JTable::getInstance('user_detail', 'Table');
     if (isset($data['users_info_id']) && $data['users_info_id'] != 0) {
         $isNew = false;
         $row->load($data['users_info_id']);
         $data["old_tax_exempt_approved"] = $row->tax_exempt_approved;
         $user_id = $row->user_id;
     } else {
         $isNew = true;
         $data['password'] = JRequest::getVar('password1', '', 'post', 'string', JREQUEST_ALLOWRAW);
         $app = JFactory::getApplication();
         $is_admin = $app->isAdmin();
         if ($data['is_company'] == 1) {
             if ($is_admin && $data['shopper_group_id'] != 0) {
                 $data['shopper_group_id'] = $data['shopper_group_id'];
             } else {
                 $data['shopper_group_id'] = SHOPPER_GROUP_DEFAULT_COMPANY != 0 ? SHOPPER_GROUP_DEFAULT_COMPANY : 2;
             }
         } else {
             if ($is_admin && isset($data['shopper_group_id']) && $data['shopper_group_id'] != 0) {
                 $data['shopper_group_id'] = $data['shopper_group_id'];
             } else {
                 $data['shopper_group_id'] = SHOPPER_GROUP_DEFAULT_PRIVATE != 0 ? SHOPPER_GROUP_DEFAULT_PRIVATE : 1;
             }
         }
     }
     if ($user_id > 0) {
         $joomlauser = new JUser($user_id);
         $data['username'] = $joomlauser->username;
         $data['name'] = $joomlauser->name;
         $data['email'] = $joomlauser->email;
     }
     if (SHOW_TERMS_AND_CONDITIONS == 1 && isset($data['termscondition']) && $data['termscondition'] == 1) {
         $data['accept_terms_conditions'] = 1;
     }
     $row->user_id = $data['user_id'] = $user_id;
     if (!$row->bind($data)) {
         $this->setError($this->_db->getErrorMsg());
         return false;
     }
     if (USE_TAX_EXEMPT) {
         if (!$admin && $row->is_company == 1) {
             $row->requesting_tax_exempt = $data['tax_exempt'];
             if ($row->requesting_tax_exempt == 1) {
                 $redshopMail->sendRequestTaxExemptMail($row, $data['username']);
             }
         }
         // Sending tax exempted mails (tax_exempt_approval_mail)
         if (!$isNew && $admin && isset($data["tax_exempt_approved"]) && $data["old_tax_exempt_approved"] != $data["tax_exempt_approved"]) {
             if ($data["tax_exempt_approved"] == 1) {
                 $redshopMail->sendTaxExemptMail("tax_exempt_approval_mail", $data, $row->user_email);
             } else {
                 $redshopMail->sendTaxExemptMail("tax_exempt_disapproval_mail", $data, $row->user_email);
             }
         }
     }
     if (!$row->store()) {
         $this->setError($this->_db->getErrorMsg());
         return false;
     }
     // Update user info id
     if (ECONOMIC_INTEGRATION) {
         $economic = new economic();
         $original_info_id = $row->users_info_id;
         if ($isNew) {
             $maxDebtor = $economic->getMaxDebtorInEconomic();
             if (count($maxDebtor) > 0) {
                 $maxDebtor = $maxDebtor[0];
                 if ($row->users_info_id <= $maxDebtor) {
                     $nextId = $maxDebtor + 1;
                     $sql = "UPDATE " . $this->_table_prefix . "users_info " . "SET users_info_id = " . (int) $nextId . " " . "WHERE users_info_id = " . (int) $row->users_info_id;
                     $this->_db->setQuery($sql);
                     $this->_db->Query();
                     $row->users_info_id = $nextId;
                 }
             }
         }
         $debtorHandle = $economic->createUserInEconomic($row);
         if ($row->is_company && trim($row->ean_number) != '' && JError::isError(JError::getError())) {
             $msg = JText::_('PLEASE_ENTER_EAN_NUMBER');
             JError::raiseWarning('', $msg);
             return false;
         }
     }
     $auth['users_info_id'] = $row->users_info_id;
     $this->_session->set('auth', $auth);
     // For non-registered customers
     if (!$row->user_id) {
         $row->user_id = 0 - $row->users_info_id;
         $row->store();
         $u = JFactory::getUser();
         $u->set('username', $row->user_email);
         $u->set('email', $row->user_email);
         $u->set('usertype', 'Registered');
         $date = JFactory::getDate();
         $u->set('registerDate', $date->toMySQL());
         $data['user_id'] = $row->user_id;
         $data['username'] = $row->user_email;
         $data['email'] = $row->user_email;
     }
     if (isset($data['newsletter_signup']) && $data['newsletter_signup'] == 1) {
         $this->newsletterSubscribe($row->user_id, $data);
     }
     $billisship = 1;
     if (!isset($data['billisship'])) {
         $billisship = 0;
     }
     // Info: field_section 6 :Userinformations
     $list_field = $extra_field->extra_field_save($data, 6, $row->users_info_id);
     if ($row->is_company == 0) {
         // Info: field_section 7 :Userinformations
         $list_field = $extra_field->extra_field_save($data, 7, $row->users_info_id);
     } else {
         // Info: field_section 8 :Userinformations
         $list_field = $extra_field->extra_field_save($data, 8, $row->users_info_id);
     }
     if ($billisship != 1) {
         $rowShip = $this->storeRedshopUserShipping($data);
     }
     if (REGISTER_METHOD != 1 && $isNew && $admin == 0) {
         if (REGISTER_METHOD == 2) {
             if (isset($data['createaccount']) && $data['createaccount'] == 1) {
                 $redshopMail->sendRegistrationMail($data);
             }
         } else {
             $redshopMail->sendRegistrationMail($data);
         }
     }
     if ($isNew) {
         JPluginHelper::importPlugin('highrise');
         $dispatcher = JDispatcher::getInstance();
         $hResponses = $dispatcher->trigger('oncreateHighriseUser', array());
     }
     /**
      * redCRM includes
      */
     if ($helper->isredCRM()) {
         $this->setoreredCRMDebtor($row);
     }
     return $row;
 }