Skip to content

Instantly share code, notes, and snippets.

@viniciusalonso
Last active December 17, 2016 12:59
Show Gist options
  • Save viniciusalonso/b32ddb5b207ab946af26d9f322fbc821 to your computer and use it in GitHub Desktop.
Save viniciusalonso/b32ddb5b207ab946af26d9f322fbc821 to your computer and use it in GitHub Desktop.
<?php
class Cart {
private $owner;
private $items;
public function __construct($owner, $items) {
$this->owner = $owner;
$this->items = $items;
}
public function totalValueOfItems() {
$total = 0;
foreach ($this->items as $item) {
$total += $item->getProduct()->getValue() * $item->getQuantity();
}
return $total;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment