本文整理匯總了PHP中Food::getTotalPriceByCart方法的典型用法代碼示例。如果您正苦於以下問題:PHP Food::getTotalPriceByCart方法的具體用法?PHP Food::getTotalPriceByCart怎麽用?PHP Food::getTotalPriceByCart使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Food
的用法示例。
在下文中一共展示了Food::getTotalPriceByCart方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: checkout
public function checkout()
{
$cartModel = new Cart();
//Check cart is not empty
$cartData = $cartModel->getCount();
if ($cartData <= 0) {
$this->Session->setFlash('Your cart is empty, please back to homepage to shopping.', 'default', array(), 'success');
$this->redirect(array('controller' => 'carts', 'action' => 'view'));
}
//Check and save Customer data to database
if ($this->request->is('post') && !empty($this->request->data)) {
$this->Customer->create();
if ($this->Customer->save($this->request->data)) {
$customerId = $this->Customer->getLastInsertID();
//Save data to "invoices" table
$invoiceModel = new Invoice();
$invoiceData = array();
$invoiceData['Invoice']['customer_id'] = $customerId;
$invoiceData['Invoice']['order_date'] = date('Y-d-m H:i:s', strtotime('+1day'));
$foodModel = new Food();
$cartArray = $cartModel->readFood();
$totalPrice = $foodModel->getTotalPriceByCart($cartArray);
$invoiceData['Invoice']['total_price'] = $totalPrice;
$invoiceData['Invoice']['note'] = $this->request->data['Customer']['note'];
$invoiceData['Invoice']['price_temp'] = $totalPrice;
$invoiceData['Invoice']['price_refund'] = 0;
$invoiceData['Invoice']['payment_type'] = 'Cash';
if ($invoiceModel->save($invoiceData)) {
$invoiceId = $invoiceModel->getLastInsertID();
//Save data to "invoice_details" table
foreach ($cartArray as $foodId => $amount) {
$invoiceDetailModel = new InvoiceDetail();
$invoiceDetailData = array();
$invoiceDetailData['InvoiceDetail']['invoice_id'] = $invoiceId;
$invoiceDetailData['InvoiceDetail']['food_id'] = $foodId;
$invoiceDetailData['InvoiceDetail']['amount'] = $amount;
$foodData = $foodModel->getFoodDataById($foodId);
$invoiceDetailData['InvoiceDetail']['price'] = $foodData['Food']['price'];
$invoiceDetailData['InvoiceDetail']['is_choose'] = 0;
$invoiceDetailModel->save($invoiceDetailData);
}
//Set invoice_id to session after insert data to "invoices" table
CakeSession::write('invoice_id', $invoiceId);
//Remove cart ordered
$cartModel->resetCart();
$this->Session->setFlash('Thanks for your ordered.', 'default', array(), 'success');
$this->redirect(array('controller' => 'customers', 'action' => 'order'));
}
} else {
$this->Session->setFlash('Please input correct data.', 'default', array(), 'error');
}
}
//Show carts list
$carts = $cartModel->readFood();
$foods = array();
if (null != $carts) {
foreach ($carts as $foodId => $count) {
$foodModel = new Food();
$food = $foodModel->read(null, $foodId);
$food['Food']['count'] = $count;
$foods[] = $food;
}
}
$this->set(compact('foods'));
}
開發者ID:vinacode,項目名稱:CakePHP-ShoppingCart-with-Admin-Managements,代碼行數:65,代碼來源:CustomersController.php