Parcourir la source

Mise en place SectionUtils

feature/module_traiteur_v1
Guillaume il y a 3 ans
Parent
révision
16570cba07
6 fichiers modifiés avec 76 ajouts et 9 suppressions
  1. +8
    -0
      ShopBundle/Context/SectionUtilsInterface.php
  2. +2
    -0
      ShopBundle/Controller/Frontend/CartController.php
  3. +16
    -6
      ShopBundle/Services/Order/OrderUtils.php
  4. +3
    -2
      ShopBundle/Services/Order/OrderUtilsCartTrait.php
  5. +37
    -0
      ShopBundle/Services/SectionUtils.php
  6. +10
    -1
      ShopBundle/Services/UtilsManager.php

+ 8
- 0
ShopBundle/Context/SectionUtilsInterface.php Voir le fichier

@@ -0,0 +1,8 @@
<?php

namespace Lc\ShopBundle\Context;

interface SectionUtilsInterface
{

}

+ 2
- 0
ShopBundle/Controller/Frontend/CartController.php Voir le fichier

@@ -27,6 +27,7 @@ class CartController extends BaseController
protected $orderUtils ;
protected $userUtils ;
protected $priceUtils ;
protected $sectionUtils ;
protected $router ;
protected $productFamilyRepository ;
protected $orderProductRepository ;
@@ -42,6 +43,7 @@ class CartController extends BaseController
$this->orderUtils = $utilsManager->getOrderUtils() ;
$this->userUtils = $utilsManager->getUserUtils() ;
$this->priceUtils = $utilsManager->getPriceUtils() ;
$this->sectionUtils = $utilsManager->getSectionUtils() ;
$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()) ;

+ 16
- 6
ShopBundle/Services/Order/OrderUtils.php Voir le fichier

@@ -13,12 +13,15 @@ use Lc\ShopBundle\Context\OrderStatusHistoryInterface;
use Lc\ShopBundle\Context\PriceUtilsInterface;
use Lc\ShopBundle\Context\ProductFamilyUtilsInterface;
use Lc\ShopBundle\Context\ReductionCreditInterface;
use Lc\ShopBundle\Context\SectionInterface;
use Lc\ShopBundle\Context\SectionUtilsInterface;
use Lc\ShopBundle\Context\UserUtilsInterface;
use Lc\ShopBundle\Model\ProductFamily;
use Lc\ShopBundle\Services\CreditUtils;
use Lc\ShopBundle\Services\DocumentUtils;
use Lc\ShopBundle\Services\UserUtils;
use Lc\ShopBundle\Services\Utils;
use Lc\ShopBundle\Services\UtilsManager;
use Symfony\Component\Routing\RouterInterface;

use Symfony\Component\Security\Core\Security;
@@ -45,10 +48,11 @@ class OrderUtils
protected $utils;
protected $creditUtils;
protected $router;
protected $sectionUtils ;

public function __construct(EntityManagerInterface $em, Security $security, RouterInterface $router, UserUtilsInterface $userUtils,
MerchantUtilsInterface $merchantUtils, PriceUtilsInterface $priceUtils, ProductFamilyUtilsInterface $productFamilyUtils,
DocumentUtils $documentUtils, Utils $utils, CreditUtils $creditUtils)
DocumentUtils $documentUtils, Utils $utils, CreditUtils $creditUtils, SectionUtilsInterface $sectionUtils)
{
$this->em = $em;
$this->security = $security;
@@ -64,10 +68,9 @@ class OrderUtils
$this->utils = $utils;
$this->creditUtils = $creditUtils;
$this->router = $router;
$this->sectionUtils = $sectionUtils ;
}



public function createOrderShop($params)
{
//TODO vérifier que l'utilisateur n'a pas déjà une commande en cours
@@ -93,6 +96,15 @@ class OrderUtils
throw new \ErrorException('La commande doit être liée à un merchant.');
}

// pour le moment, à la création, on lie simplement la commande à la section "Marché"
$section = $this->sectionUtils->getSectionMarket() ;
if($section) {
$orderShop->setSection($section) ;
}
else {
throw new \ErrorException('La commande doit être liée à une section.');
}

$orderShop = $this->changeOrderStatus('cart', $orderShop);

return $orderShop;
@@ -100,10 +112,8 @@ class OrderUtils

public function addOrderProduct($orderShop, $orderProductAdd, $persist = true)
{

$return = false;


if (!$orderShop) {
$user = $this->security->getUser();
$visitor = $this->userUtils->getVisitorCurrent();
@@ -111,7 +121,7 @@ class OrderUtils
$orderShop = $this->createOrderShop([
'user' => $user,
'visitor' => $visitor,
'merchant' => $this->merchantUtils->getMerchantCurrent()
'merchant' => $this->merchantUtils->getMerchantCurrent(),
]);
}


+ 3
- 2
ShopBundle/Services/Order/OrderUtilsCartTrait.php Voir le fichier

@@ -2,7 +2,6 @@

namespace Lc\ShopBundle\Services\Order;


use Lc\ShopBundle\Context\OrderShopInterface;
use Lc\ShopBundle\Model\OrderStatus;

@@ -64,10 +63,12 @@ trait OrderUtilsCartTrait
}

if($createIfNotExist && !$orderShop) {
$merchant = $this->merchantUtils->getMerchantCurrent() ;

$orderShop = $this->createOrderShop([
'user' => $user,
'visitor' => $visitor,
'merchant' => $this->merchantUtils->getMerchantCurrent()
'merchant' => $merchant,
]);
}


+ 37
- 0
ShopBundle/Services/SectionUtils.php Voir le fichier

@@ -0,0 +1,37 @@
<?php

namespace Lc\ShopBundle\Services ;

use Doctrine\ORM\EntityManagerInterface;
use Http\Discovery\Exception\NotFoundException;
use Lc\ShopBundle\Context\MerchantUtilsInterface;
use Lc\ShopBundle\Context\SectionInterface;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

class SectionUtils
{
protected $em ;
protected $merchantUtils ;
protected $sectionRepository ;

public function __construct(EntityManagerInterface $em, MerchantUtilsInterface $merchantUtils)
{
$this->em = $em ;
$this->sectionRepository = $this->em->getRepository($this->em->getClassMetadata(SectionInterface::class)->getName()) ;
$this->merchantUtils = $merchantUtils ;
}

public function getSection($devAlias)
{
$section = $this->sectionRepository->findOneBy([
'merchant' => $this->merchantUtils->getMerchantCurrent(),
'devAlias' => $devAlias
]) ;

if(!$section) {
throw new NotFoundException('La section '.$devAlias.' est introuvable') ;
}

return $section ;
}
}

+ 10
- 1
ShopBundle/Services/UtilsManager.php Voir le fichier

@@ -8,6 +8,7 @@ use Lc\ShopBundle\Context\MerchantUtilsInterface;
use Lc\ShopBundle\Context\OrderUtilsInterface;
use Lc\ShopBundle\Context\PriceUtilsInterface;
use Lc\ShopBundle\Context\ProductFamilyUtilsInterface;
use Lc\ShopBundle\Context\SectionUtilsInterface;
use Lc\ShopBundle\Context\Services\StatisticsUtilsInterface;
use Lc\ShopBundle\Context\UserUtilsInterface;
use League\Flysystem\Util;
@@ -27,6 +28,7 @@ class UtilsManager
protected $ticketUtils ;
protected $statisticsUtils;
protected $pointLocationUtils ;
protected $sectionUtils ;

public function __construct(
Utils $utils,
@@ -41,7 +43,8 @@ class UtilsManager
MailUtils $mailUtils,
TicketUtils $ticketUtils,
PointLocationUtils $pointLocationUtils,
UtilsProcess $utilsProcess
UtilsProcess $utilsProcess,
SectionUtilsInterface $sectionUtils
)
{
$this->utils = $utils ;
@@ -57,6 +60,7 @@ class UtilsManager
$this->ticketUtils = $ticketUtils ;
$this->pointLocationUtils = $pointLocationUtils ;
$this->utilsProcess = $utilsProcess ;
$this->sectionUtils = $sectionUtils ;
}

public function getUtils(): Utils
@@ -124,4 +128,9 @@ class UtilsManager
return $this->utilsProcess ;
}

public function getSectionUtils(): SectionUtilsInterface
{
return $this->sectionUtils ;
}

}

Chargement…
Annuler
Enregistrer