Author Topic: Sorting / Ordering Additional Product Images  (Read 7406 times)

qwertyqwerty

  • Beginner
  • *
  • Posts: 1
Sorting / Ordering Additional Product Images
« on: January 18, 2011, 02:10:08 am »
Is there any easy way to do this?

I uploaded my images in order with neatly-numbered filenames, yet the images appear out of order on screen.

Even just alphabetically sorting ability would help. May not work for all occasions but it will certainly take care of most cases.

Any ideas anyone?

DSC

  • Beginner
  • *
  • Posts: 17
Re: Sorting / Ordering Additional Product Images
« Reply #1 on: January 19, 2011, 22:55:24 pm »
Mine show just fine in order, the way i added them as extra images, and the filenames aren't even in alpha order. I think there are a couple ways to do this but only one fail-safe way (from what i've experienced).

One the Products List page, there is a media column with a number like (2). Click the media file/number you want to add new images and a new window will pop up. In that new window, i leave pretty much everything the same. I choose my image to upload, and leave it at, "default product image path", and i put in a file title and click save.

After that, i don't think you can move them up or down but you can delete and insert again if you want. All mine show in order the way i uploaded them.

Hopefully this links to the correct place i want but see the link below and see if you are uploading additional images like this.
http://virtuemart.net/documentation/User_Manual/Product_Files_and_Images.html

Comeskey

  • Jr. Member
  • **
  • Posts: 147
Re: Sorting / Ordering Additional Product Images
« Reply #2 on: January 29, 2011, 21:51:15 pm »
As far as I can tell, Virtuemart uses the same order that the images appear in the database.  However, for reasons that I don't yet understand, it looks like the database sometimes orders the images out of sequence (ie: not according to file_id).

It seems to me that the underlying problem is with the database.  But I don't know how to fix the database, so I cheated and added an ordering statement to the product files function.

In file: administrator/components/com_virtuemart/classes/ps_product_files.php.  Line 667, find:
Code:

Code: [Select]
$db->query( "SELECT * FROM `#__{vm}_product_files` WHERE `file_product_id`=".intval($pid)." AND `file_is_image`=1 AND `file_published`=1 );
Add an ordering rule that says, "ORDER BY file_id ASC", so that you end up with:


Code: [Select]
$db->query( "SELECT * FROM `#__{vm}_product_files` WHERE `file_product_id`=".intval($pid)." AND `file_is_image`=1 AND `file_published`=1 ORDER BY file_id ASC" );

Seems to be working for me.
RESIST Theocratic Police-State Feudalism!

nickwalks

  • Beginner
  • *
  • Posts: 14
Re: Sorting / Ordering Additional Product Images
« Reply #3 on: March 30, 2011, 06:35:42 am »
Firstly thanks Comesky for the workaround.

It worked - well it worked when it decided it wanted to!

Anyway after heaps of frustration with the ordering of images showing up all out of whack I think I have found a solution. It has worked for me - 6 products in with a dozen images each and not one problem...

Ok what I did was first add Comesky's fix. Then open FileManager::Image/File List for a product. Click on new. Select the file to upload. Then the important part that I think has something to do with the order. Select additional file from the file type. Then switch it back to additional image. Hey presto the image appears in order.

Not sure 100% why but it seems just leaving it highlighted initially as additional image is not being picked up correctly and the order is all screwed up...

Hope this helps others out there with the same problem.

aardwolfau

  • Beginner
  • *
  • Posts: 8
Re: Sorting / Ordering Additional Product Images
« Reply #4 on: May 23, 2011, 06:03:18 am »
Thanks guys, this fix also worked for me as well

lorderrick

  • Beginner
  • *
  • Posts: 1
Re: Sorting / Ordering Additional Product Images
« Reply #5 on: September 01, 2011, 09:11:15 am »
Works for me too! Thanks for the post!

Cheers!

rysk

  • Beginner
  • *
  • Posts: 2
Re: Sorting / Ordering Additional Product Images
« Reply #6 on: September 28, 2011, 07:00:11 am »
this doesn't seem to be working for me.  anyone have any other suggestions or know what I might be doing wrong???

enteng011

  • Beginner
  • *
  • Posts: 5
Re: Sorting / Ordering Additional Product Images
« Reply #7 on: October 24, 2011, 00:09:30 am »
it doesn't seem to be working for me either, what version is everyone using that got this working? I'm currently on 1.1.8 on Joomla 1.5.20.

I can't see why wouldn't be working as it is a general sql function to order. Could anyone advice what could be going wrong? Or even if there is another way to order the table without this function.

Thanks for anyone that can help with this.

EDIT:
I have figured it out. What i did and it worked for me. ( After including the above advice)
I opened up the "jos_vm_product_files" table within SQL then clicked operations up the top then in the 'Alter table order by' selected file_id ascending (ideally what the PHP code Comesky put up was doing but on the sql level)

Comeskey

  • Jr. Member
  • **
  • Posts: 147
Re: Sorting / Ordering Additional Product Images
« Reply #8 on: October 24, 2011, 03:31:48 am »
I have figured it out. What i did and it worked for me. ( After including the above advice)
I opened up the "jos_vm_product_files" table within SQL then clicked operations up the top then in the 'Alter table order by' selected file_id ascending (ideally what the PHP code Comesky put up was doing but on the sql level)
I think this is actually a better fix.  As I noted, the problem is that the database is not sorting in order.  So forcing the table to order by ID is probably preferred. Nice job!!  What did you use to manage the table?  phpmyadmin?
RESIST Theocratic Police-State Feudalism!

cfleck1980

  • Beginner
  • *
  • Posts: 5
Re: Sorting / Ordering Additional Product Images
« Reply #9 on: February 06, 2013, 12:11:09 pm »
ALTER TABLE  `jos_vm_product_files` ORDER BY  `file_id`

is the SQL query u need