Example #1
0
function yab_shop_cart_quantity($atts)
{
    extract(lAtts(array('output' => 'single', 'showalways' => '1', 'break' => br, 'label' => 'Quantity: ', 'wraptag' => '', 'class' => ''), $atts));
    if ($label) {
        $label = htmlspecialchars($label);
    }
    $cart =& $_SESSION['wfcart'];
    if (!is_object($cart)) {
        $cart = new wfCart();
    }
    $qty = 0;
    $out = '';
    if ($output == 'single') {
        $qty += $cart->itemcount;
    } else {
        if ($cart->itemcount > 0) {
            foreach ($cart->get_contents() as $item) {
                $qty += $item['qty'];
            }
        }
    }
    if ($showalways == '1') {
        $out .= $label . $qty;
        $out = doTag($out, $wraptag, $class) . $break;
    } else {
        if ($cart->itemcount > 0) {
            $out .= $label . $qty;
            $out = doTag($out, $wraptag, $class) . $break;
        }
    }
    return $out;
}
Example #2
0
    $cart->del_item($rid);
}
// spit some forms
// You can have many different types of forms, such as many quantity boxes
// and an "add to cart" button at the bottom which adds all items
// but for the purposes of this demo we will handle one item at a time.
echo "<table>";
foreach ($products as $p) {
    echo "<tr><td><form method='post' action='demo.php'>";
    echo "<input type='hidden' name='id' value='" . $p['id'] . "'/>";
    echo "" . $p['name'] . ' $' . number_format($p['price'], 2) . " ";
    echo "<input type='text' name='qty' size='5' value='1'><input type='submit' value='Add to cart' name='add'>";
    echo "</form></td></tr>";
}
echo "</table>";
echo "<h2>Items in cart</h2>";
if ($cart->itemcount > 0) {
    foreach ($cart->get_contents() as $item) {
        echo "<br />Item:<br/>";
        echo "Code/ID :" . $item['id'] . "<br/>";
        echo "Quantity:" . $item['qty'] . "<br/>";
        echo "Price   :\$" . number_format($item['price'], 2) . "<br/>";
        echo "Info    :" . $item['info'] . "<br />";
        echo "Subtotal :\$" . number_format($item['subtotal'], 2) . "<br />";
        echo "<form method=post><input type='hidden' name='id' value='" . $item['id'] . "'/><input type='submit' name='remove' value='Remove'/></form>";
    }
    echo "---------------------<br>";
    echo "total: \$" . number_format($cart->total, 2);
} else {
    echo "No items in cart";
}