Skip to content

Commit

Permalink
Update to Laravel 5.4
Browse files Browse the repository at this point in the history
  • Loading branch information
raylight75 committed Mar 4, 2017
1 parent 75a8f77 commit 0e5550f
Show file tree
Hide file tree
Showing 19 changed files with 366 additions and 566 deletions.
680 changes: 215 additions & 465 deletions .idea/workspace.xml

Large diffs are not rendered by default.

13 changes: 1 addition & 12 deletions app/Helpers/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Helper
* @link https://raylight75@bitbucket.org/raylight75/ecommerce-cms.git
*/

public static function currency($input)
public static function price($input)
{
$var = session('currency');
if (isset($var)) {
Expand All @@ -47,15 +47,4 @@ public static function currency($input)
$total = (double)$input * (double)$rate;
return number_format((double)$total, 2);
}

public static function label()
{
$var = session('currency');
if (isset($var)) {
$result = $var;
} else {
$result = "usd";
}
return $result;
}
}
58 changes: 25 additions & 33 deletions app/Http/Controllers/BaseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use App\Services\BaseService;
use Illuminate\Contracts\Auth\Guard;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\App;
use View;

class BaseController extends Controller
Expand Down Expand Up @@ -43,17 +42,22 @@ class BaseController extends Controller

protected $base;

protected $request;


/**
* BaseController constructor.
* @param BaseService $baseService
* @param Request $request
*/
public function __construct(BaseService $baseService)
public function __construct(BaseService $baseService, Request $request)
{
$this->base = $baseService;
$this->request = $request;
}

/**
* Show the home page to the user.
*
* Show the home page to the user. *
* @return Response
*/
public function index()
Expand All @@ -71,14 +75,14 @@ public function aboutus()
return view('frontend.aboutus');
}


/**
* @param Request $request
* @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse
*/
public function autocomplete(Request $request)
public function autocomplete()
{
$results = $this->base->autocomplete($request);
if ($request->ajax()) {
$results = $this->base->autocomplete($this->request);
if ($this->request->ajax()) {
return response()->json($results);
} else {
return redirect()->back();
Expand All @@ -99,10 +103,10 @@ public function contacts()
* @param $parent
* @return View
*/
public function filter(Request $request, $crud, $parent)
public function filter($crud, $parent)
{
$data = $this->base->getFilter($request, $parent);
if ($request->ajax()) {
$data = $this->base->getFilter($this->request, $parent);
if ($this->request->ajax()) {
return response()->json(view('frontend.ajax-products', $data)->render());
} else {
return view('frontend.filter_view', $data);
Expand Down Expand Up @@ -135,37 +139,25 @@ public function frame($id)
* @param $parent
* @return \Illuminate\Http\JsonResponse|View
*/
public function search(Request $request, $parent)
public function search($parent)
{
$data = $this->base->prepareSearch($request, $parent);
if ($request->ajax()) {
$data = $this->base->prepareSearch($this->request, $parent);
if ($this->request->ajax()) {
return response()->json(view('frontend.ajax-products', $data)->render());
} else {
return view('frontend.filter_view', $data);
}
}

/**
* Set currency to session
* @param string $currency
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*/
public function set_currency(Request $request,$currency = "")
{
$currency = ($currency != "") ? $currency : "USD";
$request->session()->put('currency', $currency);
return redirect()->back();
}

/**
* Set language to session
* @param string $locale
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
* @param string $value
* @return \Illuminate\Http\RedirectResponse
*/
public function set_language(Request $request,$locale = "")
public function set_Session($value = "")
{
$locale = ($locale != "") ? $locale : "en";
$request->session()->put('locale', $locale);
$field = $this->request->segment(1);
$this->request->session()->put($field, $value);
return redirect()->back();
}

Expand All @@ -178,11 +170,11 @@ public function userLogin()
return view('frontend.login');
}

public function welcome(Guard $auth,Request $request)
public function welcome(Guard $auth)
{
//redirect trait AuthenticatesUsers getLogout()
$user = $auth->user()->name;
$request->session()->flash('flash_message', 'You have been successfully Logged In!');
$this->request->session()->flash('flash_message', 'You have been successfully Logged In!');
return view('messages.welcome')->with('user', $user);
}
}
50 changes: 31 additions & 19 deletions app/Http/Controllers/ShoppingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,23 @@ class ShoppingController extends BaseController

protected $shopping;

public function __construct(ShoppingService $shoppingService, Cart $cart)
protected $request;

/**
* ShoppingController constructor.
* @param ShoppingService $shoppingService
* @param Cart $cart
* @param Request $request
*/
public function __construct
(
ShoppingService $shoppingService,
Cart $cart,
Request $request
)
{
$this->cart = $cart;
$this->request = $request;
$this->shopping = $shoppingService;
}

Expand Down Expand Up @@ -82,39 +96,37 @@ public function customerStore(SubmitCheckout $request)
}

/**
* Show order information from session.
* @param Request $request
* Show order information from session. *
* @return View
*/
public function checkoutShow(Request $request)
public function checkoutShow()
{
$country = $request->session()->get('country');
$country = $this->request->session()->get('country');
if (!isset($country)) {
$request->session()->flash('flash_message', 'YOUR MUST FILL REQUIRED FIELDS!');
$this->request->session()->flash('flash_message', 'YOUR MUST FILL REQUIRED FIELDS!');
return redirect('checkout/shipping');
}
$data = $this->shopping->prepareShow($request);
$data = $this->shopping->prepareShow($this->request);
return view('frontend.checkoutTwo', $data);
}

/**
* Create Order and Customer in Database.
* @param Request $request
* Create Order and Customer in Database. *
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*/
public function createOrder(Request $request)
public function createOrder()
{
$cart = $this->cart->instance(auth()->id())->content();
if (!$request->session()->has('email')) {
$request->session()->flash('flash_message', 'YOUR MUST FILL REQUIRED FIELDS!');
if (!$this->request->session()->has('email')) {
$this->request->session()->flash('flash_message', 'YOUR MUST FILL REQUIRED FIELDS!');
return redirect('checkout/shipping');
} elseif ($cart->isEmpty()) {
$request->session()->flash('flash_message', 'YOU MUST SELECT PRODUCT!');
$this->request->session()->flash('flash_message', 'YOU MUST SELECT PRODUCT!');
return redirect()->back();
}
$this->shopping->createOrder($request);
$this->shopping->createOrder($this->request);
$this->cart->instance(auth()->id())->destroy();
$this->shopping->forgetSessionKeys($request);
$this->shopping->forgetSessionKeys($this->request);
return redirect('checkout/order');
}

Expand Down Expand Up @@ -144,9 +156,9 @@ public function storeItem(SubmitProduct $request)
* Update products in shopping cart.
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*/
public function updateItem(Request $request)
public function updateItem()
{
$content = $request->input('qty');
$content = $this->request->input('qty');
foreach ($content as $id => $row) {
$this->cart->instance(auth()->id())
->update($row['rowId'], $row['qty']);
Expand Down Expand Up @@ -179,9 +191,9 @@ public function delete()
* Show user confirmation for finalazing order.
* @return View
*/
public function finalOrder(Request $request)
public function finalOrder()
{
$request->session()->flash('flash_message', 'YOUR ORDER HAVE BEEN SUCCESSFULY PLACED!');
$this->request->session()->flash('flash_message', 'YOUR ORDER HAVE BEEN SUCCESSFULY PLACED!');
return view('frontend.placeOrder');
}
}
2 changes: 1 addition & 1 deletion app/Http/Middleware/LanguageMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function __construct(Application $app, Request $request)
*/
public function handle($request, Closure $next)
{
$locale = $request->session()->get('locale');
$locale = $request->session()->get('locale', config('app.locale'));
$this->app->setLocale($locale);
return $next($request);
}
Expand Down
21 changes: 17 additions & 4 deletions app/Services/ShareService.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use App\Repositories\SettingRepository;
use Gloudemans\Shoppingcart\Cart;
use Illuminate\Contracts\Auth\Guard;
use Illuminate\Foundation\Application;
use View;

class ShareService
Expand Down Expand Up @@ -40,35 +41,45 @@ class ShareService
* @link https://raylight75@bitbucket.org/raylight75/ecommerce-cms.git
*/

protected $auth;

protected $app;

protected $cat;

protected $cart;

protected $currency;

protected $auth;

protected $setting;

protected $parent_id = 0;


/**
* GlobalService constructor.
* ShareService constructor.
* @param Application $app
* @param CategoryRepository $cat
* @param Cart $cart
* @param CurrencyRepository $currency
* @param Guard $auth
* @param SettingRepository $setting
*/
public function __construct
(
Application $app,
CategoryRepository $cat,
Cart $cart,
CurrencyRepository $currency,
Guard $auth,
SettingRepository $setting
)
{
$this->auth = $auth;
$this->app = $app;
$this->cat = $cat;
$this->cart = $cart;
$this->currency = $currency;
$this->auth = $auth;
$this->setting = $setting;
}

Expand Down Expand Up @@ -115,6 +126,8 @@ public function globalData()
$data = array(
'menu' => $this->getMenuData($this->parent_id),
'header' => $this->setting->findOrFail(1),
'locale' => $this->app->getLocale(),
'label' => session('currency', config('app.currency')),
'rows' => $rows,
'cart' => $cart,
'grand_total' => $grandTotal,
Expand Down
Loading

0 comments on commit 0e5550f

Please sign in to comment.