Browse Source

Gestion commandes au montant total négatif

feature/export_comptable
Guillaume 4 years ago
parent
commit
16b3500a23
3 changed files with 41 additions and 22 deletions
  1. +15
    -6
      ShopBundle/Controller/Frontend/CartController.php
  2. +10
    -10
      ShopBundle/Services/Order/OrderUtils.php
  3. +16
    -6
      ShopBundle/Services/Order/OrderUtilsReductionTrait.php

+ 15
- 6
ShopBundle/Controller/Frontend/CartController.php View File

@@ -15,6 +15,7 @@ use Lc\ShopBundle\Context\ReductionCartInterface;
use Lc\ShopBundle\Model\OrderReductionCart;
use Lc\ShopBundle\Model\ProductFamily;
use Lc\ShopBundle\Services\UserUtils;
use Lc\ShopBundle\Services\UtilsManager;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Generator\UrlGenerator;
@@ -25,6 +26,7 @@ class CartController extends BaseController
{
protected $orderUtils ;
protected $userUtils ;
protected $priceUtils ;
protected $router ;
protected $productFamilyRepository ;
protected $orderProductRepository ;
@@ -33,12 +35,13 @@ class CartController extends BaseController
protected $orderProducts = [] ;


public function __construct(EntityManagerInterface $em, Security $security, MerchantUtilsInterface $merchantUtils, OrderUtilsInterface $orderUtils,
UserUtils $userUtils, UrlGeneratorInterface $router)
public function __construct(EntityManagerInterface $em, Security $security, MerchantUtilsInterface $merchantUtils,
UrlGeneratorInterface $router, UtilsManager $utilsManager)
{
parent::__construct($em, $security, $merchantUtils);
$this->orderUtils = $orderUtils ;
$this->userUtils = $userUtils ;
$this->orderUtils = $utilsManager->getOrderUtils() ;
$this->userUtils = $utilsManager->getUserUtils() ;
$this->priceUtils = $utilsManager->getPriceUtils() ;
$this->router = $router ;
$this->productFamilyRepository = $this->em->getRepository($this->em->getClassMetaData(ProductFamilyInterface::class)->getName()) ;
$this->orderProductRepository = $this->em->getRepository($this->em->getClassMetaData(OrderProductInterface::class)->getName()) ;
@@ -130,8 +133,14 @@ class CartController extends BaseController
&& $this->orderUtils->isReductionCreditAllowAddToOrder($orderShop, $reductionCredit)
&& !$this->orderUtils->isReductionCreditAddedToOrder($orderShop, $reductionCredit)) {

$this->orderUtils->createOrderReductionCredit($orderShop, $reductionCredit) ;
$this->addFlash('success', 'Votre avoir a bien été ajouté à votre panier.') ;
$return = $this->orderUtils->createOrderReductionCredit($orderShop, $reductionCredit) ;

if($return) {
$this->addFlash('success', 'Votre avoir a bien été ajouté à 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");

+ 10
- 10
ShopBundle/Services/Order/OrderUtils.php View File

@@ -162,16 +162,12 @@ class OrderUtils
if (!$updated) {
$orderShop->addOrderProduct($orderProductAdd);

if (isset($orderProductReductionCatalog)) {
$this->em->persist($orderProductReductionCatalog);

if ($persist) {
if (isset($orderProductReductionCatalog)) {
$this->em->persist($orderProductReductionCatalog);
}
$this->em->persist($orderProductAdd);
$this->em->persist($orderShop);
if ($persist) {
if (isset($orderProductReductionCatalog)) {
$this->em->persist($orderProductReductionCatalog);
}
$this->em->persist($orderProductAdd);
$this->em->persist($orderShop);
}

$return = true;
@@ -338,9 +334,13 @@ class OrderUtils
return $orderProductsByProductFamily;
}

public function isOrderShopPositiveAmount(OrderShopInterface $orderShop)
{
return $this->priceUtils->getTotalWithTax($orderShop) > 0 ;
}

public function eventOrderShopChangeQuantity(OrderShopInterface $orderShop)
{

}

}

+ 16
- 6
ShopBundle/Services/Order/OrderUtilsReductionTrait.php View File

@@ -55,10 +55,15 @@ trait OrderUtilsReductionTrait
$orderReductionCart->setAppliedTo($reductionCart->getAppliedTo());
$orderReductionCart->setType($reductionCart->getType());

$this->em->persist($orderReductionCart);
$this->em->flush();
$orderShop->addOrderReductionCart($orderReductionCart) ;

return $orderReductionCart;
if($this->isOrderShopPositiveAmount($orderShop)) {
$this->em->persist($orderReductionCart);
$this->em->flush();
return $orderReductionCart ;
}

return false;
}

public function isReductionCreditAllowAddToOrder($orderShop, $reductionCredit)
@@ -104,10 +109,15 @@ trait OrderUtilsReductionTrait
$orderReductionCredit->setUnit($reductionCredit->getUnit());
$orderReductionCredit->setBehaviorTaxRate($reductionCredit->getBehaviorTaxRate());

$this->em->persist($orderReductionCredit);
$this->em->flush();
$orderShop->addOrderReductionCredit($orderReductionCredit) ;

return $orderReductionCredit;
if($this->isOrderShopPositiveAmount($orderShop)) {
$this->em->persist($orderReductionCredit);
$this->em->flush();
return $orderReductionCredit;
}

return false ;
}

/*public function getReductionCreditsAvailable($order)

Loading…
Cancel
Save