Jump to content

Multiple Quantity Fields On Form


NFD

Recommended Posts

Hi,

 

Got a bit of an interesting problem here regarding quantity fields on a dynamically generated form in a shopping cart.

 

On the view product page, what I am trying to do is have it so there is a form a customer can fill out specifying a quantity for each option available.

All options relate directly to the product being viewed.

e.g.

1 x red colored widget

5 x black colored widgets

0 x white colored widgets

2 x blue colored widgets

 

Here is the query I am currently running to retrieve the available options for a product:

 

if($prodArray == TRUE && $prodArray[0]['subOptionsStatus']==1){

$subOptionsQuery = "SELECT * FROM ".$glob['dbprefix']."inventory_sub_options WHERE subOptionStatus = 1 AND subOptionProductId = ".$db->mySQLSafe($_GET['productId'])." ORDER BY subOptionIdSortId ";
$subOptionsResults = $db->select($subOptionsQuery);

}

if($subOptionsResults == TRUE){

for ($i=0; $i<count($subOptionsResults); $i++){

	$view_prod->assign("VAL_SUB_OPTION_ID", $subOptionsResults[$i]['subOptionId']);
	$view_prod->assign("VAL_SUB_OPTION_GENDER", $subOptionsResults[$i]['subOptionGender']);
	$view_prod->assign("VAL_SUB_OPTION_COLOR", $subOptionsResults[$i]['subOptionColor']);
	$view_prod->assign("VAL_SUB_OPTION_STYLE", $subOptionsResults[$i]['subOptionStyle']);
	$view_prod->assign("VAL_SUB_OPTION_SIZE", $subOptionsResults[$i]['subOptionSize']);
	$view_prod->assign("VAL_SUB_OPTION_PRICE", priceFormat($subOptionsResults[$i]['subOptionPrice']));

	$view_prod->parse("view_prod.prod_true.sub_options.sub_option_loop");

}

$view_prod->parse("view_prod.prod_true.sub_options");
}

 

That so far does exactly what I want.

 

Then there is the html for the form itself.

Here is what I currently have:

 

		<table cellpadding="0" cellspacing="0" width="100%" border="1">

		<tr>
			<td align="center" colspan="6"><strong>Title Goes Here</strong></td>
		</tr>

		<tr>
			<td align="center"><strong>Gender</strong></td>
			<td align="center"><strong>Color</strong></td>
			<td align="center"><strong>Style</strong></td>
			<td align="center"><strong>Size</strong></td>
			<td align="center"><strong>Price</strong></td>
			<td align="center"><strong>Qty</strong></td>
		</tr>

		<!-- BEGIN: sub_option_loop -->

		<tr>
			<td align="center">{VAL_SUB_OPTION_GENDER}</td>
			<td align="center">{VAL_SUB_OPTION_COLOR}</td>
			<td align="center">{VAL_SUB_OPTION_STYLE}</td>
			<td align="center">{VAL_SUB_OPTION_SIZE}</td>
			<td align="center">{VAL_SUB_OPTION_PRICE}</td>
			<td align="center">
			<input name="subOptionQuantity[]" type="text" value="0" size="2" class="textbox" style="text-align:center;" />
			<input type="hidden" name="multiadd" value="{VAL_SUB_OPTION_ID}" />
			</td>
		</tr>

		<!-- END: sub_option_loop -->

		<input type="hidden" name="multiAddMaster" value="{PRODUCT_ID}" />

	</table>

 

Now I don't think that is quite correct when it comes to the fields themselves, but visually it achieves what I want to be displayed.

 

Finally, there is the code to run when the form itself gets submitted.

The standard code for just a single product is like this:

 

if(isset($_POST['add']) && $_POST['add']>0) {

// add product to the cart
if($_POST['quan']>0){
	$quantity = ceil($_POST['quan']);
} else {
	$quantity = 1;
}

}

 

As above, that is simply how it adds a single product based off quantity entered.

Obviously it does more after all that, but i am just trying to get the initial stage working first.

 

My 2 questions are:

1. What changes need to be made to the HTML code I am currently using?

2. How do I do the add quantity for each one specified in the form using the above as an example?

If the quantity is at 0, I want it ignored.

If the quantity is greater than 0, its to be added as its own entry.

 

Once I get past this initial stage, I am hoping it ends up basically adding each as its own product to the cart.

Any help provided getting started here would be greatly appreciated.

 

Link to comment
Share on other sites

if you have

 

<input name="subOptionQuantity[{VAL_SUB_OPTION_ID}]" type="text" value="0" size="2" class="textbox" style="text-align:center;" />

 

To process


foreach ($_POST['subOptionQuantity'] as $id => $qty)
{
    // now you have id and qty to process as required
}

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.