本文整理汇总了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";
}
}
}
}
示例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);
}