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
| <?php
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
class Shoppingcart {
protected $items = array("Korb" => array("produktname", "quantity", "price"));
public function add($produktname, $quantity, $price) {
if (is_string($produktname) && is_int($quantity) && is_float($price)) {
$this->$items["Korb"][] = array("produktname"=>$produktname,"quantity"=> $quantity,"price" =>$price);
// = $this->items["Korb"] ;
// $price = $this->items["Korb"] [] ;
} else {
echo " Sorry Produktname oder quantity oder noch Price nicht korrekt <br/> uuml;berprulm;fen Sie
, ob sie alle Daten richtig eingelegt haben.";
}
}
public function delete($produktname,$quantity)
{
if(is_string($produktname) && is_int($quantity))
{
$vorchange;
if($this->items["Korb"]["produktname"] == $produktname)
{
if($this->items["Korb"]["quantity"] >=$quantity)
{
$vorchange = $this->items["Korb"]["quantity"];
$rest = $vorchange - $quantity;
echo 'rest ist :'.$rest.'<br/>';
}
}
}
}
public function subtotal()
{
if(is_string($produktname) && is_int($quantity) && is_float($price))
{
$this->items["Korb"]["quantity"] = $quantity;
$this->items["Korb"]["price"] = $price;
echo 'Die Summe ist :'.$summe = $quantity * $price .'<br/>';
}
}
public function display() {
echo '<table border = "5">' .
'<caption>Ihre Kassen Bon</caption>' .
'<tr> <td> Artikel </td><td> Preis </td><td> Mengen </td>';
for ($i = 0; $i < sizeof($this->items['Korb']); $i++) {
echo '<tr><td>' . $this->items['WarenKorb'][$i]['produktname'] . '</td><td>' . $this->items['Korb'][$i]['price'] .
'</td><td>' . $this->items['WarenKorb'][$i]['quantity'] . '</td></tr>';
}
echo
'<tr><td></td><td></td><td>Summe: </td><td>' . number_format($this->subtotal(), 2, ",", ".") . '</td></tr>' . '</table>';
}
}
?> |
Partager