how to show price in search results

  • Posts: 15
  • Thank you received: 1
11 years 7 months ago #98954

Hello!
I would like to make the view of search results containing price.
Is it possible to use product/listing_price.php for this like in listing_table.php:
<td class="hikashop_product_price_row">
<?php
$this->setLayout('listing_price');
echo $this->loadTemplate();
?>
</td>
I would like to use product/listing_price.php template for this.
How can I create object productviewproduct in \components\com_search\views\search\tmpl\default_results.php and to display price with setLayout metod using listing_price template?
I know I can take all product info in /plugins/search/hikashop_products/hikasohop_products.php but can't figure it out how to take price including discount.

Thank you for the help!

Last edit: 11 years 7 months ago by kostia_lev.

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

  • Posts: 82868
  • Thank you received: 13376
  • MODERATOR
11 years 7 months ago #99069

Hi,

Displaying the price is more complex than that as you first need to retrieve it from the database, make the necessary calculations, format it and only then display it.
In the listing_table, all that is hidden "under the hood". But since the joomla search results page cannot display the prices, they are not loaded by the search plugin so you need to add the code for that yourself. Needless to say that is it more than just two lines of code to add...

The simplest would be to actually not use the joomla search module but instead create a HikaShop text filter and use the HikaShop filter module to actually use a products listing menu for the results of the search:
www.hikashop.com/en/support/documentatio...-filter-listing.html

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

  • Posts: 15
  • Thank you received: 1
11 years 7 months ago #99202

Thanx, but it is impossible to just use text filter for me.
I see that listing_price.php template just receives $price object containing all prices.

Can you please point me to where this object which contains all prices is created so that I have an example.

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

  • Posts: 82868
  • Thank you received: 13376
  • MODERATOR
11 years 7 months ago #99211

It is done in the components/com_hikashop/views/product/view.html.php file with the call to the getPrices function.

The following user(s) said Thank You: kostia_lev

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

  • Posts: 10
  • Thank you received: 1
3 years 8 months ago #330623

For someone who still needs this ;-)

Solved the same question with a dirty hack in components/com_finder/models/search.php:

/**
* Add prices to search results - mSnus
* Joomla 3.9.25
* components/com_finder/models/search.php
* around line 118
*/

// Load the results from the database.
		$db->setQuery($query);
		$rows = $db->loadObjectList('link_id');

		// Set up our results container.
		$results = $items;

		$arrHikaIds = [];

		// Convert the rows to result objects.
		foreach ($rows as $rk => $row)
		{
			// Build the result object.
			$result = unserialize($row->object);
			$result->weight = $results[$rk];
			$result->link_id = $rk;
			$arrHikaIds[] = $result->__get('id');

			// Add the result back to the stack.
			$results[$rk] = $result;
		}

		$query2 = $db->getQuery(true)
		->select($db->quoteName('product_id') . ', ' . $db->quoteName('product_sort_price'))
		->from($db->quoteName('#__hikashop_product'))
		->where($db->quoteName('product_id') . ' IN (' . implode(',', $arrHikaIds) . ')');

		$db->setQuery($query2);
		$rows2 = $db->loadAssocList();
		$idToPrice = [];
		foreach ($rows2 as $rk => $row) {
			$idToPrice[$row['product_id']] = $row['product_sort_price'];
		}

		foreach ($results as $rk => &$result) {
			$oid = $results[$rk]->__get('id');
			$results[$rk]->__set('price', $idToPrice[$oid]);
		}

		/**
		 * -- end adding price to search results
		 */

After this modification you will be able to use $this->result->price
in your templates/<...your template name...>/html/com_finder/search/default_result.php , for example:
<h5>USD <?php echo(intval($this->result->price)); ?> </h5>

Maybe someone could improve the answer with moving my function to some SmartSearch plugin, but my way will do.

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

Time to create page: 0.074 seconds
Powered by Kunena Forum