Jump to content

Does Prestashop identify new products by ID or Date Added?


Recommended Posts

I had to manually add the products as they couldn't be imported from old shopping cart. Thought I could just change the date added in phpmyadmin but this doesn't seem to be working. 

 

Problem is, most recently added products (high ID numbers) are showing as New when their date_add is changed to, for example 2012-01-25, but products whose date_add is changed to, for example, 2015-01-25, are not showing at all, even when Number of days for which the product is considered 'new' is set to 10 days.

 

This doesn't make sense as Prestashop *must* be using data_add to identify new/old products. How else would it know highest ID was added in the last 10 days?

 

I don't fancy adding all of the products again in reverse order. Any idea what's going on and how I tell Prestashop to consider products with older date_add as old and, therefore, not mark as new, or show in the New Products page?

 

TIA

Link to comment
Share on other sites

Eureka! I stumbled upon a solution after reading this thread: https://www.prestashop.com/forums/topic/164393-setting-a-product-status-to-new/

The date_add is stored in ps_product and in ps_product_shop. All this time i was looking at ps_product, but the "new products" for your shop are calculated with the date_add from ps_product_shop! I think this is on purpose for multishop-support. Since this is a single shop the solution was easy: just correct the dates.

 

If anybody wants to use my php-script:

$db_presta = @mysql_connect($hostname_presta, $username_presta, $password_presta) or die("!no Database connection");
$select_presta = mysql_select_db($dbname_presta, $db_presta);
mysql_query("SET character_set_results = 'utf8', character_set_client = 'utf8', character_set_connection = 'utf8', character_set_database = 'utf8', character_set_server = 'utf8'", $db_presta);


echo "# Database connected<br />".PHP_EOL;

echo "<br /># Searching...<br />".PHP_EOL;
$select_presta = mysql_select_db($dbname_presta, $db_presta);
$ps_product_query="SELECT DISTINCT pp.id_product,pp.date_add AS pp_date_add, pps.date_add AS pps_date_add 
						FROM ps_product pp
						LEFT JOIN ps_product_shop pps ON pps.id_product=pp.id_product 
						WHERE pp.date_add>pps.date_add OR pp.date_add<pps.date_add								
						ORDER BY pp.id_product";

$result_ps_product = mysql_query($ps_product_query,$db_presta) or die("Fehler bei Presta-Abfrage (Hauptsuchlauf): ".mysql_error());	
$i=0;$j=0;							
while ($row_product = mysql_fetch_object($result_ps_product))
{
	echo "[] Product with ID ".$row_product->id_product."<br />".PHP_EOL;
	$i++;
	echo "<font color='darkgreen'>Date-Add in ps_product: $row_product->pp_date_add</font><br />".PHP_EOL; 
	echo "<font color='darkgreen'>Date-Add in ps_product_shop: $row_product->pps_date_add</font><br />".PHP_EOL; 

	$query1=("UPDATE ps_product_shop SET date_add='".$row_product->pp_date_add."' WHERE id_product='".$row_product->id_product."'");
	if(!mysql_query($query1,$db_presta))
	{
		echo ("<font color='red'>Error setting date_add! </font>".mysql_error()); 	
		echo "<br />".PHP_EOL; 	
	}
	else 
	{
		echo "<font color='green'>setting date_add in ps_product_shop succesful</font><br />".PHP_EOL; 
	}		

	
}
echo "# ".$i." Products edited.<br /><br />".PHP_EOL;

I hope this applys to your situation as well. 

As always, before messing with the database, make a backup!

 

Greetings,

Michael

Edited by HiFish (see edit history)
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...