Jump to content

How do I remove my quantity function and add same product twice with options?


The_Dude_1978

Recommended Posts

Hi There,

 

Would someone please help me out with disabling my quantity function and let me be able to add the same product twice each on a new row (item)?

 

These are my first 2 functions:

function createCart()
{

//Create a new cart as a session variable with the value being an array
$_SESSION['paypalCart'] = array();

}

function insertToCart($productID, $username, $thumbnail, $title, $price, $qty = 1)
{

//Function is run when a user presses an add to cart button

//Check if the product ID exists in the paypal cart array
if(array_key_exists($productID, $_SESSION['paypalCart']))
{

	//Calculate new total based on current quantity
	$newTotal = $_SESSION['paypalCart'][$productID]['qty'] + $qty;

	//Update the product quantity with the new total of products
	$_SESSION['paypalCart'][$productID]['qty'] = $newTotal;

}
else
{

	//If the product doesn't exist in the cart array then add the product
	$_SESSION['paypalCart'][$productID]['item'] = $productID;
	$_SESSION['paypalCart'][$productID]['username'] = $username;
	$_SESSION['paypalCart'][$productID]['thumbnail'] = $thumbnail;
	$_SESSION['paypalCart'][$productID]['name'] = $title;
	$_SESSION['paypalCart'][$productID]['price'] = $price;
	$_SESSION['paypalCart'][$productID]['qty'] = $qty;

}

}

 

And this is my function to get the shopping cart but with Toevoegen/Verwijderen (read add/delete) the quantity items.

 

function getShoppingCart()
{

//Function creates the display for the cart

//If the cart exists then follow on
if(cartExists())
{

	//Check if there are any products in the cart by counting the array keys
	if(count($_SESSION['paypalCart']) > 0)
	{

		//The table header html
		$html = '
		<table cellpadding="0" cellspacing="0" border="0">
			<tr>
				<th>Thumbnail</th>
				<th>Item naam</th>
				<th>Prijs</th>
				<th>Hoeveelheid</th>
				<th></th>
			</tr>
		';

		$count = 1;

		//Loop through the items in the paypal cart
		foreach($_SESSION['paypalCart'] as $product)
		{

			$html .= '
			<tr>
				<td width="250"><img src='.$product['username'].'/pics/thumbs/'.$product['thumbnail'].'></td>
				<td width="200">'.$product['name'].'</td>
				<td width="200">€'.number_format($product['price'], 2).'</td>
				<td width="250">'.$product['qty'].'</td>
				<td width="200"><a href="addToCart.php?item='.$product['item'].'">Toevoegen</a> / <a href="removeFromCart.php?item='.$product['item'].'">Verwijderen</a></td>
				<input type="hidden" name="amount_'.$count.'" value="'.$product['price'].'" />
				<input type="hidden" name="quantity_'.$count.'" value="'.$product['qty'].'" />
				<input type="hidden" name="tax_rate_'.$count.'" value="'.TAX.'" />
				<input type="hidden" name="item_name_'.$count.'" value="'.stripslashes($product['name']).'" />
				<input type="hidden" name="item_number_'.$count.'" value="'.$product['item'].'" />
			</tr>
			';

			$count++;

		}

		//HTML for the subrows such as the subtotal, tax and total
		$html .= '
			<tr class="empty">
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
			</tr>
			<tr>
				<td></td>
				<td></td>
				<td></td>
				<td class="bold">Subtotaal</td>
				<td>'.calculateSubtotal().'</td>
			</tr>
			<tr>
				<td></td>
				<td></td>
				<td></td>
				<td class="bold">'.TAX.'% BTW</td>
				<td>'.calculateTax().'</td>
			</tr>
			<tr>
				<td></td>
				<td></td>
				<td></td>
				<td class="bold">Totaal</td>
				<td>'.calculateTotal().'</td>
			</tr>

		</table>



		';

		echo $html;

	}
	else
	{

		//If there are no products then print out a message saying there are no products
		echo '<p>Er zijn momenteel geen producten in uw winkelwagen.</p>';
		unset($_SESSION['paypalCart']);
	}

}
else
{

	//If there are no products then print out a message saying there are no products
	echo '<p>Er zijn momenteel geen producten in uw winkelwagen.</p>';
	unset($_SESSION['paypalCart']);
}

}

 

I hope you can help me out, because i'm really stuck here.

 

Kind regards,

 

Martijn

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.