Jump to content

Products list - sort products that have images/photos first?


NixxxoN

Recommended Posts

Hi!

We're building a big shop, around 700.000 products, and some of them have photos/images and some dont.

I wonder if it's possible to sort products in the product list in this way. Separate products that have image/photo from the others that don't, and then show first the ones that do have images/photos.

Any idea?? Thanks!

Link to comment
Share on other sites

hmmm...I can recommend using a third-party tool - Store Manager for PrestaShop (there's a trial version available), with it you can:

1) find products without images with Store Diagnostics (you'll have the list of products with the possibility to export them)

2) change product position via export/import having 2 columns in the file: product ID and position

* you can also add images to products right from the diagnostics window

Screenshot_1.png

Link to comment
Share on other sites

17 minutes ago, Constantino said:

hmmm...I can recommend using a third-party tool - Store Manager for PrestaShop (there's a trial version available), with it you can:

1) find products without images with Store Diagnostics (you'll have the list of products with the possibility to export them)

2) change product position via export/import having 2 columns in the file: product ID and position

* you can also add images to products right from the diagnostics window

Screenshot_1.png

We bought this already!
But it gives us error 504 gateway timeout when trying to get all the data from the server! :(
Its about 700.000 products, takes so long...! How can we solve this?

Link to comment
Share on other sites

56 minutes ago, musicmaster said:

With so many products I would just customize the queries that Prestashop uses.

It is also the more logical approach. You don't want sort products again each time you a few new ones.

Yes, I suppose this is the logical way. But how would you query to show products with no images to appear last??

Link to comment
Share on other sites

1 hour ago, NixxxoN said:

Yes, I suppose this is the logical way. But how would you query to show products with no images to appear last??

Basically: when a product has an image it has a presence in the ps_image table. When not, then not. I don't remember at the moment the best way to put it into a query. But you could always ask on some SQL forum.

 

 

  • Like 1
Link to comment
Share on other sites

  • 2 years later...

I resolved this with with a little override of classes/controller/ProductListingFrontController.php inside the method getProductSearchVariables()
 

// EDIT: THIS CODE DOESN'T WORK AS INTENDED

// IT REMOVES FROM THE PRODUCTS OF THE PAGE
// ALL PRODUCTS WITHOUT IMAGE

// prepare the products
$products = $this->prepareMultipleProductsForTemplate(
$result->getProducts()
);

// --- custom code - start

// order products with cover_image_id not null first
$products = array_filter($products, function($product) {
	return $product['cover_image_id'] != null;
});

// --- custom code - end

EDIT:

I'm updating this post to avoid anyone using this code to have problems. Mostly because is a very subtle problem where effectively you don't see anymore the products without image, but, you will never see them...

Integrating this with prestashop was a little bit tricky, and to do this I ended up using the `mpn` column value as a 'product has image or not' column value. So, after cycling to every prestashop product something like this code:

public function setHasImage() : void
{
  $hasImage = Image::hasImages(1, $this->id);

  if ($hasImage)
  {
  	$this->mpn = 1;
  }
  else
  {
	$this->mpn = 0;
  }
}

I went ahead adding one line of code in an override of classes/controller/ProductListingFrontController.php inside the method getProductSearchVariables()
 

// set the sort order if provided in the URL
if (($encodedSortOrder = Tools::getValue('order'))) {
	$query->setSortOrder(SortOrder::newFromString(
	$encodedSortOrder
));
}

// start custom code

// mpn is used as hasImage flag
$query->setSortOrder(new SortOrder('product', 'mpn', 'desc'));

// end custom code

 

Edited by Zudjo
Precedent proposed solution wasn't actually resolving the problem (see edit history)
Link to comment
Share on other sites

6 hours ago, Zudjo said:

I resolved this with with a little override of classes/controller/ProductListingFrontController.php inside the method getProductSearchVariables()
 

// prepare the products
$products = $this->prepareMultipleProductsForTemplate(
$result->getProducts()
);

// --- custom code - start

// order products with cover_image_id not null first
$products = array_filter($products, function($product) {
	return $product['cover_image_id'] != null;
});

// --- custom code - end

 

Wow, that's a really old thread and this project is done now. I completely forgot.

When I say "it's done" I mean its abandonned haha. I'll sum up the story for you - My customer wanted to do an over-ambitious project, he was willing to go alone against kinda large companies to sell books on the internet. He hired me to do a massive online shop with more than half a million products (books) with a Prestashop store, and I "kinda" eventually did it, more or less, with many pictures remaining still.... but then after a long time he realised it was an impossible task, the server requirements were very high, so a lot of money to spend on it, and too much work to do...

The Prestashop system surprisingly held up, but still... So many problems for him.

Thanks anyway for the reply, appreciate it!

Edited by NixxxoN (see edit history)
  • Like 1
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...