Ich möchte Produkte in der Kategorie standardmäßig Filter (wie: Position, Preis ...) und nach Menge sortieren. Produkte mit der Menge = 0 müssen am Ende der Liste stehen.PrestaShop Sortierung mehrerer Felder in der Kategorie
Standardabfrage in category.php (https://github.com/PrestaShop/PrestaShop/blob/1.6.1.x/classes/Category.php#L688)
Ich versuche Menge hinzuzufügen, indem zu bestellen, aber Ergebnisse nur von Position sortiert werden
if ($random === true) {
$sql .= ' ORDER BY RAND(), stock.`quantity` DESC LIMIT '.(int)$random_number_products;
} else {
$sql .= ' ORDER BY '.(!empty($order_by_prefix) ? $order_by_prefix.'.' : '').'`'.bqSQL($order_by).'` '.pSQL($order_way).', stock.`quantity` DESC
LIMIT '.(((int)$p - 1) * (int)$n).','.(int)$n;
}
Ich versuche, diese Abfrage zu ändern durch Unterabfrage für avaliable_stock Zugabe, aber die Ergebnisse sind die gleichen, sortiert nur von Position
$sql = 'SELECT p.*, product_shop.*, real_quantity.*'.(Combination::isFeatureActive() ? ', IFNULL(product_attribute_shop.id_product_attribute, 0) AS 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` id_image,
il.`legend` as legend, m.`name` AS manufacturer_name, cl.`name` AS category_default,
DATEDIFF(product_shop.`date_add`, DATE_SUB("'.date('Y-m-d').' 00:00:00",
INTERVAL '.(int)$nb_days_new_product.' 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').
(Combination::isFeatureActive() ? ' LEFT JOIN `'._DB_PREFIX_.'product_attribute_shop` product_attribute_shop
ON (p.`id_product` = product_attribute_shop.`id_product` AND product_attribute_shop.`default_on` = 1 AND product_attribute_shop.id_shop='.(int)$context->shop->id.')':'').'
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_shop` image_shop
ON (image_shop.`id_product` = p.`id_product` AND image_shop.cover=1 AND image_shop.id_shop='.(int)$context->shop->id.')
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 (SELECT * FROM `'._DB_PREFIX_.'stock_available` ORDER BY `quantity` DESC) AS real_quantity
ON (real_quantity.id_product = p.id_product AND real_quantity.id_product_attribute = 0 AND real_quantity.id_shop = '.(int)$context->shop->id.')
WHERE product_shop.`id_shop` = '.(int)$context->shop->id.'
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 : '');
if ($random === true) {
$sql .= ' ORDER BY RAND(), real_quantity.`quantity` DESC LIMIT '.(int)$random_number_products;
} else {
$sql .= ' ORDER BY '.(!empty($order_by_prefix) ? $order_by_prefix.'.' : '').'`'.bqSQL($order_by).'` '.pSQL($order_way).', real_quantity.`quantity` DESC
LIMIT '.(((int)$p - 1) * (int)$n).','.(int)$n;
}
Kann mir jemand helfen/beraten Sie mich mit diesem Problem?
Der Standardauftrag muss beibehalten werden, und Produkte mit der Menge Null erscheinen am Ende der Liste mit Paginierung (LIMIT) – esik
Wenn am Ende der Liste ein Produkt mit der Menge 0 erscheinen muss, funktioniert die Standardreihenfolge nicht wie ich es dir vorher erkläre. Wenn Sie die Standardreihenfolge beibehalten möchten, aber am Ende das Produkt ohne Lagerbestand anzeigen möchten, sollten Sie zwei separate SQL-Anweisungen eingeben: 1 für Produkte mit Warenbestand> 0 (mit WHERE-Bedingung), die Standardbestellung und die andere mit Produkten ohne Lagerbestand. Dann füge Ergebnisse zusammen. – PixelWeb
Ich habe einen besseren Weg gefunden, zum Beispiel 'ORDER BY stock.quantity> 0 DESC, pl.name ASC' sortiert zuerst nach Menge und dann nach Namen – esik