当前位置: 首页>>代码示例>>PHP>>正文


PHP Food::read方法代码示例

本文整理汇总了PHP中Food::read方法的典型用法代码示例。如果您正苦于以下问题:PHP Food::read方法的具体用法?PHP Food::read怎么用?PHP Food::read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Food的用法示例。


在下文中一共展示了Food::read方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: read

 public function read()
 {
     $totalCount = 0;
     $returnValue = Food::read($this->params, $totalCount);
     $this->additionalReturnValues["total"] = $totalCount;
     return $returnValue;
 }
开发者ID:ncowan15,项目名称:FoodApp3,代码行数:7,代码来源:foods.php

示例2: 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


注:本文中的Food::read方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。