简体   繁体   中英

How do I override PrestaShop's products class to limit the number of products returned in an SQL query?

line 2070 there is an SQL like this :

SELECT product_shop.id_product, product_attribute_shop.id_product_attribute
FROM `'._DB_PREFIX_.'product` p
'.Shop::addSqlAssociation('product', 'p').'
LEFT JOIN  `'._DB_PREFIX_.'product_attribute` pa ON (product_shop.id_product = pa.id_product)
'.Shop::addSqlAssociation('product_attribute', 'pa', false, 'product_attribute_shop.default_on = 1').'
WHERE product_shop.`active` = 1
'.(($ids_product) ? $ids_product : '').'
AND p.`id_product` IN (
    SELECT cp.`id_product`
    FROM `'._DB_PREFIX_.'category_group` cg
    LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_category` = cg.`id_category`)
    WHERE cg.`id_group` '.$sql_groups.'
)
'.($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
ORDER BY RAND()

I want to know if I can Delete :

'.(($ids_product) ? $ids_product : '').'

Because with 16k products, I have 16k "OR" and it's too big and it takes too much ressource from my server.

I Added a "LIMIT 0, 200" too and I don't know if it's good ?

Thanks

The limit should work. Your other changes may produce the desired results as well.

The most important thing is that you do not alter the core files as this could lead to unanticipated changes to other parts of your site.

Prestashop provides a way for you to override the core files without breaking everything and will allow you to quickly revert back to the original.

Copy the file products.php to the overrides directory and make your changes there.

You can find support and documentation for Prestashop overrides @ Overriding default behaviors

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM