Parcourir la source

Refactoring services

packProduct
Guillaume il y a 3 ans
Parent
révision
eb4b79a9c2
13 fichiers modifiés avec 76 ajouts et 56 suppressions
  1. +18
    -19
      Builder/Order/OrderShopBuilder.php
  2. +10
    -5
      Controller/ControllerTrait.php
  3. +1
    -1
      Controller/Order/CartController.php
  4. +2
    -0
      Factory/Order/OrderPaymentFactory.php
  5. +1
    -1
      Generator/OrderReferenceGenerator.php
  6. +2
    -1
      Model/Order/OrderReductionCartModel.php
  7. +1
    -4
      Model/Order/OrderShopInterface.php
  8. +1
    -6
      Model/Order/OrderShopModel.php
  9. +0
    -3
      Model/Product/ProductFamilyInterface.php
  10. +9
    -7
      Repository/Order/OrderShopStore.php
  11. +7
    -0
      Resources/translations/admin.fr.yaml
  12. +6
    -0
      Solver/Order/OrderShopSolver.php
  13. +18
    -9
      Twig/StoreTwigExtension.php

+ 18
- 19
Builder/Order/OrderShopBuilder.php Voir le fichier

@@ -26,7 +26,6 @@ use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface;
use Lc\CaracoleBundle\Model\Product\ProductFamilyModel;
use Lc\CaracoleBundle\Model\Reduction\ReductionCartInterface;
use Lc\CaracoleBundle\Model\Reduction\ReductionCreditInterface;
use Lc\CaracoleBundle\Model\Section\OpeningModel;
use Lc\CaracoleBundle\Model\Section\SectionInterface;
use Lc\CaracoleBundle\Model\Section\SectionModel;
use Lc\CaracoleBundle\Model\User\VisitorInterface;
@@ -35,7 +34,7 @@ use Lc\CaracoleBundle\Repository\Order\OrderShopStore;
use Lc\CaracoleBundle\Repository\Order\OrderStatusStore;
use Lc\CaracoleBundle\Repository\Product\ProductFamilyStore;
use Lc\CaracoleBundle\Resolver\OpeningResolver;
use Lc\CaracoleBundle\Resolver\Price\PriceResolver;
use Lc\CaracoleBundle\Resolver\OrderShopResolver;
use Lc\CaracoleBundle\Solver\Order\OrderShopSolver;
use Lc\CaracoleBundle\Solver\Price\PriceSolver;
use Lc\CaracoleBundle\Solver\Product\ProductSolver;
@@ -59,6 +58,7 @@ class OrderShopBuilder
protected FlashBagInterface $flashBag;
protected OpeningResolver $openingResolver;
protected ProductSolver $productSolver;
protected OrderShopResolver $orderShopResolver;

public function __construct(
EntityManagerInterface $entityManager,
@@ -73,7 +73,8 @@ class OrderShopBuilder
EventDispatcherInterface $eventDispatcher,
FlashBagInterface $flashBag,
OpeningResolver $openingResolver,
ProductSolver $productSolver
ProductSolver $productSolver,
OrderShopResolver $orderShopResolver
) {
$this->entityManager = $entityManager;
$this->orderShopStore = $orderShopStore;
@@ -88,6 +89,7 @@ class OrderShopBuilder
$this->flashBag = $flashBag;
$this->openingResolver = $openingResolver;
$this->productSolver = $productSolver;
$this->orderShopResolver = $orderShopResolver;
}

public function create(
@@ -95,7 +97,6 @@ class OrderShopBuilder
UserInterface $user = null,
VisitorInterface $visitor = null
): OrderShopInterface {

$orderShopFactory = new OrderShopFactory();
$orderShop = $orderShopFactory->create($section, $user, $visitor);

@@ -112,13 +113,9 @@ class OrderShopBuilder
UserInterface $user = null,
VisitorInterface $visitor = null
): OrderShopInterface {
$cart = $this->orderShopStore->getOneCartCurrent(
[
'section' => $section,
'user' => $user,
'visitor' => $visitor
]
);
$cart = $this->orderShopStore
->setSection($section)
->getOneCartCurrent($user, $visitor);

if (!$cart) {
$cart = $this->create($section, $user, $visitor);
@@ -132,7 +129,6 @@ class OrderShopBuilder
string $alias,
bool $forceByAdmin = false
): OrderShopInterface {

$orderStatus = $this->orderStatusStore->getOneByAlias($alias);

if ($orderStatus) {
@@ -313,7 +309,7 @@ class OrderShopBuilder

$orderShop->addOrderPayment($orderPayment);

if ($this->orderSh->isPaid($orderShop)) {
if ($this->orderShopResolver->isPaid($orderShop)) {
$nextStatus = OrderStatusModel::ALIAS_PAID;
} else {
$nextStatus = OrderStatusModel::ALIAS_PARTIAL_PAYMENT;
@@ -360,11 +356,11 @@ class OrderShopBuilder
$cycleNumber = null;
$deliveryDate = $orderShop->getDeliveryDate();

switch ($orderShop->getSection()->getCycle()) {
case SectionModel::CYCLE_DAY:
switch ($orderShop->getSection()->getCycleType()) {
case SectionModel::CYCLE_TYPE_DAY:
$cycleNumber = $deliveryDate->format('z');
break;
case SectionModel::CYCLE_WEEK:
case SectionModel::CYCLE_TYPE_WEEK:
$cycleNumber = $deliveryDate->format('W');
break;
}
@@ -483,7 +479,11 @@ class OrderShopBuilder
public function updatePriceByProductFamily(ProductFamilyInterface $productFamily)
{
// @TODO : faire la vérification isOpenSale depuis la méthode appelante
if (!$this->openingResolver->isOpenSale($productFamily->getSection(), null, OpeningResolver::OPENING_CONTEXT_BACKEND)) {
if (!$this->openingResolver->isOpenSale(
$productFamily->getSection(),
null,
OpeningResolver::OPENING_CONTEXT_BACKEND
)) {
$countOrderProductUpdated = 0;

foreach ($productFamily->getProducts() as $product) {
@@ -567,7 +567,7 @@ class OrderShopBuilder
}

// setDeliveryAddress
public function initDeliveryAddress(OrderShopInterface $orderShop, AddressInterface $address = null):void
public function initDeliveryAddress(OrderShopInterface $orderShop, AddressInterface $address = null): void
{
$orderShop->setDeliveryAddress($address);
$orderShop->setDeliveryInfos($address ? $address->getDeliveryInfos() : null);
@@ -595,5 +595,4 @@ class OrderShopBuilder
}



}

+ 10
- 5
Controller/ControllerTrait.php Voir le fichier

@@ -53,7 +53,7 @@ trait ControllerTrait
[
PriceSolver::class => PriceSolver::class,
MerchantResolver::class => MerchantResolver::class,
SectionResolver::class=> SectionResolver::class,
SectionResolver::class => SectionResolver::class,
OrderShopContainer::class => OrderShopContainer::class,
AddressContainer::class => AddressContainer::class,
TaxRateContainer::class => TaxRateContainer::class,
@@ -115,7 +115,10 @@ trait ControllerTrait

public function getUserMerchantCurrent(): UserMerchantInterface
{
return $this->getUserMerchantContainer()->getBuilder()->createIfNotExist($this->getUserCurrent(), $this->getMerchantCurrent());
return $this->getUserMerchantContainer()->getBuilder()->createIfNotExist(
$this->getUserCurrent(),
$this->getMerchantCurrent()
);
}

public function getMerchantUserCurrent(): MerchantInterface
@@ -130,9 +133,11 @@ trait ControllerTrait

public function getCartCurrent(): OrderShopInterface
{
return $this->getOrderShopContainer()->getStore()
->setSection($this->getSectionCurrent())
->getOneCartCurrent();
return $this->getOrderShopContainer()->getBuilder()->createIfNotExist(
$this->getSectionCurrent(),
$this->getUserCurrent(),
$this->getVisitorCurrent()
);
}

public function getPriceSolver(): PriceSolver

+ 1
- 1
Controller/Order/CartController.php Voir le fichier

@@ -84,7 +84,7 @@ class CartController extends AbstractController
{
$entityManager = $this->getEntityManager();
$id = $request->get('id');
$orderReductionCart = $this->getOrderReductionCartContainer()->getStore()->getOneById((int)$id);
$orderReductionCart = $this->getOrderReductionCartContainer()->getStore()->getOneById((int) $id);
$orderShop = $this->getCartCurrent();

if ($orderReductionCart && $orderShop->getOrderReductionCarts() && $orderShop->getOrderReductionCarts(

+ 2
- 0
Factory/Order/OrderPaymentFactory.php Voir le fichier

@@ -16,6 +16,8 @@ class OrderPaymentFactory extends AbstractFactory
$orderPayment->setOrderShop($orderShop);
$orderPayment->setMeanPayment($meanPayment);
$orderPayment->setAmount($amount);
$orderPayment->setPaidAt(new \DateTime());
$orderPayment->setEditable(false);

return $orderPayment;
}

+ 1
- 1
Generator/OrderReferenceGenerator.php Voir le fichier

@@ -18,7 +18,7 @@ class OrderReferenceGenerator

public function buildReference(OrderShopInterface $orderShop, \DateTime $distributionDate = null): string
{
switch ($orderShop->getSection()->getCycle()) {
switch ($orderShop->getSection()->getCycleType()) {
case SectionModel::CYCLE_TYPE_DAY:
return $this->buildReferenceCycleDay($orderShop);
case SectionModel::CYCLE_TYPE_WEEK:

+ 2
- 1
Model/Order/OrderReductionCartModel.php Voir le fichier

@@ -8,11 +8,12 @@ use Lc\CaracoleBundle\Doctrine\Extension\ReductionCartPropertyTrait;
use Lc\CaracoleBundle\Doctrine\Extension\ReductionTrait;
use Lc\CaracoleBundle\Doctrine\Extension\ReductionInterface;
use Lc\CaracoleBundle\Model\Reduction\ReductionCartInterface;
use Lc\SovBundle\Doctrine\EntityInterface;

/**
* @ORM\MappedSuperclass()
*/
abstract class OrderReductionCartModel implements ReductionInterface, ReductionCartPropertyInterface
abstract class OrderReductionCartModel implements EntityInterface, ReductionInterface, ReductionCartPropertyInterface
{
use ReductionTrait;
use ReductionCartPropertyTrait;

+ 1
- 4
Model/Order/OrderShopInterface.php Voir le fichier

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

namespace Lc\CaracoleBundle\Model\Order;


use Doctrine\Common\Collections\Collection;
use Lc\CaracoleBundle\Model\Address\AddressInterface;
use Lc\CaracoleBundle\Model\Config\TaxRateInterface;
@@ -13,9 +12,7 @@ use Lc\CaracoleBundle\Model\User\VisitorInterface;
use Lc\SovBundle\Model\Ticket\TicketInterface;
use Lc\SovBundle\Model\User\UserInterface;

/**
* @ORM\MappedSuperclass()
*/

interface OrderShopInterface
{
public function getValidationDate(): ?\DateTimeInterface;

+ 1
- 6
Model/Order/OrderShopModel.php Voir le fichier

@@ -4,7 +4,6 @@ namespace Lc\CaracoleBundle\Model\Order;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Gedmo\Mapping\Annotation as Gedmo;
use Doctrine\ORM\Mapping as ORM;
use Lc\CaracoleBundle\Doctrine\Extension\FilterSectionInterface;
use Lc\CaracoleBundle\Model\Address\AddressInterface;
@@ -12,15 +11,11 @@ use Lc\CaracoleBundle\Model\Config\TaxRateInterface;
use Lc\CaracoleBundle\Model\File\DocumentInterface;
use Lc\CaracoleBundle\Model\PointSale\PointSaleInterface;
use Lc\CaracoleBundle\Model\Section\SectionInterface;
use Lc\SovBundle\Doctrine\Extension\BlameableNullableTrait;
use Lc\SovBundle\Model\Ticket\TicketInterface;
use Lc\CaracoleBundle\Model\User\VisitorInterface;
use Lc\SovBundle\Doctrine\Pattern\AbstractLightEntity;
use Lc\SovBundle\Model\User\UserInterface;

/**
* @ORM\MappedSuperclass()
*/
abstract class OrderShopModel extends AbstractLightEntity implements FilterSectionInterface, OrderShopInterface
{

@@ -68,7 +63,7 @@ abstract class OrderShopModel extends AbstractLightEntity implements FilterSecti
protected $orderStatusHistories;

/**
* @ORM\OneToMany(targetEntity="Lc\CaracoleBundle\Model\Order\OrderPaymentInterface", mappedBy="orderShop", orphanRemoval=true)
* @ORM\OneToMany(targetEntity="Lc\CaracoleBundle\Model\Order\OrderPaymentInterface", mappedBy="orderShop", orphanRemoval=true,cascade={"persist"})
*/
protected $orderPayments;


+ 0
- 3
Model/Product/ProductFamilyInterface.php Voir le fichier

@@ -2,9 +2,6 @@

namespace Lc\CaracoleBundle\Model\Product;

/**
* @ORM\MappedSuperclass()
*/
interface ProductFamilyInterface
{


+ 9
- 7
Repository/Order/OrderShopStore.php Voir le fichier

@@ -9,6 +9,7 @@ use Lc\CaracoleBundle\Model\Order\OrderStatusModel;
use Lc\CaracoleBundle\Model\Reduction\ReductionCartInterface;
use Lc\CaracoleBundle\Model\Reduction\ReductionCreditInterface;
use Lc\CaracoleBundle\Model\Reduction\ReductionCreditModel;
use Lc\CaracoleBundle\Model\User\VisitorInterface;
use Lc\CaracoleBundle\Repository\Merchant\MerchantStore;
use Lc\CaracoleBundle\Repository\Reduction\ReductionCartStore;
use Lc\CaracoleBundle\Repository\Reduction\ReductionCreditStore;
@@ -272,21 +273,22 @@ class OrderShopStore extends AbstractStore
}

// findCartCurrent
public function getOneCartCurrent(array $params = [], $query = null): ?OrderShopInterface
public function getOneCartCurrent(UserInterface $user = null, VisitorInterface $visitor = null, $query = null): ?OrderShopInterface
{
$query = $this->createDefaultQuery($query);

if (isset($params['user'])) {
$query->filterByUser($params['user']);
if (!is_null($user)) {
$query->filterByUser($user);
}

if (isset($params['visitor'])) {
$query->filterByVisitor($params['visitor']);
else {
if (!is_null($visitor)) {
$query->filterByVisitor($visitor);
}
}

$query
->selectOrderReductionCarts()
->filterByStatus(OrderStatusModel::$statusAliasAsValid);
->filterByStatus(OrderStatusModel::$statusAliasAsCart);

return $query->findOne();
}

+ 7
- 0
Resources/translations/admin.fr.yaml Voir le fichier

@@ -122,6 +122,13 @@ entity:
reference: Référence
comment: Commentaire

OrderShop:
fields:
deliveryInfos: |
Merci de nous laisser le maximum d'informations pour faciliter notre arrivée : digicode,
étage, rue non répertoriée dans les GPS, accès vers la porte d'entrée ...
useDeliveryAddressAsBillingAddress: Utiliser l'adresse de livraison

GroupUser:
label: Groupe d'utilisateur
label_plurial: Groupes d'utilisateurs

+ 6
- 0
Solver/Order/OrderShopSolver.php Voir le fichier

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

namespace Lc\CaracoleBundle\Solver\Order;

use App\Entity\Order\OrderShop;
use Doctrine\ORM\EntityManagerInterface;
use Lc\CaracoleBundle\Model\File\DocumentInterface;
use Lc\CaracoleBundle\Model\File\DocumentModel;
@@ -345,4 +346,9 @@ class OrderShopSolver
$byWeight
);
}

public function hasMakeAChoiceAboutComplementaryOrder(OrderShop $orderShop): bool
{
return $orderShop->getMainOrderShop() || $orderShop->getDeclineComplementaryOrderShop();
}
}

+ 18
- 9
Twig/StoreTwigExtension.php Voir le fichier

@@ -2,25 +2,23 @@

namespace Lc\CaracoleBundle\Twig;

use Lc\CaracoleBundle\Builder\Order\OrderShopBuilder;
use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
use Lc\CaracoleBundle\Model\Order\OrderShopInterface;
use Lc\CaracoleBundle\Model\Section\SectionInterface;
use Lc\CaracoleBundle\Model\User\UserMerchantInterface;
use Lc\CaracoleBundle\Repository\Config\TaxRateStore;
use Lc\CaracoleBundle\Repository\Config\UnitStore;
use Lc\CaracoleBundle\Repository\Merchant\MerchantRepositoryQuery;
use Lc\CaracoleBundle\Repository\Merchant\MerchantStore;
use Lc\CaracoleBundle\Repository\Order\OrderShopStore;
use Lc\CaracoleBundle\Repository\Product\ProductCategoryStore;
use Lc\CaracoleBundle\Repository\Reminder\ReminderStore;
use Lc\CaracoleBundle\Repository\Section\SectionRepository;
use Lc\CaracoleBundle\Repository\Section\SectionRepositoryInterface;
use Lc\CaracoleBundle\Repository\Section\SectionRepositoryQuery;
use Lc\CaracoleBundle\Repository\Section\SectionStore;
use Lc\CaracoleBundle\Resolver\MerchantResolver;
use Lc\CaracoleBundle\Resolver\SectionResolver;
use Lc\ShopBundle\Context\UnitInterface;
use Lc\CaracoleBundle\Resolver\VisitorResolver;
use Lc\SovBundle\Solver\Setting\SettingSolver;
use Symfony\Component\Security\Core\Security;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;

@@ -36,6 +34,9 @@ class StoreTwigExtension extends AbstractExtension
protected ProductCategoryStore $productCategoryStore;
protected OrderShopStore $orderShopStore;
protected SettingSolver $settingSolver;
protected OrderShopBuilder $orderShopBuilder;
protected Security $security;
protected VisitorResolver $visitorResolver;

public function __construct(
MerchantResolver $merchantResolver,
@@ -47,7 +48,10 @@ class StoreTwigExtension extends AbstractExtension
TaxRateStore $taxRateStore,
ProductCategoryStore $productCategoryStore,
OrderShopStore $orderShopStore,
SettingSolver $settingSolver
SettingSolver $settingSolver,
OrderShopBuilder $orderShopBuilder,
Security $security,
VisitorResolver $visitorResolver
) {
$this->merchantResolver = $merchantResolver;
$this->sectionResolver = $sectionResolver;
@@ -59,6 +63,9 @@ class StoreTwigExtension extends AbstractExtension
$this->productCategoryStore = $productCategoryStore;
$this->orderShopStore = $orderShopStore;
$this->settingSolver = $settingSolver;
$this->orderShopBuilder = $orderShopBuilder;
$this->security = $security;
$this->visitorResolver = $visitorResolver;
}

public function getFunctions()
@@ -104,9 +111,11 @@ class StoreTwigExtension extends AbstractExtension

public function getCartCurrent(): OrderShopInterface
{
return $this->orderShopStore
->setSection($this->sectionResolver->getCurrent())
->getOneCartCurrent();
return $this->orderShopBuilder->createIfNotExist(
$this->sectionResolver->getCurrent(),
$this->security->getUser(),
$this->visitorResolver->getCurrent()
);
}

public function getMerchantCurrent(): MerchantInterface

Chargement…
Annuler
Enregistrer