New Seach Classes
Written by Harald Ponce de Leon on October 10, 2005With the template structure implementation now in place, more classes have been introduced to take care of specific tasks. For example, osC_Account now takes care of the account related tasks including logging in and the creation of a user account, osC_AddressBook takes care of the address book related tasks, osC_Product takes care of retrieving all related information to one product, ..
These classes now take care of the heavy duty logic and leave the template page modules contain only the minimum amount of PHP coded needed to form the page properly (mainly while() loops for database result sets).
With these new classes also comes the introduction of a new approach to searching for products and the presentation of the search results, with the new osC_Products and osC_Search classes.
There might be some confusion as to what osC_Product and osC_Products do and may see a name change before MS3 is finalized, however osC_Product takes care of retrieving all information specific to one product (including attributes), and the osC_Products class takes care of retrieving a list of products meeting certain criteria.
For example, the way to retrieve a list of products for a category is now done as:
$osC_Products = new osC_Products($category_id);
$osC_Listing = $osC_Products->execute();
The $osC_Listing variable then holds the database result set, powered ofcourse by our powerful database class, and can be looped through with:
while ($osC_Listing->next()) {
...
}
The full potential of the class can be seen with the following example:
$osC_Products = new osC_Products($category_id);
$osC_Products->setManufacturer($manufacturer_id);
$osC_Products->setSortBy($sort, $direction);
$osC_Listing = $osC_Products->execute();
The setManufacturer() call returns all products by the defined manufacturer (and in the defined category passed in the constructor ($category_id)), and the setSortBy() call sets the ordering of the result set.
That is the basics of the osC_Products class and takes care of the minimum amount of work to list products for a certain category.
The new osC_Search class extends on the osC_Products class by allowing the result set to be fine tuned further with the options provided on the advance search page.
The full potential of the osC_Search class can be seen in this example:
$osC_Search = new osC_Search();
$osC_Search->setKeywords($keywords);
$osC_Search->setDateFrom($date_from);
$osC_Search->setDateTo($date_to);
$osC_Search->setPriceFrom($price_from);
$osC_Search->setPriceTo($price_to);
$osC_Search->setCategory($category_id, $recursive);
$osC_Search->setManufacturer($manufacturer_id);
$osC_Search->setSortBy($sort, $direction);
$osC_Listing = $osC_Search->execute();
while ($osC_Listing->next()) {
...
}
The wonder behind the osC_Search class is the ability to take advantage of the database features. For the MySQL class it is possible to search with native FULLTEXT functionality. If MySQL > 4.0.1 is used it is also possible to use native boolean features.
That greatly increases the performance when searching is done on a database that contains loads of products.
Here is a peek as to how our template content pages look like with minimum PHP code needed, specifically for the search results page:
getPageImage(), $osC_Template->getPageTitle(), HEADING_IMAGE_WIDTH, HEADING_IMAGE_HEIGHT, ‘class=”pageIcon”‘); ?>
getPageTitle(); ?>
$Qlisting = $osC_Search->execute();
require(’includes/modules/product_listing.php’);
?>
Ok, there’s no secret the formating logic exists in the product_listing.php module file, however that module file is only taking care of the $Qlisting result set and is also shared by the normal product listing view when navigating through the categories.
Where is the rest of the logic? Exclusive sneak peeks to be continued… ![]()
Leave a Comment
You must be logged in to post a comment.
