Author Topic: Minimum amount of products before checkout  (Read 9747 times)

Jenna

  • Beginner
  • *
  • Posts: 9
Minimum amount of products before checkout
« on: February 09, 2009, 08:39:56 AM »
Hi there,

I have a website which is selling wine by the bottle, however by law we are not suppose to sell less than 12 bottles (1 carton) in one transaction. i would like the customer to be able to make up their own carton from all the different types of wine, so i cannot do this based on a minimum price.

I am wondering if anyone knows a way of restricting the checkout so the customer cannot proceed unless it has more than 11 products in their cart?

Any help would be much appreciated!

risko

  • Beginner
  • *
  • Posts: 34
Re: Minimum amount of products before checkout
« Reply #1 on: February 09, 2009, 10:56:27 AM »
try insert this code to ps_checkout.php under case 'CHECK_OUT_GET_SHIPPING_ADDR' : after original one   
               
Code: [Select]
//begin of quantity check
$quant = 0;
for($i = 0; $i < $cart["idx"]; $i++) {
$quant += $cart[$i]["quantity"];
}
if ($quant < 11) {
$vmLogger->err( 'The Total Quantity of the Products is  "'.$quant.'". Minimal quantity is 12. Add some blablablablabla products.');
unset( $_POST['checkout_this_step']);
return False;
}
//end of quantity check

Jenna

  • Beginner
  • *
  • Posts: 9
Re: Minimum amount of products before checkout
« Reply #2 on: February 18, 2009, 07:10:18 AM »
Thanks for the help, unfortunately when i add the above code and proceed to checkout i get a blank screen. I am using Virtue mart 1.5 if that would have made a difference?

risko

  • Beginner
  • *
  • Posts: 34
Re: Minimum amount of products before checkout
« Reply #3 on: February 18, 2009, 09:44:59 AM »
I tried it and it was working for me in VM1.1.3 and J1.5.9. But,... I inserted it in function "process" I forgot to write about it.

maybe a few next "improvements" are "must to do" - You have to add (in this function "process") variable $cart into the global variables list and set it as a $cart = $_SESSION['cart'];

btw, you can check it on my TEST page - http://www.skromny.co.uk/shop

brendan

  • Beginner
  • *
  • Posts: 20
Re: Minimum amount of products before checkout
« Reply #4 on: February 25, 2009, 04:16:04 AM »
i also want to enable customers to only purchase in lots of 12.
Can this be done with this code?

risko

  • Beginner
  • *
  • Posts: 34
Re: Minimum amount of products before checkout
« Reply #5 on: February 25, 2009, 09:19:14 AM »
@brendan:
this solution is for !@ and more items in cart. Are you talking about "lots of 12" - you mean 12, 24, 36,...?? I think it can be used, but with other condition - not "$quant < 11" but with something like "($quant % 12) != 0"

brendan

  • Beginner
  • *
  • Posts: 20
Re: Minimum amount of products before checkout
« Reply #6 on: February 26, 2009, 01:29:43 AM »
hey jenna, i've done that by using shipping method. (WHIP shipping in config page). For each item i've set a weight of 1kg (or 12 for wine in dozens) and when setting up shipping rates I've set a minimum of 12 kgs.

Now that gets you a minimum of a 12, but not in "lots of 12" (which is what i am after doing now risko, so yes, 12, 24, 36)
And still trying to get that to work risko....any tips

risko

  • Beginner
  • *
  • Posts: 34
Re: Minimum amount of products before checkout
« Reply #7 on: February 26, 2009, 09:03:30 AM »
I tested my solution and it is going through for 12,24,... and not for other quantities...

You can try and test it on my TEST page - http://www.skromny.co.uk/shop

is it what you want?

brendan

  • Beginner
  • *
  • Posts: 20
Re: Minimum amount of products before checkout
« Reply #8 on: February 26, 2009, 09:21:39 AM »
tests ok for minimum of 12 on your site risko, but it still lets me order in other amounts (eg: 16).
i'm a bit of a coding novice. do you have the code and where you'd put it?
I got the minimum working properly with your code, just need to know where to put the "lots of 12" code.
many thanks risko!

risko

  • Beginner
  • *
  • Posts: 34
Re: Minimum amount of products before checkout
« Reply #9 on: February 26, 2009, 09:34:00 AM »
the code above is for 12 and more...

check is working in step Please select a Shipping Address

if you want to check "step 12" (I tested it on my site right now and it is working for me (I have got message Error: The Total Quantity of the Products is "16". Minimal quantity is 12. Add some blabla products.) - but not as a input step to checkout in actual status - as a check after address confirmation)

you have to add in
Code: [Select]
function process(&$d) {
variable
Code: [Select]
$cart, to global (on the begin of this function)
and the case CHECK_OUT_GET_SHIPPING_ADDR modify to following:
Code: [Select]
case 'CHECK_OUT_GET_SHIPPING_ADDR' :
// The User has choosen a Shipping address
if (empty($d["ship_to_info_id"])) {
$vmLogger->err( $VM_LANG->_('PHPSHOP_CHECKOUT_ERR_NO_SHIPTO',false) );
unset( $_POST['checkout_this_step']);
return False;
}
//begin of quantity check
$quant = 0;
for($i = 0; $i < $cart["idx"]; $i++) {
$quant += $cart[$i]["quantity"];
}
// if ($quant < 11) {
if (($quant % 12) != 0) {
$vmLogger->err( 'The Total Quantity of the Products is  "'.$quant.'". Minimal quantity is 12. Add some blabla products.');
unset( $_POST['checkout_this_step']);
return False;
}
//end of quantity check
break;

If you think you need this check in next steps too (customer can change quantity in next steps), you can add it on other case's

and, of course, you have to change my blabla and minimum quantity texts

ronanf

  • Beginner
  • *
  • Posts: 10
Re: Minimum amount of products before checkout
« Reply #10 on: February 26, 2009, 14:10:18 PM »
Hi risko - thanks for taking this on! I tried your first piece of code and it displays the error message no matter what the quantity in the cart is! Almost there

I'm using VM 1.1.3 and Joomla 1.0.12
Less like Celtic Tiger, more like Golden Calf

ronanf

  • Beginner
  • *
  • Posts: 10
Result
« Reply #11 on: February 26, 2009, 16:05:19 PM »
Found a solution from someone else's code:

In administrator/components/com_virtuemart/html/checkout.index.php you will need to insert the following

After line
Code: [Select]
if( in_array('CHECK_OUT_GET_FINAL_CONFIRMATION', $checkout_steps[$current_stage]) ) {
    $next_page = 'checkout.thankyou';
    if( sizeof($checkout_steps[$current_stage]) > 1 ) {
    include_once( PAGEPATH . 'basket.php' );
    } else {
    include_once( PAGEPATH . 'ro_basket.php' );
    }
} else {
$next_page = 'checkout.index';
include_once( PAGEPATH . 'basket.php' );
}
insert the following:

Code: [Select]
/* mod to check for minimum item number in cart */

if ($cart["idx"] == 0) {
   echo $VM_LANG->_PHPSHOP_EMPTY_CART;
   $checkout = False;
}
else {
   
   for ($i=0;$i<$cart["idx"];$i++) {

   $db->setQuery("SELECT product_packaging FROM #__{vm}_product WHERE product_id='" . $cart[$i]["product_id"] . "' ");
 
   $multipleof = "6";
   $mincartqt = "12";
   $total_count = $total_count + ($cart[$i]["quantity"]);
   $total_count_in = $total_count_in + ($cart[$i]["quantity"]);
   }
   
  if (($total_count%($multipleof) !== 0 ) OR ($total_count < ($mincartqt) )) {
   
  echo $basket_html;
       ?>
        <div align="center">
            <script type="text/javascript">alert('<?php echo 'Order quantities must be a multiple of six, with the minimum order quantity being one case of 12 bottles [eg:12,18,24...]' ?>');</script>
            <strong><?php echo $VM_LANG->_('test'?></strong><br />
            <strong><?php echo 'Order quantities must be a multiple of six, with the minimum order quantity being one case of 12 bottles  [eg:12,18,24...]' ?></strong>           
            <?php echo '<br>' ?>
            <strong><?php echo 'Your current order quantity is '" ".$total_count ?></strong>
        </div><?php
        
return;
   
//mosRedirect( $sess->url( 'index.php?page=shop.cart' ) );
    
}
}


/*  end minimum items in cart mod */   

This creates a minimum order quantities that must be a multiple of six, with the absolute minimum quantity being one case of 12... Bingo
Less like Celtic Tiger, more like Golden Calf

brendan

  • Beginner
  • *
  • Posts: 20
Re: Minimum amount of products before checkout
« Reply #12 on: February 27, 2009, 01:28:12 AM »
sweet! you are officially awesome! got to do a bit more testing but looks perfect. thanks

tylacatsa

  • Beginner
  • *
  • Posts: 2
Re: Minimum amount of products before checkout
« Reply #13 on: October 07, 2011, 14:04:09 PM »
can this be done per category.

IE minimum order of 12 bottles under 'Loose bottles' section or product type - Where purchases in gift vouchers and accessories categories do not add to this order quantity