Prev | Current Page 443 | Next

Emilian Balanescu and Cristian Darie

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


??? GetProductInfo returns the product details.
??? GetCategoriesForProduct is used to get the list of categories that are related to the specified
product.
??? SetProductDisplayOption sets the product??™s display setting.
??? AssignProductToCategory assigns a product to a category.
??? MoveProductToCategory moves a product from one category to another.
??? GetAttributesNotAssignedToProduct returns all the attribute values from the table of
attribute_values that have not been assigned to a product.
CHAPTER 11 ?–  CATALOG ADMINISTRATION: PRODUCTS AND ATTRIBUTES 341
??? AssignAttributeValueToProduct assigns an attribute value to a product.
??? RemoveProductAttributeValue removes the association between a product and an
attribute value from the product_attribute table.
??? SetImage1 changes the image file name in the database for a certain product.
??? SetImage2 changes the second image file name in the database for a certain product.
??? SetThumbnail changes the thumbnail image file name for a certain product.
Exercise: Implementing the Business Tier Methods
Because the functionality is better expressed by the data tier functions that the methods call, we??™ll discuss them
in more detail when we implement the data tier. For now, simply add the following code to the Catalog class, in
business/catalog.php:
// Updates a product
public static function UpdateProduct($productId, $productName,
$productDescription, $productPrice,
$productDiscountedPrice)
{
// Build the SQL query
$sql = 'CALL catalog_update_product(:product_id, :product_name,
:product_description, :product_price,
:product_discounted_price)';
// Build the parameters array
$params = array (':product_id' => $productId,
':product_name' => $productName,
':product_description' => $productDescription,
':product_price' => $productPrice,
':product_discounted_price' => $productDiscountedPrice);
// Execute the query
DatabaseHandler::Execute($sql, $params);
}
// Removes a product from the product catalog
public static function DeleteProduct($productId)
{
// Build SQL query
$sql = 'CALL catalog_delete_product(:product_id)';
// Build the parameters array
$params = array (':product_id' => $productId);
CHAPTER 11 ?–  CATALOG ADMINISTRATION: PRODUCTS AND ATTRIBUTES 342
// Execute the query
DatabaseHandler::Execute($sql, $params);
}
// Unassigns a product from a category
public static function RemoveProductFromCategory($productId, $categoryId)
{
// Build SQL query
$sql = 'CALL catalog_remove_product_from_category(
:product_id, :category_id)';
// Build the parameters array
$params = array (':product_id' => $productId,
':category_id' => $categoryId);
// Execute the query and return the results
return DatabaseHandler::GetOne($sql, $params);
}
// Retrieves the list of categories a product belongs to
public static function GetCategories()
{
// Build SQL query
$sql = 'CALL catalog_get_categories()';
// Execute the query and return the results
return DatabaseHandler::GetAll($sql);
}
// Retrieves product info
public static function GetProductInfo($productId)
{
// Build SQL query
$sql = 'CALL catalog_get_product_info(:product_id)';
// Build the parameters array
$params = array (':product_id' => $productId);
// Execute the query and return the results
return DatabaseHandler::GetRow($sql, $params);
}
// Retrieves the list of categories a product belongs to
public static function GetCategoriesForProduct($productId)
{
// Build SQL query
$sql = 'CALL catalog_get_categories_for_product(:product_id)';
CHAPTER 11 ?–  CATALOG ADMINISTRATION: PRODUCTS AND ATTRIBUTES 343
// Build the parameters array
$params = array (':product_id' => $productId);
// Execute the query and return the results
return DatabaseHandler::GetAll($sql, $params);
}
// Assigns a product to a category
public static function SetProductDisplayOption($productId, $display)
{
// Build SQL query
$sql = 'CALL catalog_set_product_display_option(
:product_id, :display)';
// Build the parameters array
$params = array (':product_id' => $productId,
':display' => $display);
// Execute the query
DatabaseHandler::Execute($sql, $params);
}
// Assigns a product to a category
public static function AssignProductToCategory($productId, $categoryId)
{
// Build SQL query
$sql = 'CALL catalog_assign_product_to_category(
:product_id, :category_id)';
// Build the parameters array
$params = array (':product_id' => $productId,
':category_id' => $categoryId);
// Execute the query
DatabaseHandler::Execute($sql, $params);
}
// Moves a product from one category to another
public static function MoveProductToCategory($productId, $sourceCategoryId,
$targetCategoryId)
{
// Build SQL query
$sql = 'CALL catalog_move_product_to_category(:product_id,
:source_category_id, :target_category_id)';
// Build the parameters array
$params = array (':product_id' => $productId,
CHAPTER 11 ?–  CATALOG ADMINISTRATION: PRODUCTS AND ATTRIBUTES 344
':source_category_id' => $sourceCategoryId,
':target_category_id' => $targetCategoryId);
// Execute the query
DatabaseHandler::Execute($sql, $params);
}
// Gets the catalog attributes that are not assigned to the specified product
public static function GetAttributesNotAssignedToProduct($productId)
{
// Build the SQL query
$sql = 'CALL catalog_get_attributes_not_assigned_to_product(:product_id)';
// Build the parameters array
$params = array (':product_id' => $productId);
// Execute the query and return the results
return DatabaseHandler::GetAll($sql, $params);
}
// Assign an attribute value to the specified product
public static function AssignAttributeValueToProduct($productId,
$attributeValueId)
{
// Build SQL query
$sql = 'CALL catalog_assign_attribute_value_to_product(
:product_id, :attribute_value_id)';
// Build the parameters array
$params = array (':product_id' => $productId,
':attribute_value_id' => $attributeValueId);
// Execute the query
DatabaseHandler::Execute($sql, $params);
}
// Removes a product attribute value
public static function RemoveProductAttributeValue($productId,
$attributeValueId)
{
// Build SQL query
$sql = 'CALL catalog_remove_product_attribute_value(
:product_id, :attribute_value_id)';
// Build the parameters array
$params = array (':product_id' => $productId,
':attribute_value_id' => $attributeValueId);
CHAPTER 11 ?–  CATALOG ADMINISTRATION: PRODUCTS AND ATTRIBUTES 345
// Execute the query
DatabaseHandler::Execute($sql, $params);
}
// Changes the name of the product image file in the database
public static function SetImage($productId, $imageName)
{
// Build SQL query
$sql = 'CALL catalog_set_image(:product_id, :image_name)';
// Build the parameters array
$params = array (':product_id' => $productId, ':image_name' => $imageName);
// Execute the query
DatabaseHandler::Execute($sql, $params);
}
// Changes the name of the second product image file in the database
public static function SetImage2($productId, $imageName)
{
// Build SQL query
$sql = 'CALL catalog_set_image_2(:product_id, :image_name)';
// Build the parameters array
$params = array (':product_id' => $productId, ':image_name' => $imageName);
// Execute the query
DatabaseHandler::Execute($sql, $params);
}
// Changes the name of the product thumbnail file in the database
public static function SetThumbnail($productId, $thumbnailName)
{
// Build SQL query
$sql = 'CALL catalog_set_thumbnail(:product_id, :thumbnail_name)';
// Build the parameters array
$params = array (':product_id' => $productId,
':thumbnail_name' => $thumbnailName);
// Execute the query
DatabaseHandler::Execute($sql, $params);
}
CHAPTER 11 ?–  CATALOG ADMINISTRATION: PRODUCTS AND ATTRIBUTES 346
Product Details: Implementing the Data Tier
In the data tier, you add the stored procedures that correspond to the business tier methods in
the Catalog class you have just seen.


Pages:
431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455
drukarki fiskalne kraków willa karmazyn międzyzdroje www.books61.hobbitstory.com terapia magnetyczna Informacje o hostingu