Skip to content

Commit

Permalink
Merge pull request #1 from wagnerwagner/feature-shipping-costs
Browse files Browse the repository at this point in the history
Added Cart hook
  • Loading branch information
tobiasfabian authored Jun 26, 2019
2 parents 37e4d51 + 6c8e0c5 commit b4ae36f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
1 change: 0 additions & 1 deletion blueprints/pages/product.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ fields:
type: number
required: true
step: .01
min: 0
tax:
label: Tax
type: number
Expand Down
6 changes: 4 additions & 2 deletions src/cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ class Cart extends ProductList
*/
public function __construct(array $data = [])
{
if (count($data) === 0 && is_array(kirby()->session()->get($this->sessionName))) {
$data = kirby()->session()->get($this->sessionName);
$kirby = kirby();
if (count($data) === 0 && is_array($kirby->session()->get($this->sessionName))) {
$data = $kirby->session()->get($this->sessionName);
}
parent::__construct($data);
$kirby->trigger('ww.merx.cart', $this);
}


Expand Down
15 changes: 7 additions & 8 deletions src/productList.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,15 @@ public function __set(string $key, $value): self
if ($value['quantity'] < 0) {
throw new \Exception('Quantity cannot be negative.');
}
if ($value['price'] < 0) {
throw new \Exception('Price cannot be negative.');
}
if ($value['tax'] < 0) {
throw new \Exception('Tax cannot be negative');
$this->data[strtolower($key)] = $value;

if ($this->getTax() < 0) {
throw new \Exception('Tax of Cart must be positive');
}
if ($value['sum'] < 0) {
throw new \Exception('Sum cannot be negative');

if ($this->getSum() < 0) {
throw new \Exception('Sum of Cart must be positive');
}
$this->data[strtolower($key)] = $value;

return $this;
}
Expand Down

0 comments on commit b4ae36f

Please sign in to comment.