Explorar el Código

Merge branch 'develop'

master
Guillaume Bourgeois hace 1 año
padre
commit
ef72c7f6ab
Se han modificado 3 ficheros con 51 adiciones y 2 borrados
  1. +32
    -0
      Controller/Order/CartController.php
  2. +5
    -2
      Repository/Order/OrderShopStore.php
  3. +14
    -0
      Solver/Order/OrderShopSolver.php

+ 32
- 0
Controller/Order/CartController.php Ver fichero

@@ -96,6 +96,38 @@ class CartController extends AbstractController
}
}

/**
* @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")
*/

+ 5
- 2
Repository/Order/OrderShopStore.php Ver fichero

@@ -582,7 +582,7 @@ class OrderShopStore extends AbstractStore
}

// findAllAvailableForUser / getReductionCartsAvailableByUser
public function getReductionCartAvailableByUser(UserInterface $user, $query = null)
public function getReductionCartAvailableByUser(UserInterface $user, string $type = null, $query = null)
{
$reductionCarts = $this->reductionCartStore
->setMerchant($this->merchant)
@@ -595,7 +595,10 @@ class OrderShopStore extends AbstractStore
&& $this->getReductionCartRemainingQuantityByUser($reductionCart, $user)
&& ($reductionCart->getUsers()->count() > 0 || $reductionCart->getGroupUsers()->count() > 0)
&& (!$this->merchant || $reductionCart->getMerchant() == $this->merchant)) {
$reductionCartsArray[] = $reductionCart;

if(!$type || $reductionCart->getType() == $type) {
$reductionCartsArray[] = $reductionCart;
}
}
}


+ 14
- 0
Solver/Order/OrderShopSolver.php Ver fichero

@@ -16,6 +16,7 @@ use Lc\CaracoleBundle\Model\Order\OrderStatusModel;
use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface;
use Lc\CaracoleBundle\Model\Product\ProductFamilyModel;
use Lc\CaracoleBundle\Model\Product\ProductInterface;
use Lc\CaracoleBundle\Model\Reduction\ReductionCartInterface;
use Lc\CaracoleBundle\Model\Reduction\ReductionCreditInterface;
use Lc\CaracoleBundle\Model\Section\SectionInterface;
use Lc\CaracoleBundle\Solver\Product\ProductFamilySectionPropertySolver;
@@ -332,6 +333,7 @@ class OrderShopSolver
}
return $orderShops;
}

public function isReductionCreditAddedToOrder(
OrderShopInterface $orderShop,
ReductionCreditInterface $reductionCredit
@@ -345,6 +347,18 @@ class OrderShopSolver
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(
OrderShopInterface $orderShop,

Cargando…
Cancelar
Guardar