Beispiel #1
0
 /**
  * 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;
 }
Beispiel #2
0
 /**
  * Retrieve the price of combination
  *
  * @param int $product_attribute_id
  * @return float mixed
  */
 public static function getPrice($product_attribute_id)
 {
     $db = JFactory::getDBO();
     $query = "SELECT product_attribute_shop." . $db->quoteName('price') . " FROM " . $db->quoteName('#__jeproshop_product_attribute');
     $query .= " AS product_attribute " . JeproshopShopModelShop::addSqlAssociation('product_attribute') . "\tWHERE product_attribute.";
     $query .= $db->quoteName('product_attribute_id') . " = " . (int) $product_attribute_id;
     $db->setQuery($query);
     return $db->loadResult();
 }
Beispiel #3
0
 public static function getTaxRulesGroups($published = TRUE)
 {
     $db = JFactory::getDBO();
     $query = "SELECT DISTINCT tax_rules_group.tax_rules_group_id, tax_rules_group.name, tax_rules_group.published FROM ";
     $query .= $db->quoteName('#__jeproshop_tax_rules_group') . " AS tax_rules_group " . JeproshopShopModelShop::addSqlAssociation('tax_rules_group');
     $query .= ($published ? " WHERE tax_rules_group." . $db->quoteName('published') . " =  1" : "") . " ORDER BY name ASC";
     $db->setQuery($query);
     return $db->loadObjectList();
 }
Beispiel #4
0
 public static function getStaticGroups($lang_id, $shop_id = false)
 {
     $db = JFactory::getDBO();
     $shop_criteria = '';
     if ($shop_id) {
         $shop_criteria = JeproshopShopModelShop::addSqlAssociation('group');
     }
     $query = "SELECT DISTINCT grp." . $db->quoteName('group_id') . ", grp." . $db->quoteName('reduction') . ", grp." . $db->quoteName('price_display_method');
     $query .= ", group_lang." . $db->quoteName('name') . " FROM " . $db->quoteName('#__jeproshop_group') . " AS grp LEFT JOIN " . $db->quoteName('#__jeproshop_group_lang');
     $query .= " AS group_lang ON (grp." . $db->quoteName('group_id') . " = group_lang." . $db->quoteName('group_id') . " AND group_lang." . $db->quoteName('lang_id');
     $query .= " = " . (int) $lang_id . ") " . $shop_criteria . " ORDER BY grp." . $db->quoteName('group_id') . " ASC";
     $db->setQuery($query);
     return $db->loadObjectList();
 }
Beispiel #5
0
 /**
  *
  * @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);
 }
Beispiel #6
0
 public function updateCountry(JeproshopContext $context = null)
 {
     $db = JFactory::getDBO();
     $app = JFactory::getApplication();
     $input = JRequest::get('post');
     $input_data = $input['jform'];
     if (!isset($context)) {
         $context = JeproshopContext::getContext();
     }
     $languages = $context->controller->getLanguages();
     $country_id = $app->input->get('country_id') ? $app->input->get('country_id') : $input['country_id'];
     $country = new JeproshopCountryModelCountry($country_id);
     $currency_id = $input_data['default_currency'];
     $iso_code = $input_data['iso_code'];
     $contains_states = $input_data['contains_states'];
     $need_zip_code = $input_data['need_zip_code'];
     $zone_id = $input_data['zone_id'];
     $display_tax_label = $input_data['display_tax_label'];
     $call_prefix = $input_data['call_prefix'];
     $published = $input_data['published'];
     $need_identification_number = $input_data['need_identification_number'];
     $result = true;
     if (JeproshopTools::isLoadedObject($country, 'country_id')) {
         $oldZoneId = $country->zone_id;
         $query = "SELECT " . $db->quoteName('state_id') . " FROM " . $db->quoteName('#__jeproshop_state') . " WHERE " . $db->quoteName('country_id') . " = " . (int) $country->country_id . " AND " . $db->quoteName('zone_id') . " = " . (int) $oldZoneId;
         $db->setQuery($query);
         $results = $db->loadObjectList();
         if ($results && count($results)) {
             $ids = array();
             foreach ($results as $res) {
                 $ids[] = (int) $res->state_id;
             }
             if (count($ids)) {
                 $query = "UPDATE " . $db->quoteName('#__jeproshop_state') . " SET " . $db->quoteName('zone_id') . " = " . (int) $zone_id . "\tWHERE " . $db->quoteName('state_id') . " IN (" . implode(',', $ids) . ")";
                 $db->setQuery($query);
                 $result &= $db->query();
             }
         }
         if (!$context->controller->has_errors) {
             $query = "UPDATE " . $db->quoteName('#__jeproshop_country') . " country " . JeproshopShopModelShop::addSqlAssociation('country', true, null, true) . " SET country." . $db->quoteName('zone_id') . " = " . (int) $zone_id . ", country.";
             $query .= $db->quoteName('currency_id') . " = " . (int) $currency_id . ", " . $db->quoteName('iso_code') . " = " . $db->quote($iso_code) . ", country." . $db->quoteName('call_prefix') . " = " . $db->quote($call_prefix) . ", country.";
             $query .= $db->quoteName('published') . " = " . (int) $published . ", country." . $db->quoteName('contains_states') . " = " . (int) $contains_states . ", country." . $db->quoteName('need_identification_number') . " = ";
             $query .= (int) $need_identification_number . ", country." . $db->quoteName('need_zip_code') . " = " . (int) $need_zip_code . ", country." . $db->quoteName('display_tax_label') . " = " . (int) $display_tax_label . " WHERE country.";
             $query .= $db->quoteName('country_id') . " = " . (int) $country_id;
             $db->setQuery($query);
             $result &= $db->query();
             foreach ($languages as $language) {
                 $query = "UPDATE " . $db->quoteName('#__jeproshop_country_lang') . " SET " . $db->quoteName('name') . " = " . $db->quote($input_data['name_' . $language->lang_id]) . " WHERE " . $db->quoteName('country_id');
                 $query .= " = " . (int) $country_id . " AND " . $db->quoteName('lang_id') . " = " . (int) $language->lang_id;
                 $db->setQuery($query);
                 $result &= $db->query();
             }
         }
     }
     return $result;
 }
Beispiel #7
0
 /**
  * Return manufacturers
  *
  * @param boolean $get_nb_products [optional] return products numbers for each
  * @param int $lang_id
  * @param bool $published
  * @param int $p
  * @param int $n
  * @param bool $all_group
  * @return array Manufacturers
  */
 public static function getManufacturers($get_nb_products = false, $lang_id = 0, $published = true, $p = false, $n = false, $all_group = false, $group_by = false)
 {
     if (!$lang_id) {
         $lang_id = (int) JeproshopSettingModelSetting::getValue('default_lang');
     }
     if (!JeproshopGroupModelGroup::isFeaturePublished()) {
         $all_group = true;
     }
     $db = JFactory::getDBO();
     $query = "SELECT manufacturer.*, manufacturer_lang." . $db->quoteName('description') . ", manufacturer_lang.";
     $query .= $db->quoteName('short_description') . " FROM " . $db->quoteName('#__jeproshop_manufacturer') . " AS ";
     $query .= "manufacturer " . JeproshopShopModelShop::addSqlAssociation('manufacturer') . " INNER JOIN ";
     $query .= $db->quoteName('#__jeproshop_manufacturer_lang') . " AS manufacturer_lang ON (manufacturer.";
     $query .= $db->quoteName('manufacturer_id') . " = manufacturer_lang." . $db->quoteName('manufacturer_id');
     $query .= " AND manufacturer_lang." . $db->quoteName('lang_id') . " = " . (int) $lang_id . ")";
     $query .= $published ? " WHERE manufacturer." . $db->quoteName('published') . " = 1" : "";
     $query .= ($group_by ? " GROUP BY manufacturer." . $db->quoteName('manufacturer_id') : "") . " ORDER BY ";
     $query .= "manufacturer." . $db->quoteName('name') . " ASC " . ($p ? " LIMIT " . ((int) $p - 1) * (int) $n . ", " . (int) $n : "");
     $db->setQuery($query);
     $manufacturers = $db->loadObjectList();
     if ($manufacturers === false) {
         return false;
     }
     /*
     if ($get_nb_products)
     {
     	$sql_groups = '';
     	if (!$all_group)
     	{
     		$groups = FrontController::getCurrentCustomerGroups();
     		$sql_groups = (count($groups) ? 'IN ('.implode(',', $groups).')' : '= 1');
     	}
     	
     	foreach ($manufacturers as $key => $manufacturer)
     	{
     		$manufacturers[$key]['nb_products'] = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
     		SELECT COUNT(DISTINCT p.`id_product`)
     		FROM `'._DB_PREFIX_.'product` p
     		'.Shop::addSqlAssociation('product', 'p').'
     		WHERE p.`id_manufacturer` = '.(int)$manufacturer['id_manufacturer'].'
     		AND product_shop.`visibility` NOT IN ("none")
     		'.($active ? ' AND product_shop.`active` = 1 ' : '').'
     		'.($all_group ? '' : ' AND p.`id_product` IN (
     			SELECT cp.`id_product`
     			FROM `'._DB_PREFIX_.'category_group` cg
     			LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_category` = cg.`id_category`)
     			WHERE cg.`id_group` '.$sql_groups.'
     		)'));
     	}
     }	
     */
     $total_manufacturers = count($manufacturers);
     $rewrite_settings = (int) JeproshopSettingModelSetting::getValue('rewrite_settings');
     for ($i = 0; $i < $total_manufacturers; $i++) {
         $manufacturers[$i]->link_rewrite = $rewrite_settings ? JeproshopValidator::link_rewrite($manufacturers[$i]->name) : 0;
     }
     return $manufacturers;
 }
Beispiel #8
0
 public function getAttributeGroupList($explicitSelect = TRUE)
 {
     jimport('joomla.html.pagination');
     $db = JFactory::getDBO();
     $app = JFactory::getApplication();
     $option = $app->input->get('option');
     $view = $app->input->get('view');
     $context = JeproshopContext::getContext();
     $limit = $app->getUserStateFromRequest('global.list.limit', 'limit', $app->getCfg('list_limit'), 'int');
     $limitstart = $app->getUserStateFromRequest($option . $view . '.limit_start', 'limit_start', 0, 'int');
     $lang_id = $app->getUserStateFromRequest($option . $view . '.lang_id', 'lang_id', $context->language->lang_id, 'int');
     $shop_id = $app->getUserStateFromRequest($option . $view . '.shop_id', 'shop_id', $context->shop->shop_id, 'int');
     $shop_group_id = $app->getUserStateFromRequest($option . $view . '.shop_group_id', 'shop_group_id', $context->shop->shop_group_id, 'int');
     $category_id = $app->getUserStateFromRequest($option . $view . '.category_id', 'category_id', 0, 'int');
     $order_by = $app->getUserStateFromRequest($option . $view . '.order_by', 'order_by', 'position', 'string');
     $order_way = $app->getUserStateFromRequest($option . $view . '.order_way', 'order_way', 'ASC', 'string');
     $published = $app->getUserStateFromRequest($option . $view . '.published', 'published', 0, 'string');
     /* Manage default params values */
     $use_limit = true;
     if ($limit === false) {
         $use_limit = false;
     }
     /* Query in order to get results with all fields */
     $lang_join = '';
     if ($lang_id) {
         $lang_join = " LEFT JOIN " . $db->quoteName('#__jeproshop_attribute_group_lang') . " AS attribute_group_lang ON (";
         $lang_join .= "attribute_group_lang." . $db->quoteName('attribute_group_id') . " = attribute_group.";
         $lang_join .= $db->quoteName('attribute_group_id');
         $lang_join .= " AND attribute_group_lang." . $db->quoteName('lang_id') . " = " . (int) $lang_id . ") ";
     }
     do {
         $query = "SELECT SQL_CALC_FOUND_ROWS ";
         if ($explicitSelect) {
             $query .= "attribute_group." . $db->quoteName('attribute_group_id') . ", attribute_group_lang.";
             $query .= $db->quoteName('name') . ", attribute_group." . $db->quoteName('position');
         }
         $query .= " FROM " . $db->quoteName('#__jeproshop_attribute_group') . " AS attribute_group " . $lang_join;
         $query .= " ORDER BY " . (str_replace('`', '', $order_by) == 'attribute_group_id' ? "attribute_group." : "") . " attribute_group.";
         $query .= $order_by . " " . $db->escape($order_way) . ($use_limit === true ? " LIMIT " . (int) $limitstart . ", " . (int) $limit : "");
         $db->setQuery($query);
         $attribute_groups = $db->loadObjectList();
         if ($use_limit === true) {
             $limitstart = (int) $limitstart - (int) $limit;
             if ($limitstart < 0) {
                 break;
             }
         } else {
             break;
         }
     } while (empty($attribute_groups));
     foreach ($attribute_groups as $attribute_group) {
         $query = "SELECT attribute.attribute_id as count_values FROM " . $db->quoteName('#__jeproshop_attribute') . " AS attribute ";
         $query .= JeproshopShopModelShop::addSqlAssociation('attribute') . " WHERE attribute.attribute_group_id = ";
         $query .= (int) $attribute_group->attribute_group_id . " GROUP BY attribute_shop.shop_id ORDER BY count_values DESC";
         $db->setQuery($query);
         $attribute_group->count_values = (int) count($db->loadObjectList());
     }
     $total = count($attribute_groups);
     $this->pagination = new JPagination($total, $limitstart, $limit);
     return $attribute_groups;
 }
Beispiel #9
0
 /**
  * Return available currencies
  *
  * @param bool $object
  * @param bool $published
  * @param bool $group_by
  * @return array Currencies
  */
 public static function getStaticCurrencies($object = false, $published = true, $group_by = false)
 {
     $db = JFactory::getDBO();
     $query = "SELECT * FROM " . $db->quoteName('#__jeproshop_currency') . " AS currency " . JeproshopShopModelShop::addSqlAssociation('currency');
     $query .= " WHERE " . $db->quoteName('deleted') . " = 0" . ($published ? " AND currency." . $db->quoteName('published') . " = 1" : "");
     $query .= ($group_by ? " GROUP BY currency." . $db->quoteName('currency_id') : "") . " ORDER BY " . $db->quoteName('name') . " ASC";
     $db->setQuery($query);
     $tab = $db->loadObjectList();
     if ($object) {
         foreach ($tab as $key => $currency) {
             $tab[$key] = JeproshopCurrencyModelCurrency::getCurrencyInstance($currency->currency_id);
         }
     }
     return $tab;
 }
Beispiel #10
0
 public static function getSimpleCategories($lang_id)
 {
     $db = JFactory::getDBO();
     $query = "SELECT category." . $db->quoteName('category_id') . ", category_lang." . $db->quoteName('name') . " 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 category_lang." . $db->quoteName('lang_id') . " = " . (int) $lang_id . " AND category." . $db->quoteName('category_id') . " != " . JeproshopSettingModelSetting::getValue('root_category');
     $query .= "\tGROUP BY category.category_id ORDER BY category." . $db->quoteName('category_id') . ", category_shop." . $db->quoteName('position');
     $db->setQuery($query);
     return $db->loadObjectList();
 }
Beispiel #11
0
    /**
     * Return suppliers
     *
     * @param bool $get_nb_products
     * @param int $lang_id
     * @param bool $published
     * @param bool $p
     * @param bool $n
     * @param bool $all_groups
     * @return array Suppliers
     */
    public static function getSuppliers($get_nb_products = false, $lang_id = 0, $published = true, $p = false, $n = false, $all_groups = false)
    {
        if (!$lang_id) {
            $lang_id = JeproshopSettingModelSetting::getValue('default_lang');
        }
        if (!JeproshopGroupModelGroup::isFeaturePublished()) {
            $all_groups = true;
        }
        $db = JFactory::getDBO();
        $query = "SELECT supplier.*, supplier_lang." . $db->quoteName('description') . " FROM " . $db->quoteName('#__jeproshop_supplier');
        $query .= " AS supplier LEFT JOIN " . $db->quoteName('#__jeproshop_supplier_lang') . " AS supplier_lang ON(supplier.";
        $query .= $db->quoteName('supplier_id') . " = supplier_lang." . $db->quoteName('supplier_id') . " AND supplier_lang.";
        $query .= $db->quoteName('lang_id') . " = " . (int) $lang_id . JeproshopShopModelShop::addSqlAssociation('supplier') . ")";
        $query .= ($published ? " WHERE supplier." . $db->quoteName('published') . " = 1" : "") . " ORDER BY supplier.";
        $query .= $db->quoteName('name') . " ASC " . ($p && $n ? " LIMIT " . $n . ", " . ($p - 1) * $n : "");
        //. " GROUP BY supplier" . $db->quoteName('supplier_id');
        $db->setQuery($query);
        $suppliers = $db->loadObjectList();
        if ($suppliers === false) {
            return false;
        }
        if ($get_nb_products) {
            $sql_groups = '';
            if (!$all_groups) {
                $groups = FrontController::getCurrentCustomerGroups();
                $sql_groups = count($groups) ? 'IN (' . implode(',', $groups) . ')' : '= 1';
            }
            foreach ($suppliers as $key => $supplier) {
                $sql = '
					SELECT DISTINCT(ps.`id_product`)
					FROM `' . _DB_PREFIX_ . 'product_supplier` ps
					JOIN `' . _DB_PREFIX_ . 'product` p ON (ps.`id_product`= p.`id_product`)
					' . Shop::addSqlAssociation('product', 'p') . '
					WHERE ps.`id_supplier` = ' . (int) $supplier['id_supplier'] . '
					AND ps.id_product_attribute = 0' . ($active ? ' AND product_shop.`active` = 1' : '') . ' AND product_shop.`visibility` NOT IN ("none")' . ($all_groups ? '' : '
					AND ps.`id_product` IN (
						SELECT cp.`id_product`
						FROM `' . _DB_PREFIX_ . 'category_group` cg
						LEFT JOIN `' . _DB_PREFIX_ . 'category_product` cp ON (cp.`id_category` = cg.`id_category`)
						WHERE cg.`id_group` ' . $sql_groups . '
					)');
                $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
                $suppliers[$key]['nb_products'] = count($result);
            }
        }
        $nb_suppliers = count($suppliers);
        $rewrite_settings = (int) JeproshopSettingModelSetting::getValue('rewrite_settings');
        for ($i = 0; $i < $nb_suppliers; $i++) {
            $suppliers[$i]->link_rewrite = $rewrite_settings ? JeproshopValidator::link_rewrite($suppliers[$i]->name) : 0;
        }
        return $suppliers;
    }
Beispiel #12
0
 /**
  * Return customer addresses
  *
  * @param integer $lang_id Language ID
  * @return array Addresses
  */
 public function getAddresses($lang_id)
 {
     $share_order = (bool) JeproshopContext::getContext()->shop->getShopGroup()->share_order;
     $cache_id = 'jeproshop_customer_getAddresses_' . (int) $this->customer_id . '-' . (int) $lang_id . '_' . $share_order;
     if (!JeproshopCache::isStored($cache_id)) {
         $db = JFactory::getDBO();
         $query = "SELECT DISTINCT address.*, country_lang." . $db->quoteName('name') . " AS country, stat.name AS ";
         $query .= "state, stat.iso_code AS state_iso FROM " . $db->quoteName('#__jeproshop_address') . " AS address";
         $query .= " LEFT JOIN " . $db->quoteName('#__jeproshop_country') . " AS country ON (address.";
         $query .= $db->quoteName('country_id') . " = country." . $db->quoteName('country_id') . ") LEFT JOIN ";
         $query .= $db->quoteName('#__jeproshop_country_lang') . " AS country_lang ON (country." . $db->quoteName('country_id');
         $query .= " = country_lang." . $db->quoteName('country_id') . ") LEFT JOIN " . $db->quoteName('#__jeproshop_state');
         $query .= " AS stat ON (stat." . $db->quoteName('state_id') . " = address." . $db->quoteName('state_id') . ") ";
         $query .= ($share_order ? "" : JeproshopShopModelShop::addSqlAssociation('country')) . " WHERE " . $db->quoteName('lang_id');
         $query .= " = " . (int) $lang_id . " AND " . $db->quoteName('customer_id') . " = " . (int) $this->customer_id . " AND address.";
         $query .= $db->quoteName('deleted') . " = 0";
         $db->setQuery($query);
         $result = $db->loadObjectList();
         JeproshopCache::store($cache_id, $result);
     }
     return JeproshopCache::retrieve($cache_id);
 }
Beispiel #13
0
 public static function getCurrencies($published = true)
 {
     $db = JFactory::getDBO();
     $query = "SELECT * FROM " . $db->quoteName('#__jeproshop_currency') . " AS currency " . JeproshopShopModelShop::addSqlAssociation('currency');
     $query .= " WHERE currency." . $db->quoteName('deleted') . " = 0 " . ($published ? " AND currency." . $db->quoteName('published') . " = 1" : "");
     $query .= " GROUP BY currency.currency_id ORDER BY " . $db->quoteName('name') . " ASC ";
     $db->setQuery($query);
     return $db->loadObjectList();
 }
Beispiel #14
0
 public static function getPacksTable($product_id, $lang_id, $full = false, $limit = null)
 {
     if (!JeproshopProductPack::isFeaturePublished()) {
         return array();
     }
     $db = JFactory::getDBO();
     $query = "SELECT GROUP_CONCAT(pack." . $db->quoteName('product_pack_id') . ") FROM " . $db->quoteName('#__jeproshop_pack') . " AS pack WHERE pack." . $db->qsuoteName('product_item_id') . " = " . (int) $product_id;
     $db->quoteName($query);
     $packs = $db->loadResult();
     if (!(int) $packs) {
         return array();
     }
     $query = "SELECT product.*, product_shop.*, product_lang.*, MAX(image_shop." . $db->quoteName('image_id') . ") image_id, image_lang." . $db->quoteName('legend') . " FROM " . $db->quoteName('#__jeproshop_product') . " AS product NATURAL LEFT JOIN ";
     $query .= $db->quoteName('#__jeproshop_product_lang') . " AS product_lang " . JeproshopShopModelShop::addSqlAssociation('product') . " LEFT JOIN " . $db->quoteName('#__jeproshop_image') . " AS image ON (image." . $db->quoteName('product_id') . " = product.";
     $query .= $db->quoteName('product_id') . ") " . JeproshopShopModelShop::addSqlAssociation('image', false, 'image_shop.cover=1') . "\tLEFT JOIN " . $db->quoteName('#__jeproshop_image_lang') . " AS image_lang ON (image." . $db->quoteName('image_id');
     $query .= " = image_lang." . $db->quoteName('image_id') . " AND image_lang." . $db->quoteName('lang_id') . " = " . (int) $lang_id . ") WHERE product_lang." . $db->quoteName('lang_id') . " = " . (int) $lang_id . JeproshopShopModelShop::addSqlRestrictionOnLang('product_lang');
     $query .= "\tAND product." . $db->quoteName('product_id') . " IN (" . $packs . ") GROUP BY product_shop.product_id";
     if ($limit) {
         $query .= " LIMIT " . (int) $limit;
     }
     $db->setQuery($query);
     $result = $db->loadObjectList();
     if (!$full) {
         return $result;
     }
     $array_result = array();
     foreach ($result as $row) {
         if (!JeproshopProductPack::isPacked($row->product_id)) {
             $array_result[] = JeproshopProductModelProduct::getProductProperties($lang_id, $row);
         }
     }
     return $array_result;
 }
Beispiel #15
0
 /**
  * Return suppliers
  *
  * @param bool $get_nb_products
  * @param int $lang_id
  * @param bool $published
  * @param bool $p
  * @param bool $n
  * @param bool $all_groups
  * @return array Suppliers
  */
 public static function getSuppliers($get_nb_products = false, $lang_id = 0, $published = true, $p = false, $n = false, $all_groups = false)
 {
     if (!$lang_id) {
         $lang_id = JeproshopSettingModelSetting::getValue('default_lang');
     }
     if (!JeproshopGroupModelGroup::isFeatureActive()) {
         $all_groups = true;
     }
     $db = JFactory::getDBO();
     $query = "SELECT supplier.*, supplier_lang." . $db->quoteName('description') . " FROM " . $db->quoteName('#__jeproshop_supplier') . " AS supplier LEFT JOIN ";
     $query .= $db->quoteName('#__jeproshop_supplier_lang') . " AS supplier_lang ON (supplier." . $db->quoteName('supplier_id') . " = supplier_lang.";
     $query .= $db->quoteName('supplier_id') . " AND supplier_lang." . $db->quoteName('supplier_id') . " = " . (int) $lang_id;
     $query .= JeproshopShopModelShop::addSqlAssociation('supplier') . ")" . ($published ? " WHERE supplier." . $db->quoteName('published') . " = 1" : "") . " ORDER BY supplier.";
     $query .= $db->quoteName('name') . " ASC " . ($n && $p ? "LIMIT " . $n . ", " . ($p - 1) * $n : "");
     $db->setQuery($query);
     $suppliers = $db->loadObjectList();
     if ($suppliers === false) {
         return false;
     }
     if ($get_nb_products) {
         $sql_groups = '';
         if (!$all_groups) {
             $groups = FrontController::getCurrentCustomerGroups();
             $sql_groups = count($groups) ? 'IN (' . implode(',', $groups) . ')' : '= 1';
         }
         foreach ($suppliers as $key => $supplier) {
             $query = "SELECT DISTINCT(product_supplier." . $db->quoteName('product_id') . ") FROM " . $db->quoteName('#__jeproshop_product_supplier') . " AS product_supplier ";
             $query .= " LEFT JOIN " . $db->quoteName('#__jeproshop_product') . " AS product ON (product_supplier." . $db->quoteName('product_id') . " = product.";
             $query .= $db->quoteName('supplier_id') . ") " . JeproshopShopModelShop::addSqlAssociation('product') . " WHERE product_supplier." . $db->quoteName('supplier_id');
             $query .= " = " . (int) $supplier->supplier_id . " AND product_supplier.product_attribute_id = 0 " . ($published ? "AND product_supplier." . $db->quoteName('published') . " = 1" : "");
             $query .= " AND product_shop." . $db->quoteName('visibility') . " NOT IN (\"none\") " . ($all_groups ? "" : " AND product_supplier." . $db->quoteName('product_id') . " IN (SELECT category_product." . $db->quoteName('product_id') . " FROM " . $db->quoteName('#__jeproshop_category_group') . " AS category_group LEFT JOIN " . $db->quoteName('#__jeproshop_category_product') . "  AS category_group ON (category_group." . $db->quoteName('category_id') . " = category_product." . $db->quoteName('category_id') . ") WHERE category_group." . $db->quoteName('group_id') . $sql_groups . ")");
             $db->setQuery($query);
             $result = $db->loadObjectList();
             $suppliers[$key]['nb_products'] = count($result);
         }
     }
     $nb_suppliers = count($suppliers);
     $rewrite_settings = (int) JeproshopSettingModelSetting::getValue('rewrite_settings');
     for ($i = 0; $i < $nb_suppliers; $i++) {
         $suppliers[$i]['link_rewrite'] = $rewrite_settings ? JeproshopTools::link_rewrite($suppliers[$i]['name']) : 0;
     }
     return $suppliers;
 }
Beispiel #16
0
 public static function getDeliveredCountries($lang_id, $active_countries = false, $active_carriers = false, $contain_states = null)
 {
     if (!JeproshopTools::isBool($active_countries) || !JeproshopTools::isBool($active_carriers)) {
         die(Tools::displayError());
     }
     $db = JFactory::getDBO();
     $query = "SELECT state.* FROM " . $db->quoteName('#__jeproshop_state') . " AS state ORDER BY state." . $db->quoteName('name') . " ASC";
     $db->setQuery($query);
     $states = $db->loadObjectList();
     $query = "SELECT country_lang.*, country.*, country_lang." . $db->quoteName('name') . " AS country_name, zone." . $db->quoteName('name') . " AS zone_name FROM " . $db->quoteName('#__jeproshop_country') . " AS country ";
     $query .= JeproshopShopModelShop::addSqlAssociation('country') . " LEFT JOIN " . $db->quoteName('#__jeproshop_country_lang') . " AS country_lang ON (country." . $db->quoteName('country_id') . " = country_lang." . $db->quoteName('country_id');
     $query .= " AND country_lang." . $db->quoteName('lang_id') . " = " . (int) $lang_id . ") INNER JOIN (" . $db->quoteName('#__jeproshop_carrier_zone') . " AS carrier_zone INNER JOIN " . $db->quoteName('#__jeproshop_carrier');
     $query .= " AS carrier ON ( carrier.carrier_id = carrier_zone.carrier_id AND carrier.deleted = 0 " . ($active_carriers ? " AND carrier.published = 1) " : ") ") . " LEFT JOIN " . $db->quoteName('#__jeproshop_zone') . " AS zone ON(carrier_zone.";
     $query .= $db->quoteName('zone_id') . " = zone." . $db->quoteName('zone_id') . " AND zone." . $db->quoteName('zone_id') . " = country." . $db->quoteName('zone_id') . ") WHERE 1 " . ($active_countries ? " AND country." . $db->quoteName('published') . " = 1" : "");
     $query .= (!is_null($contain_states) ? " AND country." . $db->quoteName('contains_states') . " = " . (int) $contain_states : "") . " ORDER BY country_lang.name ASC";
     $db->setQuery($query);
     $result = $db->loadObjectList();
     $countries = array();
     foreach ($result as &$country) {
         $countries[$country->country_id] = $country;
     }
     foreach ($states as &$state) {
         if (isset($countries[$state->country_id])) {
             /* Does not keep the state if its country has been disabled and not selected */
             if ($state->published == 1) {
                 $countries[$state->country_id]['states'][] = $state;
             }
         }
     }
     return $countries;
 }
Beispiel #17
0
 /**
  * Get the user's journey
  *
  * @param integer $category_id Category ID
  * @param string $path Path end
  * @param bool $link_on_the_item
  * @param string $category_type
  * @param JeproshopContext $context
  * @return string
  * @internal param bool $linkOnTheLastItem Put or not a link on the current category
  * @internal param $string [optional] $categoryType defined what type of categories is used (products or cms)
  */
 public static function getPath($category_id, $path = '', $link_on_the_item = false, $category_type = 'products', JeproshopContext $context = null)
 {
     if (!$context) {
         $context = JeproshopContext::getContext();
     }
     $category_id = (int) $category_id;
     if ($category_id == 1) {
         return '<span class="navigation_end">' . $path . '</span>';
     }
     $pipe = '>';
     //Configuration::get('PS_NAVIGATION_PIPE');
     if (empty($pipe)) {
         $pipe = '>';
     }
     $full_path = '';
     if ($category_type === 'products') {
         $interval = JeproshopCategoryModelCategory::getInterval($category_id);
         $root_category_id = $context->shop->getCategoryId();
         $interval_root = JeproshopCategoryModelCategory::getInterval($root_category_id);
         $db = JFactory::getDBO();
         if ($interval) {
             $query = "SELECT category.category_id, category_lang.name, category_lang.link_rewrite FROM " . $db->quoteName('#__jeproshop_category');
             $query .= " AS category LEFT JOIN " . $db->quoteName('#__jeproshop_category_lang') . " AS category_lang ON (category_lang.category_id =";
             $query .= "category.category_id" . JeproshopShopModelShop::addSqlRestrictionOnLang('category_lang') . ")" . JeproshopShopModelShop::addSqlAssociation('category');
             $query .= "\tWHERE category.n_left <= " . $interval->n_left . " AND category.n_right >= " . $interval->n_right . "\tAND category.n_left >= ";
             $query .= $interval_root->n_left . " AND category.n_right <= " . $interval_root->n_right . " AND category_lang.lang_id = " . (int) $context->language->lang_id;
             $query .= "\tAND category.published = 1 AND category.depth_level > " . (int) $interval_root->depth_level . " ORDER BY category.depth_level ASC";
             $db->setQuery($query);
             $categories = $db->loadObjectList();
             $n = 1;
             $n_categories = count($categories);
             foreach ($categories as $category) {
                 $full_path .= ($n < $n_categories || $link_on_the_item ? '<a href="' . JeproshopTools::safeOutput($context->controller->getCategoryLink((int) $category->category_id, $category->link_rewrite)) . '" title="' . htmlentities($category->name, ENT_NOQUOTES, 'UTF-8') . '">' : '') . htmlentities($category->name, ENT_NOQUOTES, 'UTF-8') . ($n < $n_categories || $link_on_the_item ? '</a>' : '') . ($n++ != $n_categories || !empty($path) ? '<span class="navigation-pipe">' . $pipe . '</span>' : '');
             }
             return $full_path . $path;
         }
     } else {
         if ($category_type === 'CMS') {
             $category = new CMSCategory($category_id, $context->language->id);
             if (!Validate::isLoadedObject($category)) {
                 die(Tools::displayError());
             }
             $category_link = $context->link->getCMSCategoryLink($category);
             if ($path != $category->name) {
                 $full_path .= '<a href="' . Tools::safeOutput($category_link) . '">' . htmlentities($category->name, ENT_NOQUOTES, 'UTF-8') . '</a><span class="navigation-pipe">' . $pipe . '</span>' . $path;
             } else {
                 $full_path = ($link_on_the_item ? '<a href="' . Tools::safeOutput($category_link) . '">' : '') . htmlentities($path, ENT_NOQUOTES, 'UTF-8') . ($link_on_the_item ? '</a>' : '');
             }
             return Tools::getPath($category->parent_id, $full_path, $link_on_the_item, $category_type);
         }
     }
 }
Beispiel #18
0
 /**
  * Get all features for a given language
  *
  * @param integer $lang_id Language id
  * @param bool $with_shop
  * @return array Multiple arrays with feature's data
  * @static
  */
 public static function getFeatures($lang_id, $with_shop = true)
 {
     $db = JFactory::getDBO();
     $query = "SELECT DISTINCT feature.feature_id, feature.*, feature_lang.* FROM " . $db->quoteName('#__jeproshop_feature');
     $query .= " AS feature " . ($with_shop ? JeproshopShopModelShop::addSqlAssociation('feature') : "") . " LEFT JOIN ";
     $query .= $db->quoteName('#__jeproshop_feature_lang') . " AS feature_lang ON (feature." . $db->quoteName('feature_id');
     $query .= " = feature_lang." . $db->quoteName('feature_id') . " AND feature_lang." . $db->quoteName('lang_id') . " = ";
     $query .= (int) $lang_id . ") ORDER BY feature." . $db->quoteName('position') . " ASC";
     $db->setQuery($query);
     return $db->loadObjectList();
 }
Beispiel #19
0
 public static function getProducts($lang_id, $limit_start, $limit, $order_by = null, $order_way = null, $get_total = false, $published = true, $random = false, $random_number_products = 1, $check_access = true, JeproshopContext $context = null)
 {
     if (!$context) {
         $context = JeproshopContext::getContext();
     }
     $db = JFactory::getDBO();
     $app = JFactory::getApplication();
     jimport('joomla.html.pagination');
     //if ($check_access && !$context->controller->checkAccess($context->customer->customer_id, $category_id)){ return false; }
     if ($limit_start < 1) {
         $limit_start = 0;
     }
     if (empty($order_by)) {
         $order_by = 'position';
     } else {
         /* Fix for all modules which are now using lowercase values for 'orderBy' parameter */
         $order_by = strtolower($order_by);
     }
     if (empty($order_way)) {
         $order_way = "DESC";
     }
     $order_by_prefix = false;
     if ($order_by == 'product_id' || $order_by == 'date_add' || $order_by == 'date_upd') {
         $order_by_prefix = "product";
     } elseif ($order_by == 'name') {
         $order_by_prefix = "product_lang";
     } elseif ($order_by == 'manufacturer') {
         $order_by_prefix = "manufacturer";
         $order_by = "name";
     } elseif ($order_by == 'position') {
         $order_by_prefix = "product";
     }
     if ($order_by == 'price') {
         $order_by = 'order_price';
     }
     if (!JeproshopTools::isOrderBy($order_by) || !JeproshopTools::isOrderWay($order_way)) {
         die(JError::raiseError());
     }
     $supplier_id = (int) $app->input->get('supplier_id');
     /* Return only the number of products */
     $query = "SELECT COUNT(product." . $db->quoteName('product_id') . ") AS total FROM " . $db->quoteName('#__jeproshop_product') . " AS product ";
     $query .= JeproshopShopModelShop::addSqlAssociation('product') . " WHERE product_shop." . $db->quoteName('visibility') . " IN ('both', 'catalog')";
     $query .= " AND product_shop." . $db->quoteName('published') . " = 1 " . ($supplier_id ? " AND product.supplier_id = " . (int) $supplier_id : "");
     $db->setQuery($query);
     $total = (int) $db->loadResult();
     $number_days_new_product = JeproshopSettingModelSetting::getValue('number_days_new_product');
     $query = "SELECT product.*, product_shop.*, stock.out_of_stock, IFNULL(stock.quantity, 0) as quantity, MAX(product_attribute_shop.product_attribute_id) AS  ";
     $query .= "product_attribute_id, product_attribute_shop.minimal_quantity AS product_attribute_minimal_quantity,  product_lang." . $db->quoteName('description');
     $query .= ", product_lang." . $db->quoteName('short_description') . ", product_lang." . $db->quoteName('available_now') . ", product_lang." . $db->quoteName('available_later');
     $query .= ", product_lang." . $db->quoteName('link_rewrite') . ", product_lang." . $db->quoteName('meta_description') . ", product_lang." . $db->quoteName('meta_keywords');
     $query .= ", product_lang." . $db->quoteName('meta_title') . ", product_lang." . $db->quoteName('name') . ", MAX(image_shop." . $db->quoteName('image_id') . " ) AS ";
     $query .= "image_id, image_lang." . $db->quoteName('legend') . ", manufacturer." . $db->quoteName('name') . " AS manufacturer_name, DATEDIFF(product_shop." . $db->quoteName('date_add');
     $query .= ", DATE_SUB(NOW(), INTERVAL " . (JeproshopTools::isUnsignedInt($number_days_new_product) ? $number_days_new_product : 20) . "\tDAY)) > 0 AS new, product_shop.price AS";
     $query .= " order_price FROM " . $db->quoteName('#__jeproshop_product') . " AS product " . JeproshopShopModelShop::addSqlAssociation('product') . " LEFT JOIN ";
     $query .= $db->quoteName('#__jeproshop_product_attribute') . " AS product_attribute ON (product." . $db->quoteName('product_id') . " = product_attribute." . $db->quoteName('product_id');
     $query .= ") " . JeproshopShopModelShop::addSqlAssociation('product_attribute', false, 'product_attribute_shop.`default_on` = 1');
     $query .= JeproshopProductModelProduct::sqlStock('product', 'product_attribute_shop', false, $context->shop) . " LEFT JOIN " . $db->quoteName('#__jeproshop_product_lang');
     $query .= " AS product_lang ON (product." . $db->quoteName('product_id') . " = product_lang." . $db->quoteName('product_id') . " AND product_lang." . $db->quoteName('lang_id') . " = " . (int) $lang_id . JeproshopShopModelShop::addSqlRestrictionOnLang('product_lang');
     $query .= ") LEFT JOIN " . $db->quoteName('#__jeproshop_image') . " AS image ON (image." . $db->quoteName('product_id') . " = product." . $db->quoteName('product_id') . ") " . JeproshopShopModelShop::addSqlAssociation('image', false, 'image_shop.cover=1') . " LEFT JOIN ";
     $query .= $db->quoteName('#__jeproshop_image_lang') . " AS image_lang ON (image_shop." . $db->quoteName('image_id') . " = image_lang." . $db->quoteName('image_id') . " AND image_lang." . $db->quoteName('lang_id') . " = " . (int) $lang_id . ") LEFT JOIN ";
     $query .= $db->quoteName('#__jeproshop_manufacturer') . " AS manufacturer ON manufacturer." . $db->quoteName('manufacturer_id') . " = product." . $db->quoteName('manufacturer_id') . "\tWHERE product_shop." . $db->quoteName('shop_id') . " = " . (int) $context->shop->shop_id;
     $query .= " AND product_shop." . $db->quoteName('published') . " = 1 AND product_shop." . $db->quoteName('visibility') . " IN ('both', 'catalog') ";
     $query .= ($supplier_id ? " AND product.supplier_id = " . (int) $supplier_id : "") . " GROUP BY product_shop.product_id";
     if ($random === true) {
         $query .= " ORDER BY RAND() LIMIT " . (int) $random_number_products;
     } else {
         //$query .= " ORDER BY " . (!empty($order_by_prefix) ? $order_by_prefix. "." : "") . $db->quoteName($order_by);
         $query .= " " . $order_way . " LIMIT " . (int) $limit_start . ", " . (int) $limit;
     }
     $db->setQuery($query);
     $result = $db->loadObjectList();
     if ($order_by == 'order_price') {
         JeproshopTools::orderbyPrice($result, $order_way);
     }
     if (!$result) {
         return array();
     }
     self::$_pagination = new JPagination($total, $limit_start, $limit);
     /* Modify SQL result */
     return JeproshopProductModelProduct::getProductsProperties($lang_id, $result);
 }
Beispiel #20
0
 public static function getItemTable($product_id, $lang_id, $full = false)
 {
     if (!JeproshopProductPack::isFeaturePublished()) {
         return array();
     }
     $db = JFactory::getDBO();
     $query = "SELECT product.*, product_shop.*, product_lang.*, MAX(image_shop." . $db->quoteName('image_id') . ") image_id, image_lang." . $db->quoteName('legend');
     $query .= ", category_lang." . $db->quoteName('name') . " AS default_category, pack.quantity AS pack_quantity, product_shop." . $db->quoteName('default_category_id');
     $query .= ", pack.product_pack_id FROM " . $db->quoteName('#__jeproshop_pack') . " AS pack LEFT JOIN " . $db->quoteName('#__jeproshop_product') . " AS product ON(";
     $query .= "product.product_id = pack.product_item_id) LEFT JOIN " . $db->quoteName('#__jeproshop_product_lang') . " AS product_lang ON(product.product_id = product_lang.";
     $query .= "product_id AND product_lang.lang_id = " . (int) $lang_id . JeproshopShopModelShop::addSqlRestrictionOnLang('product_lang') . ") LEFT JOIN ";
     $query .= $db->quoteName('#__jeproshop_image') . " AS image ON( image.product_id = product.product_id )" . JeproshopShopModelShop::addSqlAssociation('product', FALSE, 'image_shop.cover = 1');
     $query .= " LEFT JOIN " . $db->quoteName('#__jeproshop_image_lang') . " AS image_lang ON (image.image_id = image_lang.image_id AND image_lang.lang_id = " . (int) $lang_id . " ) ";
     $query .= JeproshopShopModelShop::addSqlAssociation('product') . " LEFT JOIN " . $db->quoteName('#__jeproshop_category_lang') . " AS category_lang ON product_shop.";
     $query .= $db->quoteName('default_category_id') . " = category_lang." . $db->quoteName('category_id') . " AND category_lang." . $db->quoteName('lang_id') . " = " . (int) $lang_id;
     $query .= JeproshopShopModelShop::addSqlRestrictionOnLang('category_lang') . " WHERE product_shop." . $db->quoteName('shop_id') . " = " . (int) JeproshopContext::getContext()->shop->shop_id;
     $query .= " AND pack." . $db->quoteName('product_pack_id') . " = " . (int) $product_id . " GROUP BY product_shop.product_id";
     $db->setQuery($query);
     $result = $db->loadObjectList();
     foreach ($result as &$line) {
         $line = JeproshopProductModelProduct::getTaxesInformations($line);
     }
     if (!$full) {
         return $result;
     }
     $array_result = array();
     foreach ($result as $prow) {
         if (!JeproshopProductPack::isPack($prow->product_id)) {
             $array_result[] = JeproshopProductModelProduct::getProductProperties($lang_id, $prow);
         }
     }
     return $array_result;
 }
Beispiel #21
0
 /**
  *
  * This method allow to add image information on a product detail
  * @param array &$product
  */
 protected function setProductImageInformations(&$product)
 {
     $db = JFactory::getDBO();
     if (isset($product->product_attribute_id) && $product->product_attribute_id) {
         $query = "SELECT image_shop.image_id FROM " . $db->quoteName('#__jeproshop_product_attribute_image') . " AS product_attribte_image";
         $query .= JeproshopShopModelShop::addSqlAssociation('image', 'pai', true) . " WHERE product_attribute_id = " . (int) $product->product_attribute_id;
         $db->setQuery($query);
         $image_id = $db->loadResult();
     }
     if (!isset($image_id) || !$image_id) {
         $query = "SELECT image_shop.image_id FROM " . $db->quoteName('#__jeproshop_image') . " AS image";
         $query .= JeproshopShopModelShop::addSqlAssociation('image', true, 'image_shop.cover=1') . " WHERE";
         $query .= " product_id = " . (int) $product->product_id;
         $db->setQuery($query);
         $image_id = $db->loadResult();
     }
     $product->image = null;
     $product->image_size = null;
     if ($image_id) {
         $product->image = new JeproshopImageModelImage($image_id);
     }
 }
Beispiel #22
0
 public static function searchTag($id_lang, $tag, $count = false, $pageNumber = 0, $pageSize = 10, $orderBy = false, $orderWay = false, $useCookie = true, JeproshopContext $context = null)
 {
     if (!$context) {
         $context = JeproshopContext::getContext();
     }
     // Only use cookie if id_customer is not present
     if ($useCookie) {
         $customer_id = (int) $context->customer->customer_id;
     } else {
         $customer_id = 0;
     }
     if (!is_numeric($pageNumber) || !is_numeric($pageSize) || !Validate::isBool($count) || !Validate::isValidSearch($tag) || $orderBy && !$orderWay || $orderBy && !Validate::isOrderBy($orderBy) || $orderWay && !Validate::isOrderBy($orderWay)) {
         return false;
     }
     if ($pageNumber < 1) {
         $pageNumber = 1;
     }
     if ($pageSize < 1) {
         $pageSize = 10;
     }
     $shop_id = JeproshopContext::getContext()->shop->shop_id;
     $shop_id = $shop_id ? $shop_id : JeproshopSettingModelSetting::getValue('default_shop');
     $sql_groups = '';
     if (JeproshopGroupModelGroup::isFeaturePublished()) {
         $groups = JeproshopController::getCurrentCustomerGroups();
         $sql_groups = " AND customer_group." . $db->quoteName('group_id') . (count($groups) ? " IN (" . implode(',', $groups) . ")" : "= 1");
     }
     if ($count) {
         $query = "SELECT COUNT(DISTINCT product_tag." . $db->quoteName('product_id') . ") nb FROM " . $db->quoteName('#__jeproshop_product');
         $query .= " AS product " . JeproshopShopModelShop::addSqlAssociation('product') . "\tLEFT JOIN " . $db->quoteName('#__jeproshop_product_tag');
         $query .= " AS product_tag ON (product." . $db->quoteName('product_id') . " = product_tag." . $db->quoteName('product_id') . ") LEFT JOIN ";
         $query .= $db->quoteName('#__jeproshop_tag') . " AS tag ON (product_tag." . $db->quoteName('tag_id') . " = tag." . $db->quoteName('tag_id');
         $query .= " AND tag." . $db->quoteName('lang_id') . " = " . (int) $lang_id . ") LEFT JOIN " . $db->quoteName('#__jeproshop_product_category');
         $query .= " AS product_category ON (product_category." . $db->quoteName('product_id') . " = product." . $db->quoteName('product_id') . ") LEFT JOIN ";
         $query .= $db->quoteName('#__jeproshop_category_shop') . " AS category_shop ON (product_category." . $db->quoteName('category_id') . " = category_shop.";
         $query .= $db->quoteName('category_id') . " AND category_shop." . $db->quoteName('shop_id') . " = " . (int) $shop_id . ") ";
         $query .= JeproshopGroupModelGroup::isFeaturePublished() ? " LEFT JOIN " . $db->quoteName('#__jeproshop_category_group') . " AS category_group ON (category_group." . $db->quoteName('category_id') . " = product_category." . $db->quoteName('category_id') . ")" : "";
         $query .= "\tWHERE product_shop." . $db->quoteName('publishd') . " = 1 AND product.visibility IN ('both', 'search') AND category_shop." . $db->quoteName('shop_id');
         $query .= " = " . (int) JeproshopContext::getContext()->shop->shop_id . $sql_groups . " AND tag." . $db->quoteName('name') . " LIKE '%'" . $db->quote($tag) . "'%')";
         /*$query .= " } 
         	
         				$sql = 'SELECT DISTINCT p.*, product_shop.*, stock.out_of_stock, IFNULL(stock.quantity, 0) as quantity, pl.`description_short`, pl.`link_rewrite`, pl.`name`,
         					MAX(image_shop.`id_image`) id_image, il.`legend`, m.`name` manufacturer_name, 1 position,
         					DATEDIFF(
         						p.`date_add`,
         						DATE_SUB(
         							NOW(),
         							INTERVAL '.(Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20).' DAY
         						)
         					) > 0 new
         				FROM `' $db->quoteName('#__jeproshop_product` p
         				INNER JOIN `'.$db->quoteName('#__jeproshop_product_lang` pl ON (
         					p.`id_product` = pl.`id_product`
         					AND pl.`id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('pl').'
         				)'.Shop::addSqlAssociation('product', 'p', false).'
         				LEFT JOIN `'.$db->quoteName('#__jeproshop_image` i ON (i.`id_product` = p.`id_product`)'.
         					Shop::addSqlAssociation('image', 'i', false, 'image_shop.cover=1').'
         				LEFT JOIN `' . $db->quoteName('#__jeproshop_image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$id_lang.')
         				LEFT JOIN `'. $db->quoteName('#__jeproshop_manufacturer` m ON (m.`id_manufacturer` = p.`id_manufacturer`)
         				LEFT JOIN `'. $db->quoteName('#__jeproshop_product_tag` pt ON (p.`id_product` = pt.`id_product`)
         				LEFT JOIN `'. $db->quoteName('#__jeproshop_tag` t ON (pt.`id_tag` = t.`id_tag` AND t.`id_lang` = '.(int)$id_lang.')
         				LEFT JOIN `'. $db->quoteName('#__jeproshop_category_product` cp ON (cp.`id_product` = p.`id_product`)
         				'.(Group::isFeatureActive() ? 'LEFT JOIN `'._DB_PREFIX_.'category_group` cg ON (cg.`id_category` = cp.`id_category`)' : '').'
         				LEFT JOIN `'. $db->quoteName('#__jeproshop_category_shop` cs ON (cp.`id_category` = cs.`id_category` AND cs.`id_shop` = '.(int)$id_shop.')
         				'.Product::sqlStock('p', 0).'
         				WHERE product_shop.`active` = 1
         					AND cs.`id_shop` = '.(int)Context::getContext()->shop->id.'
         					'.$sql_groups.'
         					AND t.`name` LIKE \'%'.pSQL($tag).'%\'
         					return (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(
         			
         				
         					GROUP BY product_shop.id_product
         				ORDER BY position DESC'.($orderBy ? ', '.$orderBy : '').($orderWay ? ' '.$orderWay : '').'
         				LIMIT '.(int)(($pageNumber - 1) * $pageSize).','.(int)$pageSize;
         				$db->setQuery($query);
         				$result = $db->loadObjectList();
         				if (!$result)
         					return false; */
     }
     return JeproshopProductModelProduct::getProductsProperties((int) $lang_id, $result);
 }