Page 1 of 1
[SOLVED] Sort download files - data added [solution inside]
Posted: Tue Mar 04, 2025 1:17 am
by sylwekb
Hello
How can I sort downloads by the date the file was added? There is no sorting option, which means the files are very scattered. I have Opencart 4.1.0.0.
Thank you
Re: Sort download files - data added
Posted: Tue Mar 04, 2025 4:05 am
by by mona
Have you checked the marketplace?
Most developers recommend not to use OC4 as you know so if you can not find an extension for OC4 you might find one for an earlier OC version and edit it yourself or hire a developer.
You can also search google and adapt the information to suit
https://www.google.com/search?q=opencar ... data+added
Re: SOLVED Sort download files - data added
Posted: Tue Mar 04, 2025 9:02 pm
by sylwekb
SOLVED!
Go to catalog/model/account/download.php
Code: Select all
$query = $this->db->query("SELECT DISTINCT `d`.`download_id`, `o`.`order_id`, `o`.`date_added`, `dd`.`name`, `d`.`filename` FROM `" . DB_PREFIX . "order` `o` LEFT JOIN `" . DB_PREFIX . "order_product` `op` ON (`o`.`order_id` = `op`.`order_id`) LEFT JOIN `" . DB_PREFIX . "product_to_download` `p2d` ON (`op`.`product_id` = `p2d`.`product_id`) LEFT JOIN `" . DB_PREFIX . "download` `d` ON (`p2d`.`download_id` = `d`.`download_id`) LEFT JOIN `" . DB_PREFIX . "download_description` `dd` ON (`d`.`download_id` = `dd`.`download_id`) WHERE `o`.`customer_id` = '" . (int)$this->customer->getId() . "' AND `o`.`store_id` = '" . (int)$this->config->get('config_store_id') . "' AND (" . implode(" OR ", $implode) . ") AND `dd`.`language_id` = '" . (int)$this->config->get('config_language_id') . "' ORDER BY `dd`.`name` DESC LIMIT " . (int)$start . "," . (int)$limit);
replace
Code: Select all
$query = $this->db->query("SELECT DISTINCT `d`.`download_id`, `o`.`order_id`, `o`.`date_added`, `dd`.`name`, `d`.`filename` FROM `" . DB_PREFIX . "order` `o` LEFT JOIN `" . DB_PREFIX . "order_product` `op` ON (`o`.`order_id` = `op`.`order_id`) LEFT JOIN `" . DB_PREFIX . "product_to_download` `p2d` ON (`op`.`product_id` = `p2d`.`product_id`) LEFT JOIN `" . DB_PREFIX . "download` `d` ON (`p2d`.`download_id` = `d`.`download_id`) LEFT JOIN `" . DB_PREFIX . "download_description` `dd` ON (`d`.`download_id` = `dd`.`download_id`) WHERE `o`.`customer_id` = '" . (int)$this->customer->getId() . "' AND `o`.`store_id` = '" . (int)$this->config->get('config_store_id') . "' AND (" . implode(" OR ", $implode) . ") AND `dd`.`language_id` = '" . (int)$this->config->get('config_language_id') . "' ORDER BY `o`.`date_added` DESC LIMIT " . (int)$start . "," . (int)$limit);
Re: SOLVED Sort download files - data added
Posted: Tue Mar 04, 2025 9:42 pm
by by mona
Great well done - thank you for posting your solution.
Thank you for adding [SOLVED] to the title
If you would be so kind as to use the </> mark up when posting code.
Highlight the first first part of the code and press the </> button in the button bar.
Do the same for the second (replacement) code
For anyone wishing to understand
Customer Account Downloads are not ordered randomly they are ordered by name
THIS => ORDER BY `dd`.`name
The user wanted it ordered by date added
THIS => ORDER BY `o`.`date_added`
What is written above is basically to replace the ORDER BY from name to date_added
The references dd and o are shorthand table names
If you look at the code you can see that they are shortened by
THIS => DB_PREFIX . "download_description` `dd`
THIS => DB_PREFIX . "order` `o`