Exemple #1
0
 public function __construct($address_id = NULL, $lang_id = NULL)
 {
     if ($lang_id !== NULL) {
         $this->lang_id = JeproshopLanguageModelLanguage::getLanguage($lang_id) !== FALSE ? (int) $lang_id : JeproshopSettingModelSetting::getValue('default_lang');
     }
     if ($address_id) {
         //Load address from database if address id is provided
         $cache_id = 'jeproshop_address_model_' . $address_id . '_' . $lang_id;
         if (!JeproshopCache::isStored($cache_id)) {
             $db = JFactory::getDBO();
             $query = "SELECT * FROM " . $db->quoteName('#__jeproshop_address') . " AS address ";
             $query .= " WHERE address.address_id = " . (int) $address_id;
             $db->setQuery($query);
             $address_data = $db->loadObject();
             if ($address_data) {
                 JeproshopCache::store($cache_id, $address_data);
             }
         } else {
             $address_data = JeproshopCache::retrieve($cache_id);
         }
         if ($address_data) {
             $address_data->address_id = $address_id;
             foreach ($address_data as $key => $value) {
                 if (array_key_exists($key, $this)) {
                     $this->{$key} = $value;
                 }
             }
         }
     }
     if ($this->address_id) {
         $this->country = JeproshopCountryModelCountry::getNameById($lang_id, $this->country_id);
     }
 }