Jump to content

[Resolved] product image order


foz1234

Recommended Posts

We run two CC stores. I load images from the Product Filemanager tab. I load them in the order I want them to appear, but on one store the FIRST image is the starred main image, and on the other store the LAST image chosen is the starred main image. I have absolutely no idea why they work differently, but as long as I use the appropriate sequence for each store, they both end up with a series of images in the order I want them to be.

Link to comment
Share on other sites

that did not seem to work for me, but i do have other images in there, i will try tomorrow to remove all images and add in order, the starred images can be changed by selecting a product then images tab select a box keep pressing empty/tick/star. 

Link to comment
Share on other sites

This is what Brian said to do - works for me in 6.0.12  I number my images the way you do FOZ1234

In /classes/catalogue.class.php the private function _productGallery():

CODE

Find about 25 lines into the function:  Around Line 1747

$GLOBALS['smarty']->assign('GALLERY_JSON', json_encode($json));

return $return;

 

Edit:

$GLOBALS['smarty']->assign('GALLERY_JSON', json_encode($json));

asort($return); return $return;

Link to comment
Share on other sites

I create folders for my images in filemanager. ex. clocks/vintage-united-mantle-clock.  I had this product listed but decided to delete the images, clear cache, and create new image folder with a different name.  I then control/clicked all 8 images from my computer for this product at once and dropped and dragged them. Then went to the product and selected the images (as before) and saved.  Glad to report the edit from 6.0.12 works and my images were in the order I wanted. Nice to be able to do all 8 at once. It was a little confusing there was no save button after drop and drag though the images were checked.  Wasn't sure it had worked until i went to the parent directory. So if you number your images 01-???-front   02-???-side  03-???-top etc in the order you want them to appear you will be fine.  Just a note - it's important to put the 0 in front of your number in case you have over 10 images for a product.

Link to comment
Share on other sites

I use Photoshop.  I don't save them in photoshop though.  I "Save for the Web" to my computer in an individual file I've setup for each product.  This file includes the images, and since I move items between my store, Etsy and eBay I created a form that keeps track of where the item is listed, if it sold and where and how much.  This is handy if I get more or similar products. It also has the html code and plain text for Etsy for easy copy/paste into these venues.  The form has a lot more neat stuff too. Boy I rambled didn't I!  LOL.  Anyway when I want to delete the image from photoshop and it asks if I want to save it I say no since I have it on my computer where I can rename it whatever I want.

Link to comment
Share on other sites

Actually, after more experimentation, I conclude the asort($return) edit will not sort on the filename as hoped. Instead, it (unreasonably) sorts on the value of the first element in the second-tier array.

$result is an array of arrays. The sort function works on the first-tier values of the array. For $result, the first tier is another array. What could a sort work on if the expected argument is not something that can be sorted (like, a number or a word). For reasons unknown (and probably not reliably), the sort then grabs the value of the first element of the second tier array from each element in the main first tier array.

That value happens to be the "id" of the row returned from the query against the CubeCart_image_index table. Therefore, regardless of the actual order of rows returned by the database, the sort results in the order that CubeCart gave the list of records to be databased. (The table row "id" is auto-incremented.)

So, if the resulting gallery happens to be sorted by filename, it is completely coincidental and not intentional.

There is a hook we can use at this very spot in the code. I will have a better solution to getting the gallery sorted by filename shortly.

 

Link to comment
Share on other sites

In admin, Manage Hooks, Code Snippets tab, click Add Snippet.

Enabled: Checked
Unique ID: sort_gallery@cubecart
Execution Order: 99
Description: Sorts the Product's Image Gallery by Image Filename
Trigger: class.cubecart.gallery
Version: 1.0
Author: forums.cubecart.com product image order
PHP Code:

<?php
  $return_filenames = array_map(function($element){return $element['filename'];},$return);
  array_multisort($return_filenames,$return);
?>

Save.

What I have available to test this myself is already sorted by filename.

So, make a few tests for yourselves and see what happens. Specifically, look for instances where, when the page is first displayed, the "main" (starred) image is shown initially, but the gallery is sorted by filename.

Link to comment
Share on other sites

Ok it did as you said.  Starred image is shown initially but the gallery is sorted by filename.  Should I change the code /classes/catalogue.class.php the private function _productGallery(): back to what it is originally? See above post

Thanks Brian

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...