Esempio n. 1
0
 public function getShippingAddress($user_id = 0)
 {
     $helper = new redhelper();
     $user = JFactory::getUser();
     $session = JFactory::getSession();
     // Get redCRM Contact person session array
     $isredcrmuser = $session->get('isredcrmuser', false);
     $isredcrmuser_debitor = $session->get('isredcrmuser_debitor', false);
     $app = JFactory::getApplication();
     $is_admin = $app->isAdmin();
     if ($user_id == 0) {
         $user_id = $user->id;
     }
     if ($helper->isredCRM()) {
         $crmHelper = new crmHelper();
         $crmDebitorHelper = new crmDebitorHelper();
         /*
          * function will check loign redshop user
          * is redCRM contact person or not
          *
          * @return: joomla user of redSHOP shipping user belong to contact person
          */
         $crmuserssid = 0;
         $crmusers = array();
         if ($isredcrmuser) {
             $contact_person = $crmDebitorHelper->getContactPersons(0, 0, 0, $user_id);
             $contact_person = $contact_person[0];
             $crmuserssid = $contact_person->shipping_id;
             $crmusers = $crmHelper->getShippingUserId(0, $crmuserssid);
         }
         $list = array();
         if (count($crmusers) > 0) {
             $crmusersinfo = '';
             JArrayHelper::toInteger($crmusers);
             $crmusersinfo = implode(",", $crmusers);
             $query = 'SELECT ui.*,IFNULL(destination_name,CONCAT(firstname," ",lastname)) AS text FROM ' . $this->_table_prefix . 'users_info as ui' . ' LEFT JOIN ' . $this->_table_prefix_crm . 'shipping as rcs ON rcs.users_info_id = ui.users_info_id ' . ' WHERE address_type like "ST" ' . ' AND ui.users_info_id IN (' . $crmusersinfo . ') ';
         } else {
             if (!$is_admin) {
                 $isredcrmuser_debitor = explode(',', $isredcrmuser_debitor);
                 JArrayHelper::toInteger($isredcrmuser_debitor);
                 $isredcrmuser_debitor = implode(',', $isredcrmuser_debitor);
                 $query = 'SELECT ui.*,IFNULL(destination_name,CONCAT(firstname," ",lastname)) AS text FROM ' . $this->_table_prefix . 'users_info as ui' . ' LEFT JOIN #__redcrm_shipping as rcs ON rcs.users_info_id = ui.users_info_id ' . ' WHERE address_type like "ST" AND rcs.destination_name!="" ' . ' AND rcs.debitor_id IN (' . $isredcrmuser_debitor . ') ';
             } else {
                 $query = 'SELECT ui.*,IFNULL(destination_name,CONCAT(firstname," ",lastname)) AS text FROM ' . $this->_table_prefix . 'users_info as ui' . ' LEFT JOIN #__redcrm_shipping as rcs ON rcs.users_info_id = ui.users_info_id ' . ' WHERE address_type like "ST" ' . ' AND ui.user_id  = ' . (int) $user_id;
             }
         }
         $this->_db->setQuery($query);
         $list = $this->_db->loadObjectlist();
         return $list;
     }
     $query = 'SELECT *,CONCAT(firstname," ",lastname) AS text FROM ' . $this->_table_prefix . 'users_info ' . 'WHERE address_type="ST" ' . 'AND user_id = ' . (int) $user_id;
     $this->_db->setQuery($query);
     $list = $this->_db->loadObjectlist();
     return $list;
 }