-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
All functionalities connected with shopping cart was added. All based…
… on AJAX calls, to add and delete from cart, dynamic displaying number of products in cart. Improvements in appearance and also refactoring
- Loading branch information
vilgefortzz
committed
Apr 23, 2017
1 parent
f6b22aa
commit 66b89fa
Showing
43 changed files
with
564 additions
and
294 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use App\Cart; | ||
use App\Item; | ||
use App\Product; | ||
use Illuminate\Http\Request; | ||
use Session; | ||
|
||
class CartController extends Controller | ||
{ | ||
|
||
public function showProducts() { | ||
|
||
if (!Session::has('cart')){ | ||
return view('cart'); | ||
} | ||
$oldCart = Session::get('cart'); | ||
$cart = new Cart($oldCart); | ||
return view('cart', ['products' => $cart->products, 'totalPrice' => $cart->totalPrice, 'totalQuantity' => $cart->totalQuantity]); | ||
|
||
} | ||
|
||
/* | ||
* AJAX request | ||
*/ | ||
public function addProduct(Product $product, Request $request) { | ||
|
||
$oldCart = $request->session()->has('cart') ? $request->session()->get('cart') : null; | ||
|
||
$cart = new Cart($oldCart); | ||
|
||
$cart->addProduct($product); | ||
|
||
$request->session()->put('cart', $cart); | ||
|
||
/* | ||
* To have essential data in ajax request | ||
*/ | ||
return response()->json($product); | ||
} | ||
|
||
/* | ||
* AJAX request | ||
*/ | ||
public function deleteProduct(Product $product, Request $request) { | ||
|
||
$oldCart = $request->session()->has('cart') ? $request->session()->get('cart') : null; | ||
|
||
$cart = new Cart($oldCart); | ||
|
||
$cart->deleteProduct($product); | ||
|
||
$request->session()->put('cart', $cart); | ||
|
||
return response()->json($product); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 0 additions & 35 deletions
35
database/migrations/2017_03_05_194709_create_carts_table.php
This file was deleted.
Oops, something went wrong.
38 changes: 0 additions & 38 deletions
38
database/migrations/2017_03_05_202645_create_items_table.php
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.