diff --git a/components/Basket.php b/components/Basket.php index 4341ab5..1e8ef49 100644 --- a/components/Basket.php +++ b/components/Basket.php @@ -92,23 +92,15 @@ public function onRender() public function prepareVars($on = 'run') { if ($on == 'run') { - $this->paymentPage = $this->page['paymentPage'] = $this->property('paymentPage'); - $this->productPage = $this->page['productPage'] = $this->property('productPage'); + $this->registerBasketInfo(); + $this->registerPages(); $this->basketComponent = $this->page['basketComponent'] = $this->property('basketComponent');; $this->basketPartial = $this->page['basketPartial'] = $this->property('basketPartial');; - $this->basketItems = $this->page['basketItems'] = Cart::content(); - $this->basketCount = $this->page['basketCount'] = Cart::count(); - $this->basketTotal = $this->page['basketTotal'] = Cart::total(); } if ($on == 'render') { - $this->tableClass = $this->page['tableClass'] = $this->propertyOrParam('tableClass'); - $this->nameColClass = $this->page['nameColClass'] = $this->property('nameColClass'); - $this->qtyColClass = $this->page['qtyColClass'] = $this->property('qtyColClass'); - $this->priceColClass = $this->page['priceColClass'] = $this->property('priceColClass'); - $this->subtotalColClass = $this->page['subtotalColClass'] = $this->property('subtotalColClass'); - $this->totalLabelClass = $this->page['totalLabelClass'] = $this->property('totalLabelClass'); + $this->registerClasses(); } if (Session::has('orderId')) { @@ -116,6 +108,29 @@ public function prepareVars($on = 'run') } } + public function registerBasketInfo() + { + $this->basketCount = $this->page['basketCount'] = Cart::count(); + $this->basketItems = $this->page['basketItems'] = Cart::content(); + $this->basketTotal = $this->page['basketTotal'] = Cart::total(); + } + + public function registerPages() + { + $this->paymentPage = $this->page['paymentPage'] = $this->property('paymentPage'); + $this->productPage = $this->page['productPage'] = $this->property('productPage'); + } + + public function registerClasses() + { + $this->tableClass = $this->page['tableClass'] = $this->propertyOrParam('tableClass'); + $this->nameColClass = $this->page['nameColClass'] = $this->property('nameColClass'); + $this->qtyColClass = $this->page['qtyColClass'] = $this->property('qtyColClass'); + $this->priceColClass = $this->page['priceColClass'] = $this->property('priceColClass'); + $this->subtotalColClass = $this->page['subtotalColClass'] = $this->property('subtotalColClass'); + $this->totalLabelClass = $this->page['totalLabelClass'] = $this->property('totalLabelClass'); + } + public function onAddProduct() { $id = post('id'); @@ -125,9 +140,19 @@ public function onAddProduct() Cart::add($id, $product->title, $quantity, $product->price); - $this->page['basketCount'] = Cart::count(); - $this->page['basketItems'] = Cart::content(); - $this->page['basketTotal'] = Cart::total(); + $this->registerBasketInfo(); + } + + public function onRemoveProduct() + { + Cart::remove(post('row_id')); + + $this->registerBasketInfo(); + + return [ + 'total' => $this->basketTotal, + 'count' => $this->basketCount, + ]; } public function onCheckout() diff --git a/components/basket/default.htm b/components/basket/default.htm index 3cc1cf9..0d63a63 100644 --- a/components/basket/default.htm +++ b/components/basket/default.htm @@ -1,6 +1,7 @@
Product | Qty. | Price | @@ -9,7 +10,15 @@||||||
---|---|---|---|---|---|---|---|---|
+ + | {{ item.name }} | {{ item.qty }} | {{ item.price }} | @@ -17,10 +26,10 @@|||||
+ | Total: | -£{{ basketTotal }} | +£{{ basketTotal }} |