function doesUserExist($userName, $password)
{
    require 'connect.php';
    $getUsers = 'select userName, password, firstName from users';
    $result = mysqli_query($connection, $getUsers);
    if ($result->num_rows > 0) {
        while ($user = mysqli_fetch_array($result)) {
            if ($user['userName'] == $userName && $user['password'] == $password) {
                //echo 'setting session userName variable as : ' . $userName;
                $_SESSION['userName'] = $userName;
                $_SESSION['firstName'] = $user['firstName'];
                $_SESSION['orderId'] = createOrderId();
                addOrderIdToDb($_SESSION['orderId'], $userName);
                return true;
            }
        }
    }
    return false;
}
use ClearSale\XmlEntity\SendOrder\Address;
use ClearSale\XmlEntity\SendOrder\AbstractCustomer;
use ClearSale\XmlEntity\SendOrder\CustomerBillingData;
use ClearSale\XmlEntity\SendOrder\CustomerShippingData;
use ClearSale\XmlEntity\SendOrder\FingerPrint;
use ClearSale\XmlEntity\SendOrder\Item;
use ClearSale\XmlEntity\SendOrder\Order;
use ClearSale\XmlEntity\SendOrder\Payment;
use ClearSale\XmlEntity\SendOrder\Phone;
try {
    // Dados da Integração com a ClearSale
    $entityCode = '<CLEARSALE_ENTITY_CODE>';
    $environment = new Sandbox($entityCode);
    // Dados do Pedido
    $fingerPrint = new FingerPrint(createSessionId());
    $orderId = createOrderId();
    $date = new \DateTime();
    $email = '*****@*****.**';
    $totalItems = 10.0;
    $totalOrder = 17.5;
    $quantityInstallments = 1;
    $ip = '127.0.0.1';
    $origin = 'WEB';
    $customerBillingData = createCustomerBillingData();
    $customerShippingData = createCustomerShippingData();
    $item = Item::create(1, 'Adaptador USB', 10.0, 1);
    $payment = Payment::create(Payment::BOLETO_BANCARIO, new \DateTime(), 17.5);
    // Criar Pedido
    $order = Order::createEcommerceOrder($fingerPrint, $orderId, $date, $email, $totalItems, $totalOrder, $quantityInstallments, $ip, $origin, $customerBillingData, $customerShippingData, $payment, $item);
    // Enviar pedido para análise
    $clearSale = new ClearSaleAnalysis($environment);
 public function show()
 {
     if (!isset($_SESSION['account'])) {
         $this->redirect('Member/login');
     }
     $model = D('Order');
     if ($vo = $model->create()) {
         //创建订单号
         $model->orderid = $orderid = createOrderId();
         if (isset($_SESSION['id'])) {
             $model->memberid = $_SESSION['id'];
         } else {
             $model->memberid = 0;
         }
         $model->ip = get_client_ip();
         $model->status = 2;
         $model->create_time = time();
         $list = $model->add();
         if ($list != false) {
             $type = $_REQUEST['type'];
             if ($type) {
                 $scmodel = D('Shopcart');
                 //购物车
                 $cartid = $_REQUEST['cartid'];
             }
             $id = $_REQUEST['id'];
             $price = $_REQUEST['price'];
             $num = $_REQUEST['num'];
             $allprice = $_REQUEST['allprice'];
             $orderdetail = D('Orderdetail');
             //订单详细
             if ($orderdetail->create()) {
                 for ($i = 0; $i < count($allprice); $i++) {
                     //加入订单详细
                     $orderdetail->orderid = $list;
                     $orderdetail->proid = $id[$i];
                     $orderdetail->price = $price[$i];
                     $orderdetail->num = $num[$i];
                     $orderdetail->allprice = $allprice[$i];
                     $orderdetail->status = 2;
                     $orderdetail->create_time = time();
                     $ok = $orderdetail->add();
                     if ($type) {
                         //删除购物车商品
                         $data = array();
                         $data['id'] = $cartid[$i];
                         $data['status'] = -1;
                         $up = $scmodel->save($data);
                     }
                 }
             }
             if ($ok) {
                 $this->success = "操作成功<br>您的订单号是:{$orderid}<br>我们的销售代表将主动和您联系!";
                 $this->display();
             }
         } else {
             //失败提示
             $this->error('订单提交失败,请稍后重试!');
         }
     } else {
         $this->error($model->getError());
     }
 }
        $allOrderedDishes = mysqli_query($connection, $fetchOrderedDishes);
        if ($allOrderedDishes->num_rows > 0) {
            while ($orderedDish = mysqli_fetch_array($allOrderedDishes)) {
                $dishId = $orderedDish['dishId'];
                $dishQuantity = $orderedDish['quantity'];
                $dishPrice = $orderedDish['price'];
                $insertIntoDishOrderHistory = "insert into dishOrderHistory\n\t\t\t\t\tvalues ('" . $orderId . "', " . $dishId . ", " . $dishQuantity . ", " . $dishPrice . ");";
                mysqli_query($connection, $insertIntoDishOrderHistory);
            }
        }
        $deleteDishOrders = "delete from dishOrders where orderId = '" . $orderId . "';";
        mysqli_query($connection, $deleteDishOrders);
        $deleteOrderId = "delete from orders where orderId = '" . $orderId . "';";
        mysqli_query($connection, $deleteOrderId);
        require 'functions.php';
        $_SESSION['orderId'] = createOrderId();
        addOrderIdToDb($_SESSION['orderId'], $_SESSION['userName']);
        $_SESSION['orderPlaced'] = true;
        header('Location: placeOrder.php') && exit;
    }
} else {
    $orderId = $_SESSION['orderId'];
    $fetchOrderedDishes = "select * from dishOrders where orderId = '" . $orderId . "';";
    $result = mysqli_query($connection, $fetchOrderedDishes);
    if ($result->num_rows > 0) {
        $totalPrice = 0.0;
        while ($orderedDish = mysqli_fetch_array($result)) {
            $totalPrice += $orderedDish['price'];
        }
        $_SESSION['totalPrice'] = $totalPrice;
        echo '<label id="totalPrice">Order Total : &#x20b9; ' . $totalPrice . '</label>';