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


PHP ShoppingCart::addToCart方法代码示例

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


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

示例1: index

 /**
  *
  * init Detail page
  */
 public function index()
 {
     $editItemSession = new Session('editItem');
     $editItemSession->emptySession();
     if (!\Project\Auth\models\AuthModel::getUser()) {
         // echo "you should log in first";
         if (isset($_POST["filmId"])) {
             $filmId = $_POST["filmId"];
             header("Location: ./index.php?route=HomePageController/postToBooking/{$filmId}&click=click");
         } else {
             header("Location: ./index.php");
         }
     } else {
         //var_dump(\Project\Auth\models\AuthModel::getUser());
         $filmBooking = new FilmBookingModel();
         $cart = new ShoppingCart();
         if (!empty($_POST["OrderInfo"]) && !empty($_POST["filmId"])) {
             // if(isset($_POST["OrderInfo"])&& isset($_POST["seatsNums"]) &&isset($_POST["filmId"])){
             $bookingInfo = explode("| ", $_POST["OrderInfo"]);
             $seats = explode(" ", $_POST["seatsNums"]);
             $price = $_POST["totalPrice"];
             $tax = 0.13;
             $totalPrice = (1 + $tax) * $price;
             $bookInfo = new stdClass();
             $bookInfo->Run_Time = $bookingInfo[0];
             $bookInfo->Film_Name = $bookingInfo[1];
             $bookInfo->Cinema = $bookingInfo[2];
             $bookInfo->Room = $bookingInfo[3];
             $bookInfo->Cinema_Address = $bookingInfo[4];
             $bookInfo->Room_ID = $bookingInfo[5];
             $bookInfo->Seats = $_POST["seatsNums"];
             $bookInfo->TotalPrice = $totalPrice;
             $bookInfo->Price = $price;
             $bookInfo->Tax = $tax;
             $bookInfo->FilmId = $_POST["filmId"];
             $bookInfo->Cinema_ID = $_POST["Cinema"];
             $bookInfo->showDate = $bookingInfo[6];
             $bookInfo->showTime = $bookingInfo[7];
             $itemId = trim($_POST["itemId"]);
             //$cart->showCart();
             if (!empty($_POST["seatsNums"])) {
                 //check database first
                 foreach ($seats as $seat) {
                     $sql = "SELECT Seat_Name, available\n                           From seats WHERE Room_ID=:Room_ID AND Run_Time=:Run_Time AND Seat_Name=:Seat_Name";
                     $param = ["Room_ID" => $bookInfo->Room_ID, "Run_Time" => $bookInfo->Run_Time, "Seat_Name" => $seat];
                     $seatInfo = $filmBooking->getBookingDetail($param, $sql);
                     // var_dump($seatInfo);
                     if (is_array($seatInfo)) {
                         if ($seatInfo[0]->available == 'N') {
                             // require_once"./View/Error404.php";
                             self::seatsOccupied($bookInfo, $itemId);
                             exit;
                         }
                     }
                 }
             } else {
                 self::seatsEmpty($bookInfo, $itemId);
                 exit;
             }
             if ($itemId != "") {
                 //echo"Item id not null";
                 $cart->updateCartByItemId($itemId, $bookInfo);
             } else {
                 $cart->addToCart($bookInfo);
             }
             /*
              * Calculate Total Price
              *
              */
             $grandPrice = 0;
             foreach ($cart->shoppingCart->data as $item) {
                 $grandPrice += $item->TotalPrice;
             }
             $totalPrice = new Session('grandPrice');
             $totalPrice->emptySession();
             $totalPrice->data[] = $grandPrice;
             //var_dump($bookInfo);
             //$cart->showCart();
             foreach ($seats as $seat) {
                 $sql = "UPDATE seats\n                       SET available='N'\n                       WHERE Room_ID=:Room_ID AND Run_Time=:Run_Time AND Seat_Name=:Seat_Name";
                 $param = ["Room_ID" => $bookInfo->Room_ID, "Run_Time" => $bookInfo->Run_Time, "Seat_Name" => $seat];
                 $filmBooking->updateSeats($param, $sql);
                 require_once "./View/Comfirm.php";
             }
         }
     }
 }
开发者ID:zhaoyiyi,项目名称:php-project,代码行数:91,代码来源:DetailController.php

示例2: explode

<?php

if (!isset($quantity) || $quantity <= 0) {
    $quantity = 1;
}
if (isset($_COOKIE['cart']) || isset($_REQUEST['addp'])) {
    $basket = null;
    if (isset($_REQUEST['addp'])) {
        $addp = $_REQUEST['addp'];
        $prInfo = explode('&', $addp);
        $prId = $prInfo[0];
        $prName = $prInfo[1];
        $prPrice = $prInfo[2];
        $basket = ShoppingCart::addToCart($prId, $quantity, $prName, $prPrice, 1);
    } else {
        $basket = ShoppingCart::getCart();
    }
    $subtotal = ShoppingCart::subTotal($basket);
    $smarty->assign("basketItems", $basket);
    $smarty->assign("subtotal", $subtotal);
}
开发者ID:nateirwin,项目名称:custom-historic,代码行数:21,代码来源:cart.php


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