Skip to content

Commit

Permalink
fixed issue bagisto#749
Browse files Browse the repository at this point in the history
  • Loading branch information
prashant-webkul committed Mar 31, 2019
1 parent 91b4d1f commit 4a2efc8
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 33 deletions.
Expand Up @@ -115,6 +115,8 @@ public function edit($id)
}
}

session()->flash('warning', trans('shop::app.security-warning'));

return redirect()->route('customer.address.index');
}

Expand Down Expand Up @@ -151,7 +153,7 @@ public function update($id)
}
}

session()->flash('success', trans('shop::app.security-warning'));
session()->flash('warning', trans('shop::app.security-warning'));

return redirect()->route('customer.address.index');
}
Expand Down Expand Up @@ -185,16 +187,18 @@ public function makeDefault($id)
*/
public function destroy($id)
{
if (request()->is('customer/*') || request()->is('admin/*')) {
$this->address->delete($id);
$addresses = $this->customer->addresses;

session()->flash('success', trans('shop::app.customer.account.address.delete.success'));
foreach($addresses as $address) {
if($id == $address->id) {
$this->address->delete($id);

return redirect()->back();
} else {
session()->flash('warning', trans('shop::app.security-warning'));
session()->flash('success', trans('shop::app.customer.account.address.delete.success'));

return redirect()->route('customer.address.index');
return redirect()->route('customer.address.index');
}
}

return redirect()->route('customer.address.index');
}
}
Expand Up @@ -40,8 +40,6 @@ public function __construct(CustomerRepository $customer, WishlistRepository $wi

$this->_config = request('_config');

$this->customer = $customer;

$this->wishlist = $wishlist;

$this->product = $product;
Expand Down Expand Up @@ -104,29 +102,22 @@ public function add($itemId) {
* @param integer $itemId
*/
public function remove($itemId) {
$found = $this->wishlist->find($itemId);

if(isset($found)) {
$found = true;
} else {
$found = false;
}
$customerWishlistItems = auth()->guard('customer')->user()->wishlist_items;

if($found) {
$result = $this->wishlist->deleteWhere(['customer_id' => auth()->guard('customer')->user()->id, 'channel_id' => core()->getCurrentChannel()->id, 'id' => $itemId]);
foreach($customerWishlistItems as $customerWishlistItem) {
if($itemId == $customerWishlistItem->id) {
$this->wishlist->delete($itemId);

if ($result) {
session()->flash('success', trans('customer::app.wishlist.removed'));

return redirect()->back();
} else {
session()->flash('error', trans('customer::app.wishlist.remove-fail'));

return redirect()->back();
}
} else {
return redirect()->back();
}

session()->flash('error', trans('customer::app.wishlist.remove-fail'));

return redirect()->back();
}

/**
Expand All @@ -136,6 +127,13 @@ public function remove($itemId) {
*/
public function move($itemId) {
$wishlistItem = $this->wishlist->findOneByField('id', $itemId);

if(!isset($wishlistItem) || $wishlistItem->customer_id != auth()->guard('customer')->user()->id) {
session()->flash('warning', trans('shop::app.security-warning'));

return redirect()->route( 'customer.wishlist.index');
}

$result = Cart::moveToCart($wishlistItem);

if ($result == 1) {
Expand All @@ -151,7 +149,7 @@ public function move($itemId) {
return redirect()->back();
}
} else if ($result == 0) {
Session('error', trans('shop::app.wishlist.error'));
session()->flash('error', trans('shop::app.wishlist.error'));

return redirect()->back();
} else if ($result == -1) {
Expand Down Expand Up @@ -184,4 +182,4 @@ public function removeAll() {
session()->flash('success', trans('customer::app.wishlist.remove-all-success'));
return redirect()->back();
}
}
}
7 changes: 7 additions & 0 deletions packages/Webkul/Customer/src/Models/Customer.php
Expand Up @@ -96,4 +96,11 @@ public function active_carts() {
public function all_reviews() {
return $this->hasMany(ProductReviewProxy::modelClass(), 'customer_id');
}

/**
* get all orders of a customer
*/
public function all_orders() {
return $this->hasMany(OrderProxy::modelClass(), 'customer_id');
}
}
2 changes: 1 addition & 1 deletion packages/Webkul/Shop/package.json
Expand Up @@ -21,6 +21,6 @@
"vee-validate": "2.0.0-rc.26",
"vue-flatpickr": "^2.3.0",
"vue-slider-component": "^2.7.5",
"ez-plus":"^1.2.1"
"ez-plus": "^1.2.1"
}
}
14 changes: 11 additions & 3 deletions packages/Webkul/Shop/src/Http/Controllers/OrderController.php
Expand Up @@ -82,9 +82,17 @@ public function index()
*/
public function view($id)
{
$order = $this->order->find($id);
$orders = auth()->guard('customer')->user()->all_orders;

if(isset($orders) && count($orders)) {
$order = $orders->first();

return view($this->_config['view'], compact('order'));
} else {
return redirect()->route( 'customer.orders.index');
}


return view($this->_config['view'], compact('order'));
}

/**
Expand All @@ -101,4 +109,4 @@ public function print($id)

return $pdf->download('invoice-' . $invoice->created_at->format('d-m-Y') . '.pdf');
}
}
}
Expand Up @@ -84,6 +84,7 @@ public function store(Request $request , $id)

$data = request()->all();


if (auth()->guard('customer')->user()) {
$data['customer_id'] = auth()->guard('customer')->user()->id;
$data['name'] = auth()->guard('customer')->user()->first_name .' ' . auth()->guard('customer')->user()->last_name;
Expand All @@ -96,7 +97,7 @@ public function store(Request $request , $id)

session()->flash('success', trans('shop::app.response.submit-success', ['name' => 'Product Review']));

return redirect()->route($this->_config['redirect']);
return redirect()->back();
}

/**
Expand Down
3 changes: 2 additions & 1 deletion packages/Webkul/Shop/src/Resources/lang/en/app.php
Expand Up @@ -2,6 +2,7 @@

return [
'security-warning' => 'Suspicious Activity Found!!!',
'nothing-to-delete' => 'Nothing to delete',

'layouts' => [
'my-account' => 'My Account',
Expand Down Expand Up @@ -501,4 +502,4 @@
'delete-success' => ':name deleted successfully.',
'submit-success' => ':name submitted successfully.'
],
];
];

0 comments on commit 4a2efc8

Please sign in to comment.