function countItems($item)
{
    $count = 0;
    if ($item['children']) {
        foreach ($item['children'] as $i) {
            $count++;
            $count += countItems($i);
        }
    }
    return $count;
}
Exemple #2
0
function showCartTable($cart, $readonly = FALSE)
{
    if (!is_array($cart)) {
        echo "Empty cart<br>";
        return;
    }
    echo "<table border='0' width='100%'>\r\n\t\t\t<tr><td bgcolor='black'>Item</td>\r\n\t\t\t<td bgcolor='black'>Price</td>\r\n\t\t\t<td bgcolor='black'>Quantity</td>\r\n\t\t\t<td bgcolor='black' align='right'>Total</td></tr>";
    if (!$readonly) {
        echo "<form action='cart.php' method='post' id='editqty'>";
    }
    foreach ($cart as $pid => $qty) {
        $product = getProductInfo($pid);
        echo "<tr>";
        echo "<td><a href='viewitem.php?p=" . $pid . "'>" . $product['productname'] . "</a></td>";
        echo "<td>\$" . $product['price'] . "</td>";
        if ($readonly) {
            echo "<td>" . $qty . "</td>";
        } else {
            echo "<td><input type='text' name='" . $pid . "' value='" . $qty . "' size='2'></td>";
        }
        echo "<td align='right'>\$" . number_format($qty * $product['price'], 2) . "</td>";
        if (!$readonly) {
            echo "<td align='right'><a href='cart.php?remove=" . $pid . "'>Remove</a></td>";
        } else {
            echo "";
        }
        echo "</tr>";
    }
    echo "<tr>";
    echo "<td colspan='2'>&nbsp;</td>\r\n\t\t\t<td><b>" . countItems($cart) . "</b></td>\r\n\t\t\t<td align='right'><b>\$" . number_format(calculateTotal($cart), 2) . "</b></td>";
    echo "</tr>";
    if (!$readonly) {
        echo "<tr>";
        echo "<td colspan='2'>&nbsp;</td>\r\n\t\t\t<td align='center'><input type='submit' name='edit' value='Update' /></td>\r\n\t\t\t<td>&nbsp;</td>";
        echo "</tr></form>";
    }
    echo "</table>";
}
Exemple #3
0
// Remove a product from the cart completely (ignores quantity)
if (isset($_GET['remove'])) {
    $pid = $_GET['remove'];
    if (isset($_SESSION['cart'][$pid])) {
        unset($_SESSION['cart'][$pid]);
    }
    $_SESSION['numcart'] = countItems($_SESSION['cart']);
    $_SESSION['statusmsg'] = "Item removed from cart.";
    header("Location: viewcart.php");
    die;
}
if (isset($_POST['edit'])) {
    // Edit quantities from the view cart page here
    foreach ($_SESSION['cart'] as $pid => $qty) {
        if ($_POST[$pid] <= 0) {
            unset($_SESSION['cart'][$pid]);
        } else {
            $product = getProductInfo($pid);
            if ($product['stock'] < $_POST[$pid]) {
                // Immediately error back to view cart, I guess?
                $_SESSION['errmsg'] = "Unable to modify quantity for product: " . $product['productname'] . "<br>Not enough left in stock!";
                header("Location: viewcart.php");
                die;
            }
            $_SESSION['cart'][$pid] = $_POST[$pid];
        }
    }
    $_SESSION['numcart'] = countItems($_SESSION['cart']);
}
header("Location: viewcart.php");
die;
Exemple #4
0
</table>
<?php 
    }
    ?>

<?php 
    if ($ad_shop) {
        ?>
<div class="dg_head_background"<?php 
        echo checkBasket();
        ?>
><?php 
        echo JText::_('COM_DATSOGALLERY_BASKET_ITEMS');
        ?>
 <span id="items"><?php 
        countItems();
        ?>
</span> <?php 
        echo dgTip(JText::_('COM_DATSOGALLERY_CHECKOUT'), $image = 'basket_go.png', '', JRoute::_('index.php?option=com_datsogallery&amp;task=checkout' . $itemid), '', $link = 1);
        ?>
 <div style="float: right"><?php 
        echo JText::_('COM_DATSOGALLERY_BASKET_SUBTOTAL');
        ?>
: <?php 
        echo currencySymbol($ad_pp_currency);
        ?>
<span id="subtotal"><?php 
        echo subTotal();
        ?>
</span></div></div>
<div id="dg_body_background_basket" class="dg_slider"<?php