Mini Tutorial: How to Set Ordered Quantity to Quantity on Hand

Some times, customers add quantities of items that exceed the inventory amount.
Magento’s default reaction to this is to throw a “The requested quantity for ____ is not available” message and the product is not added to the cart.

Another way to handle this is to automatically set the quantity ordered to the quantity on hand value.

To do this, one has to override the checkQuoteItemQty($qty, $summaryQty, $origQty = 0) function inside the Model: Mage_CatalogInventory_Model_Stock_Item.

Simple change this portion of the code:

$message = Mage::helper('cataloginventory')->__('The requested quantity for "%s" is not available.', $this->getProductName());
$result->setHasError(true)
->setMessage($message)
->setQuoteMessage($message)
->setQuoteMessageIndex('qty');

To

$message = Mage::helper('cataloginventory')->__('The requested quantity for "%s" is not available.', $this->getProductName());
$result->setHasError(false)
->setOrigQty($this->getQty())
->setMessage($message)
->setQuoteMessage($message)
->setQuoteMessageIndex('qty');