..
14. Now everything is in its place, and you can see the results. Log in to your site, add some products to your
shopping cart, and then click the Checkout link on your shopping cart page. Your page will look something
like Figure 16-9 shown earlier.
How It Works: The checkout_info Componentized Template
In the init() method of the CheckoutInfo class, you start by checking whether the customer clicked the Place
Order button. If so, you save the order in the database and redirect the customer to the home page:
// If the Place Order button was clicked, save the order to database ...
if(isset ($_POST['place_order']))
{
// Create the order and get the order ID
$order_id = ShoppingCart::CreateOrder();
// This will contain the PayPal link
$redirect =
PAYPAL_URL . '&item_name=TShirtShop Order ' .
urlencode('#') . $order_id .
'&item_number=' . $order_id .
'&amount=' . $this->mTotalAmount .
CHAPTER 16 ?– MANAGING CUSTOMER DETAILS 538
'¤cy_code=' . PAYPAL_CURRENCY_CODE .
'&return=' . PAYPAL_RETURN_URL .
'&cancel_return=' . PAYPAL_CANCEL_RETURN_URL;
// Redirection to the payment page
header('Location: ' . $redirect);
exit();
}
We also set up some variables for the template to use:
// Set members for use in the Smarty template
$this->mCartItems = ShoppingCart::GetCartProducts(GET_CART_PRODUCTS);
$this->mTotalAmount = ShoppingCart::GetTotalAmount();
$this->mCustomerData = Customer::Get();
If the customer didn??™t enter credit card information or a shipping address yet, a notice is displayed, and the Place
Order button is disabled.
Pages:
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649