Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Add quantity box to product_info.php


Jolanta

Recommended Posts

Posted

Hi Developers.

 

I have coded a quantity box to product_info.php and added code to application_top.php it works fine with quantity set to 1... but if quantity is changed to other than 1 it's not passing the parameters over to the shopping cart page... has anyone come across this issue before or know what the problem is... I have tried multiple fixes without success.

 

I am using the Master Products contrib to also show slave products on the product_info.php page.

 

HERE IS THE CODE FOR BOTH PAGES

//file name is ---> product_info.php

<?php echo tep_draw_input_field('cart_quantity[]', $products[$i]['quantity'], 'size="4" value="1"' . tep_get_all_get_params(array('action')) . 'action=add_product'); ?>

 

//file name is ---> includes/application_top.php
// 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']);
						  }
						  tep_redirect(tep_href_link($goto, tep_get_all_get_params($parameters)));
						  break;
 //Master Products
 // customer adds multiple products from the master_listing page
 case 'add_slave' :
						 reset($HTTP_POST_VARS);
						 while ( list( $key, $val ) = each( $HTTP_POST_VARS ) ) {
						   if (substr($key,0,11) == "Qty_ProdId_") {
							 $prodId = substr($key,11);
							 $qty = $val;
							 if(isset($HTTP_POST_VARS["id_$prodId"]) && is_array($HTTP_POST_VARS["id_$prodId"])) {
							   // We have attributes
							   $cart->add_cart($prodId, $cart->get_quantity(tep_get_uprid($prodId,$HTTP_POST_VARS["id_$prodId"]))+$qty, $HTTP_POST_VARS["id_$prodId"]);
							 } else {
							   // No attributes
							   $cart->add_cart($prodId, $cart->get_quantity($prodId)+$qty);
							 }
						   }
						 }
						 tep_redirect(tep_href_link($goto, tep_get_all_get_params($parameters)));
						 break;
//Master Products EOF

 

Thank you in advance for any suggestions/help etc...

 

Jolanta

Posted
Hi Developers.

 

I have coded a quantity box to product_info.php and added code to application_top.php it works fine with quantity set to 1... but if quantity is changed to other than 1 it's not passing the parameters over to the shopping cart page... has anyone come across this issue before or know what the problem is... I have tried multiple fixes without success.

 

I am using the Master Products contrib to also show slave products on the product_info.php page.

 

HERE IS THE CODE FOR BOTH PAGES

//file name is ---> product_info.php

<?php echo tep_draw_input_field('cart_quantity[]', $products[$i]['quantity'], 'size="4" value="1"' . tep_get_all_get_params(array('action')) . 'action=add_product'); ?>

 

//file name is ---> includes/application_top.php
// 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']);
						  }
						  tep_redirect(tep_href_link($goto, tep_get_all_get_params($parameters)));
						  break;
 //Master Products
 // customer adds multiple products from the master_listing page
 case 'add_slave' :
						 reset($HTTP_POST_VARS);
						 while ( list( $key, $val ) = each( $HTTP_POST_VARS ) ) {
						   if (substr($key,0,11) == "Qty_ProdId_") {
							 $prodId = substr($key,11);
							 $qty = $val;
							 if(isset($HTTP_POST_VARS["id_$prodId"]) && is_array($HTTP_POST_VARS["id_$prodId"])) {
							   // We have attributes
							   $cart->add_cart($prodId, $cart->get_quantity(tep_get_uprid($prodId,$HTTP_POST_VARS["id_$prodId"]))+$qty, $HTTP_POST_VARS["id_$prodId"]);
							 } else {
							   // No attributes
							   $cart->add_cart($prodId, $cart->get_quantity($prodId)+$qty);
							 }
						   }
						 }
						 tep_redirect(tep_href_link($goto, tep_get_all_get_params($parameters)));
						 break;
//Master Products EOF

 

Thank you in advance for any suggestions/help etc...

 

Jolanta

I think you need to have your code in product_listing.php. I have minimums and multiples in a site, the code

to set the quantity for the cart looks like this:

 

if ($min_mult == "min" && $listing['quantity'] > $min_qty)

 

$min_qty = $listing['quantity'];

 

else

 

$listing['quantity'] = $min_qty;

 

 

 

if ($min_mult == "min") { $product[$i]['quantity'] = $min_qty;

 

$lc_text .= '<div><font size=2> Minimum: </font></div><div>' . tep_draw_input_field('cart_quantity', $listing['quantity'], 'size=2, maxlength=2') . '   </div>';

 

} else {

 

$lc_text .= '<div><font size=2> Multiple:</font></div><div>' . tep_draw_pull_down_menu('cart_quantity', $options, 'size=3 maxlength=3') . '</div>';

 

}

 

$lc_text .= '</td><td>  </td><td align="center" width="75%" valign="absmiddle">' . tep_image_submit('button_in_cart.gif', IMAGE_BUTTON_IN_CART, 'align=middle') . '</td></tr></table></form>';

 

Not exactly what you want, but might help.

Posted
I think you need to have your code in product_listing.php. I have minimums and multiples in a site, the code

to set the quantity for the cart looks like this:

 

if ($min_mult == "min" && $listing['quantity'] > $min_qty)

 

$min_qty = $listing['quantity'];

 

else

 

$listing['quantity'] = $min_qty;

if ($min_mult == "min") { $product[$i]['quantity'] = $min_qty;

 

$lc_text .= '<div><font size=2> Minimum: </font></div><div>' . tep_draw_input_field('cart_quantity', $listing['quantity'], 'size=2, maxlength=2') . '   </div>';

 

} else {

 

$lc_text .= '<div><font size=2> Multiple:</font></div><div>' . tep_draw_pull_down_menu('cart_quantity', $options, 'size=3 maxlength=3') . '</div>';

 

}

 

$lc_text .= '</td><td>  </td><td align="center" width="75%" valign="absmiddle">' . tep_image_submit('button_in_cart.gif', IMAGE_BUTTON_IN_CART, 'align=middle') . '</td></tr></table></form>';

 

Not exactly what you want, but might help.

 

 

Hi

 

Thank you very much for the reply... I will give it a try... been trying to get this to work for about a week :(

 

best regards

 

Jolanta

Posted

I found the code and it is working great.

 

 

ADD CODE BELOW TO product_info.php

 

or see bottom of this page

http://www.oscommerce.com/forums/index.php?act...quantity+%2Bbox

 

<tr>
   <td align="right" class="main"><?php if ($product_info['products_quantity'] > 0) {
 echo TEXT_QUANTITY . '  ' . tep_draw_input_field('Qty_ProdId_' . $product_info['products_id'], '', 'size="3" maxlength="10"'); 
 } elseif ((STOCK_CHECK == 'false')&& ($product_info['products_quantity'] < 1)) {
  $qty_array = array();
	   for ($i=0; $ns = 20, $i <= $ns; $i++) {
	   $qty_array[] = array('id' => $i, 'text' => $i); 
   }	 
 echo TEXT_QUANTITY . '  ' . tep_draw_input_field('Qty_ProdId_' . $product_info['products_id'], '', 'size="3" maxlength="10"');
 } else {
 echo TEXT_STOCK;
}
echo tep_draw_separator('pixel_trans.gif', '30', '10');
?>
   </td>
 </tr>

 

Good Luck

Archived

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

×
×
  • Create New...