Image in Search Results

  • Posts: 26
  • Thank you received: 0
10 years 5 months ago #158509

I am adding a html overide to display images and prices in the Joomla! search results. I have got the prices but not the images:

defined('_JEXEC') or die;
?>

<dl class="search-results<?php echo $this->pageclass_sfx; ?>">
<?php foreach ($this->results as $result) : ?>
	<div class="nr-search">
	<dt class="result-title">
		<?php echo $this->pagination->limitstart + $result->count.'. ';?>
		<?php if ($result->href) :?>
			<a href="<?php echo JRoute::_($result->href); ?>"<?php if ($result->browsernav == 1) :?> target="_blank"<?php endif;?>>
				<?php echo $this->escape($result->title);?>
			</a>
		<?php else:?>
			<?php echo $this->escape($result->title);?>
		<?php endif; ?>
	</dt>
	<?php if ($result->section) : ?>
		<dd class="result-category">
			<span class="small<?php echo $this->pageclass_sfx; ?>">
				(<?php echo $this->escape($result->section); ?>)
			</span>
		</dd>
	<?php endif; ?>
	<dd class="result-text">
		<?php echo $result->text; ?>
	</dd>
    <dd class="result-price">
		<?php echo $result->price; ?>
	</dd>
    <dd class="result-image">
		<?php echo $result->image; ?>
	</dd>
	<?php if ($this->params->get('show_date')) : ?>
		<dd class="result-created<?php echo $this->pageclass_sfx; ?>">
			<?php echo JText::sprintf('JGLOBAL_CREATED_DATE_ON', $result->created); ?>
		</dd>
	<?php endif; ?>
    </div>
<?php endforeach; ?>
</dl>

<div class="pagination">
	<?php echo $this->pagination->getPagesLinks(); ?>
</div>

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

  • Posts: 13201
  • Thank you received: 2322
10 years 5 months ago #158530

Hi,

I am not really aware of this part but I think that you will have to load the full product in order to get the image path and then use code like the one in the view "product / show_block_img" in order to display it.

To get the full product you need code like:

$productClass = hikashop_get('class.product');
$fullProduct = $productClass->get($result->id);

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

  • Posts: 26
  • Thank you received: 0
10 years 5 months ago #158955

Hi Xavier,
Got the image in, what I had forgotten to do is add the html to convert the url into an image link. So what I have done is modify the plugin and added the following code the the view, (added divs as well to help with styling):

<div class="nr-search">
        <div class="nr-search-image">
            <img src="<?php echo $result->image; ?>" width="150" alt="Not Just Nappies">
        </div>
        <div class="nr-search-desc">
            <dt class="result-title">
                <?php echo $this->pagination->limitstart + $result->count.'. ';?>
                <?php if ($result->href) :?>
                    <a href="<?php echo JRoute::_($result->href); ?>"<?php if ($result->browsernav == 1) :?> target="_blank"<?php endif;?>>
                        <?php echo $this->escape($result->title);?>
                    </a>
                <?php else:?>
                    <?php echo $this->escape($result->title);?>
                <?php endif; ?>
            </dt>
            <?php if ($result->section) : ?>
                <dd class="result-category">
                    <span class="small<?php echo $this->pageclass_sfx; ?>">
                        (<?php echo $this->escape($result->section); ?>)
                    </span>
                </dd>
            <?php endif; ?>
            <dd class="result-text">
                <?php echo $result->text; ?>
            </dd>
            <dd class="result-price">
                <?php echo $result->price; ?>
            </dd>
            <?php if ($this->params->get('show_date')) : ?>
            <dd class="result-created<?php echo $this->pageclass_sfx; ?>">
                <?php echo JText::sprintf('JGLOBAL_CREATED_DATE_ON', $result->created); ?>
            </dd>
            <?php endif; ?>
        </div>
    </div>

I modified the hikashop_products.php file (thanks to a free plugin by the guys at offlajn.com/ ):
$query = ' SELECT DISTINCT '.$select.', f.file_path AS product_image FROM '.hikashop_table($trans_table,false) . ' AS b LEFT JOIN '.hikashop_table('product').' AS a ON b.reference_id=a.product_id INNER JOIN '.hikashop_table('file').' AS f ON f.file_ref_id=a.product_id WHERE '.implode(' AND ',$filters2).' AND f.file_type="product" ORDER BY '.$order;	
			$db->setQuery($query, 0, $limit);
			$rows = $db->loadObjectList("id");
			$count = count($rows);
			if($count){
				$limit = $limit-$count;
				$filters[]='a.product_id NOT IN ('.implode(',',array_keys($rows)).')';
			}
		}

		if($limit){
			if(!empty($leftjoin)){
				$select.=', b.category_id as category_id';
			}
			$db->setQuery('SET SQL_BIG_SELECTS=1');
			$db->query();

			$query = ' SELECT DISTINCT '.$select.', f.file_path AS product_image FROM '.hikashop_table('product') . ' AS a '.$leftjoin.' LEFT JOIN '.hikashop_table('file').' AS f ON f.file_ref_id=a.product_id WHERE '.implode(' AND ',$filters).' GROUP BY (a.product_id) ORDER BY '.$order;

			$db->setQuery( $query, 0, $limit );
			$mainRows = $db->loadObjectList("id");
			if(!empty($mainRows)){
				foreach($mainRows as $k => $main){
					$rows[$k]=$main;
				}
				$count = count( $rows );
			}
		}
		if($count){

			if($multi && !empty($lg)){
				$query = ' SELECT * FROM '.hikashop_table($trans_table,false) . ' WHERE reference_table=\'hikashop_product\' AND language_id=\''.$lg.'\' AND published=1 AND reference_id IN ('.implode(',',array_keys($rows)).')';
				$db->setQuery($query);
				$trans = $db->loadObjectList();
				foreach($trans as $item){
					foreach($rows as $key => $row){
						if($row->id==$item->reference_id){
							if($item->reference_field=='product_name'){
								$row->product_name=$item->value;
							}elseif($item->reference_field=='product_description'){
								$row->product_description=$item->value;
							}else{
								$row->product_name=$item->value;
							}
							break;
						}
					}
				}
			}
			$parent = '';
			$item_id = $this->params->get('item_id','');
			$menuClass = hikashop_get('class.menus');
			$config =& hikashop_config();
			$pathway_sef_name = $config->get('pathway_sef_name','category_pathway');
			$menus=array();
			$Itemid='';
			if(!empty($item_id)){
				$Itemid='&Itemid='.$item_id;
				if($this->params->get('full_path',1)){
					$menuData = $menus[$item_id] = $menuClass->get($item_id);
					if(!empty($menuData->hikashop_params['selectparentlisting'])){
						$parent = '&'.$pathway_sef_name.'='.(int)$menuData->hikashop_params['selectparentlisting'];
					}
				}
			}
			$itemids=array();
			$app= JFactory::getApplication();
			$class = hikashop_get('class.product');
			foreach ( $rows as $k => $row ) {
				if(!empty($row->category_id)){
					if(empty($item_id)){
						if(!isset($itemids[$row->category_id])) $itemids[$row->category_id] = $menuClass->getItemidFromCategory($row->category_id);
						$item_id = $itemids[$row->category_id];
					}
					if(!empty($item_id)){
						$Itemid='&Itemid='.$item_id;
					}
					if($this->params->get('full_path',1)){
						$parent = '&'.$pathway_sef_name.'='.(int)$row->category_id;
					}
					if(!$this->params->get('item_id','')) $item_id = '';
				}
				$class->addAlias($row);
				$row->title=$row->product_name;
				$row->text=$row->product_description;
				if($variants && $row->product_type=='variant'){
					static $mains = array();
					if(!isset($mains[$row->product_parent_id])){
						$mains[$row->product_parent_id] = $class->get((int)$row->product_parent_id);
						$class->addAlias($mains[$row->product_parent_id]);
					}
					$db = JFactory::getDBO();
					$db->setQuery('SELECT * FROM '.hikashop_table('variant').' AS a LEFT JOIN '.hikashop_table('characteristic') .' AS b ON a.variant_characteristic_id=b.characteristic_id WHERE a.variant_product_id='.(int)$row->id.' ORDER BY a.ordering');
					$row->characteristics = $db->loadObjectList();
					$class->checkVariant($row,$mains[$row->product_parent_id]);
					if(empty($row->title)){
						$row->title = $row->product_name;
					}
					if(empty($row->text)){
						$row->text = $mains[$row->product_parent_id]->product_description;
					}
				}

				$rows[$k]->href = 'index.php?option=com_hikashop&ctrl=product&task=show&name='.$row->alias.'&cid='.$row->id.$Itemid.$parent;
				$rows[$k]->section 	= JText::_( 'PRODUCT' );				
				$rows[$k]->price = $this->getPrice($row->id);
				if ($row->product_image) {
  				  $rows[$k]->image = JUri::Root().'media/com_hikashop/upload/'.$row->product_image;
  			}
			}

		}
		return $rows;
	}
    function getPrice($pid) {
    $arr = array();
    $arr[0] = new stdClass();
    $arr[0]->product_id = $pid;   
    $currency = hikashop_get('type.currency');
    $currencyClass = hikashop_get('class.currency');
    $zone = hikashop_getZone();
    $cur = hikashop_getCurrency();
    $currencyClass->getListingPrices($arr,$zone,$cur);
  return $currencyClass->format($arr[0]->prices[0]->price_value, $cur);
  }
}

What I am missing to how to display the price_value_with_tax field (price including tax)

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

  • Posts: 82910
  • Thank you received: 13379
  • MODERATOR
10 years 5 months ago #158992

Now that you added the price in the result $rows, you can display them with such code in the joomla result page:
<?php echo $result->price; ?>

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

  • Posts: 26
  • Thank you received: 0
10 years 5 months ago #159130

Hi Nicolas,
Yes I have the code <?php echo $result->price; ?> in the joomla result page however it displays the price without the tax. How can I display the price with tax

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

  • Posts: 82910
  • Thank you received: 13379
  • MODERATOR
10 years 5 months ago #159135

Au lieu de la ligne:

return $currencyClass->format($arr[0]->prices[0]->price_value, $cur);
il vous faudrait la ligne:
return $currencyClass->format($arr[0]->prices[0]->price_value_with_tax, $cur);

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

  • Posts: 26
  • Thank you received: 0
10 years 5 months ago #159302

Hi Nicolas,

I have tried that but does not seem to work?

function getPrice($pid) {
    $arr = array();
    $arr[0] = new stdClass();
    $arr[0]->product_id = $pid;   
    $currency = hikashop_get('type.currency');
    $currencyClass = hikashop_get('class.currency');
    $zone = hikashop_getZone();
    $cur = hikashop_getCurrency();
    $currencyClass->getListingPrices($arr,$zone,$cur);
  	return $currencyClass->format($arr[0]->prices[0]->price_value_with_tax, $cur);

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

  • Posts: 82910
  • Thank you received: 13379
  • MODERATOR
10 years 5 months ago #159328

Hi,

Then it means that between your tax settings and your current customer address (or the main tax zone option of the configuration), taxes shouldn't be applied to the prices.
You say that it doesn't work but what do you mean by that ? You still see the price without tax ? You don't see any price at all ? Are you sure that you don't have any cache on your website which could prevent you from seeing the change ?

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

  • Posts: 26
  • Thank you received: 0
10 years 5 months ago #159365

Hi Nicolas,

Sorry I will try to be clearer,

The price does display, however it display the price without the tax amount (for both logged in users with a New Zealand address) and non logged in users). I have a tax code of 15% set as the default for all users and for zone New Zealand, and the main tax zone as New Zealand in the configuration.

If I do a search the result is:

Search

You will see the results do not include tax, however if you click on a product it does show the price with tax

http://www.notjustnappies.co.nz/component/hikashop/product/103-vapor-eze

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

  • Posts: 82910
  • Thank you received: 13379
  • MODERATOR
10 years 5 months ago #159394

Hi,

Ah I know! You're missing the product_tax_id of each product in the $arr variable in your code. Without it, the getListingPrices function cannot link the products with the tax rules in your system.

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

Time to create page: 0.080 seconds
Powered by Kunena Forum