Post by dashik » Sat Nov 14, 2009 3:19 am

I want to utilize the downloads feature more as a place where we can upload things like PDFs and informative documents that are vital to each product WITHOUT actually having to purchase anything to view these files.

They would be listed right on the product.tpl template.

I noticed that there is a public function in admin/model/catalog/product.php and I think it looks like it might do what I need it to do but I can't quite figure out how to use it.

Is there a way to call this directly into catalog/view/theme/default/template/product/product.tpl somehow?

Code: Select all

	public function getProductDownloads($product_id) {
		$product_download_data = array();
		
		$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_to_download WHERE product_id = '" . (int)$product_id . "'");
		
		foreach ($query->rows as $result) {
			$product_download_data[] = $result['download_id'];
		}
		
		return $product_download_data;
	}
Thanks! ;D

New member

Posts

Joined
Fri Jul 31, 2009 8:10 pm

Post by Qphoria » Sat Nov 14, 2009 3:54 am

why not just put a separate folder on your ftp and put a link to the files on your site?

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by dashik » Sat Nov 14, 2009 5:12 am

I guess technically I could do that but I love the idea of being able to simply upload and manage uploads via the opencart backend. Plus, my client is more of a visual person and not very tech-savvy. ;D

Is there any way to get them to display on the product page?

I ran a few tests and I do indeed see them in the downloads folder and in the database.

Would the SQL query above not work for this?

I'm thinking it's got to be just a matter of grabbing them via some sort of SQL query and displaying them on the products.tpl template.

New member

Posts

Joined
Fri Jul 31, 2009 8:10 pm

Post by Qphoria » Sat Nov 14, 2009 5:26 am

it should work. You seem to have done the research so try it out.
Check out how the link is structured in the downloads area for normal downloads.

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by dashik » Sat Nov 14, 2009 5:54 am

Qphoria wrote:it should work. You seem to have done the research so try it out.
Check out how the link is structured in the downloads area for normal downloads.
Where is the downloads area template located?

Is it catalog/view/theme/default/template/account/download.tpl? Doesn't seem right but it's the only one I have found.

New member

Posts

Joined
Fri Jul 31, 2009 8:10 pm

Post by Qphoria » Sat Nov 14, 2009 6:07 am

that is the correct path.

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by dashik » Sat Nov 14, 2009 8:47 am

Thanks Q, you put me on the right track.

Now -- i have the following code working but it only returns one result. I'm pretty sure I'll need to join these table queries somehow but my SQL skills are VERY limited.

Do any MySQL experts want to take a stab at joining these 3 queries into one so I can then display more than one result at a time?

Thanks!

Code: Select all

<?php
mysql_connect("hostname", "user", "pass") or die(mysql_error());
mysql_select_db("opencartdb") or die(mysql_error());
      
$result = mysql_query("SELECT * FROM " . DB_PREFIX . "product_to_download WHERE product_id = '" . (int)$product_id . "'");
      
$row = mysql_fetch_array( $result );

$result2 = mysql_query("SELECT * FROM " . DB_PREFIX . "download WHERE download_id = '" . (int)$row['download_id'] . "'");

$row2 = mysql_fetch_array( $result2 );

$result3 = mysql_query("SELECT * FROM " . DB_PREFIX . "download_description WHERE download_id = '" . (int)$row['download_id'] . "'");

$row3 = mysql_fetch_array( $result3 );

echo "<a href='http://www.domain.com/products/download/";
echo "".$row2['filename']."' target='_blank'>".$row3['name']."</a>";

?>
Yes, it's quite ugly but it does pull up a single result lol

New member

Posts

Joined
Fri Jul 31, 2009 8:10 pm
Who is online

Users browsing this forum: No registered users and 285 guests