How can I manually change/limit the amount of order items in the shopping cart?

For instance, the max items for France is 120, Switzerland is 12, while the rest of available countries is 60.

This is the input field for getting the total order from the cart's session.

<input name="cart[<?php echo $_item->getId() ?>][qty]" value="<?php echo $this->getQty() ?>" size="4" title="<?php echo $this->__('Qty') ?>"/>

Below is what I am currently doing but it does not effect the number of $this->getQty()

<?php if($shippingCountry === 'FR' || $shippingCountry === 'MC' || $shippingCountry === null):?>120<?php elseif($shippingCountry === 'CH'):?>12<?php else:?>60<?php endif;?> 

I still get 120 for Switzerland for instance with $this->getQty() but it should be 12.

is it possible to change that?

  • 1
    Tealau,if you getting this message "The maximum quantity allowed for purchase.." then it ok.it magento bug
    – Amit Bera
    Commented Aug 28, 2014 at 6:34

1 Answer 1


I would do this by hooking onto the event: sales_quote_save_before and check the total quantity of items in the quote. Something like:

public function myObserverMethod($Observer)

   $quote = $observer->getDataObject();
   foreach($quote->getAllItems() as $item){    
       $totalQty += $item->getQty();       
     if($totalQty > 60 ) //Whatever your conditions are
         Mage::getSingleton('checkout/session')->addError('Quantity limit exceeded');

    return $this;    


EDIT : Follow this to create an observer for event: sales_quote_save_before

  • thanks but where can I locate sales_quote_save_before?
    – Run
    Commented Aug 28, 2014 at 9:56
  • Edited my answer with a link.
    – Paras Sood
    Commented Aug 28, 2014 at 10:48

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.