😕
I am in the process of modifying a shopping cart ap and would like a little help with the array part of this. The current shopping cart stores the product id which it uses to retrieve details when you view the cart, adn it stores teh quantity. I would like to change it to store a color associated witht the product aand allow the user to choose teh quantity of items fromt eh product detail page (as it is, user can only change quantity on the show_cart page). The show cart file does the dirty work and seems to be the main place for the modification of the array. The code for this page is as follows:
<?
include ('products_sc_fns.php');
// The shopping cart needs sessions, so start one
session_start();
if($new)
{
//new item selected
if(!session_is_registered("cart"))
{
$cart = array();
session_register("cart");
$items = 0;
session_register("items");
$total_price = "0.00";
session_register("total_price");
}
if($cart[$new])
$cart[$new]++;
else
$cart[$new] = 1;
$total_price = calculate_price($cart);
$items = calculate_items($cart);
}
if($save)
{
foreach ($cart as $id => $qty)
{
if($$id=="0")
unset($cart[$id]);
else
$cart[$id] = $$id;
}
$total_price = calculate_price($cart);
$items = calculate_items($cart);
}
do_html_header("Your Shopping Cart");
if($cart&&array_count_values($cart))
display_cart($cart);
else
{
echo "<p>There are no items in your cart";
echo "<hr>";
}
$target = "index.php";
// if we have just added an item to the cart, continue shopping in that category
if($new)
{
$details = get_products_details($new);
if($details["catid"])
$target = "show_cat.php?catid=".$details["catid"];
}
display_button($target, "continue-shopping", "Continue Shopping");
$path = $PHP_SELF;
$path = str_replace("show_cart.php", "", $path);
display_button("http://".$SERVER_NAME.$path."checkout.php", "go-to-checkout", "Go To Checkout");
do_html_footer();
?>
You can see that by default the quantity is going to be 1 and then will be incremented if added again. The incrementing is good, but I need to receive the value of a form element named $quantity instead and increment that if added again.
The other part, and most confusing to me, is how can I modify the array and its' loop to account for the color value I am try to pass to this script?
Thanks for any help!!!! 🙂