|
|
|
@ -398,58 +398,8 @@ class ClientController extends Controller
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function productCompareToggle($slug)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
$product = Product::where('slug', $slug)->firstOrFail();
|
|
|
|
|
if (\Cookie::has('compares')) {
|
|
|
|
|
$compares = json_decode(\Cookie::get('compares'), true);
|
|
|
|
|
if (in_array($product->id, $compares)) {
|
|
|
|
|
$msg = "Product removed from compare";
|
|
|
|
|
unset($compares[array_search($product->id, $compares)]);
|
|
|
|
|
} else {
|
|
|
|
|
$compares[] = $product->id;
|
|
|
|
|
$msg = "Product added to compare";
|
|
|
|
|
}
|
|
|
|
|
\Cookie::queue('compares', json_encode($compares), 2000);
|
|
|
|
|
} else {
|
|
|
|
|
$msg = "Product added to compare";
|
|
|
|
|
\Cookie::queue('compares', "[$product->id]", 2000);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (\request()->ajax()) {
|
|
|
|
|
return success(null, $msg);
|
|
|
|
|
} else {
|
|
|
|
|
return redirect()->back()->with(['message' => $msg]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function ProductFavToggle($slug)
|
|
|
|
|
{
|
|
|
|
|
$product = Product::where('slug', $slug)->firstOrFail();
|
|
|
|
|
|
|
|
|
|
if (!auth('customer')->check()) {
|
|
|
|
|
return errors([
|
|
|
|
|
__("You need to login first"),
|
|
|
|
|
], 403, __("You need to login first"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (auth('customer')->user()->favorites()->where('product_id', $product->id)->count() == 0) {
|
|
|
|
|
auth('customer')->user()->favorites()->attach($product->id);
|
|
|
|
|
$message = __('Product added to favorites');
|
|
|
|
|
$fav = '1';
|
|
|
|
|
} else {
|
|
|
|
|
auth('customer')->user()->favorites()->detach($product->id);
|
|
|
|
|
$message = __('Product removed from favorites');
|
|
|
|
|
$fav = '0';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (\request()->ajax()) {
|
|
|
|
|
return success($fav, $message);
|
|
|
|
|
} else {
|
|
|
|
|
return redirect()->back()->with(['message' => $message]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function compare()
|
|
|
|
|