Was contacted recently by someone who wanted the ability to define a minimum number of items in the cart to allow checkout. The answer to this is very simple; in checkout_shipping.php, use $cart->count_contents() and link that to a tep_redirect back to shopping_cart if the number is not big enough;
if ($cart->count_contents() < 5) tep_redirect(tep_href_link(FILENAME_SHOPPING_CART)); So, if there is less than 5 items in the cart, they cannot progress through the checkout. Then I got to thinking. What about if the shopowner wanted the buyer to have at least 5 different items in their cart before checking out? Again, something similar, but instead of using cart->count_contents(), use $cart->get_product_id_list()
I thought that something like this might come in handy one day, so I set out to make it. Within an hour I had the basics in place;
Admin
This shows the three options that I coded;
Minimum Items.
“What is the minimum number of items to allow checkout”. If the shopowner inserted the number 3, then the buyer would be forced to add at least 3 of EACH product to his cart.
Minimum Items (Overall)
“Minimum number of items per order overall to allow checkout”. If the shopowner inserted 5 here, then the buyer would need to have at least 5 products in his cart in order to checkout. These 5 could be ANY combination; 5 of the same product, 5 different, 3 of 1 and 2 of another and so on.
These also work in conjunction with each other.
So, let’s say that “minimum items” is set to 2, and “minimum items (overall)” is set to 6. Logic would say that the buyer is forced to buy at least 2 of any item, but 6 overall, thus:
What the buyer could do is purchase 6 of 1 item and this would be OK as it satisfies both the “minimum items” and “minimum items (overall)” rule;
Or the buyer could purchase 2 of 1 item and 4 of another (as this also satisfies the rules);
Let’s take an example that at first glance appears to satisfy the rules; (eg, 2 of 1 product, 3 of another product and 1 of another) – this will not complete checkout. The example breaks the “minimum items” rule, but satisfies the “minimum items (overall)” rule;
Minimum Items (Different, Overall)
“Minimum number of different items allowed in order” – this number signifies the amount of DIFFERENT products that the buyer is forced to purchase!
So, keeping the previous example (2 of 1 product, 3 of another product and 1 of another), and setting the “Minimum Items (Different, Overall)” to (say) 4…this will fail TWO rules. As we have only 3 products in the cart -> failure of “Minimum Items (Different, Overall)”, and as we are buying only 1 of a particular item -> this fails “Minimun Items”;
Let’s correct the order to satisfy all of the rules;
We now have;
- At least 2 quantity of each product -> satisfies “minimum items” rule
- 9 quantity being purchased -> satisfies “minimum items (overall)” rule
- 4 products being purchased -> satisfies “minimum different items (overall)” rule
Using a mixture of these three rules, enables the shopowner to have really good flexibility with what is being sold.
Typical “rule failure” example
This cart breaks all three rules and so there are 3 error messages. The shopowner can change the error messages to make them more flowery or understandable for the buyer.
I can’t imagine (with my setup at least) trying to force a customer to purchase one thing or another to be able to checkout.
I can see this possibly being useful for a free shipping module or discount. “add one more item to your cart to get free shipping” -or- “add one more of this item to qualify for our 25% discount”.
Do you think it is relevant in those situations as well?
I couldn’t really see it in use on many shops. It could be used for some type of discount feature, I guess, but is not really too suitable for that either.
Maybe a shop who sold sweets could enforce a selection of different items with it? That is, if they did not have something else that worked better…