tpl so that each displayed product includes an
Add to Cart button with a link like the ones shown earlier (a link to index.php with an additional
CartAction parameter in the query string).
Exercise: Adding Products to the New Shopping Cart
1. Add the following code at the end of include/config.php:
// Cart actions
define('ADD_PRODUCT', 1);
define('REMOVE_PRODUCT', 2);
define('UPDATE_PRODUCTS_QUANTITIES', 3);
define('SAVE_PRODUCT_FOR_LATER', 4);
define('MOVE_PRODUCT_TO_CART', 5);
2. If you implemented the PayPal shopping cart, you need to delete the code from presentation/store_
front.php that redirects to a PayPal link when an Add to Cart button is clicked. Open presentation/
store_front.php, and deletethe following code from the init() method:
// Create "Continue Shopping" link for the PayPal shopping cart
if (!isset ($_GET['AddProduct']))
{
CHAPTER 12 ?– CREATING YOUR OWN SHOPPING CART 379
/* Store the current request needed for the paypal
continue shopping functionality */
$_SESSION['paypal_continue_shopping'] =
Link::Build(str_replace(VIRTUAL_LOCATION, '',
$_SERVER['REQUEST_URI']));
...
...
// Redirect to the PayPal cart page
header('HTTP/1.1 302 Found');
header('Location: ' . $paypal_url);
// clear the output buffer and stop execution
flush();
ob_flush();
ob_end_clean();
exit();
}
3. Open presentation/link.php, and modify the code of the CheckRequest() method of the Link class
as highlighted:
// Redirects to proper URL if not already there
public static function CheckRequest()
{
$proper_url = '';
if (isset ($_GET['Search']) || isset($_GET['SearchResults']) ||
isset ($_GET['CartAction']))
{
return ;
}
4.
Pages:
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490