Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

How to change default quantity in add to shopping cart?


jashnu

Recommended Posts

Hi!

 

I'd like to change the default quantity added to the shopping cart when you click add to cart from 1 to 4. I think it should be changed in classes/shopping_cart.php

 

function add_cart($products_id, $qty = '1', $attributes = '', $notify = true) {

 

but that doesn't work? Can anyone help me please? Thanks in adcance.

 

-Jani

Link to comment
Share on other sites

Hi!

 

I'd like to change the default quantity added to the shopping cart when you click add to cart from 1 to 4. I think it should be changed in classes/shopping_cart.php

 

function add_cart($products_id, $qty = '1', $attributes = '', $notify = true) {

 

but that doesn't work? Can anyone help me please? Thanks in adcance.

 

-Jani

This is easiest done by changing the (catalog)/includes/application_top.php

Search for

	  // customer adds a product from the products page
  case 'add_product' :	if (isset($HTTP_POST_VARS['products_id']) && is_numeric($HTTP_POST_VARS['products_id'])) {
							$cart->add_cart($HTTP_POST_VARS['products_id'], $cart->get_quantity(tep_get_uprid($HTTP_POST_VARS['products_id'], $HTTP_POST_VARS['id']))+1, $HTTP_POST_VARS['id']);
						  } else {
							  if (isset($HTTP_GET_VARS['products_id'])) {
							  $cart->add_cart($HTTP_GET_VARS['products_id'], $cart->get_quantity($HTTP_GET_VARS['products_id'])+1);
							}
						  }
						  tep_redirect(tep_href_link($goto, tep_get_all_get_params($parameters)));
						  break;
  // performed by the 'buy now' button in product listings and review page
  case 'buy_now' :		if (isset($HTTP_GET_VARS['products_id'])) {
							if (tep_has_product_attributes($HTTP_GET_VARS['products_id'])) {
							  tep_redirect(tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $HTTP_GET_VARS['products_id']));
							} else {
							  $cart->add_cart($HTTP_GET_VARS['products_id'], $cart->get_quantity($HTTP_GET_VARS['products_id'])+1);
							}
						  }
						  tep_redirect(tep_href_link($goto, tep_get_all_get_params($parameters)));
						  break;

and change the

+1
to
+4

 

This will add always 4 of a product with buy now and add to cart

Link to comment
Share on other sites

Let me clarify. What I mean is quantity 1 for most items, but quantity 5 or 10 for others.

 

TIA.

I see what you mean. That could be fairly simple done I guess. Somewhere you can assign quantities to your products, ie. by adding an extra database field for that purpose, and make the +1, +4 or whatever a variable depending on that value.

So something like

$cart->add_cart($HTTP_GET_VARS['products_id'], $cart->get_quantity($HTTP_GET_VARS['products_id'])+$product_quantitiy);

where $product_quantity is assigned a value before.

Link to comment
Share on other sites

  • 4 months later...

Thanks this information was very helpful in finding a solution to a problem I was having -- knowing the cart quantity was handled in the application top helped me to troubleshoot the changes.

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...