product_id = p.product_id
WHERE sc.cart_id = inCartId AND sc.buy_now;
-- Save the order's total amount
UPDATE orders
SET total_amount = (SELECT SUM(unit_cost * quantity)
FROM order_detail
WHERE order_id = orderId)
WHERE order_id = orderId;
-- Clear the shopping cart
CALL shopping_cart_empty(inCartId);
CHAPTER 17 ?– STORING CUSTOMER ORDERS 545
-- Return the Order ID
SELECT orderId;
END$$
6. Modify the CreateOrder() method of the ShoppingCart class in business/shopping_cart.php as
follows:
// Create a new order
public static function CreateOrder($customerId)
{
// Build SQL query
$sql = 'CALL shopping_cart_create_order(:cart_id, :customer_id)';
// Build the parameters array
$params = array (':cart_id' => self::GetCartId(),
':customer_id' => $customerId);
// Execute the query and return the results
return DatabaseHandler::GetOne($sql, $params);
}
7. Modify the init() method in presentation/checkout_info.php as highlighted:
public function init()
{
// 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 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(Customer::GetCurrentCustomerId());
// This will contain the PayPal link
$redirect =
PAYPAL_URL .
Pages:
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657