Prev | Current Page 234 | Next

Emilian Balanescu and Cristian Darie

"Beginning PHP and MySQL E-Commerce: From Novice to Professional, Second Edition"

It goes inside the Catalog class:
// Retrieves the list of products on catalog page
public static function GetProductsOnCatalog($pageNo, &$rHowManyPages)
{
// Query that returns the number of products for the front catalog page
$sql = 'CALL catalog_count_products_on_catalog()';
// Calculate the number of pages required to display the products
$rHowManyPages = Catalog::HowManyPages($sql, null);
// Calculate the start item
$start_item = ($pageNo - 1) * PRODUCTS_PER_PAGE;
// Retrieve the list of products
$sql = 'CALL catalog_get_products_on_catalog(
:short_product_description_length,
:products_per_page, :start_item)';
// Build the parameters array
$params = array (
':short_product_description_length' =>
SHORT_PRODUCT_DESCRIPTION_LENGTH,
':products_per_page' => PRODUCTS_PER_PAGE,
':start_item' => $start_item);
// Execute the query and return the results
return DatabaseHandler::GetAll($sql, $params);
}
GetProductDetails
Add the GetProductDetails() method to the Catalog class:
// Retrieves complete product details
public static function GetProductDetails($productId)
{
// Build SQL query
$sql = 'CALL catalog_get_product_details(:product_id)';
// Build the parameters array
$params = array (':product_id' => $productId);
// Execute the query and return the results
return DatabaseHandler::GetRow($sql, $params);
}
CHAPTER 5 ?–  CREATING THE PRODUCT CATALOG: PART 2 145
GetProductLocations
Finally, add the GetProductLocations() method, which calls the catalog_get_product_locations
stored procedure, to extract the categories and departments that a product is part of:
// Retrieves product locations
public static function GetProductLocations($productId)
{
// Build SQL query
$sql = 'CALL catalog_get_product_locations(:product_id)';
// Build the parameters array
$params = array (':product_id' => $productId);
// Execute the query and return the results
return DatabaseHandler::GetAll($sql, $params);
}
Implementing the Presentation Tier
Believe it or not, right now the data and business tiers of the product catalog are complete for
this chapter.


Pages:
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246