Display order of images.

  • Posts: 292
  • Thank you received: 5
  • Hikashop Business
13 years 11 months ago #4623

Hikashop 1.4.2, Joomla 1.6
Imported a number of products each with several images.
Images appear to be displayed in descending ID order.
I.E. the most recent image appears as the default.
Could this be changed to make images appear in the order in which they are added / listed in the import CSV file?

Please Log in or Create an account to join the conversation.

  • Posts: 83041
  • Thank you received: 13405
  • MODERATOR
13 years 11 months ago #4628

Mmm. The images as well as anything else in the CSV should be entered in the same order you entered them.
If you activate the debug mode of joomla and that you try again, could you check on the query on the table hikashop_files ?
Normally, the files in there should be in the same order as you entered them.
If that's the case, then, it means that mysql might be inserting them in reverse order...In which case we will have to reverse the array of files before building the query.
If that's not the case, then maybe there is a bug in hikashop. Funny enough though you should be able to fix that with the same change: reverse the array of files.


For that, in the function _insertFiles(&$products,$type='files') of the file administrator/components/com_hikashop/helpers/import.php you can add the code:
$values = array_reverse($values);
just before the code
$this->db->setQuery($insert.implode('),(',$values).')');

Please Log in or Create an account to join the conversation.

  • Posts: 292
  • Thank you received: 5
  • Hikashop Business
13 years 11 months ago #4654

(a) In the product screen the query looks like this (some places with IN other places with =):

SELECT *
FROM saj_hikashop_file
WHERE file_ref_id IN (142)
AND file_type = 'product'

Could it be changed to:

SELECT *
FROM saj_hikashop_file
WHERE file_ref_id IN (142)
AND file_type = 'product'
ORDER BY file_id ASC


(b) In the category product listing screen the query looks like this:

SELECT a.*,b.*
FROM saj_hikashop_category AS a
LEFT JOIN saj_hikashop_file AS b
ON a.category_id=b.file_ref_id
AND b.file_type='category'
WHERE a.category_id = 1
LIMIT 1

Could it be changed to:

SELECT a.*,b.*
FROM saj_hikashop_category AS a
LEFT JOIN saj_hikashop_file AS b
ON a.category_id=b.file_ref_id
AND b.file_type='category'
WHERE a.category_id = 1
ORDER BY b.file_id ASC
LIMIT 1


For (a) I could solve this in the product template by running my own PHP sort function over '$this->element->images'.

For (b) looks like it would be more work in the category template as I would have to write my own query.

Without the ORDER BY is relying on the database engine implementation as to which is the first and may change with different versions / engines.

Please Log in or Create an account to join the conversation.

  • Posts: 83041
  • Thank you received: 13405
  • MODERATOR
13 years 11 months ago #4666

Hi,

Great, so that means that the problem isn't in the import but in the SELECT query.
An order by on the file info loading query would indeed be great.


The query you talk about in b isn't the query loading the product images but the query loading the categories image. As there is only one image per category, this is not needed.
The query for both the product page and the products listing is actually the same.

If you change the file components/com_hikashop/views/product/view.html.php by the one in that package, that should fix the problem. That will of course be included in next version.

File Attachment:

File Name: view-20110107.zip
File Size:6 KB

Attachments:

Please Log in or Create an account to join the conversation.

  • Posts: 292
  • Thank you received: 5
  • Hikashop Business
13 years 11 months ago #4670

Thanks.

Please Log in or Create an account to join the conversation.

Time to create page: 0.060 seconds
Powered by Kunena Forum