Okay, I've been fighting this all weekend. I only want customers to be able to buy one item at a time. I doing subscriptions through the cart. I have everything set including the nasty PayPal link. My problem is, everywhere else it still says that the customer has ordered more then one item, even if they were only charged for one. I figure if I can limit the solution in the Add and Update functions, it will solve my problem.
How can I change this code to check to see if there already is an item in the cart and stop if there is. Like if (i>1) kind of thing, but I'm not sure of the variables. I can do the errors and redirects needed, I'm just not sure how to get it to check the cart. Thank you.
Code:
// customer wants to update the product quantity in their shopping cart
case 'update_product' : for ($i=0; $i<sizeof($HTTP_POST_VARS['products_id']);$i++) {
if (in_array($HTTP_POST_VARS['products_id'][$i], (is_array($HTTP_POST_VARS['cart_delete']) ? $HTTP_POST_VARS['cart_delete'] : array()))) {
$cart->remove($HTTP_POST_VARS['products_id'][$i]);
} else { // if PHP3, make correction for lack of multidimensional array in PHP3
if (ereg('^3\.', phpversion())) {
reset($HTTP_POST_VARS);
while (list($key, $value) = each($HTTP_POST_VARS)) {
if (is_array($value)) {
while (list($key2, $value2) = each($value)) {
if (ereg ("(.*)\]\[(.*)", $key2, $var)) {
$id2[$var[1]][$var[2]] = $value2;
}
}
}
}
$attributes = ($id2[$HTTP_POST_VARS['products_id'][$i]]) ? $id2[$HTTP_POST_VARS['products_id'][$i]] : '';
} else {
$attributes = ($HTTP_POST_VARS['id'][$HTTP_POST_VARS['products_id'][$i]]) ? $HTTP_POST_VARS['id'][$HTTP_POST_VARS['products_id'][$i]] : '';
}
$cart->add_cart($HTTP_POST_VARS['products_id'][$i], $HTTP_POST_VARS['cart_quantity'][$i], $attributes);
}
}
tep_redirect(tep_href_link($goto, tep_get_all_get_params($parameters), 'NONSSL'));
break;
// customer adds a product from the products page
case 'add_product' : if (ereg('^[0-9]+$', $HTTP_POST_VARS['products_id'])) {
$cart->add_cart($HTTP_POST_VARS['products_id'], $HTTP_POST_VARS['cart_quantity'], $HTTP_POST_VARS['id']);
}
tep_redirect(tep_href_link($goto, tep_get_all_get_params($parameters), 'NONSSL'));
break;
Bookmarks