Cart Limits

Posts: 30
Joined: 01/30/2008

I have some quick questions regarding products and the cart:

* Is it possible to limit the user to have only 1 (or any other number) of a certain item in their cart per order? (e.g., "Limit 1 per order")
* Is it possible to set items so they can only be ordered by themselves and with no other products?

Thanks!

Posts: 1293
Joined: 08/14/2007
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.

I answered this a while back, check it out here: http://www.ubercart.org/forum/support/2540/whats_best_way_restrict_users...

--

"Pain don't hurt." - Dalton

Mike Nelson's RiffTrax! www.rifftrax.com

Posts: 30
Joined: 01/30/2008

Thanks for the answer. Is this going to be implemented in a future release?

Also, I don't think this question was answered:
* Is it possible to set items so they can only be ordered by themselves and with no other products?

Posts: 1293
Joined: 08/14/2007
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.

I don't know if they have any plans of putting this in core, at the moment.

I did answer your second question, it was below the block of code I posted:

You can easily change this to restrict to just one item in the cart, period - just get rid of the $nid comparison.

In other words:

<?php
function uc_test_add_to_cart($nid, $qty, $data) {

$items = uc_cart_get_contents();

    foreach(
$items as $cartitem) {
     
    if (
$cartitem->qty > 0) {
       
$result[] = array(
       
'success' => FALSE,
       
'message' => t('Sorry, you can only have 1 item in your cart at a time.'),
        );
    }  
    }
  return
$result;
}
?>

This would prevent them from adding an item to their cart if there is already one in there. Another (easier) method would be to use a Cart Link, and set it up to clear the user's cart with every click. So everytime they click a new Add to Cart link, it clears the cart and adds the new item.

--

"Pain don't hurt." - Dalton

Mike Nelson's RiffTrax! www.rifftrax.com

Posts: 30
Joined: 01/30/2008

Thanks for the suggestions/code. I hope both of these features get implemented, or at least put in the FAQ.

I'm an ubercart n00b, so where would these code change be placed? In uc_cart somewhere?

Posts: 301
Joined: 11/19/2007
Bug FinderGetting busy with the Ubercode.

I don't think anyone has used this module yet, but the expected use of it was to implement simple php code snippets like the ones suggested without adding having to write a new custom module.

http://www.ubercart.org/contrib/2289

For the product you'd like to limit, you'd go to the custom price field and place...

if($item->qty > 1) {
  $item->qty = 1;
}

which would prevent more than one of these from being added to the cart. You could add in a drupal_set_message() as well to help explain.

I believe you'd be able to use this module to clear the cart when a certain product was added as well.

Posts: 30
Joined: 01/30/2008

Good idea, cYu. I'll talk with the person who I'm making this for to see what would be the better implementation.