Jump to content

Shoping cart +freight


bob_the _builder

Recommended Posts

Hi,

 

I have a shoping cart thats holds products (beds) which range from small, king single, double, queen, king. There are 5 codes depending on the area of delivery (freight).

 

So ...

 

code 1

 

small = $80, king single = $95, double = $120, queen = $136, king = $152

 

code 2

 

small = $110, king single = $125, double = $165, queen = $187, king = $209

 

code 3

 

......

 

The code is selected while in the cart and set as a session variable.

 

How can I get the freight value for each product dependant code selected and what size the bed is?

 

Thanks

Link to comment
Share on other sites

Here is the cart code, But im not sure of a simple way to check the delivery code and bed size to grab the correct freight rate for each procuct.

 

Trying to get a match to the town and bed size for the freight on each product without a ton is if statements

 

code 1

small = $80, king single = $95, double = $120, queen = $136, king = $152

code 2

small = $110, king single = $125, double = $165, queen = $187, king = $209

code 3

......

 

 

	if(!$empty) {
$query = 'SELECT p.*, h.* 
FROM products as p
JOIN headings as h ON h.headingid = p.headingid
WHERE itemid IN (';
foreach($_SESSION['cart'] as $key => $value) {
$query .= $key . ',';
}
$query = substr ($query, 0, -1) . ') ORDER BY itemid ASC';
$result = mysql_query($query);

// Explode list menu
$selec = explode(",", $_POST['location']);

// Session register code for freight location
session_register('location');
$_SESSION['location'] = $selec[1];

if(($_SESSION['location'] == 1) && ($description == Single)){
$freight = '80';
}

echo '<form name="cart" action="'.$_SERVER['PHP_SELF'].'" method="post">
  	<table width="98%" border="0" align="center" cellpadding="2" cellspacing="0">
    <tr> 
    <td align="left"><b>Code</b></td>
    <td width="380" align="left"><b>Product Name</b></td>
    <td width="162" align="right"><b>Price</b></td>
    <td width="143" align="center"><b>Qty</b></td>
    <td colspan="2" align="right"><b>Sub Total</b></td>
    </tr>
    <td width="207">';

$total = 0;
while ($row = mysql_fetch_array ($result)) {
foreach($row as $key=>$value){
$$key = ValidateInput($value);
}

$subtotal = $_SESSION['cart'][$itemid] * $price;
$total += $subtotal;

$qty = $_SESSION['cart'][$itemid];
$totalqty += $qty;

$totalweight = $_SESSION['cart'][$itemid] * $weight;
$subfreight += $totalweight;

// Old basic freight system
$totalfreight = $subfreight * $perkg;
$ntotal = $total + $totalfreight;

session_register('total');
$_SESSION['total'] = number_format($total, 2);

session_register('qty');
$_SESSION['qty'] = $qty;

session_register('totalqty');
$_SESSION['totalqty'] = $totalqty;

echo '</td>
    <tr> 
    <td align="left">'.$code.'</td>
    <td align="left">'.$heading.' '.$name.'</td>
    <td align="right">$'.$price.'</td>
    <td align="center"><center>
    <input type="text" size="3" name="qty['.$itemid.']" value="'.$_SESSION['cart'][$itemid].'" />
    </center></td>
    <td colspan="2" align="right">$'.number_format($subtotal, 2).'</td>
    </tr>';

}

    echo '<tr>
    <td colspan="4" align="right">';

// Creates array of towns and its freight code 
$cities = array('Pickup (Local)' => '1', 'town1' => '2', 'town2' => '2', 'town3' => '2', 'town4' => '2', 'town5' => '2', 'town6' => '3', 'town7' => '3', 'town8' => '4', 'town9' => '4', 'town' => '4');

// List menus of towns
echo '<select name="location" onChange="this.form.submit();">
<option value="" selected>Select Location</option>';
foreach($cities as $key => $value) {
echo '<option '.( $key==$selec[0] ? 'selected' : '' ).' value="'.$key.','.$value.'">'.$key.'</option>';
}

echo '</select>
</td> 
    <td align="right"><b>Freight:</b></td>
    <td align="right">'.number_format($totalfreight,2).'</td>
    </tr>
    <tr>
    <td colspan="3" align="right"> </td>
    <td align="right"> </td>
    <td width="106" align="right"><b>Total:</b></td>
    <td width="75" align="right"><b><font color="FF0000">$'.number_format($ntotal,2).'</font></b></td>
    </tr>
    <tr>
    <td colspan="3" align="right"> </td>
    <td colspan="3" align="right"><br /><input type="submit" name="Submit" value="Update Cart"></td>
    </tr>
</table>
</form>

<br />

<table width="95%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td colspan="8" align="right"><img src="images/black_arrow.gif" width="11" height="13"> <b><a href="./index.php?action=shop">Continue Shopping</a> <img src="images/black_arrow.gif" width="11" height="13"> <a href="./cart.php?action=custdetails">Checkout</a></b></td>
</tr>
</table>';

}else{

echo '<br /><center>Your cart is currently empty.</center><br />';
}

 

Thanks

 

 

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.