Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 34 |
App\Controllers\CartViewController | |
0.00% |
0 / 1 |
|
0.00% |
0 / 5 |
42 | |
0.00% |
0 / 34 |
__construct | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 6 |
|||
getCartTotal | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 11 |
|||
getMwst | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 4 |
|||
getTotalNoMwst | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 3 |
|||
cartTemplateAction | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 10 |
<?php | |
namespace App\Controllers; | |
use \Core\View; | |
use App\Models\Cart; | |
class CartViewController extends \Core\Controller { | |
private $cart; | |
private $cartTotal; | |
private $mwstValue; | |
private $totalNoMwst; | |
public function __construct($route_params) { | |
parent::__construct($route_params); | |
$this->cart = Cart::getInstance(); | |
$this->cartTotal = $this->getCartTotal($this->cart->getArticles()); | |
$this->mwstValue = $this->getMwst($this->cartTotal); | |
$this->totalNoMwst = $this->getTotalNoMwst($this->cartTotal, $this->mwstValue); | |
} | |
/** | |
* | |
* @param array $articles | |
* @return string | |
*/ | |
public static function getCartTotal($articles) { | |
$total = 0; | |
$quantity = 0; | |
$price = 0; | |
foreach ($articles as $value) { | |
$quantity = $value->getQuantity(); | |
$price = $value->getPrice(); | |
$articleTotal = $price * $quantity; | |
$total += $articleTotal; | |
} | |
return $total; | |
} | |
public static function getMwst($cartValue) { | |
$mwstSet = 0.19; | |
$mwstValue = $cartValue * $mwstSet; | |
return $mwstValue; | |
} | |
public static function getTotalNoMwst($cartValue, $mwstValue) { | |
$totalNoMwst = $cartValue - $mwstValue; | |
return $totalNoMwst; | |
} | |
/* | |
public static function getSubtotal($articles) { | |
$subtotal = []; | |
$quantity = 0; | |
$price = 0; | |
foreach ($articles as $value) { | |
$quantity = $value->getQuantity(); | |
$price = $value->getPrice(); | |
array_push($subtotal, $quantity * $price); | |
} | |
return $subtotal; | |
} | |
*/ | |
/** | |
* Show the Cart page | |
* | |
* @return void | |
*/ | |
public function cartTemplateAction() { | |
View::renderTemplate( | |
'cartTemplate.twig', array("name" => "Warenkorb", | |
"link" => "Formular Seite", | |
"cart" => $this->cart, | |
"total" => $this->cartTotal, | |
"mwst" => $this->mwstValue, | |
"totalNoMwst" => $this->totalNoMwst | |
) | |
); | |
} | |
} |