本文整理汇总了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