Jump to content

Is there a search string for products with no image?


vidmarc

Recommended Posts

In the file /admin/sources/products.index.inc.php, near line 1250, find and edit:

Was:
{blank line}
if (($where === false || strlen($where) > 0) && ($results = $GLOBALS['db']->select('CubeCart_inventory', false, $where, $_GET['sort'], $per_page, $page)) !== false) {
  $pagination = $GLOBALS['db']->pagination(false, $per_page, $page, 9);
  // Find fist letters to sort products by
 
Now:
if(isset($_GET['sort']['image'])) { $_GET['sort'] = "image ".$_GET['sort']['image']; }
if (($where === false || strlen($where) > 0) && ($results = $GLOBALS['db']->select('CubeCart_inventory AS I LEFT JOIN (SELECT file_id AS image, product_id FROM '.$GLOBALS['config']->get('config', 'dbprefix').'CubeCart_image_index WHERE main_img = '1') AS IDX ON IDX.product_id = I.product_id', false, $where, $_GET['sort'], $per_page, $page)) !== false) { // 'CubeCart_inventory'
  $pagination = $GLOBALS['db']->pagination(false, $per_page, $page, 9);
  // Find fist letters to sort products by

My experiments show that the query results will now include a column named 'image' (an alias of CubeCart_image_index.file_id) that, if appropriate, has been sorted on that column's value. I stress that the sort on 'image' is actually on the foreign reference to the 'file_id' column of the Filemanager table -- not on the alphabetical sort of the image filename.

 

Thus, the only significant purpose of this edit is to get a resultant sort where any product that does not have an image assigned to it (that is, no file_id) will get listed at the top (with an ascending sort).

One other consideration: there is no hook for the edit above. So, the edit will not survive an upgrade. Honestly, however, I expect Devellion to remove the ability to sort on image (as like there is no ability to sort on translations) since the current code can't make that sort anyway. (There is nothing stopping us from adding a hook, assuming Devellion will incorporate it in future versions of CC.)
 

Link to comment
Share on other sites

It didn't work for me. I get a screen with all the column headings on the Products Summary page, as usual. Other columns will sort normally, but an attempt to sort by image results in all the column headings, but no product listings at all. I do have disabled products without images.

 

System error message:

 

File: [products.index.inc.php] Line: [1262] "SELECT SQL_CALC_FOUND_ROWS * FROM `CubeCart_inventory` ORDER BY image ASC LIMIT 20 OFFSET 0;" - Unknown column 'image' in 'order clause'

Link to comment
Share on other sites

Here is just part of the edited query:

... CubeCart_inventory AS I LEFT JOIN (SELECT file_id AS image, ...

 

If you don't see this in the debug section, then the edit may not have been made correctly.

 

I see this in my debug section:

[24] SELECT SQL_CALC_FOUND_ROWS * FROM CubeCart_inventory AS I LEFT JOIN (SELECT file_id AS image, product_id FROM CubeCart_image_index WHERE main_img = '1') AS IDX ON IDX.product_id = I.product_id ORDER BY image DESC LIMIT 20 OFFSET 0; -- (0.023099899291992 sec)

Link to comment
Share on other sites

I got it sorted. Making a complicated query means juggling other parts of what gets sent to to the function. Here's a new pair of statements for lines 1250 and 1251:

if(isset($_GET['sort']['image'])) { $_GET['sort'] = "image ".$_GET['sort']['image']; $results = $GLOBALS['db']->select('CubeCart_inventory AS I LEFT JOIN (SELECT file_id AS image, product_id FROM CubeCart_image_index WHERE main_img = '1') AS IDX ON IDX.product_id = I.product_id', false, $where, $_GET['sort'], $per_page, $page); } else { $results = $GLOBALS['db']->select('CubeCart_inventory', false, $where, $_GET['sort'], $per_page, $page); }
if (($where === false || strlen($where) > 0) && $results !== false) {

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...