Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Minimum quantity for different attributes


camfab

Recommended Posts

Posted

Hi,

I cannot find a solution to set a minimum order quantity for a product which have different attributes.

 

I explain with an example the problem (I sell t-shirt printed on demand):

 

I have a product "T-Shirt A". This product has several attributes: color (red,yellow,blue, etc) and size (S,M,L etc).

The costumer should buy at least 200 "T-Shirt", but this limit of 200 I would like to be present only on the entire product, not on the single attributes.

In other words, the costumers could buy 50 T-Shirt red S , 100 blue M and 50 red XL.

 

I've installed minimum order contribution, but this contrib set to 200 pcs each choice which I made (200 red S - 200 blue M and so on)

 

Is there a mod or contrib which can help me?

 

Thanks (and sorry for my english :blush: )

 

Fabio

Posted

Pheraps I found a solution:

 

in the shopping_cart for each products (also with different attributes and options) I calculate the global quantity (i.e. 2 t-shirt red, 3 t-shirt royal, 1 t-shirt black --> total of 4 t-shirts)

 

If this result (4 t-shirt) is above the minimum order per quantity, I hide the "checkout" button to the user, and suggest him to add/change values of the articles that are under minimum

 

Here is the code:

 

shopping_cart.php, after about line 98

	$any_out_of_stock = 0;
$products = $cart->get_products();

 

insert

// BOF Minumum per Attribute

$any_under_minimum = 0;

//First loop: for each product "name" set initial quantity to 0
for ($i=0, $n=sizeof($products); $i<$n; $i++)
{
  $total_prod_qty[$products[$i]['name']]=0;
}

// Second loop: for each product get the quantity, indipendently by attributes and options
for ($i=0, $n=sizeof($products); $i<$n; $i++)
{
  if(MINIMUM_ORDERS == 'true')
  {
	$min_order_query = tep_db_query("select p.minorder as min_quant FROM " . TABLE_PRODUCTS . " p where p.products_id = '".$products[$i]['id']."'");
	while ($min_order = tep_db_fetch_array($min_order_query))
	{
		$total_prod_qty[$products[$i]['name']] += $products[$i]['quantity'];
	  $products[$i]['min_quant']=$min_order['min_quant'];
	}
  }
}
// Third loop: notice in case of products under minimum
for ($i=0, $n=sizeof($products); $i<$n; $i++)
{
  if ($total_prod_qty[$products[$i]['name']] < $products[$i]['min_quant'] )
  {
	$difference = $products[$i]['min_quant'] - $total_prod_qty[$products[$i]['name']];
	$any_under_minimum = 1;
	$cart_notice .= sprintf(MINIMUM_ORDER_NOTICE, $products[$i]["name"], $products[$i]["min_quant"], $difference);
  }
}
// EOF MINIM

 

and comments the part of code related to mimimum quantity contribution, about line 250

/*
//Minimum quantity code
if(MINIMUM_ORDERS == 'true'){
  $min_order_query = tep_db_query("select p.minorder as min_quant FROM " . TABLE_PRODUCTS . " p where p.products_id = '".$products[$i]['id']."'");
while ($min_order = tep_db_fetch_array($min_order_query))  {
  if ($products[$i]['quantity'] < $min_order['min_quant'] ) {
		$products[$i]['min_quant']=$min_order['min_quant'];
  }
}

 if ($products[$i]['quantity'] < $products[$i]['min_quant'] ) {
 	$products[$i]['quantity']=$products[$i]['min_quant'];
	$cart->add_cart($products[$i]['id'],$products[$i]['quantity'],$products[$i]['attributes']);
	$cart_notice = sprintf(MINIMUM_ORDER_NOTICE, $products[$i]["name"], $products[$i]["min_quant"]);
}

}
*/
//End Minimum quantity code

 

Finally, to hide checkout button:

				<td align="right" class="main">
			<?php
			if ($any_under_minimum == 0 && $any_out_of_stock == 0)
			{
			   echo '<a href="' . tep_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL') . '">' . tep_image_button('button_checkout.gif', IMAGE_BUTTON_CHECKOUT) . '</a>';
			}
			?></td>

 

Finally, I changed also the language files (languages/shopping_cart.php) :

define('MINIMUM_ORDER_NOTICE', 'The minimum order for article  "%s" is %d.<br>Insert at least %d articles also on different colours/size<br>');

 

What are you thinking about this solution ?

 

Fabio

Genova

  • 1 month later...
Posted

Hi,

 

I am looking for the same exact contribution, but never did find any that match the need for my website.

Did you get it to work on your website? can you please send me detail for this contribution? Thanks

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...