2017-03-20 41 views
0

我有一个自定义Prestashop主题,运行于Prestashop 1.6.1.9和产品分类(按最低价先排序)没有考虑到具体价格(折扣)。它将零售价格与税收一起使用。Prestashop - 按价格过滤器排序不会考虑到折扣价格

为了更好地解释,这是目前过滤器是如何工作的:

产品1 - $ 11 | 产品2 - 15 $ | 产品3 - 25 $ | 产品4 - 16 $

产品(35 $的折扣之前)应高于产品,但过滤采取价格折扣前​​考虑,而不是最终价格有优惠。

如何排序最终价格

这是Category.php SQL查询:)

$sql = 'SELECT p.*, product_shop.*, stock.out_of_stock, IFNULL(stock.quantity, 0) AS 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.')':'').' 
       '.Product::sqlStock('p', 0).' 
       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` 
       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() 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; 
     } 

回答

1

类网页排序的产品是由处理的getProducts(功能Category.php类。

该函数中有2个参数(即$ order_by,$ order_way),用于处理产品分类。在此函数中有一个查询来获取产品,并且还有一列也被选中(即product_shop.price AS orderprice)。您可以在此更改列名以更改排序顺序逻辑。

+0

我使用Prestashop特定价格进行折扣。我发现折扣存储在ps_specific_price表中的“减少”字段中。此字段仅存储折扣金额,所以我无法基于此单独排序。我在第一篇文章中附加了整个SQL查询。 – user3220828