From 075edcd0dd00e7987bef8fa97dc57dd233e75270 Mon Sep 17 00:00:00 2001 From: JuniJwi Date: Wed, 2 Sep 2020 00:08:03 -0500 Subject: [PATCH 1/7] Fix shop stock modal for guest viewing by adding Auth to the controller. --- app/Http/Controllers/ShopController.php | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/ShopController.php b/app/Http/Controllers/ShopController.php index 4bbc714d34..ce0790939c 100644 --- a/app/Http/Controllers/ShopController.php +++ b/app/Http/Controllers/ShopController.php @@ -71,12 +71,23 @@ public function getShop($id) public function getShopStock(ShopManager $service, $id, $stockId) { $shop = Shop::where('id', $id)->where('is_active', 1)->first(); + $stock = ShopStock::with('item')->where('id', $stockId)->where('shop_id', $id)->first(); + + $user = Auth::user(); + $quantityLimit = 0; $userPurchaseCount = 0; $purchaseLimitReached = false; + if($user){ + $quantityLimit = $service->getStockPurchaseLimit($stock, Auth::user()); + $userPurchaseCount = $service->checkUserPurchases($stock, Auth::user()); + $purchaseLimitReached = $service->checkPurchaseLimitReached($stock, Auth::user()); + } + if(!$shop) abort(404); return view('shops._stock_modal', [ 'shop' => $shop, - 'stock' => $stock = ShopStock::with('item')->where('id', $stockId)->where('shop_id', $id)->first(), - 'purchaseLimitReached' => $service->checkPurchaseLimitReached($stock, Auth::user()) - ]); + 'stock' => $stock, + 'quantityLimit' => $quantityLimit, + 'userPurchaseCount' => $userPurchaseCount, + 'purchaseLimitReached' => $purchaseLimitReached } /** From 9cddd95b430790490f6a0b4a060159115b4459ff Mon Sep 17 00:00:00 2001 From: JuniJwi Date: Wed, 2 Sep 2020 00:25:21 -0500 Subject: [PATCH 2/7] Fix empty shop bug by checking for if items is set, then clearing the shop if not --- app/Services/ShopService.php | 47 ++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/app/Services/ShopService.php b/app/Services/ShopService.php index acc49aa111..69fedbb3ce 100644 --- a/app/Services/ShopService.php +++ b/app/Services/ShopService.php @@ -108,27 +108,32 @@ public function updateShopStock($shop, $data, $user) DB::beginTransaction(); try { - foreach($data['item_id'] as $key => $itemId) - { - if(!$data['cost'][$key]) throw new \Exception("One or more of the items is missing a cost."); - } - - // Clear the existing shop stock - $shop->stock()->delete(); - - foreach($data['item_id'] as $key => $itemId) - { - $shop->stock()->create([ - 'shop_id' => $shop->id, - 'item_id' => $data['item_id'][$key], - 'currency_id' => $data['currency_id'][$key], - 'cost' => $data['cost'][$key], - 'use_user_bank' => isset($data['use_user_bank'][$key]), - 'use_character_bank' => isset($data['use_character_bank'][$key]), - 'is_limited_stock' => isset($data['is_limited_stock'][$key]), - 'quantity' => isset($data['is_limited_stock'][$key]) ? $data['quantity'][$key] : 0, - 'purchase_limit' => $data['purchase_limit'][$key], - ]); + if(isset($data['item_id'])) { + foreach($data['item_id'] as $key => $itemId) + { + if(!$data['cost'][$key]) throw new \Exception("One or more of the items is missing a cost."); + } + + // Clear the existing shop stock + $shop->stock()->delete(); + + foreach($data['item_id'] as $key => $itemId) + { + $shop->stock()->create([ + 'shop_id' => $shop->id, + 'item_id' => $data['item_id'][$key], + 'currency_id' => $data['currency_id'][$key], + 'cost' => $data['cost'][$key], + 'use_user_bank' => isset($data['use_user_bank'][$key]), + 'use_character_bank' => isset($data['use_character_bank'][$key]), + 'is_limited_stock' => isset($data['is_limited_stock'][$key]), + 'quantity' => isset($data['is_limited_stock'][$key]) ? $data['quantity'][$key] : 0, + 'purchase_limit' => $data['purchase_limit'][$key], + ]); + } + } else { + // Clear the existing shop stock + $shop->stock()->delete(); } return $this->commitReturn($shop); From 779edcc34b7061adc5861f1d0afeff782c36bc91 Mon Sep 17 00:00:00 2001 From: JuniJwi Date: Wed, 2 Sep 2020 03:30:09 -0500 Subject: [PATCH 3/7] lost a bracket during the fix for shop auth! --- app/Http/Controllers/ShopController.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Http/Controllers/ShopController.php b/app/Http/Controllers/ShopController.php index ce0790939c..f5ed97760e 100644 --- a/app/Http/Controllers/ShopController.php +++ b/app/Http/Controllers/ShopController.php @@ -88,6 +88,7 @@ public function getShopStock(ShopManager $service, $id, $stockId) 'quantityLimit' => $quantityLimit, 'userPurchaseCount' => $userPurchaseCount, 'purchaseLimitReached' => $purchaseLimitReached + ]); } /** From f0c7bfc7af23c1959f6f755da7d26d04fdf13b13 Mon Sep 17 00:00:00 2001 From: JuniJwi Date: Fri, 4 Sep 2020 01:40:40 -0500 Subject: [PATCH 4/7] Fix redirect error after deleting an MYO Slot. --- app/Http/Controllers/Admin/Characters/CharacterController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/Admin/Characters/CharacterController.php b/app/Http/Controllers/Admin/Characters/CharacterController.php index 33cb7317b5..714433417d 100644 --- a/app/Http/Controllers/Admin/Characters/CharacterController.php +++ b/app/Http/Controllers/Admin/Characters/CharacterController.php @@ -442,7 +442,7 @@ public function postMyoDelete(Request $request, CharacterManager $service, $id) if ($service->deleteCharacter($this->character, Auth::user())) { flash('Character deleted successfully.')->success(); - return redirect()->to($character->url); + return redirect()->to('myos'); } else { foreach($service->errors()->getMessages()['error'] as $error) flash($error)->error(); From 4d255059454655dc5446cfc1bbb7f66a11e8fa12 Mon Sep 17 00:00:00 2001 From: JuniJwi Date: Sun, 13 Sep 2020 16:24:07 -0500 Subject: [PATCH 5/7] fix shop auth view --- app/Http/Controllers/ShopController.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/ShopController.php b/app/Http/Controllers/ShopController.php index 4bbc714d34..337f59aedb 100644 --- a/app/Http/Controllers/ShopController.php +++ b/app/Http/Controllers/ShopController.php @@ -72,10 +72,15 @@ public function getShopStock(ShopManager $service, $id, $stockId) { $shop = Shop::where('id', $id)->where('is_active', 1)->first(); if(!$shop) abort(404); + + if(Auth::user()){ + $purchaseLimitReached = $service->checkPurchaseLimitReached($stock, Auth::user()); + } else $purchaseLimitReached = false; + return view('shops._stock_modal', [ 'shop' => $shop, 'stock' => $stock = ShopStock::with('item')->where('id', $stockId)->where('shop_id', $id)->first(), - 'purchaseLimitReached' => $service->checkPurchaseLimitReached($stock, Auth::user()) + 'purchaseLimitReached' => $purchaseLimitReached ]); } From 125c8284adbc168e826462c55e1e4d460634e216 Mon Sep 17 00:00:00 2001 From: JuniJwi Date: Tue, 6 Oct 2020 15:09:56 -0500 Subject: [PATCH 6/7] fix deleted MYO slot redirect mislink --- app/Http/Controllers/Admin/Characters/CharacterController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/Admin/Characters/CharacterController.php b/app/Http/Controllers/Admin/Characters/CharacterController.php index 33cb7317b5..714433417d 100644 --- a/app/Http/Controllers/Admin/Characters/CharacterController.php +++ b/app/Http/Controllers/Admin/Characters/CharacterController.php @@ -442,7 +442,7 @@ public function postMyoDelete(Request $request, CharacterManager $service, $id) if ($service->deleteCharacter($this->character, Auth::user())) { flash('Character deleted successfully.')->success(); - return redirect()->to($character->url); + return redirect()->to('myos'); } else { foreach($service->errors()->getMessages()['error'] as $error) flash($error)->error(); From 11f037487d3c0eccde6a0362dd7483876e46f383 Mon Sep 17 00:00:00 2001 From: JuniJwi Date: Tue, 6 Oct 2020 15:10:13 -0500 Subject: [PATCH 7/7] fix inability to remove all items from a shop --- app/Services/ShopService.php | 47 ++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/app/Services/ShopService.php b/app/Services/ShopService.php index acc49aa111..69fedbb3ce 100644 --- a/app/Services/ShopService.php +++ b/app/Services/ShopService.php @@ -108,27 +108,32 @@ public function updateShopStock($shop, $data, $user) DB::beginTransaction(); try { - foreach($data['item_id'] as $key => $itemId) - { - if(!$data['cost'][$key]) throw new \Exception("One or more of the items is missing a cost."); - } - - // Clear the existing shop stock - $shop->stock()->delete(); - - foreach($data['item_id'] as $key => $itemId) - { - $shop->stock()->create([ - 'shop_id' => $shop->id, - 'item_id' => $data['item_id'][$key], - 'currency_id' => $data['currency_id'][$key], - 'cost' => $data['cost'][$key], - 'use_user_bank' => isset($data['use_user_bank'][$key]), - 'use_character_bank' => isset($data['use_character_bank'][$key]), - 'is_limited_stock' => isset($data['is_limited_stock'][$key]), - 'quantity' => isset($data['is_limited_stock'][$key]) ? $data['quantity'][$key] : 0, - 'purchase_limit' => $data['purchase_limit'][$key], - ]); + if(isset($data['item_id'])) { + foreach($data['item_id'] as $key => $itemId) + { + if(!$data['cost'][$key]) throw new \Exception("One or more of the items is missing a cost."); + } + + // Clear the existing shop stock + $shop->stock()->delete(); + + foreach($data['item_id'] as $key => $itemId) + { + $shop->stock()->create([ + 'shop_id' => $shop->id, + 'item_id' => $data['item_id'][$key], + 'currency_id' => $data['currency_id'][$key], + 'cost' => $data['cost'][$key], + 'use_user_bank' => isset($data['use_user_bank'][$key]), + 'use_character_bank' => isset($data['use_character_bank'][$key]), + 'is_limited_stock' => isset($data['is_limited_stock'][$key]), + 'quantity' => isset($data['is_limited_stock'][$key]) ? $data['quantity'][$key] : 0, + 'purchase_limit' => $data['purchase_limit'][$key], + ]); + } + } else { + // Clear the existing shop stock + $shop->stock()->delete(); } return $this->commitReturn($shop);