Jump to content

SQL query modification in Product.php does not apply...


MathB

Recommended Posts

Hi everyone!

Unless I have missed it, I don't think that my problem has been raised in previous post, so I hope someone will be able to help me or direct me to the right place. 😊

I am currently setting up a shop with Prestashop version 8 where I want to show in the Special block and Prices Drop page only products with the 'on_sale' flag. 

To do so, I've been following this topic that is quite simple: create an override of Product.php and in the functions getRandomSpecial() and getPricesDrop() add to SQL WHERE conditions  'p.`on_sale`= 1 AND '. 

I tried to put this at the beginning of the WHERE condition, with and without brackets surrounding the rest of the condition, I tried to put it at the end of the condition and I also did so directly in the main Product.php disabling the override one. Before every attempt I cleared the cache through the BO or by erasing directories in /var/cache/

Whichever way I tried, the Prices Drop page still has every products with a specific price, even those that are not labeled as 'on_sale'...

It is as if other getRandomSpecial() and getPricesDrop() functions exist somewhere else and has the priority over my modified queries...

Can someone help me understand what is happening?

 

NB: In the case of Prices Drop page, I went down the rabbit hole of looking into controllers/front/listing/PricesDropController.php then Adapter\PricesDrop\PricesDropProductSearchProvider.php to see where getPricesDrop() is called and it is definitely called through Product class.

 

Link to comment
Share on other sites

20 hours ago, musicmaster said:

Did you try enabling _PS_DEBUG_PROFILING_ in config/defines.inc.php or the backoffice?

It will show at the bottom of the page all the queries that are run to create that page. That will help you to locate where you change goes wrong.

Thank you MusicMaster for your help! 👌

As I suspected I couldn't find any query with 'p.`on_sale` = 1 ' in it... In fact, I couldn't find any part of the whole query even though my override file is in the list of files included...

I guess the simple way to do what I want is not the right way 😅

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...