-- Create catalog_create_product_review stored procedure
CREATE PROCEDURE catalog_create_product_review(IN inCustomerId INT,
IN inProductId INT, IN inReview TEXT, IN inRating SMALLINT)
BEGIN
INSERT INTO review (customer_id, product_id, review, rating, created_on)
VALUES (inCustomerId, inProductId, inReview, inRating, NOW());
END$$
CHAPTER 21 ?– PRODUCT REVIEWS 658
4. Add the corresponding business tier methods to the Catalog class from the business/catalog.php file:
// Gets the reviews for a specific product
public static function GetProductReviews($productId)
{
// Build the SQL query
$sql = 'CALL catalog_get_product_reviews(:product_id)';
// Build the parameters array
$params = array (':product_id' => $productId);
// Execute the query and return the results
return DatabaseHandler::GetAll($sql, $params);
}
// Creates a product review
public static function CreateProductReview($customer_id, $productId,
$review, $rating)
{
// Build the SQL query
$sql ='CALL catalog_create_product_review(:customer_id, :product_id,
:review, :rating)';
// Build the parameters array
$params = array (':customer_id' => $customer_id,
':product_id' => $productId,
':review' => $review,
':rating' => $rating);
// Execute the query
DatabaseHandler::Execute($sql, $params);
}
5. The UI consists of the reviews componentized template that will be placed on the product details page.
Pages:
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773