order by cheapest price!

  • Posts: 25
  • Thank you received: 0
12 years 3 months ago #57655

Hi again i use the starter edition and i need to show my products order by cheapest (lower price)
i do not want to be a choice - filter i just want to show my products from cheapest to more expensive.
Thank you again!

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

  • Posts: 13201
  • Thank you received: 2322
12 years 3 months ago #57679

Hi papaleksi,

To change the ordering, you have to edit the file: YourSite/components/com_hikashop/views/product/view.html.php
And in the "listing()" function edit the ordering in the SQL Request.

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

  • Posts: 25
  • Thank you received: 0
12 years 3 months ago #57706

Thank you for your answer do you mean to change ....
if($this->params->get('product_order')=='ordering'){....


and change "ordering" with "product_price"?

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

  • Posts: 13201
  • Thank you received: 2322
12 years 3 months ago #57757

Hi papaleski,

You can add this line:

		$order = ' ORDER BY c.price_value ASC';

Just after:
		if(!empty($pageInfo->filter->order->value)){
			$order = ' ORDER BY '.$pageInfo->filter->order->value.' '.$pageInfo->filter->order->dir;
		}

And replace the line:
		$query = $select2.' FROM '.$b.$a.$on.' WHERE '.implode(' AND ',$filters).$order;
By:
		$query = $select2.' FROM '.$b.$a.$on.' LEFT JOIN '.hikashop_table('price').' AS c ON c.price_product_id=b.product_id WHERE '.implode(' AND ',$filters).$order;

Last edit: 12 years 3 months ago by Xavier.
The following user(s) said Thank You: FranksBank, papaleksi

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

  • Posts: 25
  • Thank you received: 0
12 years 3 months ago #57906

Hi xavier i will try your solution thank you for you precious time and help

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

  • Posts: 6
  • Thank you received: 0
12 years 2 months ago #62764

Hello guys!
I think that not good solution overwrite files of core

I have suggestion.

we have event 'onBeforeProductListingLoad'. And just need add more parameters that we can send in plugin.
Now we have only this:
$dispatcher->trigger( 'onBeforeProductListingLoad', array( & $filters, & $order, &$this) );

and if we add also '$select,$select2, $a, $b, $on,' then we could make this changes in plugins without changes core files

Best regards,
Alex

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

  • Posts: 82727
  • Thank you received: 13343
  • MODERATOR
12 years 2 months ago #62860

Unfortunately, onBeforeProductListingLoad is triggered from other files where $select,$select2, $a, $b, $on are not available.
So that would break other things in HikaShop.

Another solution is to create a system plugin and paste the whole ProductViewProduct class of the view.html.php file in it.
The system will automatically use your class instead of the HikaShop core class.

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

  • Posts: 82727
  • Thank you received: 13343
  • MODERATOR
10 years 9 months ago #139240

Instead of that code, you should use that one in order to avoid some conflict with potential filters :

You can add this line:

		$order = ' ORDER BY price_join.price_value ASC';

Just after:
		if(!empty($pageInfo->filter->order->value)){
			$order = ' ORDER BY '.$pageInfo->filter->order->value.' '.$pageInfo->filter->order->dir;
		}

And replace the line:
		$query = $select2.' FROM '.$b.$a.$on.' WHERE '.implode(' AND ',$filters).$order;
By:
		$query = $select2.' FROM '.$b.$a.$on.' LEFT JOIN '.hikashop_table('price').' AS price_join ON price_join.price_product_id=b.product_id WHERE '.implode(' AND ',$filters).$order;

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

Time to create page: 0.093 seconds
Powered by Kunena Forum