Template customization category/listing_div

  • Posts: 38
  • Thank you received: 2
12 years 10 months ago #35178

I am trying to customize hika templates. It is not hard but I've meet some problem. In category/listing_div you have to options to show pagination on top or bottom.

But this is category list only. It is not product list. Why to show pagination at all? I would just delete this part of code as do not have more than 20 categories on one page and this is default query limit.

So what should I do with it?

Also I cannot understand what is product/listing template? I can see list of the products in category but I never switch to ctrl=product&task=listing. I can see all products in category/listing

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

  • Posts: 82910
  • Thank you received: 13379
  • MODERATOR
12 years 10 months ago #35192

You can remove the pagination code if you want if you don't use it. You can also keep it for the day when you will have more that 20 categories :)
That way it would display automatically if needed.

The product listing template is used for products listings.
You don't have to be on a page ctrl=product&task=listing to use it. Anywhere you see a products listing of HikaShop that file is used.

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

  • Posts: 38
  • Thank you received: 2
12 years 10 months ago #35200

I can see only one part of the code that shows product list in category/listing

if(!empty($this->modules)){
$html = '';
jimport('joomla.application.module.helper');
foreach($this->modules as $module){
$html .= JModuleHelper::renderModule($module);
}
if(!empty($html)){
echo '<div class="hikashop_submodules" style="clear:both">dddd'.$html.'dddd</div>';
}

}

And I did not see any product template load, that is why I thought.
Also it is very confusing what it $this->modules and $this->module. At first I thought it is for using this templates when render inside module. But somehow this contain list of products.

It is ok, I know now that I need to edit product/listing_div to correct product list rendering. But when code is clean it simplify work.

Anyway I very appreciate your quick response.

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

  • Posts: 82910
  • Thank you received: 13379
  • MODERATOR
12 years 10 months ago #35203

The code is clean don't worry :)
It's just that you an't load a template from another view like that.
In your category listing menus, you have an associated module which is the one displaying the products listing.
And that's why you have these module variables.

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

  • Posts: 38
  • Thank you received: 2
12 years 10 months ago #35281

But this module variables show list of products. What is I turn off all modules? How I can see list of products then?

Actually I cannot understand how it works. Because if I add menu link to Product listing I see no products. Because i do not have products in root category.

I think that category and product listing should be one layout. Like it is in category/listing. But it should show products not through module system but through template system.

But it is ok. It is just opinion one of many. most important that at the end I can do what I need :)

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

  • Posts: 38
  • Thank you received: 2
12 years 10 months ago #35282

Another question.

in category/listing I have this

if(!empty($this->fields)

Then it shows
echo JText::_('CATEGORY_ADDITIONAL_INFORMATION');

But no matter what i do I cannot forse to show anything. Where do i set additional category information?

Last edit: 12 years 10 months ago by Sergey Romanov.

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

  • Posts: 38
  • Thank you received: 2
12 years 10 months ago #35287

$this->setLayout('filter');
   echo $this->loadTemplate();

This code in product/listing gives error. Say that template not found.

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

  • Posts: 82910
  • Thank you received: 13379
  • MODERATOR
12 years 10 months ago #35302

The modules are called directly by HikaShop. They don't have to be published in joomla. They just have to be associated with the menu in the "associated modules" option of the menu.

Indeed by default, a listing of products menu will display the products in the root category. If you want to change that category or tell the system to display all the products even in sub categories, you need to edit the hikashop options of your menu and change the corresponding options 'parent category' and 'sub elements filter'.

There is no need to change the code to display the products. It's just a matter of configuring your menu (and its associated module if it's a category listing menu).

It's normal that the filter template loading code is not working if you're not using the Business edition as this template is only available in the Business edition.

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

  • Posts: 38
  • Thank you received: 2
12 years 10 months ago #35315

i have another quesion.

I try to customize hika as download section. And I want i said to show download link right in the list, It is ok and I think I will be able to load files and fetch them.

What I want also that if user already purchased this product, hide price and write "Free download" or "Download Allowed". How to check if this user have had purchased this product with confirmed status?

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

  • Posts: 82910
  • Thank you received: 13379
  • MODERATOR
12 years 10 months ago #35324

You will have to do a query like that:
$query = 'SELECT a.order_id FROM '.hikashop_table('order').' AS a WHERE a.order_user_id='.(int)hikashop_loadUser();
$this->database->setQuery($query);
$order_ids = $this->database->loadResultArray();
if(!empty($order_ids)){
$filters = array('a.file_ref_id='.$products_id,'a.file_type=\'file\'','a.file_id='.$file_id);
$query = 'SELECT a.*,b.* FROM '.hikashop_table('file').' AS a LEFT JOIN '.hikashop_table('download').' AS b ON b.order_id IN ('.implode(',',$order_ids).') AND a.file_id = b.file_id WHERE '.implode(' AND ',$filters);
$this->database->setQuery($query);
$fileData = $this->database->loadObject();
if(!empty($fileData)){
//display link
}
}

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

  • Posts: 38
  • Thank you received: 2
12 years 10 months ago #35379

This is good example. I cannot find only one thing. Where do I take $file_id?

If I var_dump $this->row I get file information

["file_id"]=>
  string(2) "12"
  ["file_name"]=>
  string(0) ""
  ["file_description"]=>
  string(0) ""
  ["file_path"]=>
  string(7) "2co.png"
  ["file_type"]=>
  string(7) "product"
  ["file_ref_id"]=>
  string(1) "2"
  ["file_free_download"]=>
  string(1) "0"

But in all cases this is reference to thumbnail file not to download one. Should I also make another query to get list of product attached download files? What if I have 3-5 files to download along with one product?

Problem 2
If I make order "confirmed" in backend nothing get into file_download table. How records get there? Why product show Download period elapsed when I just created confirmed order? Any way I cannot manage to allow download file. Even to show it in the product.

Last edit: 12 years 10 months ago by Sergey Romanov.

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

  • Posts: 38
  • Thank you received: 2
12 years 10 months ago #35380

Here is how I solved to show file download link or not.

$query = 'SELECT product_id 
	FROM '.hikashop_table('order_product').
	' WHERE order_id IN (
		SELECT order_id FROM '.hikashop_table('order')." 
		WHERE order_status = 'confirmed' AND order_user_id = ".(int)hikashop_loadUser().")";
$this->database->setQuery($query);
$this->product_ids = $this->database->loadResultArray();

I get product ids. Then it is easy
if(in_array($this->row->product_id, $this->product_ids))
{
	//Show download link
}

The only one thing I cannot solve that file in not downloaded anyway. Probably because order marked confirmed in backend and there is nothing in file_download table.

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

  • Posts: 82910
  • Thank you received: 13379
  • MODERATOR
12 years 10 months ago #35413

The files are not loaded by default in listings. To get the file_id you first need to load all the files of the product:
$query ='SELECT a.* FROM '.hikashop_table('file').' WHERE file_ref_id = '.$product_id.' AND file_type = \'file\';


Your code is great. After that code you should simplify the code I posted and do something like that:
$filters = array('a.file_ref_id='.$this->product_ids,'a.file_type=\'file\'','a.file_id='.$file_id);
$query = 'SELECT a.* FROM '.hikashop_table('file').' AS a WHERE '.implode(' AND ',$filters);
$this->database->setQuery($query);
$fileData = $this->database->loadObject();

because there is no need to make any link between orders and files via the download table since you already did it with your query.

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

  • Posts: 38
  • Thank you received: 2
12 years 10 months ago #35547

This is what I am doing.

if($this->product_ids)
{
	$query = 'SELECT a.* FROM '.hikashop_table('file')." AS a WHERE a.file_type='file'";
	$this->database->setQuery($query);
	$files = $this->database->loadObjectList();
	foreach ($files AS $product_id => $file)
	{
		$this->files[$file->file_ref_id] = JHTML::link('index.php?option=com_hikashop&ctrl=product&task=download&file_id='.$file->file_id, JText::_('Download'), array('class' => 'hasTip', 'title' => $file->file_name.'::'.htmlspecialchars($file->file_description, ENT_COMPAT, 'UTF-8')));
	}
}

I gel links to downland all files. Because some downloads are free. And i index it by product ID. Later in product
echo $this->files[$this->row->product_id];

Everything works good when I click on free download. But when I click on paid download link it says Order Not Found. I suspected that this is because file_download table is empty. I added there record for order Id and File ID but it did not change anything.

Attachments:
Last edit: 12 years 10 months ago by Sergey Romanov.

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

  • Posts: 38
  • Thank you received: 2
12 years 10 months ago #35548

[SOLVED]

Last edit: 12 years 10 months ago by Sergey Romanov.

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

  • Posts: 82910
  • Thank you received: 13379
  • MODERATOR
12 years 10 months ago #35572

You're missing the id of the order for which the product was bought in the URL of your download link.

You should change a bit the code of that query

$query = 'SELECT product_id  
    FROM '.hikashop_table('order_product'). 
    ' WHERE order_id IN ( 
        SELECT order_id FROM '.hikashop_table('order')."  
        WHERE order_status = 'confirmed' AND order_user_id = ".(int)hikashop_loadUser().")"; 
$this->database->setQuery($query); 
$this->product_ids = $this->database->loadResultArray();
in order to get the order_id so that you can add it to the URL. Then it will work.

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

  • Posts: 38
  • Thank you received: 2
12 years 10 months ago #35618

I found the error. In your controller/product.php you have

function download() {
	$file_id = JRequest::getInt('file_id');
	if(!$file_id){ return false; }
	$fileClass = hikashop_get('class.file');
	$fileClass->download($file_id);
	return true;
}

And in classes/file.php
$orderClass = hikashop_get('class.order');
$order = $orderClass->get($order_id);
if(empty($order) || $order->order_user_id != $user_id){
	$app->enqueueMessage(JText::_('ORDER_NOT_FOUND'));
	$this->error_type = 'no_order';
	return false;
}

But you do not pass $order_id in to download method of file. You need to add either
function download() {
	$file_id = JRequest::getInt('file_id');
	if(!$file_id){ return false; }
	$order_id = JRequest::getInt('order_id', 0);
	$fileClass = hikashop_get('class.file');
	$fileClass->download($file_id, $order_id);
	return true;
}

or
$orderClass = hikashop_get('class.order');
if(!$order_id) $order_id = JRequest::getInt('order_id', 0);
$order = $orderClass->get($order_id);
if(empty($order) || $order->order_user_id != $user_id){
	$app->enqueueMessage(JText::_('ORDER_NOT_FOUND'));
	$this->error_type = 'no_order';
	return false;
}

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

  • Posts: 82910
  • Thank you received: 13379
  • MODERATOR
12 years 10 months ago #35648

Ah no, I didn't saw it but you should use the controller order and not the controller product in your URL.
In the order controller, there is also a download task which handles both the file_id and the order_id.

It's normal that the product controller's download task only handle file_id as it is used for free downloads only.

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

Time to create page: 0.083 seconds
Powered by Kunena Forum