News:

Support the VirtueMart project and become a member

Main Menu

Search box in Category Product List

Started by optmax, July 30, 2013, 21:17:03 PM

Previous topic - Next topic

optmax

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
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)
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

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
<!--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
<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

Thank you, looks good. I merged it into the svn
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

baggiesmad