Пример #1
0
    public static function getProducts($id_manufacturer, $id_lang, $p, $n, $orderBy = NULL, $orderWay = NULL, $getTotal = false, $active = true, $active_category = true, Context $context = NULL)
    {
        global $cookie;
        $agile_sql_parts = AgileSellerManager::getAdditionalSqlForProducts("p");
        if (empty($agile_sql_parts['joins']) or empty($agile_sql_parts['wheres'])) {
            parent::getProducts($id_manufacturer, $id_lang, $p, $n, $orderBy, $orderWay, $getTotal, $active, $active_category);
        }
        if ($p < 1) {
            $p = 1;
        }
        if (empty($orderBy) || $orderBy == 'position') {
            $orderBy = 'name';
        }
        if (empty($orderWay)) {
            $orderWay = 'ASC';
        }
        if (!Validate::isOrderBy($orderBy) or !Validate::isOrderWay($orderWay)) {
            die(Tools::displayError());
        }
        $groups = FrontController::getCurrentCustomerGroups();
        $sqlGroups = count($groups) ? 'IN (' . implode(',', $groups) . ')' : '= 1';
        if ($getTotal) {
            $sql = '
				SELECT p.`id_product`
				FROM `' . _DB_PREFIX_ . 'product` p
			    ' . $agile_sql_parts['joins'] . '
				WHERE p.id_manufacturer = ' . (int) $id_manufacturer . ($active ? ' AND p.`active` = 1' : '') . '
    			' . $agile_sql_parts['wheres'] . '
				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`)' . ($active_category ? ' INNER JOIN `' . _DB_PREFIX_ . 'category` ca ON cp.`id_category` = ca.`id_category` AND ca.`active` = 1' : '') . '
					WHERE cg.`id_group` ' . $sqlGroups . '
				)';
            $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS($sql);
            return (int) sizeof($result);
        }
        $sql = '
		SELECT p.*, pa.`id_product_attribute`, pl.`description`, pl.`description_short`, pl.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`, pl.`name`, i.`id_image`, il.`legend`, m.`name` AS manufacturer_name, tl.`name` AS tax_name, t.`rate`, 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 AS new,
			(p.`price` * ((100 + (t.`rate`))/100)) AS orderprice
			' . $agile_sql_parts['selects'] . '
		FROM `' . _DB_PREFIX_ . 'product` p
			    ' . $agile_sql_parts['joins'] . '
		LEFT JOIN `' . _DB_PREFIX_ . 'product_attribute` pa ON (p.`id_product` = pa.`id_product` AND default_on = 1)
		LEFT JOIN `' . _DB_PREFIX_ . 'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = ' . (int) $id_lang . ')
		LEFT JOIN `' . _DB_PREFIX_ . 'image` i ON (i.`id_product` = p.`id_product` AND i.`cover` = 1)
		LEFT JOIN `' . _DB_PREFIX_ . 'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = ' . (int) $id_lang . ')
		LEFT JOIN `' . _DB_PREFIX_ . 'tax_rule` tr ON (p.`id_tax_rules_group` = tr.`id_tax_rules_group`
		                                           AND tr.`id_country` = ' . (int) (_PS_VERSION_ > '1.5' ? Context::getContext()->country->id : Country::getDefaultCountryId()) . '
	                                           	   AND tr.`id_state` = 0)
	    LEFT JOIN `' . _DB_PREFIX_ . 'tax` t ON (t.`id_tax` = tr.`id_tax`)
		LEFT JOIN `' . _DB_PREFIX_ . 'tax_lang` tl ON (t.`id_tax` = tl.`id_tax` AND tl.`id_lang` = ' . (int) $id_lang . ')
		LEFT JOIN `' . _DB_PREFIX_ . 'manufacturer` m ON m.`id_manufacturer` = p.`id_manufacturer`
		WHERE p.`id_manufacturer` = ' . (int) $id_manufacturer . ($active ? ' AND p.`active` = 1' : '') . '
			' . $agile_sql_parts['wheres'] . '
		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`)' . ($active_category ? ' INNER JOIN `' . _DB_PREFIX_ . 'category` ca ON cp.`id_category` = ca.`id_category` AND ca.`active` = 1' : '') . '
					WHERE cg.`id_group` ' . $sqlGroups . '
				)
		ORDER BY ' . ($orderBy == 'id_product' ? 'p.' : '') . '`' . pSQL($orderBy) . '` ' . pSQL($orderWay) . '
		LIMIT ' . ((int) $p - 1) * (int) $n . ',' . (int) $n;
        $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS($sql);
        if (!$result) {
            return false;
        }
        if ($orderBy == 'price') {
            Tools::orderbyPrice($result, $orderWay);
        }
        $finalResults = Product::getProductsProperties($id_lang, $result);
        $finalResults = AgileSellerManager::prepareSellerRattingInfo($finalResults);
        return $finalResults;
    }
Пример #2
0
    public static function searchTag($id_lang, $tag, $count = false, $pageNumber = 0, $pageSize = 10, $orderBy = false, $orderWay = false, $useCookie = true, Context $context = null)
    {
        if (!$context) {
            $context = Context::getContext();
        }
        if (!Module::isInstalled('agilemultipleseller') and !Module::isInstalled('agilesellerlistoptions')) {
            return parent::searchTag($id_lang, $expr, $pageNumber, $pageSize, $orderBy, $orderWay, $ajax, $useCookie, $context);
        }
        $agile_sql_parts = AgileSellerManager::getAdditionalSqlForProducts("p");
        if ($useCookie) {
            $id_customer = (int) $context->customer->id;
        } else {
            $id_customer = 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;
        }
        $id = Context::getContext()->shop->id;
        $id_shop = $id ? $id : Configuration::get('PS_SHOP_DEFAULT');
        if ($count) {
            $sql = 'SELECT COUNT(DISTINCT pt.`id_product`) nb
					FROM `' . _DB_PREFIX_ . 'product` p
		            ' . $agile_sql_parts['joins'] . '
					' . Shop::addSqlAssociation('product', 'p') . '
					LEFT JOIN `' . _DB_PREFIX_ . 'product_tag` pt ON (p.`id_product` = pt.`id_product`)
					LEFT JOIN `' . _DB_PREFIX_ . 'tag` t ON (pt.`id_tag` = t.`id_tag` AND t.`id_lang` = ' . (int) $id_lang . ')
					LEFT JOIN `' . _DB_PREFIX_ . 'category_product` cp ON (cp.`id_product` = p.`id_product`)
					LEFT JOIN `' . _DB_PREFIX_ . 'category_shop` cs ON (cp.`id_category` = cs.`id_category` AND cs.`id_shop` = ' . (int) $id_shop . ')
					LEFT JOIN `' . _DB_PREFIX_ . 'category_group` cg ON (cg.`id_category` = cp.`id_category`)
					WHERE product_shop.`active` = 1
						' . $agile_sql_parts['wheres'] . '
						AND cs.`id_shop` = ' . (int) Context::getContext()->shop->id . '
						AND cg.`id_group` ' . (!$id_customer ? '= ' . (int) Configuration::get('PS_UNIDENTIFIED_GROUP') : 'IN (
							SELECT id_group FROM ' . _DB_PREFIX_ . 'customer_group
							WHERE id_customer = ' . (int) $id_customer . ')') . '
						AND t.`name` LIKE \'%' . pSQL($tag) . '%\'';
            return (int) Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql);
        }
        $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
	            ' . $agile_sql_parts['selects'] . '
				FROM `' . _DB_PREFIX_ . 'product` p
	            ' . $agile_sql_parts['joins'] . '
				INNER JOIN `' . _DB_PREFIX_ . '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_PREFIX_ . 'image` i ON (i.`id_product` = p.`id_product`)' . Shop::addSqlAssociation('image', 'i', false, 'image_shop.cover=1') . '		
				LEFT JOIN `' . _DB_PREFIX_ . 'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = ' . (int) $id_lang . ')
				LEFT JOIN `' . _DB_PREFIX_ . 'manufacturer` m ON (m.`id_manufacturer` = p.`id_manufacturer`)
				LEFT JOIN `' . _DB_PREFIX_ . 'product_tag` pt ON (p.`id_product` = pt.`id_product`)
				LEFT JOIN `' . _DB_PREFIX_ . 'tag` t ON (pt.`id_tag` = t.`id_tag` AND t.`id_lang` = ' . (int) $id_lang . ')
				LEFT JOIN `' . _DB_PREFIX_ . 'category_product` cp ON (cp.`id_product` = p.`id_product`)
				LEFT JOIN `' . _DB_PREFIX_ . 'category_group` cg ON (cg.`id_category` = cp.`id_category`)
				LEFT JOIN `' . _DB_PREFIX_ . 'category_shop` cs ON (cg.`id_category` = cs.`id_category` AND cs.`id_shop` = ' . (int) $id_shop . ')
				' . Product::sqlStock('p', 0) . '
				WHERE product_shop.`active` = 1
					' . $agile_sql_parts['wheres'] . '
					AND cs.`id_shop` = ' . (int) Context::getContext()->shop->id . '
					AND cg.`id_group` ' . (!$id_customer ? '= ' . (int) Configuration::get('PS_UNIDENTIFIED_GROUP') : 'IN (
						SELECT id_group FROM ' . _DB_PREFIX_ . 'customer_group
						WHERE id_customer = ' . (int) $id_customer . ')') . '
					AND t.`name` LIKE \'%' . pSQL($tag) . '%\'
					GROUP BY product_shop.id_product
				ORDER BY position DESC' . ($orderBy ? ', ' . $orderBy : '') . ($orderWay ? ' ' . $orderWay : '') . '
				LIMIT ' . (int) (($pageNumber - 1) * $pageSize) . ',' . (int) $pageSize;
        if (!($result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql))) {
            return false;
        }
        $results = Product::getProductsProperties((int) $id_lang, $result);
        $results = AgileSellerManager::prepareSellerRattingInfo($results);
        return $results;
    }
Пример #3
0
    protected function getProducts($id_lang, $p, $n, $orderBy = NULL, $orderWay = NULL, $getTotal = false, $active = true, $random = false, $randomNumberProducts = 1)
    {
        global $cookie, $smarty;
        $id_seller = $this->seller->id;
        if ($p < 1) {
            $p = 1;
        }
        if ($n <= 0) {
            $n = 10;
        }
        if (empty($orderBy)) {
            $orderBy = 'price';
        } else {
            $orderBy = strtolower($orderBy);
        }
        if (empty($orderWay)) {
            $orderWay = 'ASC';
        }
        if ($orderBy == 'id_product' or $orderBy == 'date_add') {
            $orderByPrefix = 'p';
        } elseif ($orderBy == 'name') {
            $orderByPrefix = 'pl';
        } elseif ($orderBy == 'manufacturer') {
            $orderByPrefix = 'm';
            $orderBy = 'name';
        }
        if ($orderBy == 'price') {
            $orderBy = 'orderprice';
        }
        if (!Validate::isBool($active) or !Validate::isOrderBy($orderBy) or !Validate::isOrderWay($orderWay)) {
            die(Tools::displayError());
        }
        $agile_sql_parts = AgileSellerManager::getAdditionalSqlForProducts("p", true);
        if (Module::isInstalled('agilesellerlistoptions') && empty($orderby)) {
            $orderby = 'position2';
        }
        if ($getTotal) {
            $sql = '
			SELECT COUNT(po.`id_product`) AS total
			FROM `' . _DB_PREFIX_ . 'product` p
			LEFT JOIN `' . _DB_PREFIX_ . 'product_owner` po ON p.`id_product` = po.`id_product`
			' . $agile_sql_parts['joins'] . '
			WHERE p.id_category_default>0 AND po.`id_owner` = ' . (int) $this->seller->id . '
			' . ($active ? ' AND p.`active` = 1' : '') . '
			' . $agile_sql_parts['wheres'] . '
			';
            $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql);
            return isset($result) ? $result['total'] : 0;
        }
        $sql = '
		        SELECT p.*, pa.`id_product_attribute`, pl.`description`, pl.`description_short`, pl.`available_now`, pl.`available_later`, pl.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`, pl.`name`, i.`id_image`, il.`legend`, m.`name` AS manufacturer_name, tl.`name` AS tax_name, t.`rate`, cl.`name` AS category_default, 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 AS new,
			        (p.`price` * IF(t.`rate`,((100 + (t.`rate`))/100),1)) AS orderprice
					' . $agile_sql_parts['selects'] . '
		        FROM `' . _DB_PREFIX_ . 'product_owner` po
		        LEFT JOIN `' . _DB_PREFIX_ . 'product` p ON p.`id_product` = po.`id_product`
		        LEFT JOIN `' . _DB_PREFIX_ . 'product_attribute` pa ON (p.`id_product` = pa.`id_product` AND default_on = 1)
		        LEFT JOIN `' . _DB_PREFIX_ . 'category_lang` cl ON (p.`id_category_default` = cl.`id_category` AND cl.`id_lang` = ' . (int) $cookie->id_lang . ')
		        LEFT JOIN `' . _DB_PREFIX_ . 'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = ' . (int) $cookie->id_lang . ')
		        LEFT JOIN `' . _DB_PREFIX_ . 'image` i ON (i.`id_product` = p.`id_product` AND i.`cover` = 1)
		        LEFT JOIN `' . _DB_PREFIX_ . 'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = ' . (int) $cookie->id_lang . ')
		        LEFT JOIN `' . _DB_PREFIX_ . 'tax_rule` tr ON (p.`id_tax_rules_group` = tr.`id_tax_rules_group`
		                                                   AND tr.`id_country` = ' . (int) (_PS_VERSION_ > '1.5' ? Context::getContext()->country->id : Country::getDefaultCountryId()) . '
	                                           	           AND tr.`id_state` = 0)
	            LEFT JOIN `' . _DB_PREFIX_ . 'tax` t ON (t.`id_tax` = tr.`id_tax`)
		        LEFT JOIN `' . _DB_PREFIX_ . 'tax_lang` tl ON (t.`id_tax` = tl.`id_tax` AND tl.`id_lang` = ' . (int) $cookie->id_lang . ')
		        LEFT JOIN `' . _DB_PREFIX_ . 'manufacturer` m ON m.`id_manufacturer` = p.`id_manufacturer`
    			' . $agile_sql_parts['joins'] . '
		        WHERE p.id_category_default>0 AND po.`id_owner` = ' . $id_seller . '
        			' . ($active ? ' AND p.`active` = 1' : '') . '
        			' . $agile_sql_parts['wheres'] . '
		        ';
        if ($random === true) {
            $sql .= ' ORDER BY RAND()';
            $sql .= ' LIMIT 0, ' . (int) $randomNumberProducts;
        } else {
            $sql .= ' ORDER BY ' . (isset($orderByPrefix) ? $orderByPrefix . '.' : '') . '`' . pSQL($orderBy) . '` ' . pSQL($orderWay) . '
			LIMIT ' . ((int) $p - 1) * (int) $n . ',' . (int) $n;
        }
        $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS($sql);
        if ($orderBy == 'orderprice') {
            Tools::orderbyPrice($result, $orderWay);
        }
        if (!$result) {
            return false;
        }
        $finalResults = Product::getProductsProperties($id_lang, $result);
        $finalResults = AgileSellerManager::prepareSellerRattingInfo($finalResults);
        return $finalResults;
    }
Пример #4
0
    public function getProducts($id_lang, $p, $n, $orderBy = NULL, $orderWay = NULL, $getTotal = false, $active = true, $random = false, $randomNumberProducts = 1, $checkAccess = true, Context $context = null)
    {
        global $cookie;
        if (!$checkAccess or !$this->checkAccess($cookie->id_customer)) {
            return false;
        }
        if (!$context) {
            $context = Context::getContext();
        }
        $front = true;
        if (!in_array($context->controller->controller_type, array('front', 'modulefront'))) {
            $front = false;
        }
        if (Module::isInstalled('agilemembership') and $this->id == Configuration::get('AGILE_MEMBERSHIP_CID')) {
            return parent::getProducts($id_lang, $p, $n, $orderBy, $orderWay, $getTotal, $active, $random, $randomNumberProducts, $checkAccess);
        }
        if (Module::isInstalled('agileprepaidcredit') and $this->id == Configuration::getGlobalValue('AGILE_PCREDIT_CID')) {
            return parent::getProducts($id_lang, $p, $n, $orderBy, $orderWay, $getTotal, $active, $random, $randomNumberProducts, $checkAccess);
        }
        if (Module::isInstalled('agilesellerlistoptions') and $this->id == Configuration::get('ASLO_CATEGORY_ID')) {
            return parent::getProducts($id_lang, $p, $n, $orderBy, $orderWay, $getTotal, $active, $random, $randomNumberProducts, $checkAccess);
        }
        $agile_sql_parts = AgileSellerManager::getAdditionalSqlForProducts("p");
        if (empty($agile_sql_parts['selects']) and empty($agile_sql_parts['joins']) and empty($agile_sql_parts['wheres'])) {
            return parent::getProducts($id_lang, $p, $n, $orderBy, $orderWay, $getTotal, $active, $random, $randomNumberProducts, $checkAccess);
        }
        if (Module::isInstalled('agilesellerlistoptions')) {
            require_once _PS_ROOT_DIR_ . "/modules/agilesellerlistoptions/agilesellerlistoptions.php";
            if ($this->id <= 1 or $this->id == 2 or $this->id == (int) Configuration::get('PS_HOME_CATEGORY')) {
                return AgileSellerListOptions::get_home_products($id_lang, $p, $n);
            }
            if (empty($orderBy) || $orderBy == 'position') {
                $orderBy = 'position2';
            }
        }
        if ($p < 1) {
            $p = 1;
        }
        if (empty($orderBy)) {
            $orderBy = 'position';
        } else {
            $orderBy = strtolower($orderBy);
        }
        if (empty($orderWay)) {
            $orderWay = 'ASC';
        }
        if ($orderBy == 'id_product' or $orderBy == 'date_add' or $orderBy == 'date_upd') {
            $orderByPrefix = 'p';
        } elseif ($orderBy == 'name') {
            $orderByPrefix = 'pl';
        } elseif ($orderBy == 'manufacturer') {
            $orderByPrefix = 'm';
            $orderBy = 'name';
        } elseif ($orderBy == 'position') {
            $orderByPrefix = 'cp';
        }
        if ($orderBy == 'price') {
            $orderBy = 'orderprice';
        }
        if (!Validate::isBool($active) or !Validate::isOrderBy($orderBy) or !Validate::isOrderWay($orderWay)) {
            die(Tools::displayError());
        }
        $id_supplier = (int) Tools::getValue('id_supplier');
        if ($getTotal) {
            $sql = '
			SELECT COUNT(cp.`id_product`) AS total
			FROM `' . _DB_PREFIX_ . 'product` p
			' . Shop::addSqlAssociation('product', 'p') . '
			LEFT JOIN `' . _DB_PREFIX_ . 'category_product` cp ON p.`id_product` = cp.`id_product`
			    ' . $agile_sql_parts['joins'] . '
			WHERE cp.`id_category` = ' . (int) $this->id . ($front ? ' AND product_shop.`visibility` IN ("both", "catalog")' : '') . ($active ? ' AND product_shop.`active` = 1' : '') . $agile_sql_parts['wheres'] . ($id_supplier ? 'AND p.id_supplier = ' . (int) $id_supplier : '');
            $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql);
            return isset($result) ? $result['total'] : 0;
        }
        $sql = 'SELECT p.*, product_shop.*, stock.out_of_stock, IFNULL(stock.quantity, 0) as quantity, MAX(product_attribute_shop.id_product_attribute) id_product_attribute, product_attribute_shop.minimal_quantity AS product_attribute_minimal_quantity, pl.`description`, pl.`description_short`, pl.`available_now`,
					pl.`available_later`, pl.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`, pl.`name`, MAX(image_shop.`id_image`) id_image,
					il.`legend`, m.`name` AS manufacturer_name, cl.`name` AS category_default,
					DATEDIFF(product_shop.`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 AS new, product_shop.price AS orderprice
					' . $agile_sql_parts['selects'] . '	
				FROM `' . _DB_PREFIX_ . 'category_product` cp
				LEFT JOIN `' . _DB_PREFIX_ . 'product` p
					ON p.`id_product` = cp.`id_product`
				' . Shop::addSqlAssociation('product', 'p') . '
				LEFT JOIN `' . _DB_PREFIX_ . 'product_attribute` pa
				ON (p.`id_product` = pa.`id_product`)
				' . Shop::addSqlAssociation('product_attribute', 'pa', false, 'product_attribute_shop.`default_on` = 1') . '
				' . Product::sqlStock('p', 'product_attribute_shop', false, $context->shop) . '
				LEFT JOIN `' . _DB_PREFIX_ . 'category_lang` cl
					ON (product_shop.`id_category_default` = cl.`id_category`
					AND cl.`id_lang` = ' . (int) $id_lang . Shop::addSqlRestrictionOnLang('cl') . ')
				LEFT JOIN `' . _DB_PREFIX_ . 'product_lang` pl
					ON (p.`id_product` = pl.`id_product`
					AND pl.`id_lang` = ' . (int) $id_lang . Shop::addSqlRestrictionOnLang('pl') . ')
				LEFT JOIN `' . _DB_PREFIX_ . 'image` i
					ON (i.`id_product` = p.`id_product`)' . Shop::addSqlAssociation('image', 'i', false, 'image_shop.cover=1') . '
				LEFT JOIN `' . _DB_PREFIX_ . 'image_lang` il
					ON (image_shop.`id_image` = il.`id_image`
					AND il.`id_lang` = ' . (int) $id_lang . ')
				LEFT JOIN `' . _DB_PREFIX_ . 'manufacturer` m
					ON m.`id_manufacturer` = p.`id_manufacturer`
			    ' . $agile_sql_parts['joins'] . '			
				WHERE product_shop.`id_shop` = ' . (int) $context->shop->id . '
				    ' . $agile_sql_parts['wheres'] . '
					AND cp.`id_category` = ' . (int) $this->id . ($active ? ' AND product_shop.`active` = 1' : '') . ($front ? ' AND product_shop.`visibility` IN ("both", "catalog")' : '') . ($id_supplier ? ' AND p.id_supplier = ' . (int) $id_supplier : '') . ' GROUP BY product_shop.id_product';
        if ($random === true) {
            $sql .= ' ORDER BY RAND()';
            $sql .= ' LIMIT 0, ' . (int) $randomNumberProducts;
        } else {
            $sql .= ' ORDER BY ' . (isset($orderByPrefix) ? $orderByPrefix . '.' : '') . '`' . pSQL($orderBy) . '` ' . pSQL($orderWay) . '
			LIMIT ' . ((int) $p - 1) * (int) $n . ',' . (int) $n;
        }
        $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS($sql);
        if (!$result) {
            return array();
        }
        $seller = array();
        $id_seller = array();
        $link_seller = array();
        foreach ($result as $row) {
            $pid = $row['id_product'];
            $seller[$pid] = isset($row['seller']) ? $row['seller'] : '';
            $id_seller[$pid] = isset($row['id_seller']) ? intval($row['id_seller']) : 0;
            $link_seller[$pid] = isset($row['has_sellerlink']) ? $row['has_sellerlink'] : '';
        }
        $resultsArray = Product::getProductsProperties((int) $id_lang, $result);
        for ($idx = 0; $idx < count($resultsArray); $idx++) {
            $pid = $resultsArray[$idx]['id_product'];
            $resultsArray[$idx]['seller'] = $seller[$pid];
            $resultsArray[$idx]['id_seller'] = $id_seller[$pid];
            $resultsArray[$idx]['has_sellerlink'] = $link_seller[$pid];
        }
        $resultsArray = AgileSellerManager::prepareSellerRattingInfo($resultsArray);
        return $resultsArray;
    }
Пример #5
0
    public function getProductsLite($id_lang)
    {
        $context = Context::getContext();
        $front = true;
        if (!in_array($context->controller->controller_type, array('front', 'modulefront'))) {
            $front = false;
        }
        $agile_sql_parts = AgileSellerManager::getAdditionalSqlForProducts("p");
        if (empty($agile_sql_parts['joins']) or empty($agile_sql_parts['wheres'])) {
            parent::getProductsLite($id_lang);
        }
        $sql = '
			SELECT p.`id_product`,
				   pl.`name`
			FROM `' . _DB_PREFIX_ . 'product` p
			' . Shop::addSqlAssociation('product', 'p') . '
			LEFT JOIN `' . _DB_PREFIX_ . 'product_lang` pl ON (
				p.`id_product` = pl.`id_product`
				AND pl.`id_lang` = ' . (int) $id_lang . '
			)
			INNER JOIN `' . _DB_PREFIX_ . 'product_supplier` ps ON (
				ps.`id_product` = p.`id_product`
				AND ps.`id_supplier` = ' . (int) $this->id . '
			)
			' . ($front ? ' WHERE product_shop.`visibility` IN ("both", "catalog")' : '') . '
			GROUP BY p.`id_product`';
        $finalResults = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
        $finalResults = AgileSellerManager::prepareSellerRattingInfo($finalResults);
        return $finalResults;
    }
Пример #6
0
    public static function getPricesDrop($id_lang, $page_number = 0, $nb_products = 10, $count = false, $order_by = null, $order_way = null, $beginning = false, $ending = false, Context $context = null)
    {
        if (!Validate::isBool($count)) {
            die(Tools::displayError());
        }
        if (!$context) {
            $context = Context::getContext();
        }
        $agile_sql_parts = AgileSellerManager::getAdditionalSqlForProducts("p", true);
        if (Module::isInstalled('agilesellerlistoptions') && empty($orderby)) {
            $orderby = 'position2';
        }
        if (empty($agile_sql_parts['joins']) or empty($agile_sql_parts['wheres'])) {
            parent::getPricesDrop($id_lang, $page_number, $nb_products, $count, $order_by, $order_way, $beginning, $ending, $context);
        }
        if ($page_number < 0) {
            $page_number = 0;
        }
        if ($nb_products < 1) {
            $nb_products = 10;
        }
        if (empty($order_by) || $order_by == 'position') {
            $order_by = 'price';
        }
        if (empty($order_way)) {
            $order_way = 'DESC';
        }
        if ($order_by == 'id_product' || $order_by == 'price' || $order_by == 'date_add' || $order_by == 'date_upd') {
            $order_by_prefix = 'p';
        } else {
            if ($order_by == 'name') {
                $order_by_prefix = 'pl';
            }
        }
        if (!Validate::isOrderBy($order_by) || !Validate::isOrderWay($order_way)) {
            die(Tools::displayError());
        }
        $current_date = date('Y-m-d H:i:s');
        $ids_product = Product::_getProductIdByDate(!$beginning ? $current_date : $beginning, !$ending ? $current_date : $ending, $context);
        $tab_id_product = array();
        foreach ($ids_product as $product) {
            if (is_array($product)) {
                $tab_id_product[] = (int) $product['id_product'];
            } else {
                $tab_id_product[] = (int) $product;
            }
        }
        $front = true;
        if (!in_array($context->controller->controller_type, array('front', 'modulefront'))) {
            $front = false;
        }
        $groups = FrontController::getCurrentCustomerGroups();
        $sql_groups = count($groups) ? 'IN (' . implode(',', $groups) . ')' : '= 1';
        if ($count) {
            $sql = 'SELECT COUNT(DISTINCT p.`id_product`) AS nb
					FROM `' . _DB_PREFIX_ . 'product` p
					' . $agile_sql_parts['joins'] . '
					' . Shop::addSqlAssociation('product', 'p') . '
					WHERE product_shop.`active` = 1
						AND product_shop.`show_price` = 1
						' . $agile_sql_parts['wheres'] . '
						' . ($front ? ' AND product_shop.`visibility` IN ("both", "catalog")' : '') . '
						' . (!$beginning && !$ending ? 'AND p.`id_product` IN(' . (is_array($tab_id_product) && count($tab_id_product) ? implode(', ', $tab_id_product) : 0) . ')' : '') . '
						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 . '
						)';
            $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql);
            return (int) $result['nb'];
        }
        if (strpos($order_by, '.') > 0) {
            $order_by = explode('.', $order_by);
            $order_by = pSQL($order_by[0]) . '.`' . pSQL($order_by[1]) . '`';
        }
        $sql = 'SELECT p.*, product_shop.*, stock.out_of_stock, IFNULL(stock.quantity, 0) as quantity, pl.`description`, pl.`description_short`, MAX(product_attribute_shop.id_product_attribute) id_product_attribute,
					pl.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`,
					pl.`name`, MAX(image_shop.`id_image`) id_image, il.`legend`, m.`name` AS manufacturer_name,
					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 AS new
				' . $agile_sql_parts['selects'] . '
				FROM `' . _DB_PREFIX_ . 'product` p
				' . Shop::addSqlAssociation('product', 'p') . '
				' . $agile_sql_parts['joins'] . '
				LEFT JOIN ' . _DB_PREFIX_ . 'product_attribute pa ON (pa.id_product = p.id_product)
				' . Shop::addSqlAssociation('product_attribute', 'pa', false, 'product_attribute_shop.default_on=1') . '
				' . Product::sqlStock('p', 0, false, $context->shop) . '
				LEFT JOIN `' . _DB_PREFIX_ . 'product_lang` pl ON (
					p.`id_product` = pl.`id_product`
					AND pl.`id_lang` = ' . (int) $id_lang . Shop::addSqlRestrictionOnLang('pl') . '
				)
				LEFT JOIN `' . _DB_PREFIX_ . 'image` i ON (i.`id_product` = p.`id_product`)' . Shop::addSqlAssociation('image', 'i', false, 'image_shop.cover=1') . '
				LEFT JOIN `' . _DB_PREFIX_ . 'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = ' . (int) $id_lang . ')
				LEFT JOIN `' . _DB_PREFIX_ . 'manufacturer` m ON (m.`id_manufacturer` = p.`id_manufacturer`)
				WHERE product_shop.`active` = 1
				AND product_shop.`show_price` = 1
				' . $agile_sql_parts['wheres'] . '
				' . ($front ? ' AND p.`visibility` IN ("both", "catalog")' : '') . '
				' . (!$beginning && !$ending ? ' AND p.`id_product` IN (' . (is_array($tab_id_product) && count($tab_id_product) ? implode(', ', $tab_id_product) : 0) . ')' : '') . '
				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 . '
				)
				GROUP BY product_shop.id_product
				ORDER BY ' . (isset($order_by_prefix) ? pSQL($order_by_prefix) . '.' : '') . pSQL($order_by) . ' ' . pSQL($order_way) . '
				LIMIT ' . (int) ($page_number * $nb_products) . ', ' . (int) $nb_products;
        $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
        if ($order_by == 'price') {
            Tools::orderbyPrice($result, $order_way);
        }
        if (!$result) {
            return false;
        }
        $finalResults = Product::getProductsProperties($id_lang, $result);
        $finalResults = AgileSellerManager::prepareSellerRattingInfo($finalResults);
        return $finalResults;
    }
Пример #7
0
 public static function getBestSalesLight($id_lang, $page_number = 0, $nb_products = 10, Context $context = null)
 {
     $agile_sql_parts = AgileSellerManager::getAdditionalSqlForProducts("p", true);
     if (!$context) {
         $context = Context::getContext();
     }
     if ($page_number < 0) {
         $page_number = 0;
     }
     if ($nb_products < 1) {
         $nb_products = 10;
     }
     $groups = FrontController::getCurrentCustomerGroups();
     $sql_groups = count($groups) ? 'IN (' . implode(',', $groups) . ')' : '= 1';
     $sql = 'SELECT p.id_product, pl.`link_rewrite`, pl.`name`, pl.`description_short`, MAX(image_shop.`id_image`) id_image, il.`legend`,
                                     stock.out_of_stock,
                                     MAX(product_attribute_shop.id_product_attribute) id_product_attribute,
                                     p.available_for_order,
                                     p.customizable,
                                     product_shop.id_category_default,
                                     IFNULL(pa.minimal_quantity, p.minimal_quantity) as minimal_quantity,
                                     ps.`quantity` AS sales, p.`ean13`, p.`upc`, cl.`link_rewrite` AS category
                                     ' . $agile_sql_parts['selects'] . '
                             FROM `' . _DB_PREFIX_ . 'product_sale` ps
                             LEFT JOIN `' . _DB_PREFIX_ . 'product` p ON ps.`id_product` = p.`id_product`
                             ' . $agile_sql_parts['joins'] . '
                             ' . Shop::addSqlAssociation('product', 'p') . '
                            
                             LEFT JOIN `' . _DB_PREFIX_ . 'product_attribute` pa
                                     ON (p.`id_product` = pa.`id_product`)
                             ' . Shop::addSqlAssociation('product_attribute', 'pa', false, 'product_attribute_shop.`default_on` = 1') . '
                             ' . Product::sqlStock('p', 'product_attribute_shop', false, $context->shop) . '
                            
                             LEFT JOIN `' . _DB_PREFIX_ . 'product_lang` pl
                                     ON p.`id_product` = pl.`id_product`
                                     AND pl.`id_lang` = ' . (int) $id_lang . Shop::addSqlRestrictionOnLang('pl') . '
                             LEFT JOIN `' . _DB_PREFIX_ . 'image` i ON (i.`id_product` = p.`id_product`)' . Shop::addSqlAssociation('image', 'i', false, 'image_shop.cover=1') . '
                             LEFT JOIN `' . _DB_PREFIX_ . 'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = ' . (int) $id_lang . ')
                             LEFT JOIN `' . _DB_PREFIX_ . 'category_lang` cl
                                     ON cl.`id_category` = product_shop.`id_category_default`
                                     AND cl.`id_lang` = ' . (int) $id_lang . Shop::addSqlRestrictionOnLang('cl') . '
                             WHERE product_shop.`active` = 1
                                     ' . $agile_sql_parts['wheres'] . '
                                     AND p.`visibility` != \'none\'
                                     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 . '
                                     )
                             GROUP BY product_shop.id_product
                             ORDER BY sales DESC
                             LIMIT ' . (int) ($page_number * $nb_products) . ', ' . (int) $nb_products;
     if (!($result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql))) {
         return false;
     }
     $result = Product::getProductsProperties($id_lang, $result);
     foreach ($result as &$row) {
         $row['link'] = $context->link->getProductLink($row['id_product'], $row['link_rewrite'], $row['category'], $row['ean13']);
         $row['id_image'] = Product::defineProductImage($row, $id_lang);
     }
     $result = AgileSellerManager::prepareSellerRattingInfo($result);
     return $result;
 }