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


PHP ShoppingCart::getCart方法代码示例

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


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

示例1: addToCart

 function addToCart($productId, $quantity, $productName, $price, $secure)
 {
     $basket = ShoppingCart::getCart();
     $cart = "";
     $changeProduct = "";
     $i = 0;
     $flag = 1;
     if ($basket != null) {
         $size = sizeof($basket);
         for ($i = 0; $i < $size; $i++) {
             /*add the same item to the cart and modify cookie['cart'] string*/
             if ($basket[$i][0] == $productId) {
                 $basket[$i][1] = $basket[$i][1] + $quantity;
                 $basket[$i][3] = ReceiptCalcs::calcSingleEntry($basket[$i][1], $price);
                 $changeProduct = "#" . $basket[$i][0] . "," . $basket[$i][1] . "," . $basket[$i][2] . "," . $basket[$i][3];
                 $cart = $cart . $changeProduct;
                 $flag = 0;
             } else {
                 /*product has not changed just add to the cookie['cart'] string*/
                 $product = "#" . $basket[$i][0] . "," . $basket[$i][1] . "," . $basket[$i][2] . "," . $basket[$i][3];
                 $cart = $cart . $product;
             }
         }
         /*for*/
         /*add new item to the cart and modify cookie['cart'] string*/
         if ($flag) {
             $lineTotal = ReceiptCalcs::calcSingleEntry($quantity, $price);
             $newItem = array($productId, $quantity, $productName, $lineTotal);
             array_push($basket, $newItem);
             $addProduct = "#" . $productId . "," . $quantity . "," . $productName . "," . $lineTotal;
             $cart = $cart . $addProduct;
             //print "addProduct" . $addProduct . "<br>";
             //print "cart" . $cart . "<br>";
         }
         /*if*/
     } else {
         /*basket is null add first item to the basket cookie['cart']*/
         $addProduct = "#{$productId},{$quantity},{$productName},{$price}";
         $basket[$i][0] = $productId;
         $basket[$i][1] = $quantity;
         $basket[$i][2] = $productName;
         $basket[$i][3] = ReceiptCalcs::calcSingleEntry($quantity, $price);
         $cart = $cart . $addProduct;
     }
     //print "setcookie = " . $cart ."<br>";
     //print "sizeof".sizeof($basket) ."<br>";
     setcookie("cart", $cart, 0, "/", '', $secure);
     return $basket;
 }
开发者ID:nateirwin,项目名称:custom-historic,代码行数:49,代码来源:ShoppingCart.php

示例2: render


//.........这里部分代码省略.........
        <div class="column2">' . i("Home delivery") . '</div><div class="column2"><input type="radio" name="shippingMethod" value="Home delivery" checked></input></div>
        <div class="column2" >' . i("Nearest store") . '</div><div class="column2"><input type="radio" name="shippingMethod" value="Nearest Store"></input></div>
        <div class="column2">' . i("Other") . '</div><div class="column2"><input type="radio" name="shippingMethod" value="Other"></input></div>
        <div class="bottomButton"><input type="reset" class="button button-primary" value="' . i("Reset") . '"><input  type="submit" class="button button-primary" value="' . i("Confirm") . '"/></div>
        <input class="input1" type="hidden" name="poster" value="shippingMethod"></input>
      </form>';
        $html .= '</div>';
        //a form to submit to myself
        $html .= "<div id='paymentMethod' class=" . GrootPaymentView::visibility("paymentMethod") . ">";
        $html .= '
      <div class="hidden"><input name="paymentMethodStore"></input></div>
      <form action="" method="POST">
      <h1>' . $title3 . '</h1><br />
        <div class="column2">' . i("Visa") . '</div><div class="column2"><input type="radio" name="paymentMethod" value="Visa" checked></input></div>
        <div class="column2">' . i("Postfinance") . '</div><div class="column2"><input type="radio" name="paymentMethod" value="Postfinance"></input></div>
        <div class="column2">' . i("Maestro") . '</div><div class="column2"><input type="radio" name="paymentMethod" value="Maestro"></input></div>
        <div class="column2">' . i("Check") . '</div><div class="column2"><input type="radio" name="paymentMethod" value="Check"></input></div>
        <div class="column2">' . i("PayPal") . '</div><div class="column2"><input type="radio" name="paymentMethod" value="PayPal"></input></div>
        <div class="column2">' . i("Other") . '</div><div class="column2"><input type="radio" name="paymentMethod" value="Other"></input></div>
        <div class="bottomButton"><input type="reset" class="button button-primary" value="' . i("Reset") . '"><input  type="submit" class="button button-primary" value="' . i("Confirm") . '"/></div>
        <input class="input1" type="hidden" name="poster" value="paymentMethod"></input>
      </form>';
        $html .= '</div>';
        //a form to submit to myself
        //onclick JS funktion
        $html .= "<div id='giftBox' class=" . GrootPaymentView::visibility("giftBox") . ">";
        $html .= '
      <div class="hidden"><input name="giftBox"></input></div>
      <form action="" method="POST">
      <h1>' . $title4 . '</h1><br />
        <h3>' . i("Is it a gift?") . '</h3>
        <div class="column2">' . i("No") . '</div><div class="column2"><input type="radio" name="giftBox" value="No" checked></input></div>
        <div class="column2">' . i("Yes") . '</div><div class="column2"><input type="radio" name="giftBox" value="Yes"></input></div>
        <div class="column2">' . i("Bemerkung") . ':</div><div class="column2"><textarea name="comment" rows="10" cols="80"></textarea></div>
        <div class="bottomButton"><input id="realSubmitButton"  type="submit" class="button button-primary hidden" value="' . i("Confirm") . '"/><input type="reset" class="button button-primary" value="' . i("Reset") . '"><input id="fakeSubmitButton" type="button" onclick="orderConfirmation()" class="button button-primary" value="' . i("Confirm") . '"/></div>
        <input class="input1" type="hidden" name="poster" value="giftBox"></input>
      </form>';
        $html .= '</div>';
        //a form to submit to myself
        $html .= "<div id='orderComplete' class=" . GrootPaymentView::visibility("orderComplete") . ">";
        $html .= '
      <div class="hidden"><input name="orderComplete"></input></div>
      <h1>' . $title5 . '</h1><br />
        <h3>' . i("thx_for_order_msg") . '</h3>
          ' . i("email_send_msg") . ' ' . $email . ' <br>

          <a href="index.php?view=home">
                  <input class="button button-primary" type="button" value="' . i('back_to_main') . '"></input>
                </a>

        ';
        //if the order is completed and accepted, send an email to the user email with the previous saved content
        if (GrootPaymentView::visibility("orderComplete") != "hidden") {
            $email_adress = $email;
            //"marcel.tschanz@bluemail.ch";
            $email_title = i("Order from Groot Shop");
            $emailContent = "";
            $emailContent .= "" . i("Order from Groot Shop") . " \n";
            $emailContent .= i("order_confirmation_msg") . " \n";
            $emailContent .= " \n";
            $emailContent .= $title1 . " \n";
            $emailContent .= "--------------------------------\n";
            $emailContent .= i('first_name') . ":  " . $_SESSION['payment_firstname'] . " \n";
            $emailContent .= i('last_name') . ":  " . $_SESSION['payment_lastname'] . " \n";
            $emailContent .= i('streetname') . ":  " . $_SESSION['payment_street'] . " \n";
            $emailContent .= i('zip') . ":  " . $_SESSION['payment_plz'] . " \n";
            $emailContent .= i('city') . ":  " . $_SESSION['payment_country'] . " \n";
            $emailContent .= " \n";
            $emailContent .= $title2 . ": " . i($_SESSION['payment_shippingMethod']) . " \n";
            $emailContent .= $title3 . ": " . i($_SESSION['payment_paymentMethod']) . " \n";
            $emailContent .= $title4 . ": " . i($_SESSION['payment_giftBox']) . " \n";
            $emailContent .= i('Note') . ":  " . $_SESSION['payment_comment'] . " \n";
            $emailContent .= "--------------------------------\n";
            $emailContent .= " \n";
            $emailContent .= $title5 . " \n";
            //shoppingcart content
            $myArray = json_decode($_COOKIE["shoppingCart"]);
            $myCart = new ShoppingCart($myArray);
            $cart = $myCart->getCart();
            foreach ($cart as $cartIsbn => $cartAmount) {
                $list = BookModel::findList(array('isbn' => array($cartIsbn)), null);
                $title = $list[0]['title'];
                $emailContent .= i('title') . " " . $title . "  " . i('isbn') . ":  " . $cartIsbn . "  " . $cartAmount . "x \n";
            }
            $emailContent .= "--------------------------------\n";
            $emailContent .= " \n";
            $emailContent .= " \n";
            $emailContent .= i("greetings_from_groot_team_msg") . " \n";
            $email_message = $emailContent;
            //TSCM Bitte beim Testen auskommentiert, weil es jedes mal wieder eine Email an mich versantd hat
            mail($email_adress, $email_title, $email_message);
        }
        $html .= '</div>';
        //show post values
        $postedValues = "";
        foreach ($_POST as $key => $value) {
            $postedValues .= "key = {$key} und value = {$value} </br>";
        }
        return $html;
    }
开发者ID:Makae,项目名称:ch.bfh.bti7054.w2014.q.groot,代码行数:101,代码来源:view.payment.php

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