Prev | Current Page 580 | Next

Emilian Balanescu and Cristian Darie

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

Open the shopping_cart.php file located in the business folder, and add the following code:
// Get product recommendations for the shopping cart
public static function GetRecommendations()
{
// Build the SQL query
$sql = 'CALL shopping_cart_get_recommendations(
:cart_id, :short_product_description_length)';
// Build the parameters array
$params = array (':cart_id' => self::GetCartId(),
':short_product_description_length' =>
SHORT_PRODUCT_DESCRIPTION_LENGTH);
// Execute the query and return the results
return DatabaseHandler::GetAll($sql, $params);
}
3. Now, we update the presentation tier by modifying the product and cart_details componentized templates
to display the product recommendations. Open the presentation/product.php file, and add
a member named $mRecommendations to the Product class:
// Public variables to be used in Smarty template
public $mProduct;
public $mProductLocations;
public $mLinkToContinueShopping;
public $mLocations;
public $mEditActionTarget;
public $mShowEditButton;
public $mRecommendations;
4. Next, you have to get the recommended products data in $mRecommendations and create links to their
product pages. Modify the init() method of the Product class as highlighted here:
$this->mLocations = Catalog::GetProductLocations($this->_mProductId);
// Create the Add to Cart link
$this->mProduct['link_to_add_product'] =
Link::ToCart(ADD_PRODUCT, $this->_mProductId);
// Get product recommendations
$this->mRecommendations =
Catalog::GetRecommendations($this->_mProductId);
// Create recommended product links
for ($i = 0; $i < count($this->mRecommendations); $i++)
CHAPTER 15 ?–  PRODUCT RECOMMENDATIONS 471
$this->mRecommendations[$i]['link_to_product'] =
Link::ToProduct($this->mRecommendations[$i]['product_id']);
// Build links for product departments and categories pages
for ($i = 0; $i < count($this->mLocations); $i++)
{
5.


Pages:
568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592
A*Teens ubrania rodzice mapy nieruchomości szczecin hale