fonction calcul frais livraison infini
Bonjour,
je viens d'installer une page de commande avec panier sur mon site mais le calcul des frais de port pose problème.
de 1 à 4 tables le prix est de 20 € et je doit faire une fonctione pour qu'il fait un multiple a chaque fois c'est a dire
de 5 à 8 tables le prix est de 40 € un multiple de 2 à chaque fois.
et cela à l'infini car on peut commander autant de table qu'on veut.
On m'a indique de faire 20 euros * (nbTable modulo 4) mais je ne comprend pas.
Merci pour votre aide
additioner frais de port dans panier
Bonjour,
j'ai installé un panier sur mon site avec ce code :
https://github.com/sanwebe/PHP-Shopp...press-Checkout
Quelqu'un m'a aider a automatiser les frais de port petit soucis les frais de port quand on rajoute d'autre produits ne s'additione pas il affiche les frais de port du dernier articles.
quelqu'un pourrait m'aider ?
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
|
<?php
session_start();
include_once("config.php");
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Votre commande</title>
<link href="style/style.css" rel="stylesheet" type="text/css"></head>
<body>
<br />
<div class="bg-view-cart"><br />
<img src="../images/logo-mini.png">
<br /><br />
<h1 align="center">Récapitulatif de votre commmande</h1>
<br />
<div class="cart-view-table-back">
<form method="post" action="cart_update.php">
<table width="100%" cellpadding="6" cellspacing="0" border="1px black">
<thead>
<tr><th>Quantité</th><th>Nom</th><th>Prix</th><th>Total</th><th>Supprimer</th></tr>
</thead>
<tbody>
<?php
if(isset($_SESSION["cart_products"])) //check session var
{
$total = 0; //set initial total value
$b = 0; //var for zebra stripe table
foreach ($_SESSION["cart_products"] as $cart_itm)
{
//set variables to use in content below
$product_name = $cart_itm["product_name"];
$product_qty = $cart_itm["product_qty"];
$product_price = $cart_itm["product_price"];
$product_code = $cart_itm["product_code"];
$product_finition = $cart_itm["product_finition"];
$product_color = $cart_itm["product_color"];
$subtotal = ($product_price * $product_qty); //calculate Price x Qty
$bg_color = ($b++%2==1) ? 'odd' : 'even'; //class for zebra stripe
echo '<tr class="'.$bg_color.'">';
echo '<td><input type="text" size="2" maxlength="2" name="product_qty['.$product_code.']" value="'.$product_qty.'" /></td>';
echo '<td>'.$product_name.'</td>';
echo '<td>'.$product_price.$currency.'</td>';
echo '<td>'.$subtotal.$currency.'</td>';
echo '<td><input type="checkbox" name="remove_code[]" value="'.$product_code.'" /></td>';
echo '</tr>';
$total = ($total + $subtotal); //add subtotal to total var
/**calcul frais de port shipping_cost**/
$quantite = $product_qty; // nombre de trucs à envoyer
$frais_lot = 20; // frais par lot, ici 20
$taille_lot = 4; // taille d'un lot, ici 4
$nb_lots = ceil($quantite / $taille_lot); // on arrondit à l'entier supérieur, pour avoir le nombre de lots, y compris le dernier
$shipping_cost = $frais_lot*$nb_lots;
}
$grand_total = $total + $shipping_cost; //grand total including shipping cost
foreach($taxes as $key => $value){ //list and calculate all taxes in array
$tax_amount = round($total * ($value / 100));
$tax_item[$key] = $tax_amount;
$grand_total = $grand_total + $tax_amount; //add tax val to grand total
}
$list_tax = '';
foreach($tax_item as $key => $value){ //List all taxes
$list_tax .= $key. ' : ' .sprintf("%01.2f", $value) . $currency.'<br />';
}
$shipping_cost = ($shipping_cost)?'Frais de livraison : '. sprintf("%01.2f", $shipping_cost).$currency.'<br />':'';
}
?>
<tr>
<td colspan="5">
<span style="float:right;text-align: right;">
<?php echo $shipping_cost. $list_tax; ?>Montant commande : <?php echo sprintf("%01.2f", $grand_total) .$currency?>
</span>
</td>
</tr>
<tr>
<td colspan="5">
<a href="index.php" class="button">Ajouter plus d'articles</a>
<button type="submit" style="padding:9px;">Mettre à jour le panier</button>
<a href="paypal-express-checkout" ><img src="../images/btn_pay_with_paypal.png" width="179" height="36"></a>
</td>
</tr>
</tbody>
</table>
<input type="hidden" name="return_url" value="<?php
$current_url = urlencode($url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
echo $current_url; ?>" />
</form>
</div>
</div>
</body>
</html> |
voici le code que j'ai rajouter dans la page :
Code:
1 2 3 4 5 6
| /**calcul frais de port shipping_cost**/
$quantite = $product_qty; // nombre de trucs à envoyer
$frais_lot = 20; // frais par lot, ici 20
$taille_lot = 4; // taille d'un lot, ici 4
$nb_lots = ceil($quantite / $taille_lot); // on arrondit à l'entier supérieur, pour avoir le nombre de lots, y compris le dernier
$shipping_cost = $frais_lot*$nb_lots; |
si quelqu'un peut m'aider ?
MERCI.