2

Our store basically sells 6 month and annual subscriptions to our businesses website.

I was wondering if there was a way to make it so that they can only add one subscription (product) to the cart, not multiples, so customers don't make the mistake of buying double subscriptions.

I know you can limit the number of each individual products than can be added to the cart in the inventory tab but that's not quite what I'm after.

So basically what I want is to limit it to one product per order, not one of each product per order. Does that make sense?

2 Answers 2

4

The first port of call would be to check the available event observers.

Depending on your Magento version - there may not be a before product add - only after events.

checkout_cart_save_before
checkout_cart_product_add_after
checkout_cart_update_items_before
checkout_cart_update_items_after
checkout_cart_save_after

So use the observer if its present.

Otherwise you could extend Mage_Checkout_Model_Cart and alter the addOrderItem() function to include a conditional statement.

Eg.

protected $_maxCartQty = 1;

public function addOrderItem($orderItem, $qtyFlag=null)
{
  $cartSize = $this->getQuote()->getAllItems()->getSize();        
  if ($cartSize >= $this->_maxCartQty) {
    $this->getCheckoutSession()->addError(
      Mage::helper('checkout')->__('The maximum order qty is %d', $this->_maxCartQty)
    );

    return $this;
  }
1

I prefer the checkout_cart_save_before event, because you can remove the items from the cart (maybe add an error) and you don't need to save the cart or collectTotals() or something

hook into the event, loop through all the quote_items and set the qty to 1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.