SUNIWPSC - Unified Search For WP e-commerce Documentation

Introduction

SUNIWPSC is a simple WP (Wordpress) plug-in that enables the normal WP search to also search in products created with the WP e-commerce plug-in. This way, you get both product results and posts results from a site search.

It provides a menu entry on the admin pages where you can see the searches that people have been doing on your site. It will also keep track of the number of times each search was done.

After the integration, as described in a section below, is completed, the very same WP search box will search and return results from the e-commerce products. The products will come up first and then the post results will follow.

The search is performed only on the product's SKU, name, description and additional description. The SKU search is by "exact match", while the search in the remaining fields is by "text ocurrence".

The plug-in is completely safe to install and won't change anything at all on your e-commerce data. If it doesn't work for you or any conflicts arise with other plug-ins, just uninstall it and everything will go back to what it was before, except that the search database table will not be deleted from the database (its name is <WP-db-table-prefix>psp_search_strings).

This plug-in is known to work with Wordpress 2.5 to 3.0.1 and WP e-commerce 3.6.4 to 3.7.6. It may or may not work on other versions, and it may clash with eculiarities on your Wordpress theme.

Known limitations:
- no pagination of search results
- products must be included in at least 1 category, and must be included in all levels of that category
- other limitations described below in the documentation of the "tags" below

Integration with WP

Now that you have installed the SUNIWPSC plug-in, to add the unified search to your site you still need to perform a few changes in your Wordpress theme, specifically on file search.php. Below is a sketch of a normal and minimal search.php file:

 <?php if (have_posts()) : ?>
     <?php while (have_posts()) : the_post(); ?>
         <!-- Normal post display code goes here -->
     <?php endwhile; ?>
 <?php else : ?>
     Not Found
 <?php endif; ?>

The file in your WP theme most probably complies to this structure. Now we need to accomodate the display of the e-commerce products resulting from the search, by slightly changing the structure:

 <?php if (have_posts()) : ?>
     <?php while (have_posts()) : the_post(); ?>
         <?php if (!psp_isProduct($post)) : ?>
             <!-- Normal post display code goes here -->
         <?php else : ?>
             <!-- Here goes product display code -->
         <?php endif; ?>
     <?php endwhile; ?>
 <?php else : ?>
     Not Found
 <?php endif; ?>

Now there are 2 placeholders, one to display a WP post and another to display an e-commerce product. A set of special  "tags" exist that will display in the browser specific fields of the product for display. Here goes an example of "product display code", which would be used to fill in the structure above:

  <a href="<?php psp_productPmlink($post); ?>">
      <img src="<?php psp_productImageName($post); ?>" width="56"
           alt="<?php psp_productName($post); ?>"
           title="<?php psp_productName($post); ?>" />
  </a>
  <a href="<?php psp_productPmlink($post); ?>">
      <?php psp_productName($post); ?></a>
      On product category
      <a href="<?php psp_categoryPmlink($post); ?>">
          <?php psp_productCategory($post); ?></a>
  <?php psp_productData($post); ?>

The block above displays 1 product. It relies on several tags that echo specific fields of the product to the browser. They all always have the $post argument, and the complete set of available tags is:

<?php psp_productPmlink($post); ?>
Echo the product's permanent link.

<?php psp_productName($post); ?>
Echo the product's name.

<?php psp_productPrice($post); ?>
Echo the product's price, already formatted for display.

<?php psp_categoryPmlink($post); ?>
Echo the category permanent link.

<?php psp_productCategory($post); ?>
Echo the category, ready to send to the browser.

<?php psp_productImageName($post); ?>
Echo the product's image url.

<?php psp_productData($post); ?>
Echo the description, with the style class single_additional_description.

If you know something about PHP programming, then you can open SUNIWPSC's file suniwpsc.php and look at the functions there, change them, etc.

Click here to access SUNIWPSC sale page.