Page 1 of 1

Combining two bits of code

Posted: Fri Jul 04, 2008 6:18 am
by wormington
Hi

I'm new to php and have a problem with some osCommerce php code, I've tried on various osCommerce forums with no luck.

I've added the Attribute Qty Product Info contribution which allows you to have a table of attributes with a quantity box along with the Option Type Feature contribution which allows you to add a text box to the product_info page.

The layout looks great but when products are added to the cart the text box entry is not added if I have the following in the product_info.php page (this posts the form)


<td width="100%" valign="top"><?php echo tep_draw_form('cart_quantity', tep_href_link(FILENAME_PRODUCT_INFO, tep_get_all_get_params(array('action')) . 'action=add_mult')); ?><table border="0" width="100%" cellspacing="0" cellpadding="0">


If I change the above to

<td width="100%" valign="top"><?php echo tep_draw_form('cart_quantity', tep_href_link(FILENAME_PRODUCT_INFO, tep_get_all_get_params(array('action')) . 'action=add_product')); ?><table border="0" width="100%" cellspacing="0" cellpadding="0">

the text box contents are added as an attribute to the cart but the quantity shows as 1 even if it's not, (the price shows correctly for the number of products ordered.

As far as I can work out it's down to these bits of code in application_top.php, can anyone help me sort this out as I'm mystified.

Code: Select all

/ customer adds multiple products from the products page
case 'add_mult' : if (is_array($HTTP_POST_VARS['a'])){
reset($HTTP_POST_VARS['quantity']);
reset($HTTP_POST_VARS['a']);
 
$x=0;
if (is_array($HTTP_POST_VARS['a'])){
foreach(($HTTP_POST_VARS['a']) as $key => $value){
$c = array((int)$HTTP_POST_VARS['b'] => (int)$value);
 
if (is_array($HTTP_POST_VARS['quantity'])){
$qty = (int)$HTTP_POST_VARS['quantity'][$x];
 
 
$cart->add_cart($HTTP_POST_VARS['products_id'], $cart->get_quantity(tep_get_uprid($HTTP_POST_VARS['products_id'], ($c)))+($qty),($c));
$x++;
 
}
}
}
} else {
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;
and

Code: Select all

/ 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;
You can have a look at http://www.deanforestfayre.co.uk/shop you will need to login to the store using test as the username and test as the password

I have been going around in circles for days with this and it's the last thing I need to get sorted, I would really appreciate any help in this, thanks

Re: Combining two bits of code

Posted: Fri Jul 04, 2008 2:38 pm
by califdon
Your chances are much better in a forum that deals specifically with that software package. In a general forum like this, you may or may not find anyone who has even heard of a particular package, and the rest of us have no desire to try to understand an entire software application just to answer someone's question.

Re: Combining two bits of code

Posted: Sat Jul 05, 2008 3:10 am
by miro_igov
Nowhere in your code i see usage of $_POST['id[txt_6]'] - this is the name of the text box. I believe the usage of this POST var is somewhere in the includes/application_top.php , you should check how it processes when add_mult and add_product.