Skip to content

Commit

Permalink
Merge pull request #27 from JuniJwi/master
Browse files Browse the repository at this point in the history
Shop stock view and MYO redirect
  • Loading branch information
itinerare authored Oct 14, 2020
2 parents 2b481cd + 11f0374 commit 0f34219
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,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();
Expand Down
7 changes: 6 additions & 1 deletion app/Http/Controllers/ShopController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
]);
}

Expand Down
47 changes: 26 additions & 21 deletions app/Services/ShopService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 0f34219

Please sign in to comment.