Procházet zdrojové kódy

ReductionCart : divers

develop
Guillaume Bourgeois před 1 rokem
rodič
revize
8b0cd0a835
3 změnil soubory, kde provedl 51 přidání a 2 odebrání
  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 Zobrazit soubor

@@ -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 Zobrazit soubor

@@ -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 Zobrazit soubor

@@ -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,

Načítá se…
Zrušit
Uložit