vidmarc Posted September 5, 2014 Share Posted September 5, 2014 This would make adding missing product images to the store a lot easier. Quote Link to comment Share on other sites More sharing options...
Dirty Butter Posted September 5, 2014 Share Posted September 5, 2014 You should be able to sort images on Admin>Products. Quote Link to comment Share on other sites More sharing options...
vidmarc Posted September 5, 2014 Author Share Posted September 5, 2014 You can list them but not in order of if they are there or not :-( Quote Link to comment Share on other sites More sharing options...
bsmither Posted September 5, 2014 Share Posted September 5, 2014 Indeed. CC501 removed the 'image' column from the inventory database table. So, attempting to sort on the 'image' column results in no sort at all. Quote Link to comment Share on other sites More sharing options...
bsmither Posted September 5, 2014 Share Posted September 5, 2014 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.) Quote Link to comment Share on other sites More sharing options...
Dirty Butter Posted September 6, 2014 Share Posted September 6, 2014 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' Quote Link to comment Share on other sites More sharing options...
bsmither Posted September 6, 2014 Share Posted September 6, 2014 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) Quote Link to comment Share on other sites More sharing options...
Dirty Butter Posted September 6, 2014 Share Posted September 6, 2014 Editing error on my part - sorry. Quote Link to comment Share on other sites More sharing options...
bsmither Posted September 6, 2014 Share Posted September 6, 2014 Crazy database class! By adding the above capability, now the list of products can't be sorted on anything else. Stay tuned! Quote Link to comment Share on other sites More sharing options...
bsmither Posted September 6, 2014 Share Posted September 6, 2014 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) { Quote Link to comment Share on other sites More sharing options...
Dirty Butter Posted September 6, 2014 Share Posted September 6, 2014 Seems to work on sorting any column. Quote Link to comment Share on other sites More sharing options...
vidmarc Posted September 7, 2014 Author Share Posted September 7, 2014 I think this would be a very useful addition to the next upgrade. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.