} | } | ||||
} | } | ||||
/** | |||||
* @Route("/reduction-cart/add/{id}", name="order_reduction_cart") | |||||
*/ | |||||
public function addReductionCart(Request $request): RedirectResponse | |||||
{ | |||||
$id = $request->get('id'); | |||||
$orderShop = $this->getCartCurrent(); | |||||
$user = $this->getUserCurrent(); | |||||
$orderShopContainer = $this->getOrderShopContainer(); | |||||
$reductionCart = $this->getReductionCartContainer()->getStore()->getOneById($id); | |||||
if ($orderShop && $user && $reductionCart | |||||
&& $orderShopContainer->getStore()->isReductionCartAllowAddToOrder($orderShop, $reductionCart) | |||||
&& !$orderShopContainer->getSolver()->isReductionCartAddedToOrder($orderShop, $reductionCart)) { | |||||
$return = $orderShopContainer->getBuilder()->addReductionCart($orderShop, $reductionCart); | |||||
if ($return) { | |||||
$this->addFlash('success', 'Votre réduction panier a bien été ajoutée à votre panier.'); | |||||
} else { | |||||
$this->addFlash( | |||||
'error', | |||||
'Vous ne pouvez pas effectuer cette action. Le montant de la commande est insuffisant.' | |||||
); | |||||
} | |||||
} else { | |||||
$this->addFlash('error', "Impossible d'effectuer cette action"); | |||||
} | |||||
return $this->redirectToReferer($request); | |||||
} | |||||
/** | /** | ||||
* @Route("/order-reduction-cart/delete/{id}", name="delete_reduction_cart") | * @Route("/order-reduction-cart/delete/{id}", name="delete_reduction_cart") | ||||
*/ | */ |
} | } | ||||
// findAllAvailableForUser / getReductionCartsAvailableByUser | // findAllAvailableForUser / getReductionCartsAvailableByUser | ||||
public function getReductionCartAvailableByUser(UserInterface $user, $query = null) | |||||
public function getReductionCartAvailableByUser(UserInterface $user, string $type = null, $query = null) | |||||
{ | { | ||||
$reductionCarts = $this->reductionCartStore | $reductionCarts = $this->reductionCartStore | ||||
->setMerchant($this->merchant) | ->setMerchant($this->merchant) | ||||
&& $this->getReductionCartRemainingQuantityByUser($reductionCart, $user) | && $this->getReductionCartRemainingQuantityByUser($reductionCart, $user) | ||||
&& ($reductionCart->getUsers()->count() > 0 || $reductionCart->getGroupUsers()->count() > 0) | && ($reductionCart->getUsers()->count() > 0 || $reductionCart->getGroupUsers()->count() > 0) | ||||
&& (!$this->merchant || $reductionCart->getMerchant() == $this->merchant)) { | && (!$this->merchant || $reductionCart->getMerchant() == $this->merchant)) { | ||||
$reductionCartsArray[] = $reductionCart; | |||||
if(!$type || $reductionCart->getType() == $type) { | |||||
$reductionCartsArray[] = $reductionCart; | |||||
} | |||||
} | } | ||||
} | } | ||||
use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface; | use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface; | ||||
use Lc\CaracoleBundle\Model\Product\ProductFamilyModel; | use Lc\CaracoleBundle\Model\Product\ProductFamilyModel; | ||||
use Lc\CaracoleBundle\Model\Product\ProductInterface; | use Lc\CaracoleBundle\Model\Product\ProductInterface; | ||||
use Lc\CaracoleBundle\Model\Reduction\ReductionCartInterface; | |||||
use Lc\CaracoleBundle\Model\Reduction\ReductionCreditInterface; | use Lc\CaracoleBundle\Model\Reduction\ReductionCreditInterface; | ||||
use Lc\CaracoleBundle\Model\Section\SectionInterface; | use Lc\CaracoleBundle\Model\Section\SectionInterface; | ||||
use Lc\CaracoleBundle\Solver\Product\ProductFamilySectionPropertySolver; | use Lc\CaracoleBundle\Solver\Product\ProductFamilySectionPropertySolver; | ||||
} | } | ||||
return $orderShops; | return $orderShops; | ||||
} | } | ||||
public function isReductionCreditAddedToOrder( | public function isReductionCreditAddedToOrder( | ||||
OrderShopInterface $orderShop, | OrderShopInterface $orderShop, | ||||
ReductionCreditInterface $reductionCredit | ReductionCreditInterface $reductionCredit | ||||
return false; | return false; | ||||
} | } | ||||
public function isReductionCartAddedToOrder( | |||||
OrderShopInterface $orderShop, | |||||
ReductionCartInterface $reductionCart | |||||
) { | |||||
foreach ($orderShop->getOrderReductionCarts() as $orderReductionCart) { | |||||
if ($orderReductionCart->getReductionCart() == $reductionCart) { | |||||
return true; | |||||
} | |||||
} | |||||
return false; | |||||
} | |||||
public function hasOrderProductAlreadyInCart( | public function hasOrderProductAlreadyInCart( | ||||
OrderShopInterface $orderShop, | OrderShopInterface $orderShop, |