本文整理汇总了PHP中Validate::isOrderWay方法的典型用法代码示例。如果您正苦于以下问题:PHP Validate::isOrderWay方法的具体用法?PHP Validate::isOrderWay怎么用?PHP Validate::isOrderWay使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Validate
的用法示例。
在下文中一共展示了Validate::isOrderWay方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getGlossaries
/**
* Get all available glossaries
*
* @param integer $id_lang Language id
* @param array $criteria Criterias for where clause
* @param integer $start Start number
* @param integer $limit Number of glossaries to return
* @param string $order_by Field for ordering
* @param string $order_way Way for ordering (ASC or DESC)
* @param boolean $only_active Returns only active glossaries if TRUE
* @param Context|null $context
*
* @return array list of glossaries
*/
public static function getGlossaries($id_lang, $criteria = array(), $start = null, $limit = null, $order_by = null, $order_way = null, $only_active = false, Context $context = null)
{
$where = '';
if (!$context) {
$context = Context::getContext();
}
if ($order_by !== null) {
if (!Validate::isOrderBy($order_by) || !Validate::isOrderWay($order_way)) {
die(Tools::displayError());
}
if ($order_by == 'id') {
$order_by_prefix = 'l';
} else {
$order_by_prefix = 'll';
}
if (strpos($order_by, '.') > 0) {
$order_by = explode('.', $order_by);
$order_by_prefix = $order_by[0];
$order_by = $order_by[1];
}
}
if (isset($criteria['k'])) {
$where .= " AND ll.name LIKE '" . pSQL($criteria['k']) . "%' ";
}
$sql = 'SELECT l.*, ll.*
FROM `' . _DB_PREFIX_ . 'lexikotron` l
LEFT JOIN `' . _DB_PREFIX_ . 'lexikotron_lang` ll ON (l.`id_lexikotron` = ll.`id_lexikotron`)
WHERE ll.`id_lang` = ' . (int) $id_lang . ($only_active ? ' AND l.`active` = 1' : '') . '
' . $where . '
' . ($order_by != null ? 'ORDER BY ' . (isset($order_by_prefix) ? pSQL($order_by_prefix) . '.' : '') . '`' . pSQL($order_by) . '` ' . pSQL($order_way) : '') . ($limit > 0 ? ' LIMIT ' . (int) $start . ',' . (int) $limit : '');
$rows = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
return $rows;
}
示例2: getList
public function getList($order_by, $order_way, $filter, $start, $pagination)
{
$order_way = Validate::isOrderWay($order_way) ? $order_way : 'ASC';
$id_shop = (int) Context::getContext()->shop->id;
$id_lang = (int) Context::getContext()->language->id;
$list = DB::getInstance()->executeS('
SELECT
p.`id_order` AS `id_order`,
par.`waybill` AS `id_parcel`,
CONCAT(a.`firstname`, " ", a.`lastname`) AS `receiver`,
cl.`name` AS `country`,
a.`postcode` AS `postcode`,
a.`city` AS `city`,
a.`address1` AS `address`,
p.`date_add` AS `date_add`
FROM `' . _DB_PREFIX_ . _DPDPOLAND_PARCEL_DB_ . '` par
LEFT JOIN `' . _DB_PREFIX_ . _DPDPOLAND_PACKAGE_DB_ . '` p ON (p.`id_package_ws` = par.`id_package_ws`)
LEFT JOIN `' . _DB_PREFIX_ . 'orders` o ON (o.`id_order` = p.`id_order`)
LEFT JOIN `' . _DB_PREFIX_ . 'address` a ON (a.`id_address` = p.`id_address_delivery`)
LEFT JOIN `' . _DB_PREFIX_ . 'country_lang` cl ON (cl.`id_country` = a.`id_country` AND cl.`id_lang` = "' . (int) $id_lang . '")' . (version_compare(_PS_VERSION_, '1.5', '<') ? ' ' : 'WHERE o.`id_shop` = "' . (int) $id_shop . '" ') . $filter . ($order_by && $order_way ? ' ORDER BY `' . bqSQL($order_by) . '` ' . pSQL($order_way) : '') . ($start !== null && $pagination !== null ? ' LIMIT ' . (int) $start . ', ' . (int) $pagination : ''));
if (!$list) {
$list = array();
}
return $list;
}
示例3: __construct
public function __construct()
{
global $cookie;
$this->table = 'message';
$this->className = 'Message';
$this->view = 'noActionColumn';
$this->delete = true;
$this->colorOnBackground = true;
$start = 0;
$this->_defaultOrderBy = 'date_add';
/* Manage default params values */
if (empty($limit)) {
$limit = !isset($cookie->{$this->table . '_pagination'}) ? $this->_pagination[0] : ($limit = $cookie->{$this->table . '_pagination'});
}
if (!Validate::isTableOrIdentifier($this->table)) {
die(Tools::displayError('Table name is invalid:') . ' "' . $this->table . '"');
}
if (empty($orderBy)) {
$orderBy = Tools::getValue($this->table . 'Orderby', $this->_defaultOrderBy);
} elseif ($orderBy == 'id_order') {
$orderBy = 'm.id_order';
}
if (empty($orderWay)) {
$orderWay = Tools::getValue($this->table . 'Orderway', 'ASC');
}
$limit = (int) Tools::getValue('pagination', $limit);
$cookie->{$this->table . '_pagination'} = $limit;
/* Check params validity */
if (!Validate::isOrderBy($orderBy) or !Validate::isOrderWay($orderWay) or !is_numeric($start) or !is_numeric($limit)) {
die(Tools::displayError('get list params is not valid'));
}
if ($orderBy == 'id_order') {
$orderBy = 'm.id_order';
}
/* Determine offset from current page */
if ((isset($_POST['submitFilter' . $this->table]) or isset($_POST['submitFilter' . $this->table . '_x']) or isset($_POST['submitFilter' . $this->table . '_y'])) and !empty($_POST['submitFilter' . $this->table]) and is_numeric($_POST['submitFilter' . $this->table])) {
$start = (int) ($_POST['submitFilter' . $this->table] - 1) * $limit;
}
$sql = 'SELECT SQL_CALC_FOUND_ROWS m.id_message, m.id_cart, m.id_employee, IF(m.id_order > 0, m.id_order, \'--\') id_order, m.message, m.private, m.date_add, CONCAT(LEFT(c.`firstname`, 1), \'. \', c.`lastname`) AS customer,
c.id_customer, count(m.id_message) nb_messages, (SELECT message FROM ' . _DB_PREFIX_ . 'message WHERE id_order = m.id_order ORDER BY date_add DESC LIMIT 1) last_message,
(SELECT COUNT(m2.id_message) FROM ' . _DB_PREFIX_ . 'message m2 WHERE 1 AND m2.id_customer != 0 AND m2.id_order = m.id_order AND m2.id_message NOT IN
(SELECT mr2.id_message FROM ' . _DB_PREFIX_ . 'message_readed mr2 WHERE mr2.id_employee = ' . (int) $cookie->id_employee . ') GROUP BY m2.id_order) nb_messages_not_read_by_me
FROM ' . _DB_PREFIX_ . 'message m
LEFT JOIN ' . _DB_PREFIX_ . 'orders o ON (o.id_order = m.id_order)
LEFT JOIN ' . _DB_PREFIX_ . 'customer c ON (c.id_customer = m.id_customer)
GROUP BY m.id_order
ORDER BY ' . (isset($orderBy) ? pSQL($orderBy) : 'date_add') . ' ' . (isset($orderWay) ? pSQL($orderWay) : 'DESC') . '
LIMIT ' . (int) $start . ',' . (int) $limit;
$this->_list = Db::getInstance()->ExecuteS($sql);
$this->_listTotal = Db::getInstance()->getValue('SELECT FOUND_ROWS() AS `' . md5($sql) . '`');
$this->fieldsDisplay = array('id_order' => array('title' => $this->l('Order ID'), 'align' => 'center', 'width' => 30), 'id_customer' => array('title' => $this->l('Customer ID'), 'align' => 'center', 'width' => 30), 'customer' => array('title' => $this->l('Customer'), 'width' => 100, 'filter_key' => 'customer', 'tmpTableFilter' => true), 'last_message' => array('title' => $this->l('Last message'), 'width' => 400, 'orderby' => false), 'nb_messages_not_read_by_me' => array('title' => $this->l('Unread message(s)'), 'width' => 30, 'align' => 'center'), 'nb_messages' => array('title' => $this->l('Number of messages'), 'width' => 30, 'align' => 'center'));
parent::__construct();
}
示例4: getNewProducts
public function getNewProducts($id_lang, $nbProducts = 4, $orderBy = NULL, $orderWay = NULL, $random = true, $randomNumberProducts = 4)
{
global $cookie;
if (empty($orderBy) || $orderBy == 'position') {
$orderBy = 'date_add';
}
if (empty($orderWay)) {
$orderWay = 'DESC';
}
if ($orderBy == 'id_product' || $orderBy == 'price' || $orderBy == 'date_add') {
$orderByPrefix = 'p';
} elseif ($orderBy == 'name') {
$orderByPrefix = 'pl';
}
if (!Validate::isOrderBy($orderBy) || !Validate::isOrderWay($orderWay)) {
die(Tools::displayError());
}
$sql = '
SELECT p.*, pl.`description`, pl.`description_short`, pl.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`, pl.`name`, p.`ean13`,
i.`id_image`, il.`legend`, t.`rate`, 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,
(p.`price` * ((100 + (t.`rate`))/100) - IF((DATEDIFF(`reduction_from`, CURDATE()) <= 0 AND DATEDIFF(`reduction_to`, CURDATE()) >=0) OR `reduction_from` = `reduction_to`, IF(`reduction_price` > 0, `reduction_price`, (p.`price` * ((100 + (t.`rate`))/100) * `reduction_percent` / 100)),0)) AS orderprice
FROM `' . _DB_PREFIX_ . 'product` p
LEFT JOIN `' . _DB_PREFIX_ . 'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = ' . intval($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` = ' . intval($id_lang) . ')
LEFT JOIN `' . _DB_PREFIX_ . 'tax` t ON (t.`id_tax` = p.`id_tax`)
LEFT JOIN `' . _DB_PREFIX_ . 'manufacturer` m ON (m.`id_manufacturer` = p.`id_manufacturer`)
WHERE p.`active` = 1
AND 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)
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` ' . (!$cookie->id_customer ? '= 1' : 'IN (SELECT id_group FROM ' . _DB_PREFIX_ . 'customer_group WHERE id_customer = ' . intval($cookie->id_customer) . ')') . '
)';
if ($random === true) {
$sql .= ' ORDER BY RAND()';
$sql .= ' LIMIT 0, ' . intval($randomNumberProducts);
} else {
$sql .= ' ORDER BY ' . (isset($orderByPrefix) ? $orderByPrefix . '.' : '') . '`' . pSQL($orderBy) . '` ' . pSQL($orderWay) . '
LIMIT 0, ' . intval($nbProducts);
}
$result = Db::getInstance()->ExecuteS($sql);
if ($orderBy == 'price') {
Tools::orderbyPrice($result, $orderWay);
}
if (!$result) {
return false;
}
return Product::getProductsProperties(intval($id_lang), $result);
}
示例5: getList
public function getList($order_by, $order_way, $filter, $start, $pagination)
{
$order_way = Validate::isOrderWay($order_way) ? $order_way : 'ASC';
return Db::getInstance()->executeS('
SELECT m.`id_manifest_ws` AS `id_manifest_ws`,
COUNT(p.`id_parcel`) AS `count_parcels`,
COUNT(DISTINCT m.`id_package_ws`) AS `count_orders`,
m.`date_add` AS `date_add`
FROM `' . _DB_PREFIX_ . _DPDPOLAND_MANIFEST_DB_ . '` m
LEFT JOIN `' . _DB_PREFIX_ . _DPDPOLAND_PARCEL_DB_ . '` p ON (p.`id_package_ws` = m.`id_package_ws`)
GROUP BY `id_manifest_ws`
' . $filter . '
ORDER BY `' . bqSQL($order_by) . '` ' . pSQL($order_way) . ($start !== null && $pagination !== null ? ' LIMIT ' . (int) $start . ', ' . (int) $pagination : ''));
}
示例6: getProducts
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 . ')
//.........这里部分代码省略.........
示例7: getProducts
protected function getProducts($id_lang, $p, $n, $orderBy = NULL, $orderWay = NULL, $getTotal = false, $active = true, $random = false, $randomNumberProducts = 1)
{
global $cookie, $smarty;
$id_seller_country = (int) Tools::getValue('id_seller_country');
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());
}
$requiredcond = '';
if (intval(Configuration::get('AGILE_MS_PRODUCT_APPROVAL')) == 1) {
$requiredcond = ' AND po.approved = 1 ';
}
$joins = '';
$wheres = '';
if (Module::isInstalled('agilesellerlistoptions')) {
require_once _PS_ROOT_DIR_ . "/modules/agilesellerlistoptions/agilesellerlistoptions.php";
$joins = $joins . '
LEFT JOIN `' . _DB_PREFIX_ . 'seller_listoption` slb ON (p.id_product = slb.id_product AND slb.id_option = ' . AgileSellerListOptions::ASLO_OPTION_LIST . ')
';
$aslo_list_prod_id = intval(Configuration::get('ASLO_PROD_FOR_OPTION' . AgileSellerListOptions::ASLO_OPTION_LIST));
$wheres = $wheres . '
AND (slb.status = ' . AgileSellerListOptions::ASLO_STATUS_IN_EFFECT . ' OR IFNULL(po.id_owner,0) = 0 OR ' . $aslo_list_prod_id . '=' . AgileSellerListOptions::ASLO_ALWAYS_FREE . ')
';
}
$location_conditions = '';
switch ($this->location_level) {
case 'country':
if ((int) $this->id_location > 0) {
$location_conditions = ' AND si.id_country=' . (int) $this->id_location;
}
break;
case 'state':
if ((int) $this->id_location > 0) {
$location_conditions = ' AND si.id_state=' . (int) $this->id_location;
}
break;
case 'city':
if (!empty($this->id_location)) {
$location_conditions = ' AND sil.city=\'' . $this->id_location . '\'';
}
break;
case 'sellertype':
if (!empty($this->id_location)) {
$location_conditions = ' AND si.id_sellertype1=' . $this->id_location;
}
break;
case 'custom':
if (!empty($this->id_location)) {
if (AgileMultipleShop::SHOP_BY_CUSTOM_LANG) {
$location_conditions = ' AND sil.' . AgileMultipleShop::SHOP_BY_CUSTOM_FIELD . '=\'' . $this->id_location . '\'';
} else {
$location_conditions = ' AND si.' . AgileMultipleShop::SHOP_BY_CUSTOM_FIELD . '=\'' . $this->id_location . '\'';
}
}
break;
}
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`
LEFT JOIN `' . _DB_PREFIX_ . 'sellerinfo` si ON si.`id_seller` = po.`id_owner`
LEFT JOIN `' . _DB_PREFIX_ . 'sellerinfo_lang` sil ON si.`id_sellerinfo` = sil.`id_sellerinfo` AND sil.id_lang = ' . $cookie->id_lang . '
' . $joins . '
WHERE p.active=1
' . $location_conditions . '
' . ($active ? ' AND p.`active` = 1' : '') . '
' . $requiredcond . '
' . $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, si.`id_seller`
//.........这里部分代码省略.........
示例8: find
public static function find($id_lang, $expr, $pageNumber = 1, $pageSize = 1, $orderBy = 'position', $orderWay = 'desc', $ajax = false, $useCookie = true)
{
global $cookie;
$db = Db::getInstance(_PS_USE_SQL_SLAVE_);
// Only use cookie if id_customer is not present
if ($useCookie) {
$id_customer = (int) $cookie->id_customer;
} else {
$id_customer = 0;
}
// TODO : smart page management
if ($pageNumber < 1) {
$pageNumber = 1;
}
if ($pageSize < 1) {
$pageSize = 1;
}
if (!Validate::isOrderBy($orderBy) or !Validate::isOrderWay($orderWay)) {
return false;
}
$intersectArray = array();
$scoreArray = array();
$words = explode(' ', Search::sanitize($expr, (int) $id_lang));
foreach ($words as $key => $word) {
if (!empty($word) and strlen($word) >= (int) Configuration::get('PS_SEARCH_MINWORDLEN')) {
$word = str_replace('%', '\\%', $word);
$word = str_replace('_', '\\_', $word);
$intersectArray[] = 'SELECT id_product
FROM ' . _DB_PREFIX_ . 'search_word sw
LEFT JOIN ' . _DB_PREFIX_ . 'search_index si ON sw.id_word = si.id_word
WHERE sw.id_lang = ' . (int) $id_lang . '
AND sw.word LIKE
' . ($word[0] == '-' ? ' \'' . pSQL(Tools::substr($word, 1, PS_SEARCH_MAX_WORD_LENGTH)) . '%\'' : '\'' . pSQL(Tools::substr($word, 0, PS_SEARCH_MAX_WORD_LENGTH)) . '%\'');
if ($word[0] != '-') {
$scoreArray[] = 'sw.word LIKE \'' . pSQL(Tools::substr($word, 0, PS_SEARCH_MAX_WORD_LENGTH)) . '%\'';
}
} else {
unset($words[$key]);
}
}
if (!sizeof($words)) {
return $ajax ? array() : array('total' => 0, 'result' => array());
}
$score = '';
if (sizeof($scoreArray)) {
$score = ',(
SELECT SUM(weight)
FROM ' . _DB_PREFIX_ . 'search_word sw
LEFT JOIN ' . _DB_PREFIX_ . 'search_index si ON sw.id_word = si.id_word
WHERE sw.id_lang = ' . (int) $id_lang . '
AND si.id_product = p.id_product
AND (' . implode(' OR ', $scoreArray) . ')
) position';
}
$result = $db->ExecuteS('
SELECT cp.`id_product`
FROM `' . _DB_PREFIX_ . 'category_group` cg
INNER JOIN `' . _DB_PREFIX_ . 'category_product` cp ON cp.`id_category` = cg.`id_category`
INNER JOIN `' . _DB_PREFIX_ . 'category` c ON cp.`id_category` = c.`id_category`
INNER JOIN `' . _DB_PREFIX_ . 'product` p ON cp.`id_product` = p.`id_product`
WHERE c.`active` = 1 AND p.`active` = 1 AND indexed = 1
AND cg.`id_group` ' . (!$id_customer ? '= 1' : 'IN (
SELECT id_group FROM ' . _DB_PREFIX_ . 'customer_group
WHERE id_customer = ' . (int) $id_customer . '
)'), false);
$eligibleProducts = array();
$eligibleProductsSS = array();
$productsSuperSet = array();
while ($row = $db->nextRow($result)) {
$eligibleProducts[] = $row['id_product'];
$eligibleProductsSS[] = $row['id_product'];
}
foreach ($intersectArray as $query) {
$result = $db->ExecuteS($query, false);
$eligibleProducts2 = array();
while ($row = $db->nextRow($result)) {
$eligibleProducts2[] = $row['id_product'];
$productsSuperSet[] = $row['id_product'];
}
$eligibleProducts = array_intersect($eligibleProducts, $eligibleProducts2);
//if (!count($eligibleProducts))
//return ($ajax ? array() : array('total' => 0, 'result' => array()));
}
$ssResults = 0;
//replace eligible products with superset if OR query or zero results found
if (Tools::getValue('ss') || sizeof($eligibleProducts) == 0) {
$eligibleProducts = array_intersect($eligibleProductsSS, $productsSuperSet);
$ssResults = 1;
}
array_unique($eligibleProducts);
$productPool = '';
foreach ($eligibleProducts as $id_product) {
if ($id_product) {
$productPool .= (int) $id_product . ',';
}
}
if (empty($productPool)) {
return $ajax ? array() : array('total' => 0, 'result' => array());
}
$productPool = strpos($productPool, ',') === false ? ' = ' . (int) $productPool . ' ' : ' IN (' . rtrim($productPool, ',') . ') ';
//.........这里部分代码省略.........
示例9: find
public static function find($id_lang, $expr, $pageNumber = 1, $pageSize = 1, $orderBy = 'position', $orderWay = 'desc', $ajax = false)
{
global $cookie;
// TODO : smart page management
if ($pageNumber < 1) {
$pageNumber = 1;
}
if ($pageSize < 1) {
$pageSize = 1;
}
if (!Validate::isOrderBy($orderBy) or !Validate::isOrderWay($orderWay)) {
die(Tools::displayError());
}
$whereArray = array();
$scoreArray = array();
$words = explode(' ', Search::sanitize($expr, $id_lang));
foreach ($words as $key => $word) {
if (!empty($word)) {
$word = str_replace('%', '\\%', $word);
$word = str_replace('_', '\\_', $word);
$whereArray[] = ' p.id_product ' . ($word[0] == '-' ? 'NOT' : '') . ' IN (
SELECT id_product
FROM ' . _DB_PREFIX_ . 'search_word sw
LEFT JOIN ' . _DB_PREFIX_ . 'search_index si ON sw.id_word = si.id_word
WHERE sw.id_lang = ' . intval($id_lang) . '
AND sw.word LIKE ' . ($word[0] == '-' ? ' \'' . pSQL(substr($word, 1, PS_SEARCH_MAX_WORD_LENGTH)) . '%\'' : '\'' . pSQL(substr($word, 0, PS_SEARCH_MAX_WORD_LENGTH)) . '%\'') . '
) ';
if ($word[0] != '-') {
$scoreArray[] = 'sw.word LIKE \'' . pSQL(substr($word, 0, PS_SEARCH_MAX_WORD_LENGTH)) . '%\'';
}
} else {
unset($words[$key]);
}
}
if (!sizeof($words)) {
return $ajax ? array() : array('total' => 0, 'result' => array());
}
$score = '';
if (sizeof($scoreArray)) {
$score = ',(
SELECT SUM(weight)
FROM ' . _DB_PREFIX_ . 'search_word sw
LEFT JOIN ' . _DB_PREFIX_ . 'search_index si ON sw.id_word = si.id_word
WHERE sw.id_lang = ' . intval($id_lang) . '
AND si.id_product = p.id_product
AND (' . implode(' OR ', $scoreArray) . ')
) as position';
}
if ($ajax) {
$queryResults = '
SELECT p.id_product, pl.name as pname, IF(cl.name REGEXP "^[0-9]{2}\\.", SUBSTRING(cl.name, 4), cl.name) as cname ' . $score . ', cl.link_rewrite as crewrite, pl.link_rewrite as prewrite
FROM ' . _DB_PREFIX_ . 'product p
LEFT JOIN `' . _DB_PREFIX_ . 'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = ' . intval($id_lang) . ')
LEFT JOIN `' . _DB_PREFIX_ . 'category_lang` cl ON (p.`id_category_default` = cl.`id_category` AND cl.`id_lang` = ' . intval($id_lang) . ')
WHERE ' . implode(' AND ', $whereArray) . '
AND p.active = 1
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` ' . (!$cookie->id_customer ? '= 1' : 'IN (SELECT id_group FROM ' . _DB_PREFIX_ . 'customer_group WHERE id_customer = ' . intval($cookie->id_customer) . ')') . '
)
ORDER BY position DESC
LIMIT 10';
return Db::getInstance()->ExecuteS($queryResults);
}
$queryResults = '
SELECT SQL_CALC_FOUND_ROWS p.*, pl.`description_short`, pl.`available_now`, pl.`available_later`, pl.`link_rewrite`, pl.`name`,
t.`rate`, i.`id_image`, il.`legend`, m.`name` AS manufacturer_name
' . $score . '
FROM ' . _DB_PREFIX_ . 'product p
LEFT JOIN `' . _DB_PREFIX_ . 'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = ' . intval($id_lang) . ')
LEFT OUTER 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` = ' . intval($id_lang) . ')
LEFT JOIN `' . _DB_PREFIX_ . 'tax` t ON (p.`id_tax` = t.`id_tax`)
LEFT JOIN `' . _DB_PREFIX_ . 'manufacturer` m ON (m.`id_manufacturer` = p.`id_manufacturer`)
WHERE ' . implode(' AND ', $whereArray) . '
AND p.active = 1
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` ' . (!$cookie->id_customer ? '= 1' : 'IN (SELECT id_group FROM ' . _DB_PREFIX_ . 'customer_group WHERE id_customer = ' . intval($cookie->id_customer) . ')') . '
)
' . ($orderBy ? 'ORDER BY ' . $orderBy : '') . ($orderWay ? ' ' . $orderWay : '') . '
LIMIT ' . intval(($pageNumber - 1) * $pageSize) . ',' . intval($pageSize);
$result = Db::getInstance()->ExecuteS($queryResults);
$total = Db::getInstance()->getValue('SELECT FOUND_ROWS()');
Module::hookExec('search', array('expr' => $expr, 'total' => $total));
return array('total' => $total, 'result' => Product::getProductsProperties($id_lang, $result));
}
示例10: getProducts
/**
* Return current category products
*
* @param integer $id_lang Language ID
* @param integer $p Page number
* @param integer $n Number of products per page
* @param boolean $getTotal return the number of results instead of the results themself
* @param boolean $active return only active products
* @param boolean $random active a random filter for returned products
* @param int $randomNumberProducts number of products to return if random is activated
* @return mixed Products or number of products
*/
public function getProducts($id_lang, $p, $n, $orderBy = NULL, $orderWay = NULL, $getTotal = false, $active = true, $random = false, $randomNumberProducts = 1)
{
global $cookie;
if ($p < 1) {
$p = 1;
}
if (empty($orderBy)) {
$orderBy = 'position';
}
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';
} 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 = intval(Tools::getValue('id_supplier'));
/* Return only the number of products */
if ($getTotal) {
$result = Db::getInstance()->getRow('
SELECT COUNT(cp.`id_product`) AS total
FROM `' . _DB_PREFIX_ . 'product` p
LEFT JOIN `' . _DB_PREFIX_ . 'category_product` cp ON p.`id_product` = cp.`id_product`
WHERE cp.`id_category` = ' . intval($this->id) . ($active ? ' AND p.`active` = 1' : '') . '
' . ($id_supplier ? 'AND p.id_supplier = ' . $id_supplier : '') . '');
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((DATEDIFF(reduction_from, CURDATE()) <= 0 AND DATEDIFF(reduction_to, CURDATE()) >=0) OR reduction_from = reduction_to, IFNULL(reduction_price, (p.price * reduction_percent / 100)),0)) AS orderprice
FROM `' . _DB_PREFIX_ . 'category_product` cp
LEFT JOIN `' . _DB_PREFIX_ . 'product` p ON p.`id_product` = cp.`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` = ' . intval($id_lang) . ')
LEFT JOIN `' . _DB_PREFIX_ . 'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = ' . intval($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` = ' . intval($id_lang) . ')
LEFT JOIN `' . _DB_PREFIX_ . 'tax` t ON t.`id_tax` = p.`id_tax`
LEFT JOIN `' . _DB_PREFIX_ . 'tax_lang` tl ON (t.`id_tax` = tl.`id_tax` AND tl.`id_lang` = ' . intval($id_lang) . ')
LEFT JOIN `' . _DB_PREFIX_ . 'manufacturer` m ON m.`id_manufacturer` = p.`id_manufacturer`
WHERE cp.`id_category` = ' . intval($this->id) . ($active ? ' AND p.`active` = 1' : '') . '
' . ($id_supplier ? 'AND p.id_supplier = ' . $id_supplier : '');
if ($random === true) {
$sql .= 'ORDER BY RAND()';
$sql .= 'LIMIT 0, ' . intval($randomNumberProducts);
} else {
$sql .= 'ORDER BY ' . (isset($orderByPrefix) ? $orderByPrefix . '.' : '') . '`' . pSQL($orderBy) . '` ' . pSQL($orderWay) . '
LIMIT ' . (intval($p) - 1) * intval($n) . ',' . intval($n);
}
$result = Db::getInstance()->ExecuteS($sql);
if ($orderBy == 'orderprice') {
Tools::orderbyPrice($result, $orderWay);
}
if (!$result) {
return false;
}
/* Modify SQL result */
return Product::getProductsProperties($id_lang, $result);
}
示例11: getProducts
public static function getProducts($id_manufacturer, $id_lang, $p, $n, $order_by = null, $order_way = null, $get_total = false, $active = true, $active_category = true, Context $context = null)
{
/*
* EU-Legal
* get standard shipping time from database pl.*
*/
if (!$context) {
$context = Context::getContext();
}
$front = true;
if (!in_array($context->controller->controller_type, array('front', 'modulefront'))) {
$front = false;
}
if ($p < 1) {
$p = 1;
}
if (empty($order_by) || $order_by == 'position') {
$order_by = 'name';
}
if (empty($order_way)) {
$order_way = 'ASC';
}
if (!Validate::isOrderBy($order_by) || !Validate::isOrderWay($order_way)) {
die(Tools::displayError());
}
$groups = FrontController::getCurrentCustomerGroups();
$sql_groups = count($groups) ? 'IN (' . implode(',', $groups) . ')' : '= 1';
/* Return only the number of products */
if ($get_total) {
$sql = '
SELECT p.`id_product`
FROM `' . _DB_PREFIX_ . 'product` p
' . Shop::addSqlAssociation('product', 'p') . '
WHERE p.id_manufacturer = ' . (int) $id_manufacturer . ($active ? ' AND product_shop.`active` = 1' : '') . '
' . ($front ? ' AND product_shop.`visibility` IN ("both", "catalog")' : '') . '
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` ' . $sql_groups . '
)';
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
return (int) count($result);
}
if (strpos($order_by, '.') > 0) {
$order_by = explode('.', $order_by);
$order_by = pSQL($order_by[0]) . '.`' . pSQL($order_by[1]) . '`';
}
$alias = '';
if ($order_by == 'price') {
$alias = 'product_shop.';
} elseif ($order_by == 'name') {
$alias = 'pl.';
} elseif ($order_by == 'manufacturer_name') {
$order_by = 'name';
$alias = 'm.';
} elseif ($order_by == 'quantity') {
$alias = 'stock.';
} else {
$alias = 'p.';
}
$sql = 'SELECT p.*, product_shop.*, stock.out_of_stock, IFNULL(stock.quantity, 0) as quantity' . (Combination::isFeatureActive() ? ', MAX(product_attribute_shop.minimal_quantity) AS product_attribute_minimal_quantity' : '') . ', MAX(product_attribute_shop.`id_product_attribute`) id_product_attribute
, pl.`description`, pl.`description_short`, pl.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`,
pl.`meta_title`, pl.`name`, pl.`available_now`, pl.`available_later`, pl.`delivery_now`, pl.`delivery_later`, MAX(image_shop.`id_image`) id_image, il.`legend`, m.`name` AS manufacturer_name,
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' . (Combination::isFeatureActive() ? ',MAX(product_attribute_shop.minimal_quantity) AS product_attribute_minimal_quantity' : '') . ' FROM `' . _DB_PREFIX_ . 'product` p
' . Shop::addSqlAssociation('product', 'p') . (Combination::isFeatureActive() ? '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') : '') . '
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`)
' . Product::sqlStock('p', 0);
if (Group::isFeatureActive() || $active_category) {
$sql .= 'JOIN `' . _DB_PREFIX_ . 'category_product` cp ON (p.id_product = cp.id_product)';
if (Group::isFeatureActive()) {
$sql .= 'JOIN `' . _DB_PREFIX_ . 'category_group` cg ON (cp.`id_category` = cg.`id_category` AND cg.`id_group` ' . $sql_groups . ')';
}
if ($active_category) {
$sql .= 'JOIN `' . _DB_PREFIX_ . 'category` ca ON cp.`id_category` = ca.`id_category` AND ca.`active` = 1';
}
}
$sql .= '
WHERE p.`id_manufacturer` = ' . (int) $id_manufacturer . '
' . ($active ? ' AND product_shop.`active` = 1' : '') . '
' . ($front ? ' AND product_shop.`visibility` IN ("both", "catalog")' : '') . '
GROUP BY product_shop.id_product
ORDER BY ' . $alias . '`' . bqSQL($order_by) . '` ' . pSQL($order_way) . '
LIMIT ' . ((int) $p - 1) * (int) $n . ',' . (int) $n;
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
//.........这里部分代码省略.........
示例12: _getProducts
//.........这里部分代码省略.........
}
$order_by_prefix = false;
$addJoin = '';
$addSelect = '';
if ($order_by == 'id_product' || $order_by == 'date_add' || $order_by == 'date_upd') {
$order_by_prefix = 'p';
} elseif ($order_by == 'name') {
$order_by_prefix = 'pl';
} elseif ($order_by == 'manufacturer' || $order_by == 'manufacturer_name') {
$order_by_prefix = 'm';
$order_by = 'name';
} elseif ($order_by == 'position') {
$order_by_prefix = 'cp';
} elseif ($order_by == 'discount') {
$order_by_prefix = 'sp';
$order_by = 'reduction';
$addJoin = ' LEFT JOIN `' . _DB_PREFIX_ . 'specific_price` sp On p.`id_product` = sp.`id_product` ';
$addSelect = ', sp.reduction, sp.`from`, sp.`to`';
} elseif ($order_by == 'review') {
$order_by_prefix = '';
$order_by = 'total_review';
$addJoin = ' LEFT JOIN `' . _DB_PREFIX_ . 'product_comment` pr ON pr.`id_product` = p.`id_product` ';
$addSelect = ', COUNT(pr.grade) as total_review';
} elseif ($order_by == 'view') {
$order_by_prefix = '';
$order_by = 'total_view';
$addJoin = ' LEFT JOIN ' . _DB_PREFIX_ . 'simplecategory_product_view as pv ON pv.`product_id` = p.`id_product` ';
$addSelect = ', pv.total as total_view';
} elseif ($order_by == 'rate') {
$order_by_prefix = '';
$order_by = 'total_avg';
$addJoin = ' LEFT JOIN `' . _DB_PREFIX_ . 'product_comment` pr ON pr.`id_product` = p.`id_product` ';
$addSelect = ', (SUM(pr.`grade`) / COUNT(pr.`grade`)) AS total_avg';
} elseif ($order_by == 'seller') {
$order_by_prefix = '';
$order_by = 'sales';
$addJoin = ' LEFT JOIN `' . _DB_PREFIX_ . 'product_sale` ps ON ps.`id_product` = p.`id_product` ';
$addSelect = ', ps.`quantity` AS sales';
}
if ($order_by != 'reduction' && $on_discount != 2) {
$addJoin = ' LEFT JOIN `' . _DB_PREFIX_ . 'specific_price` sp On p.`id_product` = sp.`id_product` ';
$addSelect = ', sp.reduction, sp.`from`, sp.`to`';
}
if ($order_by == 'price') {
$order_by = 'orderprice';
}
if (!Validate::isBool($active) || !Validate::isOrderBy($order_by) || !Validate::isOrderWay($order_way)) {
die(Tools::displayError());
}
$id_supplier = (int) Tools::getValue('id_supplier');
if ($get_total) {
$sql = 'SELECT COUNT(cp.`id_product`) AS total
FROM `' . _DB_PREFIX_ . 'product` p
' . Shop::addSqlAssociation('product', 'p') . ' ' . $addJoin . '
LEFT JOIN `' . _DB_PREFIX_ . 'category_product` cp ON p.`id_product` = cp.`id_product`
WHERE cp.`id_category` IN (' . implode(', ', $categoryIds) . ') ' . $where . ($front ? ' AND product_shop.`visibility` IN ("both", "catalog")' : '') . ($active ? ' AND product_shop.`active` = 1' : '') . ($ids_product ? $ids_product : '') . ($id_supplier ? 'AND p.id_supplier = ' . (int) $id_supplier : '');
return (int) Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql);
}
$sql = 'SELECT DISTINCT
p.id_product, MAX(product_attribute_shop.id_product_attribute) id_product_attribute, pl.`link_rewrite`, pl.`name`, pl.`description_short`, product_shop.`id_category_default`,
MAX(image_shop.`id_image`) id_image, il.`legend`, p.`ean13`, p.`upc`, cl.`link_rewrite` AS category, p.show_price, p.available_for_order, IFNULL(stock.quantity, 0) as quantity, p.customizable,
IFNULL(pa.minimal_quantity, p.minimal_quantity) as minimal_quantity, stock.out_of_stock,
product_shop.`date_add` > "' . date('Y-m-d', strtotime('-' . $PS_NB_DAYS_NEW_PRODUCT . ' DAY')) . '" as `new`,
product_shop.`on_sale`, MAX(product_attribute_shop.minimal_quantity) AS product_attribute_minimal_quantity, product_shop.price AS orderprice ' . $addSelect . '
FROM `' . _DB_PREFIX_ . 'category_product` cp
LEFT JOIN `' . _DB_PREFIX_ . 'product` p
ON p.`id_product` = cp.`id_product`
' . Shop::addSqlAssociation('product', 'p') . $addJoin . (Combination::isFeatureActive() ? '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) : Product::sqlStock('p', 'product', false, Context::getContext()->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`
WHERE product_shop.`id_shop` = ' . (int) $context->shop->id . '
AND cp.`id_category` IN (' . implode(', ', $categoryIds) . ') ' . $where . ($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() LIMIT ' . (int) $random_number_products;
} else {
$sql .= ' ORDER BY ' . (!empty($order_by_prefix) ? $order_by_prefix . '.' : '') . '`' . bqSQL($order_by) . '` ' . pSQL($order_way) . ' LIMIT ' . ((int) $p - 1) * (int) $n . ',' . (int) $n;
}
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
if ($order_by == 'orderprice') {
Tools::orderbyPrice($result, $order_way);
}
if (!$result) {
return array();
}
return Product::getProductsProperties($id_lang, $result);
}
示例13: getProducts
protected function getProducts($id_lang, $p, $n, $orderBy = NULL, $orderWay = NULL, $getTotal = false, $active = true, $random = false, $randomNumberProducts = 1)
{
$lgngixep = "orderBy";
${"GLOBALS"}["xbbxtwtpju"] = "orderBy";
${"GLOBALS"}["oswfwomb"] = "orderBy";
global $cookie, $smarty;
${"GLOBALS"}["sxnzkqefjkv"] = "p";
${"GLOBALS"}["kjemucya"] = "id_seller_country";
${"GLOBALS"}["plbenbkqq"] = "orderBy";
$suwenwdcxtu = "orderByPrefix";
${${"GLOBALS"}["kjemucya"]} = (int) Tools::getValue("id_seller_country");
$ljwznznuwp = "n";
${"GLOBALS"}["vwrkkkltgp"] = "orderWay";
${"GLOBALS"}["kgoezfvpcfs"] = "orderBy";
${"GLOBALS"}["iiuykexa"] = "requiredcond";
$eqwznppjxw = "orderWay";
${"GLOBALS"}["juwlrd"] = "orderWay";
$ycvcyogg = "n";
${"GLOBALS"}["ejwtvva"] = "wheres";
${"GLOBALS"}["lkqzhjp"] = "p";
${"GLOBALS"}["vmpjiojlv"] = "orderBy";
${"GLOBALS"}["qksmteq"] = "orderBy";
if (${${"GLOBALS"}["sxnzkqefjkv"]} < 1) {
${${"GLOBALS"}["lkqzhjp"]} = 1;
}
if (${$ycvcyogg} <= 0) {
${$ljwznznuwp} = 10;
}
$yciweepkl = "orderBy";
${"GLOBALS"}["xmtrrpsmnv"] = "wheres";
$hjhvngkubb = "location_conditions";
if (empty(${${"GLOBALS"}["sqkchfbmzgt"]})) {
${${"GLOBALS"}["sqkchfbmzgt"]} = "price";
} else {
${${"GLOBALS"}["vmpjiojlv"]} = strtolower(${${"GLOBALS"}["oswfwomb"]});
}
$qsfzjtrtvb = "result";
if (empty(${$eqwznppjxw})) {
${${"GLOBALS"}["vwrkkkltgp"]} = "ASC";
}
if (${${"GLOBALS"}["xbbxtwtpju"]} == "id_product" or ${$lgngixep} == "date_add") {
${${"GLOBALS"}["holuwdvhswv"]} = "p";
} elseif (${${"GLOBALS"}["kgoezfvpcfs"]} == "name") {
${$suwenwdcxtu} = "pl";
} elseif (${${"GLOBALS"}["sqkchfbmzgt"]} == "manufacturer") {
${"GLOBALS"}["obzythrk"] = "orderByPrefix";
${"GLOBALS"}["ijxsporb"] = "orderBy";
${${"GLOBALS"}["obzythrk"]} = "m";
${${"GLOBALS"}["ijxsporb"]} = "name";
}
if (${$yciweepkl} == "price") {
${${"GLOBALS"}["qksmteq"]} = "orderprice";
}
if (!Validate::isBool(${${"GLOBALS"}["mjjjizv"]}) or !Validate::isOrderBy(${${"GLOBALS"}["plbenbkqq"]}) or !Validate::isOrderWay(${${"GLOBALS"}["juwlrd"]})) {
die(Tools::displayError());
}
${"GLOBALS"}["durjvvw"] = "joins";
${"GLOBALS"}["byhruvgfcplf"] = "orderWay";
${${"GLOBALS"}["ccpfwfk"]} = "";
$kaqgrgykux = "sql";
if (intval(Configuration::get("AGILE_MS_PRODUCT_APPROVAL")) == 1) {
${${"GLOBALS"}["iiuykexa"]} = " AND po.approved = 1 ";
}
${${"GLOBALS"}["durjvvw"]} = "";
${${"GLOBALS"}["xmtrrpsmnv"]} = "";
if (Module::isInstalled("agilesellerlistoptions")) {
require_once _PS_ROOT_DIR_ . "/modules/agilesellerlistoptions/agilesellerlistoptions.php";
${"GLOBALS"}["yyvptwoqtsy"] = "wheres";
${${"GLOBALS"}["qjbfcmajvhyd"]} = ${${"GLOBALS"}["qjbfcmajvhyd"]} . "\n LEFT JOIN `" . _DB_PREFIX_ . "seller_listoption` slb ON (p.id_product = slb.id_product AND slb.id_option = " . AgileSellerListOptions::ASLO_OPTION_LIST . ")\n ";
$ghjluom = "aslo_list_prod_id";
${${"GLOBALS"}["ppufwe"]} = intval(Configuration::get("ASLO_PROD_FOR_OPTION" . AgileSellerListOptions::ASLO_OPTION_LIST));
${${"GLOBALS"}["hylelef"]} = ${${"GLOBALS"}["yyvptwoqtsy"]} . " \n \t\t AND (slb.status = " . AgileSellerListOptions::ASLO_STATUS_IN_EFFECT . " OR IFNULL(po.id_owner,0) = 0 OR " . ${$ghjluom} . "=" . AgileSellerListOptions::ASLO_ALWAYS_FREE . ")\n ";
}
${${"GLOBALS"}["lrjoesxigovv"]} = "";
switch ($this->location_level) {
case "country":
if ((int) $this->id_location > 0) {
${$hjhvngkubb} = " AND si.id_country=" . (int) $this->id_location;
}
break;
case "state":
if ((int) $this->id_location > 0) {
${${"GLOBALS"}["lrjoesxigovv"]} = " AND si.id_state=" . (int) $this->id_location;
}
break;
case "city":
if (!empty($this->id_location)) {
${${"GLOBALS"}["lrjoesxigovv"]} = " AND sil.city='" . $this->id_location . "'";
}
break;
case "sellertype":
if (!empty($this->id_location)) {
${${"GLOBALS"}["lrjoesxigovv"]} = " AND si.id_sellertype1=" . $this->id_location;
}
break;
case "custom":
if (!empty($this->id_location)) {
if (AgileMultipleShop::SHOP_BY_CUSTOM_LANG) {
${${"GLOBALS"}["lrjoesxigovv"]} = " AND sil." . AgileMultipleShop::SHOP_BY_CUSTOM_FIELD . "='" . $this->id_location . "'";
} else {
//.........这里部分代码省略.........
示例14: getRecentProducts
public function getRecentProducts($id_lang, $p, $n, $order_by = null, $order_way = null, $get_total = false, $active = true, $random = false, $random_number_products = 1, $check_access = true, Context $context = null)
{
if (!$context) {
$context = Context::getContext();
}
$front = true;
if (!in_array($context->controller->controller_type, array('front', 'modulefront'))) {
$front = false;
}
if ($p < 1) {
$p = 1;
}
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 = 'ASC';
}
// $order_by = 'dateadd';
//if ($order_by == 'price')
//$order_by = 'orderprice';
if (!Validate::isBool($active) || !Validate::isOrderBy($order_by) || !Validate::isOrderWay($order_way)) {
die(Tools::displayError());
}
$id_supplier = (int) Tools::getValue('id_supplier');
/* Return only the number of products */
if ($get_total) {
$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`
' . ($front ? ' AND product_shop.`visibility` IN ("both", "catalog")' : '') . ($active ? ' AND product_shop.`active` = 1' : '') . ($id_supplier ? 'AND p.id_supplier = ' . (int) $id_supplier : '');
return (int) Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql);
}
$sql = 'SELECT DISTINCT p.id_product, p.*, product_shop.*, stock.out_of_stock, IFNULL(stock.quantity, 0) as quantity, product_attribute_shop.`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`, image_shop.`id_image`,
il.`legend`, m.`name` AS manufacturer_name, cl.`name` AS category_default,
(SUM(pc.`grade`) / COUNT(pc.`grade`)) AS avg,
pc.`date_add` as dateadd,
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
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`
LEFT JOIN `' . _DB_PREFIX_ . 'product_comment` pc
ON p.`id_product` = pc.`id_product`
AND product_shop.`id_shop` = ' . (int) $context->shop->id . '
AND (pa.id_product_attribute IS NULL OR product_attribute_shop.id_shop=' . (int) $context->shop->id . ')
AND (i.id_image IS NULL OR image_shop.id_shop=' . (int) $context->shop->id . ')
' . ($active ? ' AND product_shop.`active` = 1' : '') . ($front ? ' AND product_shop.`visibility` IN ("both", "catalog")' : '') . ($id_supplier ? ' AND p.id_supplier = ' . (int) $id_supplier : '');
$sql .= $active ? ' WHERE p.`active` = 1' : '';
$sql .= ' GROUP BY pc.id_product ';
if ($random === true) {
$sql .= ' ORDER BY RAND()';
$sql .= ' LIMIT 0, ' . (int) $random_number_products;
} else {
$sql .= ' ORDER BY `' . pSQL($order_by) . '` ' . pSQL($order_way) . '
LIMIT ' . ((int) $p - 1) * (int) $n . ',' . (int) $n;
}
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
if (!$result) {
return array();
}
/* Modify SQL result */
return Product::getProductsProperties($id_lang, $result);
}
示例15: find
public static function find($id_lang, $expr, $pageNumber = 1, $pageSize = 1, $orderBy = 'position', $orderWay = 'desc', $ajax = false, $useCookie = true, Context $context = null)
{
global $cookie;
if (!Module::isInstalled('agilemultipleseller') and !Module::isInstalled('agilesellerlistoptions')) {
return parent::find($id_lang, $expr, $pageNumber, $pageSize, $orderBy, $orderWay, $ajax, $useCookie);
}
$agile_sql_parts = AgileSellerManager::getAdditionalSqlForProducts("p");
$db = Db::getInstance(_PS_USE_SQL_SLAVE_);
if ($useCookie) {
$id_customer = (int) $cookie->id_customer;
} else {
$id_customer = 0;
}
if ($pageNumber < 1) {
$pageNumber = 1;
}
if ($pageSize < 1) {
$pageSize = 1;
}
if (!Validate::isOrderBy($orderBy) or !Validate::isOrderWay($orderWay)) {
return false;
}
$intersectArray = array();
$scoreArray = array();
$words = explode(' ', Search::sanitize($expr, (int) $id_lang));
foreach ($words as $key => $word) {
if (!empty($word) and strlen($word) >= (int) Configuration::get('PS_SEARCH_MINWORDLEN')) {
$word = str_replace('%', '\\%', $word);
$word = str_replace('_', '\\_', $word);
$intersectArray[] = 'SELECT id_product
FROM ' . _DB_PREFIX_ . 'search_word sw
LEFT JOIN ' . _DB_PREFIX_ . 'search_index si ON sw.id_word = si.id_word
WHERE sw.id_lang = ' . (int) $id_lang . '
AND sw.word LIKE
' . ($word[0] == '-' ? ' \'' . pSQL(Tools::substr($word, 1, PS_SEARCH_MAX_WORD_LENGTH)) . '%\'' : '\'' . pSQL(Tools::substr($word, 0, PS_SEARCH_MAX_WORD_LENGTH)) . '%\'');
if ($word[0] != '-') {
$scoreArray[] = 'sw.word LIKE \'' . pSQL(Tools::substr($word, 0, PS_SEARCH_MAX_WORD_LENGTH)) . '%\'';
}
} else {
unset($words[$key]);
}
}
if (!sizeof($words)) {
return $ajax ? array() : array('total' => 0, 'result' => array());
}
$score = '';
if (sizeof($scoreArray)) {
$score = ',(
SELECT SUM(weight)
FROM ' . _DB_PREFIX_ . 'search_word sw
LEFT JOIN ' . _DB_PREFIX_ . 'search_index si ON sw.id_word = si.id_word
WHERE sw.id_lang = ' . (int) $id_lang . '
AND si.id_product = p.id_product
AND (' . implode(' OR ', $scoreArray) . ')
) position';
}
$result = $db->ExecuteS('
SELECT cp.`id_product`
FROM `' . _DB_PREFIX_ . 'category_group` cg
INNER JOIN `' . _DB_PREFIX_ . 'category_product` cp ON cp.`id_category` = cg.`id_category`
INNER JOIN `' . _DB_PREFIX_ . 'category` c ON cp.`id_category` = c.`id_category`
INNER JOIN `' . _DB_PREFIX_ . 'product` p ON cp.`id_product` = p.`id_product`
WHERE c.`active` = 1 AND p.`active` = 1 AND indexed = 1
AND cg.`id_group` ' . (!$id_customer ? '= 1' : 'IN (
SELECT id_group FROM ' . _DB_PREFIX_ . 'customer_group
WHERE id_customer = ' . (int) $id_customer . '
)'), false);
$eligibleProducts = array();
while ($row = $db->nextRow($result)) {
$eligibleProducts[] = $row['id_product'];
}
foreach ($intersectArray as $query) {
$result = $db->ExecuteS($query, false);
$eligibleProducts2 = array();
while ($row = $db->nextRow($result)) {
$eligibleProducts2[] = $row['id_product'];
}
$eligibleProducts = array_intersect($eligibleProducts, $eligibleProducts2);
if (!count($eligibleProducts)) {
return $ajax ? array() : array('total' => 0, 'result' => array());
}
}
array_unique($eligibleProducts);
$productPool = '';
foreach ($eligibleProducts as $id_product) {
if ($id_product) {
$productPool .= (int) $id_product . ',';
}
}
if (empty($productPool)) {
return $ajax ? array() : array('total' => 0, 'result' => array());
}
$productPool = strpos($productPool, ',') === false ? ' = ' . (int) $productPool . ' ' : ' IN (' . rtrim($productPool, ',') . ') ';
if ($ajax) {
$sql = 'SELECT DISTINCT p.id_product, pl.name pname, cl.name cname,
cl.link_rewrite crewrite, pl.link_rewrite prewrite ' . $score . '
' . $agile_sql_parts['selects'] . '
FROM ' . _DB_PREFIX_ . 'product p
INNER JOIN `' . _DB_PREFIX_ . 'product_lang` pl ON (
p.`id_product` = pl.`id_product`
//.........这里部分代码省略.........