Commit 44fe43c4 authored by Artem's avatar Artem

imporove add to cart method

parent 30b2976e
...@@ -25,6 +25,8 @@ class CartController extends Controller ...@@ -25,6 +25,8 @@ class CartController extends Controller
public function addToCart(Product $product) public function addToCart(Product $product)
{ {
$product->addItemToCart(); $product->addItemToCart();
$cart = Session::get('cart');
return $cart->total_qty;
} }
public function updateQtyInCart(Request $request) public function updateQtyInCart(Request $request)
......
...@@ -7,7 +7,7 @@ function setAddToCardEventListener() { ...@@ -7,7 +7,7 @@ function setAddToCardEventListener() {
axios.post(actionUrl) axios.post(actionUrl)
.then(function (response) { .then(function (response) {
const cartAmountElem = document.querySelector('.amount-in-cart'); const cartAmountElem = document.querySelector('.amount-in-cart');
cartAmountElem.textContent++; cartAmountElem.textContent = response.data;
}) })
.catch(function (error) { .catch(function (error) {
console.log(error); console.log(error);
......
...@@ -61,7 +61,7 @@ ...@@ -61,7 +61,7 @@
>Update quantity</button> >Update quantity</button>
</td> </td>
<td class="hidden-xs text-center"><strong>Total € {{ $cart->total_price }}</strong></td> <td class="hidden-xs text-center"><strong>Total € {{ $cart->total_price }}</strong></td>
<td><button class="btn btn-success btn-block">Send order</button></td> <td><button class="btn btn-success btn-block">Checkout</button></td>
</tr> </tr>
</tfoot> </tfoot>
</table> </table>
...@@ -75,5 +75,5 @@ ...@@ -75,5 +75,5 @@
@endsection @endsection
@section('script') @section('script')
<script src="js/cart.js"></script> <script src="js/cart.js" defer></script>
@endsection @endsection
...@@ -32,5 +32,5 @@ ...@@ -32,5 +32,5 @@
@endsection @endsection
@section('script') @section('script')
<script src="js/welcome.js"></script> <script src="js/welcome.js" defer></script>
@endsection @endsection
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment