[-] Core: Fix the listings in multishop context when you have at least a combination on one shop and not on the others and the same for the images

This commit is contained in:
Rémi Gaillard
2013-03-20 20:12:28 +01:00
parent 68be65e60f
commit 5f181c8e4c
8 changed files with 42 additions and 49 deletions
+4 -5
View File
@@ -604,8 +604,8 @@ class CategoryCore extends ObjectModel
return (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql); return (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql);
} }
$sql = 'SELECT 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`, $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`, image_shop.`id_image`, 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, il.`legend`, m.`name` AS manufacturer_name, cl.`name` AS category_default,
DATEDIFF(product_shop.`date_add`, DATE_SUB(NOW(), 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).' INTERVAL '.(Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20).'
@@ -633,12 +633,11 @@ class CategoryCore extends ObjectModel
LEFT JOIN `'._DB_PREFIX_.'manufacturer` m LEFT JOIN `'._DB_PREFIX_.'manufacturer` m
ON m.`id_manufacturer` = p.`id_manufacturer` ON m.`id_manufacturer` = p.`id_manufacturer`
WHERE product_shop.`id_shop` = '.(int)$context->shop->id.' WHERE 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.')
AND cp.`id_category` = '.(int)$this->id AND cp.`id_category` = '.(int)$this->id
.($active ? ' AND product_shop.`active` = 1' : '') .($active ? ' AND product_shop.`active` = 1' : '')
.($front ? ' AND product_shop.`visibility` IN ("both", "catalog")' : '') .($front ? ' AND product_shop.`visibility` IN ("both", "catalog")' : '')
.($id_supplier ? ' AND p.id_supplier = '.(int)$id_supplier : ''); .($id_supplier ? ' AND p.id_supplier = '.(int)$id_supplier : '')
.' GROUP BY product_shop.id_product';
if ($random === true) if ($random === true)
{ {
+3 -4
View File
@@ -325,9 +325,9 @@ class ManufacturerCore extends ObjectModel
$alias = 'stock.'; $alias = 'stock.';
else else
$alias = 'p.'; $alias = 'p.';
$sql = 'SELECT p.*, product_shop.*, stock.out_of_stock, IFNULL(stock.quantity, 0) as quantity, pa.`id_product_attribute`, $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,
pl.`description`, pl.`description_short`, pl.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`, pl.`description`, pl.`description_short`, 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, pl.`meta_title`, pl.`name`, MAX(image_shop.`id_image`) id_image, il.`legend`, m.`name` AS manufacturer_name,
DATEDIFF( DATEDIFF(
product_shop.`date_add`, product_shop.`date_add`,
DATE_SUB( DATE_SUB(
@@ -353,7 +353,6 @@ class ManufacturerCore extends ObjectModel
WHERE p.`id_manufacturer` = '.(int)$id_manufacturer.' WHERE p.`id_manufacturer` = '.(int)$id_manufacturer.'
'.($active ? ' AND product_shop.`active` = 1' : '').' '.($active ? ' AND product_shop.`active` = 1' : '').'
'.($front ? ' AND product_shop.`visibility` IN ("both", "catalog")' : '').' '.($front ? ' AND product_shop.`visibility` IN ("both", "catalog")' : '').'
AND (product_attribute_shop.default_on = 1 OR product_attribute_shop.default_on IS NULL)
AND p.`id_product` IN ( AND p.`id_product` IN (
SELECT cp.`id_product` SELECT cp.`id_product`
FROM `'._DB_PREFIX_.'category_group` cg FROM `'._DB_PREFIX_.'category_group` cg
@@ -362,7 +361,7 @@ class ManufacturerCore extends ObjectModel
($active_category ? ' INNER JOIN `'._DB_PREFIX_.'category` ca ON cp.`id_category` = ca.`id_category` AND ca.`active` = 1' : '').' ($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.' WHERE cg.`id_group` '.$sql_groups.'
) )
AND ((image_shop.id_image IS NOT NULL OR i.id_image IS NULL) OR (image_shop.id_image IS NULL AND i.cover=1)) GROUP BY product_shop.id_product
ORDER BY '.$alias.'`'.bqSQL($order_by).'` '.pSQL($order_way).' ORDER BY '.$alias.'`'.bqSQL($order_by).'` '.pSQL($order_way).'
LIMIT '.(((int)$p - 1) * (int)$n).','.(int)$n; LIMIT '.(((int)$p - 1) * (int)$n).','.(int)$n;
+5 -5
View File
@@ -124,7 +124,7 @@ class PackCore extends Product
if (!Pack::isFeatureActive()) if (!Pack::isFeatureActive())
return array(); return array();
$sql = 'SELECT p.*, product_shop.*, pl.*, image_shop.`id_image`, il.`legend`, cl.`name` AS category_default, a.quantity AS pack_quantity, product_shop.`id_category_default`, a.id_product_pack $sql = 'SELECT p.*, product_shop.*, pl.*, MAX(image_shop.`id_image`) id_image, il.`legend`, cl.`name` AS category_default, a.quantity AS pack_quantity, product_shop.`id_category_default`, a.id_product_pack
FROM `'._DB_PREFIX_.'pack` a FROM `'._DB_PREFIX_.'pack` a
LEFT JOIN `'._DB_PREFIX_.'product` p ON p.id_product = a.id_product_item LEFT JOIN `'._DB_PREFIX_.'product` p ON p.id_product = a.id_product_item
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl LEFT JOIN `'._DB_PREFIX_.'product_lang` pl
@@ -138,8 +138,8 @@ class PackCore extends Product
ON product_shop.`id_category_default` = cl.`id_category` ON product_shop.`id_category_default` = cl.`id_category`
AND cl.`id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('cl').' AND cl.`id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('cl').'
WHERE product_shop.`id_shop` = '.(int)Context::getContext()->shop->id.' WHERE product_shop.`id_shop` = '.(int)Context::getContext()->shop->id.'
AND ((image_shop.id_image IS NOT NULL OR i.id_image IS NULL) OR (image_shop.id_image IS NULL AND i.cover=1)) AND a.`id_product_pack` = '.(int)$id_product.'
AND a.`id_product_pack` = '.(int)$id_product; GROUP BY product_shop.id_product';
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql); $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
foreach ($result as &$line) foreach ($result as &$line)
@@ -169,7 +169,7 @@ class PackCore extends Product
return array(); return array();
$sql = ' $sql = '
SELECT p.*, product_shop.*, pl.*, image_shop.`id_image`, il.`legend` SELECT p.*, product_shop.*, pl.*, MAX(image_shop.`id_image`) id_image, il.`legend`
FROM `'._DB_PREFIX_.'product` p FROM `'._DB_PREFIX_.'product` p
NATURAL LEFT JOIN `'._DB_PREFIX_.'product_lang` pl NATURAL LEFT JOIN `'._DB_PREFIX_.'product_lang` pl
'.Shop::addSqlAssociation('product', 'p').' '.Shop::addSqlAssociation('product', 'p').'
@@ -179,7 +179,7 @@ class PackCore extends Product
WHERE pl.`id_lang` = '.(int)$id_lang.' WHERE pl.`id_lang` = '.(int)$id_lang.'
'.Shop::addSqlRestrictionOnLang('pl').' '.Shop::addSqlRestrictionOnLang('pl').'
AND p.`id_product` IN ('.$packs.') AND p.`id_product` IN ('.$packs.')
AND ((image_shop.id_image IS NOT NULL OR i.id_image IS NULL) OR (image_shop.id_image IS NULL AND i.cover=1))'; GROUP BY product_shop.id_product';
if ($limit) if ($limit)
$sql .= ' LIMIT '.(int)$limit; $sql .= ' LIMIT '.(int)$limit;
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql); $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
+14 -16
View File
@@ -1991,7 +1991,7 @@ class ProductCore extends ObjectModel
$sql = new DbQuery(); $sql = new DbQuery();
$sql->select( $sql->select(
'p.*, product_shop.*, stock.out_of_stock, IFNULL(stock.quantity, 0) as quantity, pl.`description`, pl.`description_short`, pl.`link_rewrite`, pl.`meta_description`, 'p.*, product_shop.*, stock.out_of_stock, IFNULL(stock.quantity, 0) as quantity, pl.`description`, pl.`description_short`, 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, pl.`meta_keywords`, pl.`meta_title`, pl.`name`, MAX(image_shop.`id_image`) id_image, il.`legend`, m.`name` AS manufacturer_name,
DATEDIFF( DATEDIFF(
product_shop.`date_add`, product_shop.`date_add`,
DATE_SUB( DATE_SUB(
@@ -2013,7 +2013,7 @@ class ProductCore extends ObjectModel
$sql->leftJoin('manufacturer', 'm', 'm.`id_manufacturer` = p.`id_manufacturer`'); $sql->leftJoin('manufacturer', 'm', 'm.`id_manufacturer` = p.`id_manufacturer`');
$sql->where('product_shop.`active` = 1'); $sql->where('product_shop.`active` = 1');
$sql->where('(image_shop.id_image IS NOT NULL OR i.id_image IS NULL) OR (image_shop.id_image IS NULL AND i.cover=1)');
if ($front) if ($front)
$sql->where('product_shop.`visibility` IN ("both", "catalog")'); $sql->where('product_shop.`visibility` IN ("both", "catalog")');
$sql->where(' $sql->where('
@@ -2032,16 +2032,16 @@ class ProductCore extends ObjectModel
LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_category` = cg.`id_category`) LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_category` = cg.`id_category`)
WHERE cg.`id_group` '.$sql_groups.')' WHERE cg.`id_group` '.$sql_groups.')'
); );
$sql->groupBy('product_shop.id_product');
$sql->orderBy((isset($order_by_prefix) ? pSQL($order_by_prefix).'.' : '').'`'.pSQL($order_by).'` '.pSQL($order_way)); $sql->orderBy((isset($order_by_prefix) ? pSQL($order_by_prefix).'.' : '').'`'.pSQL($order_by).'` '.pSQL($order_way));
$sql->limit($nb_products, $page_number * $nb_products); $sql->limit($nb_products, $page_number * $nb_products);
if (Combination::isFeatureActive()) if (Combination::isFeatureActive())
{ {
$sql->select('pa.id_product_attribute'); $sql->select('MAX(pa.id_product_attribute) id_product_attribute');
$sql->leftOuterJoin('product_attribute', 'pa', 'p.`id_product` = pa.`id_product`'); $sql->leftOuterJoin('product_attribute', 'pa', 'p.`id_product` = pa.`id_product`');
$sql->join(Shop::addSqlAssociation('product_attribute', 'pa', false, 'product_attribute_shop.default_on = 1')); $sql->join(Shop::addSqlAssociation('product_attribute', 'pa', false, 'product_attribute_shop.default_on = 1'));
$sql->where('(pa.id_product_attribute IS NULL OR product_attribute_shop.id_shop='.(int)$context->shop->id.')');
} }
$sql->join(Product::sqlStock('p', Combination::isFeatureActive() ? 'product_attribute_shop' : 0)); $sql->join(Product::sqlStock('p', Combination::isFeatureActive() ? 'product_attribute_shop' : 0));
@@ -2111,7 +2111,7 @@ class ProductCore extends ObjectModel
$sql_groups = (count($groups) ? 'IN ('.implode(',', $groups).')' : '= 1'); $sql_groups = (count($groups) ? 'IN ('.implode(',', $groups).')' : '= 1');
// Please keep 2 distinct queries because RAND() is an awful way to achieve this result // Please keep 2 distinct queries because RAND() is an awful way to achieve this result
$sql = 'SELECT product_shop.id_product, product_attribute_shop.id_product_attribute $sql = 'SELECT product_shop.id_product, MAX(product_attribute_shop.id_product_attribute) id_product_attribute
FROM `'._DB_PREFIX_.'product` p FROM `'._DB_PREFIX_.'product` p
'.Shop::addSqlAssociation('product', 'p').' '.Shop::addSqlAssociation('product', 'p').'
LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa ON (product_shop.id_product = pa.id_product) LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa ON (product_shop.id_product = pa.id_product)
@@ -2125,7 +2125,6 @@ class ProductCore extends ObjectModel
WHERE cg.`id_group` '.$sql_groups.' WHERE cg.`id_group` '.$sql_groups.'
) )
'.($front ? ' AND product_shop.`visibility` IN ("both", "catalog")' : '').' '.($front ? ' AND product_shop.`visibility` IN ("both", "catalog")' : '').'
AND (pa.id_product_attribute IS NULL OR product_attribute_shop.default_on = 1)
GROUP BY product_shop.id_product GROUP BY product_shop.id_product
ORDER BY RAND()'; ORDER BY RAND()';
@@ -2136,7 +2135,7 @@ class ProductCore extends ObjectModel
$sql = 'SELECT p.*, product_shop.*, stock.`out_of_stock` out_of_stock, pl.`description`, pl.`description_short`, $sql = 'SELECT p.*, product_shop.*, stock.`out_of_stock` out_of_stock, pl.`description`, pl.`description_short`,
pl.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`, pl.`name`, pl.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`, pl.`name`,
p.`ean13`, p.`upc`, image_shop.`id_image`, il.`legend` p.`ean13`, p.`upc`, MAX(image_shop.`id_image`) id_image, il.`legend`
FROM `'._DB_PREFIX_.'product` p FROM `'._DB_PREFIX_.'product` p
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON ( LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (
p.`id_product` = pl.`id_product` p.`id_product` = pl.`id_product`
@@ -2148,7 +2147,7 @@ class ProductCore extends ObjectModel
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_.'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$id_lang.')
'.Product::sqlStock('p', 0).' '.Product::sqlStock('p', 0).'
WHERE p.id_product = '.(int)$id_product.' WHERE p.id_product = '.(int)$id_product.'
AND (i.id_image IS NULL OR image_shop.id_shop='.(int)$context->shop->id.')'; GROUP BY product_shop.id_product';
$row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql); $row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql);
if (!$row) if (!$row)
@@ -2228,9 +2227,9 @@ class ProductCore extends ObjectModel
$order_by = explode('.', $order_by); $order_by = explode('.', $order_by);
$order_by = pSQL($order_by[0]).'.`'.pSQL($order_by[1]).'`'; $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`, product_attribute_shop.id_product_attribute, $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.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`,
pl.`name`, image_shop.`id_image`, il.`legend`, m.`name` AS manufacturer_name, pl.`name`, MAX(image_shop.`id_image`) id_image, il.`legend`, m.`name` AS manufacturer_name,
DATEDIFF( DATEDIFF(
p.`date_add`, p.`date_add`,
DATE_SUB( DATE_SUB(
@@ -2253,7 +2252,6 @@ class ProductCore extends ObjectModel
LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON (m.`id_manufacturer` = p.`id_manufacturer`) LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON (m.`id_manufacturer` = p.`id_manufacturer`)
WHERE product_shop.`active` = 1 WHERE product_shop.`active` = 1
AND product_shop.`show_price` = 1 AND product_shop.`show_price` = 1
AND ((image_shop.id_image IS NOT NULL OR i.id_image IS NULL) OR (image_shop.id_image IS NULL AND i.cover=1))
'.($front ? ' AND p.`visibility` IN ("both", "catalog")' : '').' '.($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).')' : '').' '.((!$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 ( AND p.`id_product` IN (
@@ -2262,7 +2260,7 @@ class ProductCore extends ObjectModel
LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_category` = cg.`id_category`) LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_category` = cg.`id_category`)
WHERE cg.`id_group` '.$sql_groups.' WHERE cg.`id_group` '.$sql_groups.'
) )
AND (pa.id_product_attribute IS NULL OR product_attribute_shop.default_on = 1) GROUP BY product_shop.id_product
ORDER BY '.(isset($order_by_prefix) ? pSQL($order_by_prefix).'.' : '').pSQL($order_by).' '.pSQL($order_way).' 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; LIMIT '.(int)($page_number * $nb_products).', '.(int)$nb_products;
@@ -3107,7 +3105,7 @@ class ProductCore extends ObjectModel
$sql = 'SELECT p.*, product_shop.*, stock.out_of_stock, IFNULL(stock.quantity, 0) as quantity, pl.`description`, pl.`description_short`, pl.`link_rewrite`, $sql = 'SELECT p.*, product_shop.*, stock.out_of_stock, IFNULL(stock.quantity, 0) as quantity, pl.`description`, pl.`description_short`, pl.`link_rewrite`,
pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`, pl.`name`, pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`, pl.`name`,
i.`id_image`, il.`legend`, m.`name` as manufacturer_name, cl.`name` AS category_default, MAX(image_shop.`id_image`) id_image, il.`legend`, m.`name` as manufacturer_name, cl.`name` AS category_default,
DATEDIFF( DATEDIFF(
p.`date_add`, p.`date_add`,
DATE_SUB( DATE_SUB(
@@ -3131,9 +3129,9 @@ class ProductCore extends ObjectModel
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_.'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$id_lang.')
LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON (p.`id_manufacturer`= m.`id_manufacturer`) LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON (p.`id_manufacturer`= m.`id_manufacturer`)
'.Product::sqlStock('p', 0).' '.Product::sqlStock('p', 0).'
WHERE `id_product_1` = '.(int)$this->id.' WHERE `id_product_1` = '.(int)$this->id.
AND ((image_shop.id_image IS NOT NULL OR i.id_image IS NULL) OR (image_shop.id_image IS NULL AND i.cover=1))'. ($active ? ' AND product_shop.`active` = 1' : '').'
($active ? ' AND product_shop.`active` = 1' : ''); GROUP BY product_shop.id_image';
if (!$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql)) if (!$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql))
return false; return false;
foreach ($result as &$row) foreach ($result as &$row)
+4 -4
View File
@@ -78,7 +78,7 @@ class ProductSaleCore
pl.`description`, pl.`description_short`, pl.`link_rewrite`, pl.`meta_description`, pl.`description`, pl.`description_short`, pl.`link_rewrite`, pl.`meta_description`,
pl.`meta_keywords`, pl.`meta_title`, pl.`name`, pl.`meta_keywords`, pl.`meta_title`, pl.`name`,
m.`name` AS manufacturer_name, p.`id_manufacturer` as id_manufacturer, m.`name` AS manufacturer_name, p.`id_manufacturer` as id_manufacturer,
image_shop.`id_image`, il.`legend`, MAX(image_shop.`id_image`) id_image, il.`legend`,
ps.`quantity` AS sales, t.`rate`, pl.`meta_keywords`, pl.`meta_title`, pl.`meta_description`, ps.`quantity` AS sales, t.`rate`, pl.`meta_keywords`, pl.`meta_title`, pl.`meta_description`,
DATEDIFF(p.`date_add`, DATE_SUB(NOW(), DATEDIFF(p.`date_add`, DATE_SUB(NOW(),
INTERVAL '.$interval.' DAY)) > 0 AS new INTERVAL '.$interval.' DAY)) > 0 AS new
@@ -105,7 +105,7 @@ class ProductSaleCore
LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_category` = cg.`id_category`) LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_category` = cg.`id_category`)
WHERE cg.`id_group` '.$sql_groups.' WHERE cg.`id_group` '.$sql_groups.'
) )
AND ((image_shop.id_image IS NOT NULL OR i.id_image IS NULL) OR (image_shop.id_image IS NULL AND i.cover=1)) GROUP BY product_shop.id_product
ORDER BY `'.pSQL($order_by).'` '.pSQL($order_way).' ORDER BY `'.pSQL($order_by).'` '.pSQL($order_way).'
LIMIT '.(int)($page_number * $nb_products).', '.(int)$nb_products; LIMIT '.(int)($page_number * $nb_products).', '.(int)$nb_products;
@@ -136,7 +136,7 @@ class ProductSaleCore
$groups = FrontController::getCurrentCustomerGroups(); $groups = FrontController::getCurrentCustomerGroups();
$sql_groups = (count($groups) ? 'IN ('.implode(',', $groups).')' : '= 1'); $sql_groups = (count($groups) ? 'IN ('.implode(',', $groups).')' : '= 1');
$sql = 'SELECT p.id_product, pl.`link_rewrite`, pl.`name`, pl.`description_short`, image_shop.`id_image`, il.`legend`, $sql = 'SELECT p.id_product, pl.`link_rewrite`, pl.`name`, pl.`description_short`, MAX(image_shop.`id_image`) id_image, il.`legend`,
ps.`quantity` AS sales, p.`ean13`, p.`upc`, cl.`link_rewrite` AS category ps.`quantity` AS sales, p.`ean13`, p.`upc`, cl.`link_rewrite` AS category
FROM `'._DB_PREFIX_.'product_sale` ps FROM `'._DB_PREFIX_.'product_sale` ps
LEFT JOIN `'._DB_PREFIX_.'product` p ON ps.`id_product` = p.`id_product` LEFT JOIN `'._DB_PREFIX_.'product` p ON ps.`id_product` = p.`id_product`
@@ -158,7 +158,7 @@ class ProductSaleCore
LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_category` = cg.`id_category`) LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_category` = cg.`id_category`)
WHERE cg.`id_group` '.$sql_groups.' WHERE cg.`id_group` '.$sql_groups.'
) )
AND ((image_shop.id_image IS NOT NULL OR i.id_image IS NULL) OR (image_shop.id_image IS NULL AND i.cover=1)) GROUP BY product_shop.id_product
ORDER BY sales DESC ORDER BY sales DESC
LIMIT '.(int)($page_number * $nb_products).', '.(int)$nb_products; LIMIT '.(int)($page_number * $nb_products).', '.(int)$nb_products;
if (!$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql)) if (!$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql))
+5 -10
View File
@@ -283,7 +283,7 @@ class SearchCore
$alias = 'product_shop.'; $alias = 'product_shop.';
$sql = 'SELECT p.*, product_shop.*, stock.out_of_stock, IFNULL(stock.quantity, 0) as quantity, $sql = 'SELECT p.*, product_shop.*, stock.out_of_stock, IFNULL(stock.quantity, 0) as quantity,
pl.`description_short`, pl.`available_now`, pl.`available_later`, pl.`link_rewrite`, pl.`name`, pl.`description_short`, pl.`available_now`, pl.`available_later`, pl.`link_rewrite`, pl.`name`,
image_shop.`id_image`, il.`legend`, m.`name` manufacturer_name '.$score.', product_attribute_shop.`id_product_attribute`, MAX(image_shop.`id_image`) id_image, il.`legend`, m.`name` manufacturer_name '.$score.', MAX(product_attribute_shop.`id_product_attribute`) id_product_attribute,
DATEDIFF( DATEDIFF(
p.`date_add`, p.`date_add`,
DATE_SUB( DATE_SUB(
@@ -305,8 +305,7 @@ class SearchCore
Shop::addSqlAssociation('image', 'i', false, 'image_shop.cover=1').' 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_.'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$id_lang.')
WHERE p.`id_product` '.$product_pool.' WHERE p.`id_product` '.$product_pool.'
AND ((image_shop.id_image IS NOT NULL OR i.id_image IS NULL) OR (image_shop.id_image IS NULL AND i.cover=1)) GROUP BY product_shop.id_product
AND (pa.id_product_attribute IS NULL OR product_attribute_shop.id_shop='.(int)$context->shop->id.')
'.($order_by ? 'ORDER BY '.$alias.$order_by : '').($order_way ? ' '.$order_way : '').' '.($order_by ? 'ORDER BY '.$alias.$order_by : '').($order_way ? ' '.$order_way : '').'
LIMIT '.(int)(($page_number - 1) * $page_size).','.(int)$page_size; LIMIT '.(int)(($page_number - 1) * $page_size).','.(int)$page_size;
$result = $db->executeS($sql); $result = $db->executeS($sql);
@@ -319,11 +318,7 @@ class SearchCore
AND pl.`id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('pl').' AND pl.`id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('pl').'
) )
LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON m.`id_manufacturer` = p.`id_manufacturer` LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON m.`id_manufacturer` = p.`id_manufacturer`
LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product`)'. WHERE p.`id_product` '.$product_pool;
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.')
WHERE p.`id_product` '.$product_pool.'
AND ((image_shop.id_image IS NOT NULL OR i.id_image IS NULL) OR (image_shop.id_image IS NULL AND i.cover=1))';
$total = $db->getValue($sql); $total = $db->getValue($sql);
if (!$result) if (!$result)
@@ -633,7 +628,7 @@ class SearchCore
} }
$sql = 'SELECT DISTINCT p.*, product_shop.*, stock.out_of_stock, IFNULL(stock.quantity, 0) as quantity, pl.`description_short`, pl.`link_rewrite`, pl.`name`, $sql = 'SELECT DISTINCT p.*, product_shop.*, stock.out_of_stock, IFNULL(stock.quantity, 0) as quantity, pl.`description_short`, pl.`link_rewrite`, pl.`name`,
image_shop.`id_image`, il.`legend`, m.`name` manufacturer_name, 1 position, MAX(image_shop.`id_image`) id_image, il.`legend`, m.`name` manufacturer_name, 1 position,
DATEDIFF( DATEDIFF(
p.`date_add`, p.`date_add`,
DATE_SUB( DATE_SUB(
@@ -663,7 +658,7 @@ class SearchCore
SELECT id_group FROM '._DB_PREFIX_.'customer_group SELECT id_group FROM '._DB_PREFIX_.'customer_group
WHERE id_customer = '.(int)$id_customer.')').' WHERE id_customer = '.(int)$id_customer.')').'
AND t.`name` LIKE \'%'.pSQL($tag).'%\' AND t.`name` LIKE \'%'.pSQL($tag).'%\'
AND ((image_shop.id_image IS NOT NULL OR i.id_image IS NULL) OR (image_shop.id_image IS NULL AND i.cover=1)) GROUP BY product_shop.id_image
ORDER BY position DESC'.($orderBy ? ', '.$orderBy : '').($orderWay ? ' '.$orderWay : '').' ORDER BY position DESC'.($orderBy ? ', '.$orderBy : '').($orderWay ? ' '.$orderWay : '').'
LIMIT '.(int)(($pageNumber - 1) * $pageSize).','.(int)$pageSize; LIMIT '.(int)(($pageNumber - 1) * $pageSize).','.(int)$pageSize;
if (!$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql)) if (!$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql))
+2 -2
View File
@@ -258,7 +258,7 @@ class SupplierCore extends ObjectModel
pl.`meta_keywords`, pl.`meta_keywords`,
pl.`meta_title`, pl.`meta_title`,
pl.`name`, pl.`name`,
image_shop.`id_image`, MAX(image_shop.`id_image`) id_image,
il.`legend`, il.`legend`,
s.`name` AS supplier_name, s.`name` AS supplier_name,
DATEDIFF(p.`date_add`, DATE_SUB(NOW(), INTERVAL '.($nb_days_new_product).' DAY)) > 0 AS new, DATEDIFF(p.`date_add`, DATE_SUB(NOW(), INTERVAL '.($nb_days_new_product).' DAY)) > 0 AS new,
@@ -286,7 +286,7 @@ class SupplierCore extends ObjectModel
($active_category ? ' INNER JOIN `'._DB_PREFIX_.'category` ca ON cp.`id_category` = ca.`id_category` AND ca.`active` = 1' : '').' ($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.' WHERE cg.`id_group` '.$sql_groups.'
) )
AND ((image_shop.id_image IS NOT NULL OR i.id_image IS NULL) OR (image_shop.id_image IS NULL AND i.cover=1)) GROUP BY product_shop.id_product
ORDER BY '.$alias.pSQL($order_by).' '.pSQL($order_way).' ORDER BY '.$alias.pSQL($order_by).' '.pSQL($order_way).'
LIMIT '.(((int)$p - 1) * (int)$n).','.(int)$n; LIMIT '.(((int)$p - 1) * (int)$n).','.(int)$n;
@@ -162,7 +162,6 @@ class AdminProductsControllerCore extends AdminController
LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON ('.$alias.'.`id_category_default` = cl.`id_category` AND b.`id_lang` = cl.`id_lang` AND cl.id_shop = '.(int)$this->context->shop->id.') LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON ('.$alias.'.`id_category_default` = cl.`id_category` AND b.`id_lang` = cl.`id_lang` AND cl.id_shop = '.(int)$this->context->shop->id.')
LEFT JOIN `'._DB_PREFIX_.'shop` shop ON (shop.id_shop = '.(int)$this->context->shop->id.') LEFT JOIN `'._DB_PREFIX_.'shop` shop ON (shop.id_shop = '.(int)$this->context->shop->id.')
LEFT JOIN `'._DB_PREFIX_.'image_shop` image_shop ON (image_shop.`id_image` = i.`id_image` AND image_shop.`cover` = 1 AND image_shop.id_shop='.(int)$this->context->shop->id.')'; LEFT JOIN `'._DB_PREFIX_.'image_shop` image_shop ON (image_shop.`id_image` = i.`id_image` AND image_shop.`cover` = 1 AND image_shop.id_shop='.(int)$this->context->shop->id.')';
$this->_where .= 'AND (i.id_image IS NULL OR image_shop.id_shop='.(int)$this->context->shop->id.')';
} }
else else
{ {
@@ -170,7 +169,6 @@ class AdminProductsControllerCore extends AdminController
LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON ('.$alias.'.`id_category_default` = cl.`id_category` AND b.`id_lang` = cl.`id_lang` AND cl.id_shop = a.id_shop_default) LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON ('.$alias.'.`id_category_default` = cl.`id_category` AND b.`id_lang` = cl.`id_lang` AND cl.id_shop = a.id_shop_default)
LEFT JOIN `'._DB_PREFIX_.'shop` shop ON (shop.id_shop = a.id_shop_default) LEFT JOIN `'._DB_PREFIX_.'shop` shop ON (shop.id_shop = a.id_shop_default)
LEFT JOIN `'._DB_PREFIX_.'image_shop` image_shop ON (image_shop.`id_image` = i.`id_image` AND image_shop.`cover` = 1 AND image_shop.id_shop=a.id_shop_default)'; LEFT JOIN `'._DB_PREFIX_.'image_shop` image_shop ON (image_shop.`id_image` = i.`id_image` AND image_shop.`cover` = 1 AND image_shop.id_shop=a.id_shop_default)';
$this->_where .= 'AND (i.id_image IS NULL OR image_shop.id_shop=a.id_shop_default)';
} }
$this->_select .= 'shop.name as shopname, '; $this->_select .= 'shop.name as shopname, ';
} }
@@ -181,11 +179,15 @@ class AdminProductsControllerCore extends AdminController
$this->_join .= 'LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON ('.$alias.'.`id_category_default` = cl.`id_category` AND b.`id_lang` = cl.`id_lang` AND cl.id_shop = 1)'; $this->_join .= 'LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON ('.$alias.'.`id_category_default` = cl.`id_category` AND b.`id_lang` = cl.`id_lang` AND cl.id_shop = 1)';
} }
$this->_select .= 'MAX('.$alias_image.'.id_image) id_image,';
$this->_join .= ($join_category ? 'INNER JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_product` = a.`id_product` AND cp.`id_category` = '.(int)$this->_category->id.')' : '').' $this->_join .= ($join_category ? 'INNER JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_product` = a.`id_product` AND cp.`id_category` = '.(int)$this->_category->id.')' : '').'
LEFT JOIN `'._DB_PREFIX_.'stock_available` sav ON (sav.`id_product` = a.`id_product` AND sav.`id_product_attribute` = 0 LEFT JOIN `'._DB_PREFIX_.'stock_available` sav ON (sav.`id_product` = a.`id_product` AND sav.`id_product_attribute` = 0
'.StockAvailable::addSqlShopRestriction(null, null, 'sav').') '; '.StockAvailable::addSqlShopRestriction(null, null, 'sav').') ';
$this->_select .= 'cl.name `name_category` '.($join_category ? ', cp.`position`' : '').', '.$alias_image.'.`id_image`, '.$alias.'.`price`, 0 AS price_final, sav.`quantity` as sav_quantity, '.$alias.'.`active`'; $this->_select .= 'cl.name `name_category` '.($join_category ? ', cp.`position`' : '').', '.$alias_image.'.`id_image`, '.$alias.'.`price`, 0 AS price_final, sav.`quantity` as sav_quantity, '.$alias.'.`active`';
$this->_group = 'GROUP BY '.$alias.'.id_product';
$this->fields_list = array(); $this->fields_list = array();
$this->fields_list['id_product'] = array( $this->fields_list['id_product'] = array(
'title' => $this->l('ID'), 'title' => $this->l('ID'),