|
|
@@ -15,9 +15,9 @@ class FavoriteController extends AbstractController |
|
|
|
public function toggle(Request $request) |
|
|
|
{ |
|
|
|
$user = $this->getUserCurrent(); |
|
|
|
if($user) { |
|
|
|
$productFamily = $this->_getProductFamily($request); |
|
|
|
$productFamily = $this->_getProductFamily($request); |
|
|
|
|
|
|
|
if($user && $productFamily) { |
|
|
|
if ($user->getFavoriteProductFamilies()->contains($productFamily)) { |
|
|
|
$user->removeFavoriteProductFamily($productFamily); |
|
|
|
$isFavorite = false; |
|
|
@@ -37,7 +37,7 @@ class FavoriteController extends AbstractController |
|
|
|
]); |
|
|
|
} |
|
|
|
else { |
|
|
|
return $this->_errorUserNotConnected(); |
|
|
|
return $this->_errorResponse(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@@ -47,9 +47,9 @@ class FavoriteController extends AbstractController |
|
|
|
public function add(Request $request) |
|
|
|
{ |
|
|
|
$user = $this->getUserCurrent(); |
|
|
|
if($user) { |
|
|
|
$productFamily = $this->_getProductFamily($request); |
|
|
|
$productFamily = $this->_getProductFamily($request); |
|
|
|
|
|
|
|
if($user && $productFamily) { |
|
|
|
$user->addFavoriteProductFamily($productFamily); |
|
|
|
$this->_saveUser($user); |
|
|
|
|
|
|
@@ -59,7 +59,7 @@ class FavoriteController extends AbstractController |
|
|
|
]); |
|
|
|
} |
|
|
|
else { |
|
|
|
return $this->_errorUserNotConnected(); |
|
|
|
return $this->_errorResponse(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@@ -69,9 +69,9 @@ class FavoriteController extends AbstractController |
|
|
|
public function delete(Request $request) |
|
|
|
{ |
|
|
|
$user = $this->getUserCurrent(); |
|
|
|
if($user) { |
|
|
|
$productFamily = $this->_getProductFamily($request); |
|
|
|
$productFamily = $this->_getProductFamily($request); |
|
|
|
|
|
|
|
if($user && $productFamily) { |
|
|
|
$user->removeFavoriteProductFamily($productFamily); |
|
|
|
$this->_saveUser($user); |
|
|
|
|
|
|
@@ -81,7 +81,7 @@ class FavoriteController extends AbstractController |
|
|
|
]); |
|
|
|
} |
|
|
|
else { |
|
|
|
return $this->_errorUserNotConnected(); |
|
|
|
return $this->_errorResponse(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@@ -105,11 +105,11 @@ class FavoriteController extends AbstractController |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private function _errorUserNotConnected() |
|
|
|
private function _errorResponse() |
|
|
|
{ |
|
|
|
return new JsonResponse([ |
|
|
|
'return' => 'error', |
|
|
|
'message' => 'Vous devez être connecté pour gérer vos favoris.' |
|
|
|
'message' => 'Une erreur est survenue.' |
|
|
|
]); |
|
|
|
} |
|
|
|
} |