Bladeren bron

[Place du Local] [ERREUR 500] Ce produit est introuvable #669

develop
Guillaume Bourgeois 2 jaren geleden
bovenliggende
commit
9bba757665
1 gewijzigde bestanden met toevoegingen van 11 en 11 verwijderingen
  1. +11
    -11
      Controller/Product/FavoriteController.php

+ 11
- 11
Controller/Product/FavoriteController.php Bestand weergeven

public function toggle(Request $request) public function toggle(Request $request)
{ {
$user = $this->getUserCurrent(); $user = $this->getUserCurrent();
if($user) {
$productFamily = $this->_getProductFamily($request);
$productFamily = $this->_getProductFamily($request);


if($user && $productFamily) {
if ($user->getFavoriteProductFamilies()->contains($productFamily)) { if ($user->getFavoriteProductFamilies()->contains($productFamily)) {
$user->removeFavoriteProductFamily($productFamily); $user->removeFavoriteProductFamily($productFamily);
$isFavorite = false; $isFavorite = false;
]); ]);
} }
else { else {
return $this->_errorUserNotConnected();
return $this->_errorResponse();
} }
} }


public function add(Request $request) public function add(Request $request)
{ {
$user = $this->getUserCurrent(); $user = $this->getUserCurrent();
if($user) {
$productFamily = $this->_getProductFamily($request);
$productFamily = $this->_getProductFamily($request);


if($user && $productFamily) {
$user->addFavoriteProductFamily($productFamily); $user->addFavoriteProductFamily($productFamily);
$this->_saveUser($user); $this->_saveUser($user);


]); ]);
} }
else { else {
return $this->_errorUserNotConnected();
return $this->_errorResponse();
} }
} }


public function delete(Request $request) public function delete(Request $request)
{ {
$user = $this->getUserCurrent(); $user = $this->getUserCurrent();
if($user) {
$productFamily = $this->_getProductFamily($request);
$productFamily = $this->_getProductFamily($request);


if($user && $productFamily) {
$user->removeFavoriteProductFamily($productFamily); $user->removeFavoriteProductFamily($productFamily);
$this->_saveUser($user); $this->_saveUser($user);


]); ]);
} }
else { else {
return $this->_errorUserNotConnected();
return $this->_errorResponse();
} }
} }


} }
} }


private function _errorUserNotConnected()
private function _errorResponse()
{ {
return new JsonResponse([ return new JsonResponse([
'return' => 'error', 'return' => 'error',
'message' => 'Vous devez être connecté pour gérer vos favoris.'
'message' => 'Une erreur est survenue.'
]); ]);
} }
} }

Laden…
Annuleren
Opslaan