Magento Forum

Only allow checkout if basket contains multiple of ‘x’ items? 
 
rscott
Jr. Member
 
Total Posts:  10
Joined:  2008-03-12
 

I’m looking to migrate a Zen Cart store over to Magento soon, but have hit a brick wall with this problem:-

The store currently sells a mixture of products (bottles of wine, spirits, corkscrews,etc).  There is a restriction that shoppers can only buy wines & spirits in multiples of 6 (can be mixed product),.

Is there a simple way of enforcing this check - basically, it’s a restriction which prevents checkout if total number of products in a category (or possibly categories...) is not a multiple of ‘x’ (currently 6).

Any suggestions where to tweak this would be appreciated…

 
Magento Community Magento Community
Magento Community
Magento Community
 
dada21
Jr. Member
 
Total Posts:  28
Joined:  2008-04-01
 

Simple?  Probably not.  Basically what you’d have to do is add a hard-code if-then check statement to every “Checkout” button on your site.  You could theoretically do this by changing the checkout page to a page that verifies how many items are there, and then sends the person to the real checkout page if it is evenly divisible by 6, or if not, sends them to an error page.

This is how I would do it:

In app/design/frontend/default/default/template/checkout/ there is a file called onepage.phtml

I’d copy that to onepage2.phtml and create a NEW onepage.phtml that only checks if the quantities are divisible by 6 evenly.  If they are, don’t even wait, just forwrd the user to the new onepage2.phtml to continue checkout.  IF they’re not evenly divisible, send them to a new page called onepageerror.html that says “Sorry, you must buy items in multiples of 6” and explain it to them and halt there, or let them have a link back to their store.  Even better, maybe throw in a “Recommended” items list below on that error page to let them quickly add items (high markup items, preferably) to finish their checkout.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Lol
Member
 
Avatar
Total Posts:  68
Joined:  2008-06-26
Plymouth, UK
 

Thanks dada.

I have to do a similar thing to rscott: I need to ensure a customer has a minimum total of $30 in their shopping cart (or 5 of one kind of product and 4 of another) before checking out is possible. In your opinion, is what you have suggested doable for somebody with ok php skills or will it require an advanced understanding of OOP concepts and a deep understanding of Magento? I don’t want to have to spend a long time on this but I am willing to give it a go if I think it might be possible for me to sort it.

 
Magento Community Magento Community
Magento Community
Magento Community
 
dada21
Jr. Member
 
Total Posts:  28
Joined:  2008-04-01
 

Lol:

Personally I haven’t done it, but if you have even mediocre coding skills, I’d say it should be a fairly easy process.  I’d toss it all in the same checkout area, basically “If order > $300, goto checkout, else goto notenough.html” sort of check.

 
Magento Community Magento Community
Magento Community
Magento Community
 
erict
Member
 
Total Posts:  31
Joined:  2008-07-21
 
dada21 - 07 August 2008 10:10 AM

Personally I haven’t done it, but if you have even mediocre coding skills, I’d say it should be a fairly easy process.  I’d toss it all in the same checkout area, basically “If order > $300, goto checkout, else goto notenough.html” sort of check.

Things are usually not that simple in Magento… just to do that check will require some understanding of OOP in PHP, and either grepping the source for the correct calls (if you have some idea what you’re looking for) or digging around manually until you find what you need (which can take hours, if not days).  Getting the session checkout/quote object, getting the items in it, getting their prices and quantities, all require method calls and instantiation through nonstandard methods.

Another problem is finding out exactly where to put that logic, as each page load instantiates (literally) THOUSANDS of objects from tens or hundreds of classes as well as dozens of template files based on at least one XML layout.

If you can pinpoint one of the first few calls and put a header redirect in, you’ll have a chance to add your logic (once you’ve figured out how to write it) without causing a “headers already sent” error.

Unless you’re a programmer… well, even if you are a programmer, good luck.  Not a simple modification.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Moshe
Magento Team
 
Avatar
Total Posts:  1770
Joined:  2007-08-07
Los Angeles
 

For minimum order amount in Magento 1.1 please see Admin > Configuration > Sales > Minimum Order Amount

For minimum quantity you could override Mage_Sales_Model_Quote_Address method validateMinimumAmount() and iterate through quote items to get total qty and validate it.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Lol
Member
 
Avatar
Total Posts:  68
Joined:  2008-06-26
Plymouth, UK
 

@Moshe: thank you very much for pointing out that Mag 1.1 has the minimum order functionality built right in! I hadn’t spotted that. In fact 1.1 provides fixes for both my client’s requirements: Minimum Order value and a Terms & Conditions check box. Awesome stuff.

Of course, it would be (will be! wink ) great if it was possible to easily set conditions for whether or not ‘Proceed to Checkout’ was allowed based on something very similar to the ‘shopping cart price rules’ methodology. If you could set up a few conditions like in the attached image and then just select whether the checkout was enabled or not and be able to add an appropriate notification message that would be so very useful. (I realise the logic in the attached image is not right but I was just experimenting and trying to find a way to specify a minimum quantity for different product categories.)

Thanks again.

Image Attachments
Cart_conditions.jpg
 
Magento Community Magento Community
Magento Community
Magento Community
 
rscott
Jr. Member
 
Total Posts:  10
Joined:  2008-03-12
 

@Moshe ..

Thanks for that - I’ll have a dig over the next few days and let you know how it goes…

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top