/** * Get all scenes of a category * * @param $category_id * @param null $lang_id * @param bool $only_published * @param bool $lite_result * @param bool $hide_scene_position * @param JeproshopContext $context * @return array Products */ public static function getScenes($category_id, $lang_id = null, $only_published = true, $lite_result = true, $hide_scene_position = true, JeproshopContext $context = null) { if (!JeproshopSceneModelScene::isFeaturePublished()) { return array(); } $cache_key = 'jeproshop_scene_get_scenes_' . $category_id . '_' . (int) $lite_result; if (!JeproshopCache::isStored($cache_key)) { if (!$context) { $context = JeproshopContext::getContext(); } $lang_id = is_null($lang_id) ? $context->language->lang_id : $lang_id; $db = JFactory::getDBO(); $query = "SELECT scene.* FROM " . $db->quoteName('#__jeproshop_scene_category') . " scene_category LEFT JOIN " . $db->quoteName('#__jeproshop_scene'); $query .= " AS scene ON (scene_category.scene_id = scene.scene_id) " . JeproshopShopModelShop::addSqlAssociation('scene') . " LEFT JOIN "; $query .= $db->quoteName('#__jeproshop_scene_lang') . " AS scene_lang ON (scene_lang.scene_id = scene.scene_id) WHERE scene_category.category_id = "; $query .= (int) $category_id . "\tAND scene_lang.lang_id = " . (int) $lang_id . ($only_published ? " AND scene.published = 1" : "") . " ORDER BY scene_lang.name ASC"; $db->setQuery($query); $scenes = $db->loadObjectList(); if (!$lite_result && $scenes) { foreach ($scenes as &$scene) { $scene = new Scene($scene->scene_id, $lang_id, false, $hide_scene_position); } } JeproshopCache::store($cache_key, $scenes); } $scenes = JeproshopCache::retrieve($cache_key); return $scenes; }
public function __construct($tag_id = null, $name = null, $lang_id = null) { $db = JFactory::getDBO(); if ($tag_id) { // Load tags from database if object is present in $cache_id = 'jeproshop_tag_model_' . (int) $tag_id . '_' . (int) $lang_id; if (!JeproshopCache::isStored($cache_id)) { $query = "SELECT * FROM " . $db->quoteName('#__jeproshop_tag') . " AS tag WHERE tag." . $db->quoteName('tag_id') . " = " . (int) $tag_id; $query .= $lang_id ? " AND " . $db->quoteName('lang_id') . " = " . (int) $lang_id : ""; $db->setQuery($query); $tagData = $db->loadObject(); JeproshopCache::store($cache_id, $tagData); } else { $tagData = JeproshopCache::retrieve($cache_id); } if ($tagData) { $this->tag_id = $tagData->tag_id; $this->lang_id = $tagData->lang_id; $this->name = $tagData->name; } } else { if ($name && JeproshopTools::isGenericName($name) && $lang_id && JeproshopTools::isUnsignedInt($lang_id)) { $query = "SELECT * FROM " . $db->quoteName('#__jeproshop_tag') . " AS tag WHERE " . $db->quoteName('name') . " LIKE " . $db->quote($db->escape($name)); $query .= " AND " . $db->quoteName('lang_id') . " = " . (int) $lang_id; $db->setQuery($query); $row = $db->loadObject(); if ($row) { $this->tag_id = (int) $row->tag_id; $this->lang_id = (int) $row->lang_id; $this->name = $row->name; } } } }
/** * @return JeproshopCache instance */ public static function getInstance() { if (self::$instance) { $caching_system = COM_JEPROSHOP_CACHING_SYSTEM; self::$instance = new $caching_system(); } return self::$instance; }
public function __construct($image_id = null, $lang_id = null) { //parent::__construct($id, $id_lang); if ($lang_id !== null) { $this->lang_id = JeproshopSettingModelSetting::getLanguage($lang_id) !== false ? $lang_id : JeproshopSettingModelSetting::getValue('default_lang'); } if ($image_id) { $cache_id = 'jeproshop_image_model_' . (int) $image_id . '_' . (int) $lang_id; if (!JeproshopCache::isStored($cache_id)) { $db = JFactory::getDBO(); $query = "SELECT * FROM " . $db->quoteName('#__jeproshop_image') . " AS image "; if ($lang_id) { $query .= " LEFT JOIN " . $db->quoteName('#__jeproshop_image_lang') . " AS image_lang ON (image." . $db->quoteName('image_id'); $query .= " = image_lang." . $db->quoteName('image_id') . " AND image." . $db->quoteName('lang_id') . " = " . (int) $lang_id . ") "; } $query .= "WHERE image." . $db->quoteName('image_id') . " = " . (int) $image_id; $db->setQuery($query); $image_data = $db->loadObject(); if ($image_data) { if (!$lang_id && isset($this->multilang) && $this->multilang) { $query = "SELECT * FROM " . $db->quoteName('#__jeproshop_image_lang'); $query .= " WHERE image_id = " . (int) $image_id; $db->setQuery($query); $image_lang_data = $db->loadObjectList(); if ($image_lang_data) { foreach ($image_lang_data as $row) { foreach ($row as $key => $value) { if (array_key_exists($key, $this) && $key != 'image_id') { if (!isset($image_data->{$key}) || !is_array($image_data->{$key})) { $image_data->{$key} = array(); } $image_data->{$key}[$row->lang_id] = $value; } } } } JeproshopCache::store($cache_id, $image_data); } } } else { $image_data = JeproshopCache::retrieve($cache_id); } if ($image_data) { $image_data->image_id = $image_id; foreach ($image_data as $key => $value) { if (array_key_exists($key, $this)) { $this->{$key} = $value; } } } } $this->image_dir = COM_JEPROSHOP_PRODUCT_IMAGE_DIRECTORY; $this->source_index = COM_JEPROSHOP_PRODUCT_IMAGE_DIRECTORY . 'index.php'; }
public function __construct($currency_id = null, $shop_id = null) { $db = JFactory::getDBO(); if ($shop_id && $this->isMultiShop()) { $this->shop_id = (int) $shop_id; $this->get_shop_from_context = false; } if ($this->isMultiShop() && !$this->shop_id) { $this->shop_id = JeproshopContext::getContext()->shop->shop_id; } if ($currency_id) { //load object from the database if the currency id is provided $cache_id = 'jeproshop_currency_model_' . (int) $currency_id . '_' . (int) $shop_id; if (!JeproshopCache::isStored($cache_id)) { $query = "SELECT * FROM " . $db->quoteName('#__jeproshop_currency') . " AS currency "; if (JeproshopShopModelShop::isTableAssociated('currency')) { $query .= " LEFT JOIN " . $db->quoteName('#__jeproshop_currency_shop') . " AS currency_shop ON( currency.currency_id = currency_shop.currency_id AND currency_shop.shop_id = " . (int) $this->shop_id . ")"; } $query .= " WHERE currency.currency_id = " . (int) $currency_id; $db->setQuery($query); $currency_data = $db->loadObject(); if ($currency_data) { JeproshopCache::store($cache_id, $currency_data); } } else { $currency_data = JeproshopCache::retrieve($cache_id); } if ($currency_data) { $currency_data->currency_id = $currency_id; foreach ($currency_data as $key => $value) { if (array_key_exists($key, $this)) { $this->{$key} = $value; } } } } /* prefix and suffix are convenient short cut for displaying price sign before or after the price number */ $this->prefix = $this->format % 2 != 0 ? $this->sign . " " : ""; $this->suffix = $this->format % 2 == 0 ? " " . $this->sign : ""; }
public function __construct($feature_id = null, $lang_id = null, $shop_id = null) { if ($lang_id !== null) { $this->lang_id = JeproshopLanguageModelLanguage::getLanguage($lang_id) !== false ? $lang_id : JeproshopSettingModelSetting::getValue('default_lang'); } if ($shop_id && $this->isMultiShop()) { $this->shop_id = (int) $shop_id; $this->get_shop_from_context = false; } if ($this->isMultiShop() && !$this->shop_id) { $this->shop_id = JeproshopContext::getContext()->shop->shop_id; } if ($feature_id) { // Load object from database if object id is present $cache_id = 'jeproshop_feature_model_' . (int) $feature_id . '_' . (int) $this->shop_id . '_' . (int) $lang_id; if (!JeproshopCache::isStored($cache_id)) { $db = JFactory::getDBO(); $query = "SELECT * FROM " . $db->quoteName('#__jeproshop_feature') . " AS feature "; $where = " WHERE feature." . $db->quoteName('feature_id') . " = " . (int) $feature_id; // Get lang informations if ($lang_id) { $query .= " LEFT JOIN " . $db->quoteName('#__jeproshop_feature_lang') . " AS feature_lang ON (feature." . $db->quoteName('feature_id') . " = "; $query .= $db->quoteName('feature_id') . " AND feature_lang." . $db->quoteName('lang_id') . " = " . (int) $lang_id . ") "; if ($this->shop_id && !empty($this->multiLangShop)) { $where .= " AND feature_lang." . $db->quoteName('shop_id') . " = " . $this->shop_id; } } // Get shop informations if (JeproshopShopModelShop::isTableAssociated('feature')) { $query .= " LEFT JOIN " . $db->quoteName('#__jeproshop_feature_shop') . " AS feature_shop ON (feature." . $db->quoteName('feature_id') . " = feature_shop."; $query .= $db->quoteName('feature_id') . " AND feature_shop." . $db->quoteName('shop_id') . " = " . (int) $this->shop_id . ") "; } $db->setQuery($query . $where); $feature_data = $db->loadObject(); if ($feature_data) { if (!$lang_id && isset($this->multiLang) && $this->multiLang) { $query = "SELECT * FROM " . $db->quoteName('#__jeproshop_feature_lang') . " WHERE " . $db->quoteName('feature_id') . " = " . (int) $feature_id; $query .= $this->shop_id && $this->isLangMultiShop() ? " AND " . $db->quoteName('shop_id') . " = " . $this->shop_id : ""; $db->setQuery($query); $feature_data_lang = $db->loadObjectList(); if ($feature_data_lang) { foreach ($feature_data_lang as $row) { foreach ($row as $key => $value) { if (array_key_exists($key, $this) && $key != 'feature_id') { if (!isset($feature_data->{$key}) || !is_array($feature_data->{$key})) { $feature_data->{$key} = array(); } $feature_data->{$key}[$row->lang_id] = $value; } } } } } JeproshopCache::store($cache_id, $feature_data); } } else { $feature_data = JeproshopCache::retrieve($cache_id); } if ($feature_data) { //$this->id = (int)$id; foreach ($feature_data as $key => $value) { if (array_key_exists($key, $this)) { $this->{$key} = $value; } } } } }
public static function getTaxRulesGroupIdByCarrierId($carrier_id, JeproshopContext $context = null) { if (!$context) { $context = JeproshopContext::getContext(); } $key = 'jeproshop_carrier_tax_rules_group_id' . (int) $carrier_id . '_' . (int) $context->shop->shop_id; if (!JeproshopCache::isStored($key)) { $db = JFactory::getDBO(); $query = "SELECT " . $db->quoteName('tax_rules_group_id') . " FROM " . $db->quoteName('#__jeproshop_carrier_tax_rules_group_shop') . " WHERE "; $query .= $db->quoteName('carrier_id') . " = " . (int) $carrier_id . " AND shop_id = " . (int) JeproshopContext::getContext()->shop->shop_id; $db->setQuery($query); JeproshopCache::store($key, $db->loadObject()->tax_rules_group_id); } return JeproshopCache::retrieve($key); }
/** * Check employee informations saved into cookie and return employee validity * * @return boolean employee validity */ public function isLoggedBack() { if (!JeproshopCache::isStored('jeproshop_is_logged_back_' . $this->employee_id)) { /* Employee is valid only if it can be load and if cookie password is the same as database one */ JeproshopCache::store('jeproshop_is_logged_back_' . $this->employee_id, $this->employee_id && JeproshopValidator::isUnsignedInt($this->employee_id) && JeproshopEmployeeModelEmployee::checkPassword($this->employee_id, JeproshopContext::getContext()->cookie->passwd) && (!isset(JeproshopContext::getContext()->cookie->remote_addr) || JeproshopContext::getContext()->cookie->remote_addr == ip2long(JeproshopValidator::getRemoteAddr()) || !JeproshopSettingModelSetting::getValue('cookie_check_ip'))); } return JeproshopCache::retrieve('jeproshop_is_logged_back_' . $this->employee_id); }
public function clearCache($all = false) { if ($all) { JeproshopCache::clean('jeproshop_image_model_*'); } elseif ($this->image_id) { JeproshopCache::clean('jeproshop_image_model_' . (int) $this->image_id . '_*'); } }
public function __construct($product_download_id = NULL) { $db = JFactory::getDBO(); if ($product_download_id) { $cache_id = 'jeproshop_product_download_model_' . $product_download_id; if (!JeproshopCache::isStored($cache_id)) { $query = "SELECT * FROM " . $db->quoteName('#__jeproshop_product_download') . " AS product_download "; /** Get shop informations **/ if (JeproshopShopModelShop::isTableAssociated('product')) { $query .= " LEFT JOIN " . $db->quoteName('#__jeproshop_product_shop') . " AS product_shop ON ("; $query .= "product.product_id = product_shop.product_id AND product_shop.shop_id = " . (int) $this->shop_id . ")"; } $query .= " WHERE product_download." . $db->quoteName('product_download_id') . " = " . (int) $product_download_id; $db->setQuery($query); $product_download_data = $db->loadObject(); if ($product_download_data) { JeproshopCache::store($cache_id, $product_download_data); } } else { $product_download_data = JeproshopCache::retrieve($cache_id); } if ($product_download_data) { $product_download_data->product_download_id = $product_download_id; foreach ($product_download_data as $key => $value) { if (array_key_exists($key, $this)) { $this->{$key} = $value; } } } } }
public function isAssociatedToShop($shop_id = null) { if ($shop_id === null) { $shop_id = JeproshopContext::getContext()->shop->shop_id; } $cache_id = 'jeproshop_model_shop_group_' . (int) $this->group_id . '_' . (int) $shop_id; if (!JeproshopCache::isStored($cache_id)) { $db = JFactory::getDBO(); $query = "SELECT shop_id FROM " . $db->quoteName('#__jeproshop_group_shop') . " WHERE "; $query .= $db->quoteName('group_id') . " = " . $this->group_id . " AND shop_id = " . (int) $shop_id; $db->setQuery($query); JeproshopCache::store($cache_id, (bool) $db->loadResult()); } return JeproshopCache::retrieve($cache_id); }
public function __construct($shop_group_id = NULL) { $db = JFactory::getDBO(); if ($shop_group_id) { /** Load object from database if shop group id is present **/ $cache_id = 'jeproshop_shop_group_model_' . $shop_group_id; if (!JeproshopCache::isStored($cache_id)) { $query = "SELECT * FROM " . $db->quoteName('#__jeproshop_shop_group') . " AS shop_group "; $query .= " WHERE shop_group." . $db->quoteName('shop_group_id') . " = " . (int) $shop_group_id; $db->setQuery($query); $shop_group_data = $db->loadObject(); if ($shop_group_data) { JeproshopCache::store($cache_id, $shop_group_data); } } else { $shop_group_data = JeproshopCache::retrieve($cache_id); } if ($shop_group_data) { $shop_group_data->shop_group_id = $shop_group_id; foreach ($shop_group_data as $key => $value) { if (array_key_exists($key, $this)) { $this->{$key} = $value; } } } } }
protected function getFormatDB($country_id) { $cache_id = 'jeproshop_address_format_get_format_db_' . $country_id; if (!JeproshopCache::isStored($cache_id)) { $db = JFactory::getDBO(); $query = "SELECT format FROM " . $db->quoteName('#__jeproshop_address_format') . " WHERE " . $db->quoteName('country_id') . " = " . (int) $country_id; $db->setQuery($query); $format = $db->loadResult(); JeproshopCache::store($cache_id, trim($format)); } return JeproshopCache::retrieve($cache_id); }
public function getCartRules($filter = JeproshopCartRuleModelCartRule::JEPROSHOP_FILTER_ACTION_ALL) { // If the cart has not been saved, then there can't be any cart rule applied if (!JeproshopCartRuleModelCartRule::isFeaturePublished() || !$this->cart_id) { return array(); } $cache_key = 'jeproshop_cart_getCartRules_' . $this->cart_id . '_' . $filter; if (!JeproshopCache::isStored($cache_key)) { $db = JFactory::getDBO(); $query = "SELECT * FROM " . $db->quoteName('#__jeproshop_cart_cart_rule') . " AS cd LEFT JOIN " . $db->quoteName('#__jeproshop_cart_rule'); $query .= " AS cart_rule ON cd." . $db->quoteName('cart_rule_id') . " = cart_rule." . $db->quoteName('cart_rule_id') . " LEFT JOIN "; $query .= $db->quoteName('#__jeproshop_cart_rule_lang') . " AS cart_rule_lang ON ( cd." . $db->quoteName('cart_rule_id') . " = cart_rule_lang."; $query .= $db->quoteName('cart_rule_id') . " AND cart_rule_lang.lang_id = " . (int) $this->lang_id . ") WHERE " . $db->quoteName('cart_id') . " = " . (int) $this->cart_id; $query .= ($filter == JeproshopCartRuleModelCartRule::JEPROSHOP_FILTER_ACTION_SHIPPING ? " AND free_shipping = 1" : "") . ($filter == JeproshopCartRuleModelCartRule::JEPROSHOP_FILTER_ACTION_GIFT ? " AND gift_product != 0" : ""); $query .= ($filter == JeproshopCartRuleModelCartRule::JEPROSHOP_FILTER_ACTION_REDUCTION ? " AND (reduction_percent != 0 OR reduction_amount != 0)" : "") . " ORDER by cart_rule.priority ASC "; $db->setQuery($query); $result = $db->loadObjectList(); JeproshopCache::store($cache_key, $result); } $result = JeproshopCache::retrieve($cache_key); // Define virtual context to prevent case where the cart is not the in the global context $virtual_context = JeproshopContext::getContext()->cloneContext(); $virtual_context->cart = $this; foreach ($result as &$row) { $row->obj = new JeproshopCartRuleModelCartRule($row->cart_rule_id, (int) $this->lang_id); $row->value_real = $row->obj->getContextualValue(true, $virtual_context, $filter); $row->value_tax_exc = $row->obj->getContextualValue(false, $virtual_context, $filter); // Retro compatibility < 1.5.0.2 $row->discount_id = $row->cart_rule_id; $row->description = $row->name; } return $result; }
public function clearCache($all = false) { if ($all) { JeproshopCache::clean('jeproshop_model_category_*'); } elseif ($this->category_id) { JeproshopCache::clean('jeproshop_model_category_' . (int) $this->category_id . '_*'); } }
/** * Get all delivery addresses object for the current cart */ public function getAddressCollection() { $collection = array(); $cache_id = 'jeproshop_cart_get_address_collection' . (int) $this->cart_id; if (!JeproshopCache::isStored($cache_id)) { $db = JFactory::getDBO(); $query = "SELECT DISTINCT " . $db->quoteName('address_delivery_id') . " FROM " . $db->quoteName('#__jeproshop_cart_product'); $query .= " WHERE cart_id = " . (int) $this->cart_id; $db->setQuery($query); $result = $db->loadObjectList(); JeproshopCache::store($cache_id, $result); } $result = JeproshopCache::retrieve($cache_id); //$result[] = array('address_delivery_id' => (int)$this->address_delivery_id); foreach ($result as $row) { if ((int) $row->address_delivery_id != 0) { $collection[(int) $row->address_delivery_id] = new JeproshopAddressModelAddress((int) $row->address_delivery_id); } } return $collection; }
/** * Check if customer password is the right one * * @param $customer_id * @param string $passwd Password * @return bool result */ public static function checkPassword($customer_id, $passwd) { if (!JeproshopTools::isUnsignedInt($customer_id) || !JeproshopValidate::isMd5($passwd)) { die(Tools::displayError()); } $cache_id = 'jeproshop_model_customer_check_password_' . (int) $customer_id . '_' . $passwd; if (!JeproshopCache::isStored($cache_id)) { $db = JFactory::getDBO(); $query = "SELECT " . $db->quoteName('customer_id') . " FROM " . $db->quoteName('#__jeproshop_customer') . " WHERE " . $db->quoteName('customer_id') . " = " . $customer_id . " AND " . $db->quoteName('passwd') . " = " . $db->quote($passwd); $db->setQuery($query); $result = (bool) $db->loadResult(); JeproshopCache::store($cache_id, $result); } return JeproshopCache::retrieve($cache_id); }
/** * Get all available geographical zones * * @param bool|type $allow_delivery * @return type */ public static function getZones($allow_delivery = FALSE) { $cache_id = 'jeproshop_zone_model_get_zones_' . (bool) $allow_delivery; if (!JeproshopCache::isStored($cache_id)) { $db = JFactory::getDBO(); $query = "SELECT * FROM " . $db->quoteName('#__jeproshop_zone') . ($allow_delivery ? " WHERE allow_delivery = 1 " : ""); $query .= " ORDER BY " . $db->quoteName('name') . " ASC "; $db->setQuery($query); $result = $db->loadObjectList(); JeproshopCache::store($cache_id, $result); } return JeproshopCache::retrieve($cache_id); }
public function __construct($manufacturer_id = null, $lang_id = null) { parent::__construct(); $db = JFactory::getDBO(); if ($lang_id !== NULL) { $this->lang_id = JeproshopLanguageModelLanguage::getLanguage($lang_id) ? (int) $lang_id : JeproshopSettingModelSetting::getValue('default_lang'); } if ($manufacturer_id) { $cache_id = 'jeproshop_manufacturer_model_' . $manufacturer_id . '_' . $lang_id; if (!JeproshopCache::isStored($cache_id)) { $query = "SELECT * FROM " . $db->quoteName('#__jeproshop_manufacturer') . " AS j_manufacturer "; $where = ""; /** get language information **/ if ($lang_id) { $query .= "LEFT JOIN " . $db->quoteName('#__jeproshop_manufacturer_lang') . " AS manufacturer_lang "; $query .= "ON (j_manufacturer.manufacturer_id = manufacturer_lang.manufacturer_id AND manufacturer_lang.lang_id = " . (int) $lang_id . ") "; /* if($this->shop_id && !(empty($this->multiLangShop))){ $where = " AND manufacturer_lang.shop_id = " . $this->shop_id; }*/ } /** Get shop informations ** / if(JeproshopShopModelShop::isTableAssociated('manufacturer')){ $query .= " LEFT JOIN " . $db->quoteName('#__jeproshop_manufacturer_shop') . " AS manufacturer_shop ON ("; $query .= "j_manufacturer.manufacturer_id = manufacturer_shop.manufacturer_id AND manufacturer_shop.shop_id = " . (int) $this->shop_id . ")"; }*/ $query .= " WHERE j_manufacturer.manufacturer_id = " . (int) $manufacturer_id . $where; $db->setQuery($query); $manufacturer_data = $db->loadObject(); if ($manufacturer_data) { if (!$lang_id && isset($this->multiLang) && $this->multiLang) { $query = "SELECT * FROM " . $db->quoteName('#__jeproshop_manufacturer_lang'); $query .= " WHERE manufacturer_id = " . (int) $manufacturer_id; $db->setQuery($query); $manufacturer_lang_data = $db->loadObjectList(); if ($manufacturer_lang_data) { foreach ($manufacturer_lang_data as $row) { foreach ($row as $key => $value) { if (array_key_exists($key, $this) && $key != 'manufacturer_id') { if (!isset($manufacturer_data->{$key}) || !is_array($manufacturer_data->{$key})) { $manufacturer_data->{$key} = array(); } $manufacturer_data->{$key}[$row->lang_id] = $value; } } } } } JeproshopCache::store($cache_id, $manufacturer_data); } } else { $manufacturer_data = JeproshopCache::retrieve($cache_id); } if ($manufacturer_data) { $manufacturer_data->manufacturer_id = $manufacturer_id; foreach ($manufacturer_data as $key => $value) { if (array_key_exists($key, $this)) { $this->{$key} = $value; } } } } $this->link_rewrite = $this->getLink(); $this->image_dir = COM_JEPROSHOP_MANUFACTURER_IMAGE_DIRECTORY; }
public static function customerIdExistsStatic($customer_id) { $cache_id = 'jeproshop_customer_exists_id_' . (int) $customer_id; if (!JeproshopCache::isStored($cache_id)) { $db = JFactory::getDBO(); $query = "SELECT " . $db->quoteName('customer_id') . " FROM " . $db->quoteName('#__jeproshop_customer') . " AS customer WHERE customer." . $db->quoteName('customer_id') . " = " . (int) $customer_id; $db->setQuery($query); $result = $db->loadResult(); JeproshopCache::store($cache_id, $result); } return JeproshopCache::retrieve($cache_id); }
public function __construct($attribute_group_id = null, $lang_id = null, $shop_id = null) { if ($lang_id !== NULL) { $this->lang_id = JeproshopLanguageModelLanguage::getLanguage($lang_id) !== FALSE ? (int) $lang_id : JeproshopSettingModelSetting::getValue('default_lang'); } if ($shop_id && $this->isMultiShop()) { $this->shop_id = (int) $shop_id; $this->get_shop_from_context = false; } if ($this->isMultiShop() && !$this->shop_id) { $this->shop_id = JeproshopContext::getContext()->shop->shop_id; } if ($attribute_group_id) { $cache_id = 'jeproshop_attribute_group_model_' . (int) $attribute_group_id; if (!JeproshopCache::isStored($cache_id)) { $db = JFactory::getDBO(); $query = "SELECT * FROM " . $db->quoteName('#__jeproshop_attribute_group') . " AS attribute_group "; $where = " WHERE attribute_group." . $db->quoteName('attribute_group_id') . " = " . (int) $attribute_group_id; //Get Language information if ($lang_id) { $query .= "LEFT JOIN " . $db->quoteName('#__jeproshop_attribute_group_lang') . " AS attribute_group_lang ON (attribute_group."; $query .= $db->quoteName('attribute_group_id') . " = attribute_group_lang." . $db->quoteName('attribute_group_id') . " AND "; $query .= "attribute_group_lang." . $db->quoteName('lang_id') . " = " . (int) $lang_id . ")"; if ($this->shop_id && !empty($this->multiLangShop)) { $where .= " AND attribute_group_lang." . $db->quoteName('shop_id') . " = " . (int) $shop_id; } } // Get Shop Information if (JeproshopShopModelShop::isTableAssociated('attribute_group')) { $query .= "LEFT JOIN " . $db->quoteName('#__jeproshop_attribute_group_shop') . " AS attribute_group_shop ON (attribute_group."; $query .= $db->quoteName('attribute_group_id') . " = attribute_group_shop." . $db->quoteName('attribute_group_id') . " AND attribute_group_shop."; $query .= $db->quoteName('shop_id') . " = " . (int) $this->shop_id . ")"; } $db->setQuery($query . $where); $attributeGroupData = $db->loadObject(); if ($attributeGroupData) { if (!$lang_id && isset($this->multiLang) && $this->multiLang) { $query = "SELECT * FROM " . $db->quoteName('#__jeproshop_attribute_group_lang') . " WHERE " . $db->quoteName('attribute_group_id') . " = "; $query .= (int) $attribute_group_id; // . (($this->shop_id && $this->isMultiLangShop()) ? " AND " . $db->quoteName('shop_id') . " = " . (int)$this->shop_id : ""); $db->setQuery($query); $attributeGroupDataLang = $db->loadObjectList(); if ($attributeGroupDataLang) { foreach ($attributeGroupDataLang as $row) { foreach ($row as $key => $value) { if (array_key_exists($key, $this) && $key != 'attribute_group_id') { if (!isset($attributeGroupData->{$key}) || !is_array($attributeGroupData->{$key})) { $attributeGroupData->{$key} = array(); } $attributeGroupData->{$key}[$row->lang_id] = $value; } } } } } JeproshopCache::store($cache_id, $attributeGroupData); } } else { $attributeGroupData = JeproshopCache::retrieve($cache_id); } if ($attributeGroupData) { $this->attribute_group_id = (int) $attribute_group_id; foreach ($attributeGroupData as $key => $value) { if (array_key_exists($key, $this)) { $this->{$key} = $value; } } } } }
/** * Removes a given product from the stock available * * @param int $product_id * @param int $product_attribute_id Optional * @param mixed $shop shop id or shop object Optional */ public static function removeProductFromStockAvailable($product_id, $product_attribute_id = null, $shop = null) { if (!JeproshopTools::isUnsignedInt($product_id)) { return false; } $db = JFactory::getDBO(); if (JeproshopShopModelShop::getShopContext() == JeproshopShopModelShop::CONTEXT_SHOP) { if (JeproshopShopModelShop::getContextShopGroup()->share_stock == 1) { $product_attribute_sql = ''; if ($product_attribute_id !== null) { $product_attribute_sql = '_attribute'; $product_attribute_id_sql = $product_attribute_id; } else { $product_attribute_id_sql = $product_id; } $query = "SELECT COUNT(*) FROM " . $db->quoteName('#__jeproshop_product' . $product_attribute_sql . '_shop') . " WHERE " . $db->quoteName('product' . $product_attribute_sql . '_id') . " = "; $query .= (int) $product_attribute_id_sql . " AND " . $db->quoteName('shop_id') . " IN (" . implode(',', array_map('intval', JeproshopShopModelShop::getContextListShopIds(JeproshopShopModelShop::SHARE_STOCK))) . ")"; $db->setQuery($query); $result = (int) $db->loadResult(); if ($result) { return true; } } } $query = "DELETE FROM " . $db->quoteName('#__jeproshop_stock_available') . " WHERE " . $db->quoteName('product_id') . " = " . (int) $product_id; $query .= ($product_attribute_id ? " AND " . $db->quoteName('product_attribute_id') . " = " . (int) $product_attribute_id : "") . JeproshopStockAvailableModelStockAvailable::addShopRestriction(null, $shop); $db->setQuery($query); $res = $db->query(); if ($product_attribute_id) { if ($shop === null || !JeproshopTools::isLoadedObject($shop, 'shop_id')) { $shop_datas = new Object(); JeproshopStockAvailableModelStockAvailable::addSqlShopParams($shop_datas); $shop_id = (int) $shop_datas->shop_id; } else { $shop_id = (int) $shop->shop_id; } $stock_available = new JeproshopStockAvailableModelStockAvailable(); $stock_available->product_id = (int) $product_id; $stock_available->product_attribute_id = (int) $product_id; $stock_available->shop_id = (int) $shop_id; $stock_available->postSave(); } JeproshopCache::clean('jeproshop_stock_available_get-quantity_Available_by_product_' . (int) $product_id . '_*'); return $res; }
public function __construct($manufacturer_id = null, $lang_id = null) { $db = JFactory::getDBO(); if ($lang_id !== null) { $this->lang_id = JeproshopLanguageModelLanguage::getLanguage($lang_id) !== false ? $lang_id : JeproshopSettingModelSetting::getValue('default_lang'); } if ($manufacturer_id) { // Load object from database if object id is present $cache_id = 'jeproshop_manufacturer_model_' . (int) $manufacturer_id . '_' . (int) $lang_id; $db = JFactory::getDBO(); if (!JeproshopCache::isStored($cache_id)) { $query = "SELECT * FROM " . $db->quoteName('#__jeproshop_manufacturer') . " AS manufacturer "; // Get lang informations if ($lang_id) { $query .= " LEFT JOIN " . $db->quoteName('#__jeproshop_manufacturer_lang') . " AS manufacturer_lang ON (manufacturer." . $db->quoteName('manufacturer_id'); $query .= " = manufacturer_lang." . $db->quoteName('manufacturer_id') . " AND manufacturer_lang." . $db->quoteName('lang_id') . " = " . (int) $lang_id . ")"; } $query .= " WHERE manufacturer." . $db->quoteName('manufacturer_id') . " = " . (int) $manufacturer_id; // Get shop informations /*if (Shop::isTableAssociated($this->def['table'])) $sql->leftJoin($this->def['table'].'_shop', 'c', 'a.'.$this->def['primary'].' = c.'.$this->def['primary'].' AND c.id_shop = '.(int)$this->id_shop); */ $db->setQuery($query); $manufacturer_data = $db->loadObject(); if ($manufacturer_data) { if (!$lang_id) { $query = "SELECT * FROM " . $db->quoteName('#__jeproshop_manufacturer_lang') . " WHERE " . $db->quoteName('manufacturer_id') . " = " . (int) $manufacturer_id; $db->setQuery($query); $manufacturer_data_lang = $db->loadObjectList(); if ($manufacturer_data_lang) { foreach ($manufacturer_data_lang as $row) { foreach ($row as $key => $value) { if (array_key_exists($key, $this) && $key != 'manufacturer_id') { if (!isset($manufacturer_data->{$key}) || !is_array($manufacturer_data->{$key})) { $manufacturer_data->{$key} = array(); } $manufacturer_data->{$key}[$row->lang_id] = $value; } } } } } JeproshopCache::store($cache_id, $manufacturer_data); } } else { $manufacturer_data = JeproshopCache::retrieve($cache_id); } if ($manufacturer_data) { //$this->id = (int)$id; foreach ($manufacturer_data as $key => $value) { if (array_key_exists($key, $this)) { $this->{$key} = $value; } } } } $this->link_rewrite = JeproshopTools::str2url($this->name); }
/** * * @param int $parent_id * @param int $lang_id * @param bool $published * @param bool $shop_id * @return array */ public static function getChildren($parent_id, $lang_id, $published = true, $shop_id = false) { if (!JeproshopTools::isBool($published)) { die(JError::_()); } $cache_id = 'Category::getChildren_' . (int) $parent_id . '_' . (int) $lang_id . '-' . (bool) $published . '_' . (int) $shop_id; if (!JeproshopCache::isStored($cache_id)) { $db = JFactory::getDBO(); $query = "SELECT category." . $db->quoteName('category_id') . ", category_lang." . $db->quoteName('name') . ", category_lang." . $db->quoteName('link_rewrite'); $query .= ", category_shop." . $db->quoteName('shop_id') . " FROM " . $db->quoteName('#__jeproshop_category') . " AS category LEFT JOIN " . $db->quoteName('#__jeproshop_category_lang'); $query .= " AS category_lang ON (category." . $db->quoteName('category_id') . " = category_lang." . $db->quoteName('category_id') . JeproshopShopModelShop::addSqlRestrictionOnLang('category_lang'); $query .= ") " . JeproshopShopModelShop::addSqlAssociation('category') . " WHERE " . $db->quoteName('lang_id') . " = " . (int) $lang_id . " AND category." . $db->quoteName('parent_id'); $query .= " = " . (int) $parent_id . ($published ? " AND " . $db->quoteName('published') . " = 1" : "") . " GROUP BY category." . $db->quoteName('category_id') . " ORDER BY category_shop."; $query .= $db->quoteName('position') . " ASC"; $db->setQuery($query); $result = $db->loadObjectList(); JeproshopCache::store($cache_id, $result); } return JeproshopCache::retrieve($cache_id); }
/** * Get all available order statuses * * @param integer $lang_id Language id for status name * @return array Order statues */ public static function getOrderStatus($lang_id) { $cache_id = 'jeproshop_order_status_get_order_status_' . (int) $lang_id; if (!JeproshopCache::isStored($cache_id)) { $db = JFactory::getDBO(); $query = "SELECT * FROM " . $db->quoteName('#__jeproshop_order_status') . " AS order_status LEFT JOIN "; $query .= $db->quoteName('#__jeproshop_order_status_lang') . " AS order_status_lang ON (order_status."; $query .= $db->quoteName('order_status_id') . " = order_status_lang." . $db->quoteName('order_status_id'); $query .= " AND order_status_lang." . $db->quoteName('lang_id') . " = " . (int) $lang_id . ") WHERE deleted = 0 "; $query .= " ORDER BY " . $db->quoteName('name') . " ASC"; $db->setQuery($query); $result = $db->loadObjectList(); JeproshopCache::store($cache_id, $result); } return JeproshopCache::retrieve($cache_id); }
/** * Return the tax calculator associated to this address * * @return TaxCalculator */ public function getTaxCalculator() { static $tax_enabled = null; if (isset($this->tax_calculator)) { return $this->tax_calculator; } if ($tax_enabled === null) { $tax_enabled = JeproshopSettingModelSetting::getValue('use_tax'); } if (!$tax_enabled) { return new JeproshopTaxCalculator(array()); } $taxes = array(); $postcode = 0; if (!empty($this->address->postcode)) { $postcode = $this->address->postcode; } $cache_id = (int) $this->address->country_id . '_' . (int) $this->address->state_id . '_' . $postcode . '_' . (int) $this->type; if (!JeproshopCache::isStored($cache_id)) { $db = JFactory::getDBO(); $query = "SELECT * FROM " . $db->quoteName('#__jeproshop_tax_rule') . " WHERE " . $db->quoteName('country_id') . " = " . (int) $this->address->country_id; $query .= " AND " . $db->quoteName('tax_rules_group_id') . " = " . (int) $this->type . " AND " . $db->quoteName('state_id') . " IN (0, " . (int) $this->address->state_id; $query .= ") AND ( " . $db->quote($db->escape($postcode)) . " BETWEEN " . $db->quoteName('zipcode_from') . " AND " . $db->quoteName('zipcode_to') . " OR ("; $query .= $db->quote('zipcode_to') . " = 0 AND " . $db->quoteName('zipcode_from') . " IN(0, " . $db->quote($db->escape($postcode)) . "))) ORDER BY "; $query .= $db->quoteName('zipcode_from') . " DESC, " . $db->quoteName('zipcode_to') . " DESC, " . $db->quoteName('state_id') . " DESC, " . $db->quoteName('country_id') . " DESC"; $db->setQuery($query); $results = $db->loadObjectList(); $behavior = 0; $first_row = true; foreach ($results as $result) { $tax = new JeproshopTaxModelTax((int) $result->tax_id); $taxes[] = $tax; // the applied behavior correspond to the most specific rules if ($first_row) { $behavior = $result->behavior; $first_row = false; } if ($result->behavior == 0) { break; } } JeproshopCache::store($cache_id, new JeproshopTaxCalculator($taxes, $behavior)); } return JeproshopCache::retrieve($cache_id); }