Post by opencartnewbie_vn » Sat Aug 29, 2015 10:42 am

I want to sort image by date upload in Imang Manager Opencart 1.5.x by fix in PHP code.
Anyone know the way to do this.
Thanks so much


Posts

Joined
Sat Aug 29, 2015 10:39 am

Post by opencartnewbie_vn » Sat Aug 29, 2015 4:51 pm

Up :( :( :(


Posts

Joined
Sat Aug 29, 2015 10:39 am

Post by straightlight » Sat Aug 29, 2015 9:58 pm

Hi,

that is an interesting request. In admin/controller/common/filemanager.php file,

find:

Code: Select all

$directories = glob($directory . '/' . $filter_name . '*', GLOB_ONLYDIR);
add after:

Code: Select all

usort($directories, create_function('$a,$b', 'return filemtime($a) - filemtime($b);'));
Reversed order (if needed):

Code: Select all

usort($directories, create_function('$a,$b', 'return filemtime($b) - filemtime($a);'));
This should resolved the ordering list.

Source: http://stackoverflow.com/questions/1249 ... rt-by-date

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by opencartnewbie_vn » Sun Aug 30, 2015 5:53 pm

I'm so sorry but I can not find this line in admin/controller/common/filemanager.php file

Code: Select all

$directories = glob($directory . '/' . $filter_name . '*', GLOB_ONLYDIR);


Posts

Joined
Sat Aug 29, 2015 10:39 am

Post by straightlight » Sun Aug 30, 2015 9:39 pm

For 1.5x releases, this would be the line to track on the same controller file:

Code: Select all

$directories = glob(rtrim(DIR_IMAGE . 'data/' . str_replace('../', '', $this->request->post['directory']), '/') . '/*', GLOB_ONLYDIR);

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by seorniyc » Wed Sep 30, 2015 5:32 pm

Hi ;

I have same problem. I have many folders named 1501 , 1502 .... 1550.. I upload new products images on folder and when i add products photo go to last page, select folder....

I want change sort order to desc. If i see last folder in first i add very easy.

Straighlight this fix not working in 2.0.0.31

can you help me ?

Thanks

straightlight wrote:Hi,

that is an interesting request. In admin/controller/common/filemanager.php file,

find:

Code: Select all

$directories = glob($directory . '/' . $filter_name . '*', GLOB_ONLYDIR);
add after:

Code: Select all

usort($directories, create_function('$a,$b', 'return filemtime($a) - filemtime($b);'));
Reversed order (if needed):

Code: Select all

usort($directories, create_function('$a,$b', 'return filemtime($b) - filemtime($a);'));
This should resolved the ordering list.

Source: http://stackoverflow.com/questions/1249 ... rt-by-date

Newbie

Posts

Joined
Tue Sep 08, 2015 4:52 pm

Post by straightlight » Thu Oct 01, 2015 6:57 am

Straighlight this fix not working in 2.0.0.31

can you help me ?
Yes, by describing exactly what you mean by not working, a possible solution could be provided on that end.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by seorniyc » Fri Oct 02, 2015 9:46 pm

Dear straightlight ;

I try your fix, but not change order. I add new folders but they are going to last. Not first.

Attachments

folders.jpg

Folders already sort by asc. name. I need reverse. - folders.jpg (52.01 KiB) Viewed 8222 times


Newbie

Posts

Joined
Tue Sep 08, 2015 4:52 pm

Post by straightlight » Fri Oct 02, 2015 9:51 pm

In the same file,

find:

Code: Select all

$files = glob($directory . '/' . $filter_name . '*.{jpg,jpeg,png,gif,JPG,JPEG,PNG,GIF}', GLOB_BRACE);
add after:

Code: Select all

usort($files, create_function('$a,$b', 'return filemtime($a) - filemtime($b);'));

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by seorniyc » Sat Oct 03, 2015 4:09 pm

straighlight

thanks for reply but nothing to change. its sort by name asc.

actually i need only sort reverse. if i can sort name desc. i use easyly.

thanks.

Newbie

Posts

Joined
Tue Sep 08, 2015 4:52 pm

Post by straightlight » Sat Oct 03, 2015 7:20 pm

Code: Select all

usort($files, create_function('$a,$b', 'return filemtime($b) - filemtime($a);'));
Reversed order ...

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by seorniyc » Mon Oct 05, 2015 3:44 pm

straightlight wrote:

Code: Select all

usort($files, create_function('$a,$b', 'return filemtime($b) - filemtime($a);'));
Reversed order ...

Dear straightlight ;

Thanks again, but nothing change. still the files and folders sort by name , sort order asc .

You try this code ? is that work ?

Whats wrong can you look ? filemanager.php attach.

Thanks.

Newbie

Posts

Joined
Tue Sep 08, 2015 4:52 pm

Post by straightlight » Thu Oct 08, 2015 8:32 am

The reason why the sort order is not applying the change on the image list is because the file dates is not included in the array from the controller. In order to re-order the list, the file added date the images has been uploaded must be captured as well. Otherwise, the order will never change.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by rmandiga » Sat Dec 26, 2015 7:02 am

Worked for me. changed the code and clicked on modifications for refresh.

Now images showing up in reverse order.

Looking to remove pagination to have all images to scroll down.


Thanks Straight !!!

Newbie

Posts

Joined
Fri Oct 16, 2015 9:43 pm

Post by coldrex » Fri Jul 15, 2016 12:18 am

rmandiga wrote:Worked for me. changed the code and clicked on modifications for refresh.

Now images showing up in reverse order.

Looking to remove pagination to have all images to scroll down.


Thanks Straight !!!
Exactly what I need also. Any news?

User avatar
New member

Posts

Joined
Thu Jun 07, 2012 10:05 pm

Post by gilles85 » Sat Aug 20, 2016 9:57 am

straightlight wrote:For 1.5x releases, this would be the line to track on the same controller file:

Code: Select all

$directories = glob(rtrim(DIR_IMAGE . 'data/' . str_replace('../', '', $this->request->post['directory']), '/') . '/*', GLOB_ONLYDIR);
Thank you mate it works :)

Cool Gadgets - Kitchen Gadget - Travel Gadgets - Pet Gadgets - Car Gadgets - Camping gear - Smartwatch on sale - Smart home gadgets


Newbie

Posts

Joined
Sat Aug 20, 2016 3:47 am

Who is online

Users browsing this forum: No registered users and 27 guests