Ordering download files

  • Posts: 63
  • Thank you received: 1
  • Hikashop Essential
9 years 9 months ago #164080

-- url of the page with the problem -- : mywebsite.com/mypage
-- HikaShop version -- : 2.3.2
-- Joomla version -- : 3.3
-- PHP version -- : 5.4

Hello,

For a downloadable product that has several files to be downloaded, is it possible to sort the download files so that they appear alphabetically? Right now they seem to be in almost random order and I can't find any way to order them (see attachment).

Thanks in advance!

Andre

Attachments:

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

  • Posts: 26000
  • Thank you received: 4004
  • MODERATOR
9 years 9 months ago #164081

Hi,

The product files are sorted by "file_ordering" and then by "file_id".
If you want to change the sorting, you will have to edit a core file (not really recommended) or to use a view override to change the sorting before the display of the list.

In the view "backend | your_backend_temple | product | file" you will find the code which display the list of product files.

The easier will be to re-generate the file list before the display.

$product_id = hikashop_getCID('product_id');
$database = JFactory::getDBO();
if(!empty($product_id) {
	$query = 'SELECT * FROM '.hikashop_table('file').' WHERE file_ref_id = '.$product_id.' AND file_type=\'file\' ORDER BY file_name ASC, file_ordering ASC, file_id ASC';
	$database->setQuery($query);
	$this->element->files = $database->loadObjectList('file_id');
	if(!empty($this->element->files)){
		$query = 'SELECT SUM(download_number) AS download_number,file_id FROM '.hikashop_table('download').' WHERE file_id IN ( '.implode(',',array_keys($this->element->files)).' ) GROUP BY file_id';
		$database->setQuery($query);
		$downloads = $database->loadObjectList('file_id');
		if(!empty($downloads)){
			foreach($downloads as $download){
				$this->element->files[$download->file_id]->download_number = $download->download_number;
			}
		}
	}
}

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

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

  • Posts: 63
  • Thank you received: 1
  • Hikashop Essential
9 years 9 months ago #164169

Many thanks for your answer, but what you are saying is not really clear:

In the view "backend | your_backend_temple | product | file"


What do you mean by "view"? Are you talking about Joomla menus? Or Hikashop menus? Or ftp file structure? Or database structure?

The easier will be to re-generate the file list before the display.


What do you mean by that? To replace some code in the file with the code you have given?

Last edit: 9 years 9 months ago by jazzbird.

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

  • Posts: 26000
  • Thank you received: 4004
  • MODERATOR
9 years 9 months ago #164170

Hi,

One basic in HikaShop is the view override.
www.hikashop.com/support/support/documen...ize-the-display.html
www.hikashop.com/support/documentation/i...op-view-listing.html

It allows you to customize HikaShop without editing core file, so you can update HikaShop without loosing your modifications.

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

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

  • Posts: 63
  • Thank you received: 1
  • Hikashop Essential
9 years 9 months ago #164182

Ok thanks, I found the file, but your previous message is still not clear. Am I supposed to insert your code anywhere in the file ? Or should I replace all the existing code in the file with your code?

Last edit: 9 years 9 months ago by jazzbird.

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

  • Posts: 26000
  • Thank you received: 4004
  • MODERATOR
9 years 9 months ago #164187

Hi,

When you have to replace some code, I mention the code before and the code after.
The code I gave you is a piece of code you have to add in the view ; before the display ; which means : at the beginning of the file.

Is it more clear ?

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

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

  • Posts: 63
  • Thank you received: 1
  • Hikashop Essential
9 years 9 months ago #164293

It's still not working.

When you write "at the beginning of the file" I assume you mean after the initial <?php , correct?

Still, when I add your code, it completely messes up the backend display so that Joomla becomes inoperable. And the notification email continues to display the download links in an apparently random order (see attached). How to order them alphabetically?

Andre

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

  • Posts: 13201
  • Thank you received: 2322
9 years 9 months ago #164333

Hi,

Thanks to use that code:

<?php
$product_id = hikashop_getCID('product_id');
$database = JFactory::getDBO();
if(!empty($product_id)) {
	$query = 'SELECT * FROM '.hikashop_table('file').' WHERE file_ref_id = '.$product_id.' AND file_type=\'file\' ORDER BY file_name ASC, file_ordering ASC, file_id ASC';
	$database->setQuery($query);
	$this->element->files = $database->loadObjectList('file_id');
	if(!empty($this->element->files)){
		$query = 'SELECT SUM(download_number) AS download_number,file_id FROM '.hikashop_table('download').' WHERE file_id IN ( '.implode(',',array_keys($this->element->files)).' ) GROUP BY file_id';
		$database->setQuery($query);
		$downloads = $database->loadObjectList('file_id');
		if(!empty($downloads)){
			foreach($downloads as $download){
				$this->element->files[$download->file_id]->download_number = $download->download_number;
			}
		}
	}
}
?>
There was just a missing parenthesis ;)

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

  • Posts: 63
  • Thank you received: 1
  • Hikashop Essential
9 years 9 months ago #164402

Thanks, but it still doesn't work. I have added the code at the beginning of the file as you indicated, but it makes no difference at all.

The download links are still disorganized and apparently in random order, either when looking at the product in the back end, or also in the customer notification email.

Still hoping for a solution.

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

  • Posts: 81481
  • Thank you received: 13062
  • MODERATOR
9 years 9 months ago #164435

Hi,

I can see that you didn't enter any name for the files in your first screenshot, so it's normal that the code of Xavier doesn't do anything.
Instead, use that code:

<?php
$product_id = hikashop_getCID('product_id');
$database = JFactory::getDBO();
if(!empty($product_id)) {
	$query = 'SELECT * FROM '.hikashop_table('file').' WHERE file_ref_id = '.$product_id.' AND file_type=\'file\' ORDER BY file_path ASC, file_ordering ASC, file_id ASC';
	$database->setQuery($query);
	$this->element->files = $database->loadObjectList('file_id');
	if(!empty($this->element->files)){
		$query = 'SELECT SUM(download_number) AS download_number,file_id FROM '.hikashop_table('download').' WHERE file_id IN ( '.implode(',',array_keys($this->element->files)).' ) GROUP BY file_id';
		$database->setQuery($query);
		$downloads = $database->loadObjectList('file_id');
		if(!empty($downloads)){
			foreach($downloads as $download){
				$this->element->files[$download->file_id]->download_number = $download->download_number;
			}
		}
	}
}
?>
That will order the files instead on the filename of the files on the backend.

For the customer emails, you need to change the line:
$query = 'SELECT a.* FROM '.hikashop_table('file').' AS a WHERE '.implode(' AND ',$filters).' ORDER BY file_ref_id ASC, file_ordering ASC';
to:
$query = 'SELECT a.* FROM '.hikashop_table('file').' AS a WHERE '.implode(' AND ',$filters).' ORDER BY file_ref_id ASC, file_path ASC, file_ordering ASC';
in the file administrator/components/com_hikashop/classes/order.php

The following user(s) said Thank You: jazzbird

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

  • Posts: 63
  • Thank you received: 1
  • Hikashop Essential
9 years 9 months ago #164523

Your code fixed the ordering problem in the backend display - thanks!

However, changing the line in order.php did not fix the order of the downloads in the notification email. They are still disordered.

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

  • Posts: 63
  • Thank you received: 1
  • Hikashop Essential
9 years 9 months ago #164526

OK, I was finally able to fix the problem in the notification email.

There was a second query on line 905 of order.php which I changed to

$query = 'SELECT b.*,a.* FROM '.hikashop_table('file').' AS a LEFT JOIN '.hikashop_table('download').' AS b ON b.order_id='.$order->order_id.' AND a.file_id = b.file_id WHERE '.implode(' AND ',$filters).' ORDER BY file_ref_id ASC, file_path ASC, file_ordering, file_pos ASC';

Thank you!

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

  • Posts: 63
  • Thank you received: 1
  • Hikashop Essential
9 years 1 month ago #192438

Hello Nicolas and Xavier,

To come back to an old post: I was wondering if it were possible to add the fixes above in a future update of Hikashop, so that the download files are always ordered in both the backend and in the confirmation email? It is rather tedious to have to go back and to change the core files every time Hikashop is updated.

Thanks!

Andre

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

  • Posts: 81481
  • Thank you received: 13062
  • MODERATOR
9 years 1 month ago #192484

Hi,

The files are ordered based on their file_ordering. Actually the interface doesn't allow you to set the ordering of the files, only the images. That's something we want to support in one of the next versions of HikaShop.
So we can't add that "fix" as it will break the sorting by the ordering of the files.

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

  • Posts: 63
  • Thank you received: 1
  • Hikashop Essential
7 years 7 months ago #248525

I am disappointed that more than 2 years later, this problem is still ongoing: for a product with multiple download files, the notification email to the customer lists the files in random and totally disorganized order. Does this mean that every time I update Hikashop I will have to hack the core files just to get the downloads to display in order? When will this be fixed?

Thanks,

Last edit: 7 years 7 months ago by jazzbird.

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

  • Posts: 26000
  • Thank you received: 4004
  • MODERATOR
7 years 7 months ago #248529

Hi,

I'm sorry but it is possible to change the ordering of product files.
You can drag'n'drop the product files like you can drag'n'drop the product images.

So, I'm afraid that the feature is already there.
And you can also see in the changelog that HikaShop 2.6.2 include a little fix for the product file ordering saving.

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

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

  • Posts: 63
  • Thank you received: 1
  • Hikashop Essential
7 years 7 months ago #248549

You are talking about the site backend - and good, I'm glad that's now possible. But I'm talking about the order email sent to the customer with the download links. These links were listed in totally disorganized manner until I hacked the order.php file to have them list alphabetically. So the problem still exists in the notification email.

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

  • Posts: 26000
  • Thank you received: 4004
  • MODERATOR
7 years 7 months ago #248553

Hi,

Okay, I see.
In the HikaShop order class, the product files are loaded and added in the order object.
That is mostly done by the function "_setDownloadFile".
You can see to replace how the variable $id is generated ; from

$id = $file->file_id.'_'.(int)$file->file_pos;
To
$id = $file->file_ordering.'_'.$file->file_id.'_'.(int)$file->file_pos;
Then, in the function just above, you have to order the files depending their key.
You will find the loop
if(!empty($files)) {
	foreach($products as $k => $product) {
		$products[$k]->files = array();
And in the end of that loop, you have to add
		ksort($products[$k]->files);
	}
}
So the added files will be sorted depending the key (now composed with the file ordering value).

Thus, you should get the same ordering in the loaded order than the ordering set in the products.

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.
The following user(s) said Thank You: jazzbird

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

  • Posts: 63
  • Thank you received: 1
  • Hikashop Essential
7 years 2 months ago #262081

In the HikaShop order class, the product files are loaded and added in the order object.
That is mostly done by the function "_setDownloadFile".


I don't understand this answer. What is the "HikaShop order class" and what is the function "_setDownloadFile"?

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

  • Posts: 81481
  • Thank you received: 13062
  • MODERATOR
7 years 2 months ago #262094

Hi,

The HikaShop order class is the file administrator/components/com_hikashop/classes/order.php
There, you'll find the function _setDownloadFile near line 1600
Note that a more complete patch has been added by Jerome to HikaShop 3.0.0 for that, so if you're on HikaShop 3.0.0, that patch shouldn't be needed.

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

Time to create page: 0.069 seconds
Powered by Kunena Forum