Skip to content

Commit

Permalink
Bugs fixed & Improvements
Browse files Browse the repository at this point in the history
- Orders Controllers bug fixed
- Authenticate Middleware comments
- Excluding pagination request from search in products list
- Address list buttons styles
- htaccess
  • Loading branch information
gocanto committed Oct 28, 2015
1 parent cde7cc4 commit 67c3f70
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 96 deletions.
15 changes: 15 additions & 0 deletions .htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>

RewriteEngine On

# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]

# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
4 changes: 2 additions & 2 deletions app/Http/Controllers/Auth/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public function create(array $data)
\Mail::queue('emails.accountVerification', ['data' => $data, 'title' => $title, 'name' => $name], function ($message) use ($data) {
$message->to($data['email'])->subject(trans('user.emails.verification_account.subject'));
});

\Session::put('message', trans('user.signUp_message', ['_name' => $name ]));

\Session::save();
Expand Down Expand Up @@ -134,7 +134,7 @@ public function postLogin(Request $request)
if (!env('APP_DEBUG', false)) {
$validate['g-recaptcha-response'] = 'required|recaptcha';
}

$this->validate($request, $validate);

$credentials = $this->getCredentials($request);
Expand Down
140 changes: 70 additions & 70 deletions app/Http/Controllers/OrdersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,87 +63,84 @@ public function addToOrder($destination, $productId, Request $request)

$user = \Auth::user();

//dd($destination, $productId, $request->get('quantity'), $request);

//checking if the user is logged

if ($user) {
if ($product->user_id == $user->id) {
return redirect()->route('orders.show_wish_list', [$product->id])
->withErrors([
'feature_images' => [trans('store.cantAddSelfProducts')]

$basicCart = Order::ofType($destination)->where('user_id', $user->id)->first();

if (!$basicCart) {
$basicCart = new Order();
$basicCart->user_id = $user->id;
$basicCart->type = $destination;
$basicCart->status = 'open';
$basicCart->save();

$log = Log::create([
'action_type_id' => '1',
'details' => $destination,
'source_id' => $basicCart->id,
'user_id' => $user->id
]);
} else {
$basicCart = Order::ofType($destination)->where('user_id', $user->id)->first();

if (!$basicCart) {
$basicCart = new Order();
$basicCart->user_id = $user->id;
$basicCart->type = $destination;
$basicCart->status = 'open';
$basicCart->save();

$log = Log::create([
'action_type_id' => '1',
'details' => $destination,
'source_id' => $basicCart->id,
'user_id' => $user->id
]);
}
}

//if the request has an email address, we keep it, otherwise we use the user one
if ($request->has('email')) {
$v = Validator::make($request->all(), ['email' => 'required|email']);
if ($v->fails()) {
$email = $user->email;
} else {
$email = $request->input('email');
}
} else {
//if the request has an email address, we keep it, otherwise we use the user one
if ($request->has('email')) {
$v = Validator::make($request->all(), ['email' => 'required|email']);
if ($v->fails()) {
$email = $user->email;
} else {
$email = $request->input('email');
}
} else {
$email = $user->email;
}

//creating visrtual order
if ($destination != 'wishlist') {
$this->addToCartVirtualsProduct($product, $email, $basicCart->id, $quantity);
}
//creating visrtual order
if ($destination != 'wishlist') {
$this->addToCartVirtualsProduct($product, $email, $basicCart->id, $quantity);
}

//checking if the user already has a product so it can be added
$orderDetail = OrderDetail::where('order_id', $basicCart->id)
->where('product_id', $product->id)
->first();
//checking if the user already has a product so it can be added
$orderDetail = OrderDetail::where('order_id', $basicCart->id)
->where('product_id', $product->id)
->first();

//creating the order detail
if ($orderDetail) {
$orderDetail->price = $product->price;
$orderDetail->quantity = $orderDetail->quantity + $quantity;
} else {
$orderDetail = new OrderDetail();
$orderDetail->order_id = $basicCart->id;
$orderDetail->product_id = $product->id;
$orderDetail->price = $product->price;
$orderDetail->quantity = $quantity;
$orderDetail->status = 1;
}
//creating the order detail
if ($orderDetail) {
$orderDetail->price = $product->price;
$orderDetail->quantity = $orderDetail->quantity + $quantity;
} else {
$orderDetail = new OrderDetail();
$orderDetail->order_id = $basicCart->id;
$orderDetail->product_id = $product->id;
$orderDetail->price = $product->price;
$orderDetail->quantity = $quantity;
$orderDetail->status = 1;
}

//saving detail order
$orderDetail->save();
//saving detail order
$orderDetail->save();

$log = Log::create([
'action_type_id' => '4',
'details' => $basicCart->id,
'source_id' =>$orderDetail->id,
'user_id' =>$user->id
]);
$log = Log::create([
'action_type_id' => '4',
'details' => $basicCart->id,
'source_id' =>$orderDetail->id,
'user_id' =>$user->id
]);

//choosing what destination to go back
if ($destination == 'wishlist') {
Session::push('message', trans('store.productAddedToWishList'));
return redirect()->route('orders.show_wish_list');
} elseif ($destination == 'later') {
Session::push('message', trans('store.productsSavedForLater'));
return redirect()->route('products.show', [$productId]);
} else {
Session::push('message', trans('store.productAdded'));
return redirect()->route('orders.show_cart');
}
//callback url
if ($destination == 'wishlist') {
Session::push('message', trans('store.productAddedToWishList'));
return redirect()->route('orders.show_wish_list');
} elseif ($destination == 'later') {
Session::push('message', trans('store.productsSavedForLater'));
return redirect()->route('products.show', [$productId]);
} else {
Session::push('message', trans('store.productAdded'));
return redirect()->route('orders.show_cart');
}
}

Expand Down Expand Up @@ -1889,13 +1886,16 @@ public static function fromGuestToUser($ordersController)
*/
$cart_content = Session::get('user.cart_content');

//dd($cart_content, Session::get('user.cart'));

foreach (Session::get('user.cart_content') as $product => $value) {
$ordersController->addToOrder(
'cart',
$product,
new Request(
[
'quantity' => $cart_content[$product] != '' ? $cart_content[$product] : 1
'quantity' => $cart_content[$product] != '' ? $cart_content[$product] : 1,
'guestToUser' => 1
]
)
);
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Middleware/Authenticate.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ public function handle($request, Closure $next)
}

/**
* If there is something saved into the guest cart. Its content will be transfer
* If there is products into the guest cart, its content is transferred
* to a logged user 'cart' order.
*/

if (\Illuminate\Support\Facades\Session::has('user.cart_content')) {
$ordersController = new OrdersController();
$ordersController->fromGuestToUser($ordersController);
Expand Down
4 changes: 2 additions & 2 deletions app/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ public function scopeRefine($query, $filters)
break;

default:
if ($key != 'category_name' && $key != 'search') {
$query->whereRaw("features LIKE '%\"".$key."\":%\"%".$value."%\"%'");
if ($key != 'category_name' && $key != 'search' && $key != 'page') {
$query->whereRaw("features LIKE '%\"".$key."\":%\"%".$value."%\"%'");
}
break;
}
Expand Down
38 changes: 19 additions & 19 deletions resources/views/address/list.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
@stop

@section('center_content')

<div class="page-header">
<h5>{{ trans('address.my_addresses') }}</h5>
</div>
Expand All @@ -21,19 +21,19 @@
<div class="col-md-12 text-right">

<button ng-controller="ModalCtrl" ng-click="modalOpen({templateUrl:'/user/address/create',controller:'AddressesControllerModal', size: 'md'})" class="btn btn-sm btn-info"><span class="glyphicon glyphicon-plus"></span>&nbsp;{{ trans('address.add') }}</button>

@if(isset($defaultId) && $defaultId != '')
<a class="btn btn-info btn-sm" href="/user/orders/checkOut/address/{{ $defaultId }}">
<span class="glyphicon glyphicon-ok"></span>&nbsp;
<a class="btn btn-success btn-sm" href="/user/orders/checkOut/address/{{ $defaultId }}">
<span class="glyphicon glyphicon-ok"></span>&nbsp;
{{ trans('address.use_selected') }}
</a>
@endif

</div>
</div>

<div class="row">&nbsp;</div>

{{-- addresses list --}}
<div class="row">

Expand All @@ -44,7 +44,7 @@
<div class="row">&nbsp;</div>
<div class="row">
<div class="col-lg-12">
{{ trans('address.no_registered_instructions') }}
{{ trans('address.no_registered_instructions') }}
<a href="javascript:void(0)" ng-controller="ModalCtrl" ng-click="modalOpen({templateUrl:'/user/address/create',controller:'AddressesControllerModal',resolve:'address', size: 'md'})">{{ trans('globals.click_here') }}</a>
</div>
</div>
Expand All @@ -53,11 +53,11 @@
@else

@foreach ($addresses as $address)

<div class="col-lg-4">

<div class="panel @if ($address->default == '1') panel-success @else panel-primary @endif">

<div class="panel-heading">
<strong>
{{ $address->name_contact }}&nbsp;
Expand All @@ -72,7 +72,7 @@
{{ $address->line1 }}<br>
@if (trim($address->line2) != '')
<span>{{ $address->line2 }}<br></span>
@endif
@endif
{{ $address->city.', '.$address->state }}<br>
{{ $address->country }}<br>
<hr>
Expand All @@ -83,14 +83,14 @@
</div>

<div class="panel-footer" ng-controller = "AddressesController">

@if ($address->default == 0)
<button ng-click="deleteAddress('{{ $address->id }}')" class="btn btn-danger btn-sm">
<span class="glyphicon glyphicon-trash"></span>&nbsp;
{{ trans('globals.delete') }}
</button>
<button ng-click="setDefaultAddress('{{ $address->id }}')" class="btn btn-info btn-sm">
<span class="glyphicon glyphicon-pushpin"></span>&nbsp;
<span class="glyphicon glyphicon-pushpin"></span>&nbsp;
{{ trans('address.make_default_1') }}
</button>
@endif
Expand All @@ -99,14 +99,14 @@
<span class="glyphicon glyphicon-edit"></span>&nbsp;
{{ trans('globals.edit') }}
</button>

@if(isset($defaultId) && $defaultId != '')
<a class="btn btn-primary btn-sm" href="/user/orders/checkOut/address/{{ $address->id }}">
<span class="glyphicon glyphicon-pushpin"></span>&nbsp;
<span class="glyphicon glyphicon-pushpin"></span>&nbsp;
{{ trans('address.use_this') }}
</a>
@endif

</div>

</div>
Expand All @@ -129,7 +129,7 @@
(function(app){
app.controller('AddressesController',['$scope','$http', '$window', 'PassInfo', function($scope, $http, $window, PassInfo){
$scope.setDefaultAddress = function(id)
{
$http.post('/user/address/default/', { 'id': id }).
Expand All @@ -151,11 +151,11 @@
@else
$window.location.href = data['url'];
@endif
});
});
};
PassInfo.setProperty('{{ isset($callBackUrl) ? $callBackUrl : '' }}');
}]);
})(angular.module("AntVel"));
Expand Down
2 changes: 1 addition & 1 deletion resources/views/products/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
</li>
<?php $filterSelected = []; ?>
@foreach ($refine as $key => $value)
@if (trim($value)!='' && $key != 'category_name')
@if (trim($value)!='' && $key != 'category_name' && $key != 'page')
<li>
<small>
<?php
Expand Down

0 comments on commit 67c3f70

Please sign in to comment.