Prev | Current Page 582 | Next

Emilian Balanescu and Cristian Darie

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

Next, you have to get the recommended products data in $mRecommendations and create links to their
product pages. Add the highlighted piece of code at the end of the init() method:
for ($i = 0; $i < count($this->mSavedCartProducts); $i++)
{
$this->mSavedCartProducts[$i]['move'] =
Link::ToCart(MOVE_PRODUCT_TO_CART,
$this->mSavedCartProducts[$i]['item_id']);
$this->mSavedCartProducts[$i]['remove'] =
Link::ToCart(REMOVE_PRODUCT,
$this->mSavedCartProducts[$i]['item_id']);
}
// Get product recommendations for the shopping cart
$this->mRecommendations =
ShoppingCart::GetRecommendations();
// Create recommended product links
for ($i = 0; $i < count($this->mRecommendations); $i++)
$this->mRecommendations[$i]['link_to_product'] =
Link::ToProduct($this->mRecommendations[$i]['product_id']);
}
}
?>
9. Finally, update the cart_details template to display the list of recommendations. Add the following lines
at the end of presentation/templates/cart_details.tpl:
{if $obj->mRecommendations}

Customers who bought this also bought:



    {section name=m loop=$obj->mRecommendations}

  1. {strip}

    {$obj->mRecommendations[m].product_name}

    {/strip}
    - {$obj->mRecommendations[m].description}

  2. {/section}

{/if}
CHAPTER 15 ?–  PRODUCT RECOMMENDATIONS 473
10.


Pages:
570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594
perfumy fm Stal rezerwacja hoteli pomiary wiatru Nike Buty Męskie Air Flex Trainer Lea