@@ -0,0 +1,8 @@ | |||
<?php | |||
namespace Lc\ShopBundle\Context; | |||
interface SectionUtilsInterface | |||
{ | |||
} |
@@ -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()) ; |
@@ -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(), | |||
]); | |||
} | |||
@@ -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, | |||
]); | |||
} | |||
@@ -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 ; | |||
} | |||
} |
@@ -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 ; | |||
} | |||
} |