Author Topic: Search box in Category Product List  (Read 5012 times)

optmax

  • Jr. Member
  • **
  • Posts: 96
Search box in Category Product List
« on: July 30, 2013, 21:17:03 pm »
VM 2.0.22a
Joomla 2.5.11

There are various posts about:
  • a 404 error when searching
  • subsequent searches using same category

Below is a suggested solution to both these problems.

After a product search then /components/com_virtuemart/views/category/tmpl/default.php adds a search box populated with the current keyword and button to search again.

The button is labelled 'Search in shop' so I assume this is meant to repeat the search on all products rather than just within the current category.

However clicking on 'Search in shop' generates the 404 error.

Even with the 404 error fixed, subsequent searches using the  'Search in shop'  button repeat the search within in current category not the whole shop.

Existing code in /components/com_virtuemart/views/category/tmpl/default.php
Code: [Select]
155  <form action="<?php echo JRoute::('index.php?option=com_virtuemart&view=category&limitstart=0&virtuemart_category_id=' $this->category->virtuemart_category_idFALSE); ?>" method="get">
156
157  <!--BEGIN Search Box -->
158  <div class="virtuemart_search">
159 <?php echo $this->searchcustom ?>
160 <br/>
161 <?php echo $this->searchcustomvalues ?>
162 <input name="keyword" class="inputbox" type="text" size="20" value="<?php echo $this->keyword ?>"/>
163 <input type="submit" value="<?php echo JText::('COM_VIRTUEMART_SEARCH'?>" class="button" onclick="this.form.keyword.focus();"/>
164 </div>
165 <input type="hidden" name="search" value="true"/>
166 <input type="hidden" name="view" value="category"/>
167
168  </form>
169  <!-- End Search Box -->

Suggested code for override [your template]/com_virtuemart/html/category/default.php  (and in any other category template overrides using the old code)
Code: [Select]
155 <form action="<?php  echo JRoute::('index.php?option=com_virtuemart&view=category&limitstart=0' FALSE); ?>" method="get">
156
157  <!--BEGIN Search Box -->
158  <div class="virtuemart_search">
159 <?php echo $this->searchcustom ?>
160 <br/>
161 <?php echo $this->searchcustomvalues ?>
162 <input name="keyword" class="inputbox" type="text" size="20" value="<?php echo $this->keyword ?>"/>
163 <input type="submit" value="<?php echo JText::('COM_VIRTUEMART_SEARCH'?>" class="button" onclick="this.form.keyword.focus();"/>
164 </div>
165 <input type="hidden" name="search" value="true"/>
166 <input type="hidden" name="view" value="category"/>
167 <input type="hidden" name="option" value="com_virtuemart"/>
168     <input type="hidden" name="virtuemart_category_id" value="0"/>
169
170  <!-- End Search Box -->

The addition of the hidden input at 167 cures the 404 error.

On the existing line 155 '&virtuemart_category_id=' . $this->category->virtuemart_category_id' causes the next search to be restricted to the current category, so removing this and adding the extra hidden input at 168 forces the seach onto all products.

I have no idea why these attribute could not be added in the JRoute at line 155 but this doesn't work for me.

There may well be better ways of solving these problems I hope the team will have time to sort it for the next release but in the mean time with these alterations in the override my site is behaving as I expect.

optmax

  • Jr. Member
  • **
  • Posts: 96
Re: Search box in Category Product List
« Reply #1 on: July 30, 2013, 23:51:59 pm »
Update...
It was all too good to be true - it stopped working when I turned SEF back on!

I was getting some very strange URLs that were ignoring the current category.

I really don't know what goes on in SEF nor indeed in JRoute but I have another temporary fix.

modules/virtuemart_search/tmpl/default.php references $category_id, but this is always 0 - it doesn't seem to get passed into this code properly.

My workround is to set $category_id again in an override so in [my template]/mod_virtuemart_search/html/default.php, near the top where the form is defined I changed the code to
Code: [Select]
<!--BEGIN Search Box -->
<?php $category_id  JRequest::getInt ('virtuemart_category_id'0); ?>
<form action="<?php echo JRoute::_('index.php?option=com_virtuemart&view=category&search=true&limitstart=0' ); ?>" method="get">
(Adding the JRequest and altering the JRoute parameter.)

At the bottom I added two more hidden inputs
Code: [Select]
<input type="hidden" name="option" value="com_virtuemart"/>
<input type="hidden" name="virtuemart_category_id" value="<?php echo $category_id?>"/>

These changes are similar to the ones I made in the category override but with the addition of redefining $category_id.

At the risk of 'famous last words' the search box appears to be working as I expect with SEF turned on.

Btw can any developer confirm that ther are problems in this area and that they are being worked on?

Milbo

  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 10000
  • VM3.2 Cached and Optimized
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 on joomla 3
Re: Search box in Category Product List
« Reply #2 on: August 12, 2013, 12:04:36 pm »
Thank you, looks good. I merged it into the svn
I should fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

baggiesmad

  • Jr. Member
  • **
  • Posts: 308
Re: Search box in Category Product List
« Reply #3 on: November 28, 2013, 15:28:05 pm »
Fixed it for me! thanks