On a recent project I had to write a piece of code which I thought I’d share with the Magento community in case it comes in useful for anyone. I have put all the code into one ‘add to cart’ controller below for the sake of simplicity, but you could break it up into separate methods to clean up the code a bit.
In a nutshell, all products on the site have a normal price and some have a package price. If they have a package price they are capable of being purchased with other products as part of a package deal, but only two at a time. Therefore these products had to be purchased as one product using the special prices as we can’t have customers adjusting the quantities of items added to the cart. Here’s the code in myPackageController.php broken up: