本文整理匯總了PHP中ShoppingCart::getItems方法的典型用法代碼示例。如果您正苦於以下問題:PHP ShoppingCart::getItems方法的具體用法?PHP ShoppingCart::getItems怎麽用?PHP ShoppingCart::getItems使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類ShoppingCart
的用法示例。
在下文中一共展示了ShoppingCart::getItems方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: ShoppingCart
<td width="40px" align="center">Preis(EUR)</td>
<td colspan="2" width="200px"> </td>
</tr>
<tr>
<td colspan="6"> </td>
</tr>
<?php
/* load or initialize the ShoppingCart */
if (!isset($shopping_cart)) {
if (isset($_SESSION["cart_product_id_array"])) {
$shopping_cart = new ShoppingCart($_SESSION["username"], $_SESSION["cart_product_id_array"], $_SESSION["cart_product_amount_array"]);
} else {
$shopping_cart = new ShoppingCart($_SESSION["username"]);
}
}
$list = $shopping_cart->getItems();
/* if there were any actions, set the focus to the next item */
$prev_edit_product_id = "";
$set_focus_next = false;
if (var_get_post("action", "") == "edit_product_amount") {
$prev_edit_product_id = var_get_post("product_id", "");
}
for ($i = 0; $i < count($list); $i++) {
echo "\t<tr class=\"list_normal\" onmouseover=\"javascript: this.className='list_hover';\" onmouseout=\"javascript: this.className='list_normal';\">\n";
echo "\t<form name=\"edit_product_amount_" . $list[$i][0] . "\" action=\"shoppingcart.php\" method=\"POST\">\n";
echo "\t<input type=\"hidden\" name=\"action\" value=\"edit_product_amount\">\n";
echo "\t<input type=\"hidden\" name=\"product_id\" value=\"" . $list[$i][0] . "\">\n";
echo "\t<input type=\"submit\" value=\"\" class=\"invisible_submit\">\n";
echo "\t\t<td onclick=\"javascript: window.location.href = 'product_details.php?product_id=" . $list[$i][0] . "';\">" . $list[$i][0] . "</td>\n";
echo "\t\t<td onclick=\"javascript: window.location.href = 'product_details.php?product_id=" . $list[$i][0] . "';\">" . $list[$i][1] . "</td>\n";
echo "\t\t<td onclick=\"javascript: window.location.href = 'product_details.php?product_id=" . $list[$i][0] . "';\">" . $list[$i][4] . "</td>\n";
示例2: foreach
case 'add':
foreach ($products as $product) {
if ($product['name'] == $name) {
$cart->add($name);
break;
}
}
break;
case 'empty':
$cart->clear();
break;
case 'remove':
$cart->remove($name);
break;
}
$items = $cart->getItems();
if (!empty($items)) {
echo '
<table class="table">
<tr>
<td><b>Product</b></td>
<td><b>Price</b></td>
<td><b>Qty</b></td>
<td><b>Total</b></td>
<td></td>
</tr>';
$total = 0;
foreach ($items as $name => $qty) {
foreach ($products as $product) {
if ($product['name'] == $name) {
break;