添加前台controller hooks

This commit is contained in:
Edward Yang 2023-02-07 10:19:30 +08:00
parent 65c65a11fb
commit 393b25f34e
11 changed files with 50 additions and 9 deletions

View File

@ -15,6 +15,8 @@ class BrandController extends Controller
'brands' => $brands,
];
$data = hook_filter('brand.index.data', $data);
return view('brand/list', $data);
}
@ -39,6 +41,8 @@ class BrandController extends Controller
'products_format' => ProductSimple::collection($products)->jsonSerialize(),
];
$data = hook_filter('brand.show.data', $data);
return view('brand/info', $data);
}

View File

@ -19,6 +19,8 @@ class CartController extends Controller
'data' => CartService::reloadData(),
];
$data = hook_filter('cart.index.data', $data);
return view('cart/cart', $data);
}
@ -37,6 +39,8 @@ class CartController extends Controller
$data = CartService::reloadData();
$data = hook_filter('cart.select.data', $data);
return json_success(trans('common.updated_success'), $data);
}
@ -64,6 +68,8 @@ class CartController extends Controller
CartService::select($customer, [$cart->id]);
}
$cart = hook_filter('cart.store.data', $cart);
return json_success(trans('shop/carts.added_to_cart'), $cart);
}
@ -81,6 +87,8 @@ class CartController extends Controller
$data = CartService::reloadData();
$data = hook_filter('cart.update.data', $data);
return json_success(trans('common.updated_success'), $data);
}
@ -97,6 +105,8 @@ class CartController extends Controller
$data = CartService::reloadData();
$data = hook_filter('cart.destroy.data', $data);
return json_success(trans('common.deleted_success'), $data);
}
@ -113,6 +123,8 @@ class CartController extends Controller
$data['quantity'] = $reloadData['quantity'];
$data['quantity_all'] = $reloadData['quantity_all'];
$data = hook_filter('cart.mini_cart.data', $data);
return json_success(trans('common.success'), $data);
}
}

View File

@ -12,7 +12,7 @@ class CategoryController extends Controller
{
public function index(Request $request)
{
return CategoryRepo::list();
return redirect('/');
}
public function show(Request $request, Category $category)
@ -34,6 +34,8 @@ class CategoryController extends Controller
'per_pages' => CategoryRepo::getPerPages(),
];
$data = hook_filter('category.show.data', $data);
return view('category', $data);
}
}

View File

@ -20,6 +20,7 @@ class CheckoutController extends Controller
{
try {
$data = (new CheckoutService)->checkoutData();
$data = hook_filter('checkout.index.data', $data);
return view('checkout', $data);
} catch (\Exception $e) {
@ -38,7 +39,9 @@ class CheckoutController extends Controller
try {
$requestData = $request->all();
return (new CheckoutService)->update($requestData);
$data = (new CheckoutService)->update($requestData);
return hook_filter('checkout.update.data', $data);
} catch (\Exception $e) {
return json_fail($e->getMessage());
}
@ -52,6 +55,8 @@ class CheckoutController extends Controller
*/
public function confirm()
{
return (new CheckoutService)->confirm();
$data = (new CheckoutService)->confirm();
return hook_filter('checkout.confirm.data', $data);
}
}

View File

@ -16,12 +16,14 @@ use Illuminate\Support\Facades\Session;
class CurrencyController extends Controller
{
public function index($lang)
public function index($currency)
{
if (in_array($lang, currencies()->where('status', true)->pluck('code')->toArray())) {
Session::put('currency', $lang);
if (in_array($currency, currencies()->where('status', true)->pluck('code')->toArray())) {
Session::put('currency', $currency);
}
hook_action('currency.index', $currency);
return Redirect::back();
}
}

View File

@ -13,9 +13,13 @@ class FileController extends Controller
$path = $file->store($type . '/', 'upload');
return json_success(trans('shop/file.uploaded_success'), [
$data = [
'url' => asset('upload/' . $path),
'value' => 'upload/' . $path,
]);
];
$data = hook_filter('file.store.data', $data);
return json_success(trans('shop/file.uploaded_success'), $data);
}
}

View File

@ -34,6 +34,10 @@ class HomeController extends Controller
}
}
return view('home', ['modules' => $moduleItems]);
$data = ['modules' => $moduleItems];
$data = hook_filter('home.index.data', $data);
return view('home', $data);
}
}

View File

@ -22,6 +22,8 @@ class LanguageController extends Controller
Session::put('locale', $lang);
}
hook_action('language.index', $lang);
return Redirect::back();
}
}

View File

@ -23,6 +23,8 @@ class PageController extends Controller
'page' => (new PageDetail($page))->jsonSerialize(),
];
$data = hook_filter('page.show.data', $data);
return view('pages/detail', $data);
}
}

View File

@ -52,6 +52,8 @@ class ProductController extends Controller
'items' => ProductSimple::collection($products)->jsonSerialize(),
];
$data = hook_filter('product.search.data', $data);
return view('search', $data);
}
}

View File

@ -24,6 +24,8 @@ class ZoneController extends Controller
'zones' => ZoneRepo::listByCountry($countryId),
];
$data = hook_filter('zone.index.data', $data);
return json_success(trans('common.success'), $data);
}
}