Mahlzeit,
ich bin ein absoluter Noob und verzweifel momentan an einer Aufgabe, die ich dem Script hinzufügen soll.
Leider weiss ich nicht weiter...
Aufgabe:
Bei Artikel mit product_code unter 100 sind die Versandkosten 0,70€.
Bei Artikel mit product_code über 100 sind die Versandkosten 6,99€.
Habe ich beide (product_code < 100 und product_code > 100) im Warenkorb,
bleiben die Versandkosten 6,99€.
Problem:
Im folgendem Script klappt das nicht so ganz.
Entweder habe ich als Versandkosten 0,70€ oder 6,99€ - kommt darauf an, was der Kunde als letztes in den Warenkorb gelegt hat.
Wie erreiche ich also, dass die Versandkosten bei 6,99€ bleiben selbst wenn ich als letztes Artikel X (product_code < 100) in den Warenkorb lege ?
Kann mir jemand helfen ?
ich bin ein absoluter Noob und verzweifel momentan an einer Aufgabe, die ich dem Script hinzufügen soll.
Leider weiss ich nicht weiter...
Aufgabe:
Bei Artikel mit product_code unter 100 sind die Versandkosten 0,70€.
Bei Artikel mit product_code über 100 sind die Versandkosten 6,99€.
Habe ich beide (product_code < 100 und product_code > 100) im Warenkorb,
bleiben die Versandkosten 6,99€.
Problem:
Im folgendem Script klappt das nicht so ganz.
Entweder habe ich als Versandkosten 0,70€ oder 6,99€ - kommt darauf an, was der Kunde als letztes in den Warenkorb gelegt hat.
Wie erreiche ich also, dass die Versandkosten bei 6,99€ bleiben selbst wenn ich als letztes Artikel X (product_code < 100) in den Warenkorb lege ?
PHP:
<?php
if(isset($_SESSION["products"]) && count($_SESSION["products"])>0){
$total = 0;
$list_tax = '';
$gs = 0.70;
$vfree = "Versandkostenfrei";
$cart_box = '<ul class="view-cart">';
foreach($_SESSION["products"] as $product){ //Print each item, quantity and price.
$product_name = $product["product_name"];
$product_qty = $product["product_qty"];
$product_price = $product["product_price"];
$product_code = $product["product_code"];
$item_price = ($product_price * $product_qty); // price x qty = total item price
$cart_box .= "<li class=\"view-cart-total\">$product_code – $product_name – Anzahl : $product_qty = <strong>" .number_format($item_price, 2, ",", "."). " ".$currency."</strong></li>";
$subtotal = ($product_price * $product_qty); //Multiply item quantity * price
$total = ($total + $subtotal); //Add up to total price
}
// MEIN VERSUCH
if($product_code < 100){
$shipping_cost = $gs;} //Gutschein-Versandkosten
elseif($product_code > 100){
$shipping_cost = 6.99;} //Gutschein-Versandkosten
else {$shipping_cost = 6.99;}
$grand_zw = number_format($total, 2, ",", "."); //Zwischensumme
// if($grand_zw > 20){$shipping_cost = 0; $gs = 0;} //Versandkostenfrei wenn Zwischensumme>20€
$grand_total = $total + $shipping_cost; //Gesamtbetrag
foreach($taxes as $key => $value){ //list and calculate all taxes in array
$tax_amount = ($grand_total - ($grand_total / 119 * 100)); //MwSt
$tax_item[$key] = $tax_amount;
$grand_total = $grand_total + 0;
}
foreach($tax_item as $key => $value){ //taxes List
$list_tax .= $key. ' ' .number_format($value, 2, ",", "."). ' '.$currency. '<br />';
}
$grand_netto = ($grand_total - $tax_amount);
$shipping_cost = ($shipping_cost)?'Versandkosten = '. number_format($shipping_cost, 2, ",", ".").' '.$currency.'<br />':'';
//Print Shipping, VAT and Total
$cart_box .= "<li class=\"view-cart-total\"><strong>Zwischensumme = $grand_zw $currency</strong></li><li class=\"view-cart-total\">$shipping_cost</li><li class=\"view-cart-total\"><strong>Gesamtbetrag = " .number_format($grand_total, 2, ",", "."). " ".$currency."</strong></li><li class=\"view-cart-total\">Nettobetrag = " .number_format($grand_netto, 2, ",", "."). " ".$currency."</li><li class=\"view-cart-total\">$list_tax</li>";
$cart_box .= "</ul>";
echo $cart_box;
}
else{
echo "Der Warenkorb ist leer.";
}
?>
Kann mir jemand helfen ?