PDA

View Full Version : Limiting one item per customer - narrowed to actions in head



Anonymous
12-08-2002, 04:57 PM
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.




// 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_i d'][$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;

Anonymous
12-09-2002, 03:25 AM
Instead of looking to disable the cart function after 1 purchase try sending to buy know directly to the checkout

Anonymous
12-09-2002, 04:42 PM
That makes sense, but then they could still navigate back. I want to make it final. The reason is because the way the store is set up, they could add a monthly and a yearly and make it through PayPal, and then I would be forced to lose a lot of money. I couldn't go back and negotiate the price. It would be like signing a contract. If I only let them get to PayPal with one item, with coding, that works but then in the email, order history and confirmation page, it shows that they bought two items. Very unprofessional.

vandiike
03-29-2004, 12:33 AM
Hi I am trying to do the similar, did you find any good solution?

Regads

Mike