public function __construct($shop_id = null, $lang_id = null) { parent::__construct(); $db = JFactory::getDBO(); if ($lang_id != null) { $this->lang_id = JeproshopLanguageModelLanguage::getLanguage($lang_id) != false ? $lang_id : JeproshopSettingModelSetting::getSettingValue('default_lang'); } if ($shop_id) { /** Load shop from database if id is supplied */ $cache_id = 'jeproshop_shop_model_' . (int) $shop_id . ($lang_id > 0 ? '_' . $lang_id : ''); if (!JeproshopCache::isStored($cache_id)) { $query = "SELECT * FROM " . $db->quoteName('#__jeproshop_shop') . " AS shop "; if ($lang_id) { $query .= " LEFT JOIN " . $db->quoteName('#__jeproshop_shop_lang'); $query .= " ON(shop." . $db->quoteName('shop_id') . " = shop_lang." . $db->quoteName('shop_id'); $query .= " AND shop_lang." . $db->quoteName('lang_id') . " = " . (int) $lang_id . ")"; } $query .= " WHERE shop." . $db->quoteName('shop_id') . " = " . (int) $shop_id; $db->setQuery($query); $shop_data = $db->loadObject(); //print_r($shop_data); if ($shop_data) { /*if($lang_id && isset($this->multilang) && $this->multilang){ $query = " SELECT * FROM " . $db->quoteName('#__jeproshop_shop_lang') . " WHERE "; $query .= $db->quoteName('shop_id') . " = " . $shop_id; $db->setQuery($query); $shop_lang_data = $db->loadObjectList(); if($shop_lang_data){ foreach($shop_lang_data as $row){ foreach($row as $key => $value){ if(array_key_exists($key, $this) && $key != 'shop_id'){ if(!isset($shop_data->{$key}) || !is_array($shop_data->{$key})){ $shop_data->{$key} = array(); } $shop_data->{$key}[$row->lang_id] = $value; } } } } }*/ JeproshopCache::store($cache_id, $shop_data); } } else { $shop_data = JeproshopCache::retrieve($cache_id); } if ($shop_data) { $this->shop_id = (int) $shop_id; foreach ($shop_data as $key => $value) { if (array_key_exists($key, $this)) { //if($key != 'name'){ $this->{$key} = $value; /*}else{ $prop = 'shop_' . $key; $this->{$prop} = $value; }*/ } } } } if ($this->shop_id) { $this->setShopUrl(); } }
public function __construct($shop_id = NULL, $lang_id = NULL) { parent::__construct(); $db = JFactory::getDBO(); if ($lang_id !== NULL) { $this->lang_id = JeproshopLanguageModelLanguage::getLanguage($lang_id) != FALSE ? $lang_id : JeproshopSettingModelSetting::getSettingValue('default_lang'); } if ($shop_id) { $this->shop_id = (int) $shop_id; $this->get_shop_from_context = FALSE; } if (!$this->shop_id) { $this->shop_id = JeproshopContext::getContext()->shop->shop_id; } if ($shop_id) { //load object from database if object id is present $cache_id = 'jeproshop_shop_model_' . $shop_id . '_' . $lang_id; if (!JeproshopCache::isStored($cache_id)) { $query = "SELECT * FROM " . $db->quoteName('#__jeproshop_shop') . " AS shop "; $where = ""; if ($lang_id) { //Get lang informations $query .= " LEFT JOIN " . $db->quoteName('#__jeproshop_shop_lang') . " AS shop_lang "; $query .= " ON (shop.shop_id = shop_lang.shop_id AND shop_lang.lang_id = " . (int) $lang_id . ")"; if ($this->shop_id && !empty($this->multiLangShop)) { $where = " AND shop_lang.shop_id = " . $this->shop_id; } } $query .= "WHERE shop.shop_id = " . (int) $shop_id . $where; $db->setQuery($query); $shop_data = $db->loadObject(); if ($shop_data) { if (!$lang_id && isset($this->multiLang) && $this->multiLang) { $query = "SELECT * FROM " . $db->quoteName('#__jeproshop_shop_lang') . " WHERE shop_id = " . (int) $shop_id; $db->setQuery($query); $shop_lang_data = $db->loadObjectList(); if ($shop_lang_data) { foreach ($shop_lang_data as $row) { foreach ($row as $key => $value) { if (array_key_exists($key, $this) && $key != 'shop_id') { if (!isset($shop_data->{$key}) || !is_array($shop_data->{$key})) { $shop_data->{$key} = array(); } $shop_data->{$key}[$row->lang_id] = $value; } } } } } JeproshopCache::store($cache_id, $shop_data); } } else { $shop_data = JeproshopCache::retrieve($cache_id); } if ($shop_data) { $shop_data->shop_id = (int) $shop_id; foreach ($shop_data as $key => $value) { if (array_key_exists($key, $this)) { $this->{$key} = $value; } } } } if ($this->shop_id) { $this->setShopUrl(); } }