Page 1 of 1

Shopping cart +freight

Posted: Mon Apr 14, 2008 12:34 am
by bob_the _builder
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

Re: Shopping cart +freight

Posted: Mon Apr 14, 2008 1:37 am
by Christopher
bob_the _builder wrote:How can I get the freight value for each product dependant code selected and what size the bed is?
I assume that the actual product data for each SKU will contain the size of the bed. It sounds like you need to add that data when you add the item to the cart

Re: Shopping cart +freight

Posted: Mon Apr 14, 2008 2:39 am
by bob_the _builder
Hi,

The product field holds either single, king single, double, queen, king, super king which I will check against

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 city (freight code) and bed size for the freight on each product without a ton is if statements

Code: Select all

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
 
......

Code: Select all

 
    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];
 
    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">&nbsp;</td>
    <td align="right">&nbsp;</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">&nbsp;</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