Browse Source

Refactoring services

packProduct
Guillaume 2 years ago
parent
commit
85cceba306
67 changed files with 999 additions and 747 deletions
  1. +6
    -5
      Builder/Order/OrderProductBuilder.php
  2. +4
    -3
      Builder/Order/OrderShopBuilder.php
  3. +88
    -0
      Checker/OrderChecker.php
  4. +0
    -20
      Container/MyContainer.php
  5. +39
    -0
      Container/Order/OrderProductContainer.php
  6. +58
    -0
      Container/Order/OrderShopContainer.php
  7. +8
    -4
      Controller/AdminControllerTrait.php
  8. +2
    -3
      Controller/Config/TaxRateAdminController.php
  9. +2
    -2
      Controller/Config/UnitAdminController.php
  10. +2
    -2
      Controller/Credit/CreditHistoryAdminController.php
  11. +3
    -2
      Controller/Merchant/MerchantAdminController.php
  12. +5
    -3
      Controller/Newsletter/NewsletterAdminController.php
  13. +5
    -3
      Controller/PointSale/PointSaleAdminController.php
  14. +3
    -0
      Controller/Product/ProductCategoryAdminController.php
  15. +7
    -4
      Controller/Reminder/ReminderAdminController.php
  16. +5
    -3
      Controller/Section/OpeningAdminController.php
  17. +6
    -3
      Controller/Section/SectionAdminController.php
  18. +5
    -4
      Controller/Site/NewsAdminController.php
  19. +5
    -4
      Controller/Site/PageAdminController.php
  20. +5
    -4
      Controller/Ticket/TicketAdminController.php
  21. +5
    -4
      Controller/User/GroupUserAdminController.php
  22. +10
    -4
      Controller/User/UserMerchantAdminController.php
  23. +4
    -3
      Factory/Address/AddressFactory.php
  24. +2
    -1
      Factory/File/DocumentFactory.php
  25. +1
    -2
      Factory/MerchantFactoryTrait.php
  26. +3
    -12
      Factory/Order/OrderShopFactory.php
  27. +4
    -2
      Factory/PointSale/PointSaleFactory.php
  28. +7
    -3
      Factory/Product/ProductCategoryFactory.php
  29. +2
    -7
      Factory/Product/ProductFamilyFactory.php
  30. +4
    -2
      Factory/Reduction/ReductionCartFactory.php
  31. +4
    -2
      Factory/Reduction/ReductionCatalogFactory.php
  32. +4
    -2
      Factory/Reduction/ReductionCreditFactory.php
  33. +11
    -4
      Factory/Reminder/ReminderFactory.php
  34. +4
    -4
      Factory/Section/OpeningFactory.php
  35. +4
    -3
      Factory/Section/SectionFactory.php
  36. +1
    -2
      Factory/SectionFactoryTrait.php
  37. +3
    -2
      Factory/Setting/MerchantSettingFactory.php
  38. +3
    -2
      Factory/Setting/SectionSettingFactory.php
  39. +1
    -0
      Factory/Site/NewsFactory.php
  40. +1
    -0
      Factory/Site/PageFactory.php
  41. +1
    -0
      Factory/Ticket/TicketFactory.php
  42. +1
    -0
      Factory/User/GroupUserFactory.php
  43. +1
    -1
      Factory/User/UserMerchantFactory.php
  44. +1
    -1
      Factory/User/VisitorFactory.php
  45. +1
    -103
      Model/Order/OrderShopModel.php
  46. +0
    -86
      Model/Product/ProductModel.php
  47. +8
    -9
      Repository/Config/TaxRateStore.php
  48. +2
    -1
      Repository/Config/UnitStore.php
  49. +8
    -8
      Repository/Credit/CreditHistoryStore.php
  50. +0
    -29
      Repository/Order/OrderProductStore.php
  51. +59
    -198
      Repository/Order/OrderShopStore.php
  52. +4
    -98
      Repository/Product/ProductFamilyStore.php
  53. +4
    -6
      Repository/Reduction/ReductionCartStore.php
  54. +0
    -28
      Repository/Reduction/ReductionCreditStore.php
  55. +7
    -22
      Repository/User/UserMerchantStore.php
  56. +48
    -0
      Resolver/ReductionResolver.php
  57. +61
    -0
      Solver/Order/OrderProductSolver.php
  58. +116
    -0
      Solver/Order/OrderShopSolver.php
  59. +6
    -6
      Solver/Price/OrderProductPriceSolver.php
  60. +5
    -5
      Solver/Price/OrderShopPriceSolver.php
  61. +11
    -11
      Solver/Price/PriceSolver.php
  62. +2
    -2
      Solver/Price/PriceSolverTrait.php
  63. +3
    -3
      Solver/Price/ProductPriceSolver.php
  64. +103
    -0
      Solver/Product/ProductFamilySolver.php
  65. +110
    -0
      Solver/Product/ProductSolver.php
  66. +26
    -0
      Solver/User/UserMerchantSolver.php
  67. +75
    -0
      Transformer/Order/OrderShopTransformer.php

+ 6
- 5
Builder/Order/OrderProductBuilder.php View File

@@ -6,28 +6,29 @@ use Doctrine\ORM\EntityManagerInterface;
use Lc\CaracoleBundle\Model\Order\OrderProductInterface;
use Lc\CaracoleBundle\Repository\Order\OrderProductStore;
use Lc\CaracoleBundle\Resolver\Price\PriceResolver;
use Lc\CaracoleBundle\Solver\Price\PriceSolver;

class OrderProductBuilder
{
protected EntityManagerInterface $entityManager;
protected PriceResolver $priceResolver;
protected PriceSolver $priceSolver;
protected OrderProductStore $orderProductStore;

public function __construct(
EntityManagerInterface $entityManager,
PriceResolver $priceResolver,
PriceSolver $priceSolver,
OrderProductStore $orderProductStore
) {
$this->entityManager = $entityManager;
$this->priceResolver = $priceResolver;
$this->priceSolver = $priceSolver;
$this->orderProductStore = $orderProductStore;
}

public function init(OrderProductInterface $orderProduct)
{
$orderProduct->setTitle($orderProduct->getTitleOrderShop());
$orderProduct->setPrice($this->priceResolver->getPrice($orderProduct->getProduct()));
$orderProduct->setBuyingPrice($this->priceResolver->getBuyingPrice($orderProduct->getProduct()));
$orderProduct->setPrice($this->priceSolver->getPrice($orderProduct->getProduct()));
$orderProduct->setBuyingPrice($this->priceSolver->getBuyingPrice($orderProduct->getProduct()));
$orderProduct->setUnit($orderProduct->getProduct()->getUnitInherited());
$orderProduct->setTaxRate($orderProduct->getProduct()->getTaxRateInherited());
$orderProduct->setQuantityProduct($orderProduct->getProduct()->getQuantityInherited());

+ 4
- 3
Builder/Order/OrderShopBuilder.php View File

@@ -27,6 +27,7 @@ use Lc\CaracoleBundle\Repository\Order\OrderShopStore;
use Lc\CaracoleBundle\Repository\Order\OrderStatusStore;
use Lc\CaracoleBundle\Repository\Product\ProductFamilyStore;
use Lc\CaracoleBundle\Resolver\Price\PriceResolver;
use Lc\CaracoleBundle\Solver\Price\PriceSolver;
use Lc\SovBundle\Model\User\UserInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
@@ -37,7 +38,7 @@ class OrderShopBuilder
protected OrderStatusStore $orderStatusStore;
protected OrderProductStore $orderProductStore;
protected ProductFamilyStore $productFamilyStore;
protected PriceResolver $priceResolver;
protected PriceSolver $priceSolver;
protected OrderProductBuilder $orderProductBuilder;
protected DocumentBuilder $documentBuilder;
protected EventDispatcherInterface $eventDispatcher;
@@ -51,7 +52,7 @@ class OrderShopBuilder
ProductFamilyStore $productFamilyStore,
OrderProductBuilder $orderProductBuilder,
DocumentBuilder $documentBuilder,
PriceResolver $priceResolver,
PriceSolver $priceSolver,
EventDispatcherInterface $eventDispatcher,
FlashBagInterface $flashBag
) {
@@ -62,7 +63,7 @@ class OrderShopBuilder
$this->productFamilyStore = $productFamilyStore;
$this->orderProductBuilder = $orderProductBuilder;
$this->documentBuilder = $documentBuilder;
$this->priceResolver = $priceResolver;
$this->priceSolver = $priceSolver;
$this->eventDispatcher = $eventDispatcher;
$this->flashBag = $flashBag;
}

+ 88
- 0
Checker/OrderChecker.php View File

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

namespace Lc\CaracoleBundle\Checker;

use Lc\CaracoleBundle\Model\Order\OrderProductInterface;
use Lc\CaracoleBundle\Model\Order\OrderShopInterface;
use Lc\CaracoleBundle\Model\Order\OrderStatusModel;
use Lc\CaracoleBundle\Solver\Order\OrderShopSolver;
use Lc\CaracoleBundle\Solver\Price\PriceSolver;

class OrderChecker
{
protected PriceSolver $priceSolver;
protected OrderShopSolver $orderShopSolver;

public function __construct(PriceSolver $priceSolver, OrderShopSolver $orderShopSolver)
{
$this->priceSolver = $priceSolver;
$this->orderShopSolver = $orderShopSolver;
}

public function hasOrderProductAlreadyInCart(OrderShopInterface $orderShop, OrderProductInterface $orderProductTest)
{
foreach ($orderShop->getOrderProducts() as $orderProduct) {
if ($orderProduct->getProduct() == $orderProductTest->getProduct()) {
return $orderProduct;
}
}

return false;
}

public function isValid(OrderShopInterface $orderShop)
{
if ($orderShop->getOrderStatus() && in_array(
$orderShop->getOrderStatus()->getAlias(),
OrderStatusModel::$statusAliasAsValid
) > 0) {
return true;
}

return false;
}

public function isCart(OrderShopInterface $orderShop)
{
if ($orderShop->getOrderStatus() && in_array(
$orderShop->getOrderStatus()->getAlias(),
OrderStatusModel::$statusAliasAsCart
) > 0) {
return true;
}

return false;
}

// isOrderShopPositiveAmount
public function isPositiveAmount(OrderShopInterface $orderShop)
{
return $this->priceSolver->getTotalWithTax($orderShop) >= 0;
}

public function isPaid(OrderShopInterface $orderShop, $mergeComplementaryOrderShop = false)
{
$totalOrderPayments = $this->orderShopSolver->getTotalOrderPayments($orderShop, $mergeComplementaryOrderShop);
$totalOrder = $this->priceSolver->getTotalWithTax($orderShop);

if ((abs($totalOrderPayments - $totalOrder) < 0.00001
|| $totalOrderPayments >= $totalOrder)
&& $totalOrder > 0) {
return true;
} else {
return false;
}
}

// isOrderShopPositiveAmountRemainingToBePaid
public function isPositiveAmountRemainingToBePaid(OrderShopInterface $orderShop): bool
{
return $this->orderShopSolver->getTotalRemainingToBePaid($orderShop) > 0;
}

public function isCartAllowToBeOrder(OrderShopInterface $orderShop)
{
return true;
}

}

+ 0
- 20
Container/MyContainer.php View File

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

namespace Lc\CaracoleBundle\Container;

use Lc\CaracoleBundle\Resolver\MerchantResolver;

/**
* class MyContainer.
*
* @author Simon Vieille <simon@deblan.fr>
*/
class MyContainer
{
public MerchantResolver $merchantResolver;

public function __construct(MerchantResolver $merchantResolver)
{
$this->merchantResolver = $merchantResolver;
}
}

+ 39
- 0
Container/Order/OrderProductContainer.php View File

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

namespace Lc\CaracoleBundle\Container\Order;

use Lc\CaracoleBundle\Builder\Order\OrderProductBuilder;
use Lc\CaracoleBundle\Repository\Order\OrderProductRepositoryQuery;
use Lc\CaracoleBundle\Repository\Order\OrderProductStore;

class OrderProductContainer
{
protected OrderProductBuilder $orderProductBuilder;
protected OrderProductRepositoryQuery $orderProductRepositoryQuery;
protected OrderProductStore $orderProductStore;

public function __construct(
OrderProductBuilder $orderProductBuilder,
OrderProductRepositoryQuery $orderProductRepositoryQuery,
OrderProductStore $orderProductStore
) {
$this->orderProductBuilder = $orderProductBuilder;
$this->orderProductRepositoryQuery = $orderProductRepositoryQuery;
$this->orderProductStore = $orderProductStore;
}

public function getBuilder(): OrderProductBuilder
{
return $this->orderProductBuilder;
}

public function getRepositoryQuery(): OrderProductRepositoryQuery
{
return $this->orderProductRepositoryQuery;
}

public function getStore(): OrderProductStore
{
return $this->orderProductStore;
}
}

+ 58
- 0
Container/Order/OrderShopContainer.php View File

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

namespace Lc\CaracoleBundle\Container\Order;

use Lc\CaracoleBundle\Builder\Order\OrderShopBuilder;
use Lc\CaracoleBundle\Checker\OrderChecker;
use Lc\CaracoleBundle\Repository\Order\OrderShopRepositoryQuery;
use Lc\CaracoleBundle\Repository\Order\OrderShopStore;
use Lc\CaracoleBundle\Solver\Order\OrderShopSolver;

class OrderShopContainer
{
protected OrderShopSolver $orderShopSolver;
protected OrderChecker $orderChecker;
protected OrderShopRepositoryQuery $orderShopRepositoryQuery;
protected OrderShopStore $orderShopStore;
protected OrderShopBuilder $orderShopBuilder;

public function __construct(
OrderShopSolver $orderShopSolver,
OrderChecker $orderChecker,
OrderShopRepositoryQuery $orderShopRepositoryQuery,
OrderShopStore $orderShopStore,
OrderShopBuilder $orderShopBuilder
) {
$this->orderShopSolver = $orderShopSolver;
$this->orderChecker = $orderChecker;
$this->orderShopRepositoryQuery = $orderShopRepositoryQuery;
$this->orderShopStore = $orderShopStore;
$this->orderShopBuilder = $orderShopBuilder;
}

public function getSolver(): OrderShopSolver
{
return $this->orderShopSolver;
}

public function getChecker(): OrderChecker
{
return $this->orderChecker;
}

public function getRepositoryQuery(): OrderShopRepositoryQuery
{
return $this->orderShopRepositoryQuery;
}

public function getStore(): OrderShopStore
{
return $this->orderShopStore;
}

public function getBuilder(): OrderShopBuilder
{
return $this->orderShopBuilder;
}

}

+ 8
- 4
Controller/AdminControllerTrait.php View File

@@ -15,6 +15,7 @@ use EasyCorp\Bundle\EasyAdminBundle\Exception\ForbiddenActionException;
use EasyCorp\Bundle\EasyAdminBundle\Exception\InsufficientEntityPermissionException;
use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator;
use EasyCorp\Bundle\EasyAdminBundle\Security\Permission;
use Lc\CaracoleBundle\Container\Order\OrderShopContainer;
use Lc\CaracoleBundle\Doctrine\Extension\FilterMerchantInterface;
use Lc\CaracoleBundle\Doctrine\Extension\FilterMultipleMerchantsInterface;
use Lc\CaracoleBundle\Doctrine\Extension\FilterSectionInterface;
@@ -44,7 +45,10 @@ trait AdminControllerTrait
'section_resolver' => SectionResolver::class,
'user_factory' => UserFactory::class,
'user_merchant_factory' => UserMerchantFactory::class,
MerchantResolver::class => MerchantResolver::class,
SectionResolver::class => SectionResolver::class,
ReductionCatalogStore::class => ReductionCatalogStore::class,
OrderShopContainer::class => OrderShopContainer::class
]
);
}
@@ -120,7 +124,7 @@ trait AdminControllerTrait
'entityClass' => $context->getEntity()->getFqcn(),
'entityId' => $context->getEntity()->getInstance()->getId(),
'action' => $context->getRequest()->getUri(),
'attr' => ['id'=> 'duplicate-other-merchant-form'],
'attr' => ['id' => 'duplicate-other-merchant-form'],

)
);
@@ -162,7 +166,7 @@ trait AdminControllerTrait
);

return new Response(json_encode($response));
}else{
} else {
throw new \ErrorException('La requête doit être effectué en ajax');
}
}
@@ -194,7 +198,7 @@ trait AdminControllerTrait
'entityClass' => $context->getEntity()->getFqcn(),
'entityId' => $context->getEntity()->getInstance()->getId(),
'action' => $context->getRequest()->getUri(),
'attr' => ['id'=> 'duplicate-other-section-form'],
'attr' => ['id' => 'duplicate-other-section-form'],
)
);

@@ -235,7 +239,7 @@ trait AdminControllerTrait
);

return new Response(json_encode($response));
}else{
} else {
throw new \ErrorException('La requête doit être effectué en ajax');
}
}

+ 2
- 3
Controller/Config/TaxRateAdminController.php View File

@@ -3,7 +3,6 @@
namespace Lc\CaracoleBundle\Controller\Config;

use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
use EasyCorp\Bundle\EasyAdminBundle\Field\IntegerField;
use EasyCorp\Bundle\EasyAdminBundle\Field\NumberField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use Lc\CaracoleBundle\Controller\AdminControllerTrait;
@@ -29,7 +28,7 @@ abstract class TaxRateAdminController extends AbstractAdminController

public function createEntity(string $entityFqcn)
{
$factory = new TaxRateFactory();
return $factory->create();
$taxRateFactory = new TaxRateFactory();
return $taxRateFactory->create();
}
}

+ 2
- 2
Controller/Config/UnitAdminController.php View File

@@ -29,7 +29,7 @@ abstract class UnitAdminController extends AbstractAdminController

public function createEntity(string $entityFqcn)
{
$factory = new UnitFactory();
return $factory->create();
$unitFactory = new UnitFactory();
return $unitFactory->create();
}
}

+ 2
- 2
Controller/Credit/CreditHistoryAdminController.php View File

@@ -52,8 +52,8 @@ abstract class CreditHistoryAdminController extends AbstractAdminController

public function createEntity(string $entityFqcn)
{
$factory = new CreditHistoryFactory();
return $factory->create();
$creditHistoryFactory = new CreditHistoryFactory();
return $creditHistoryFactory->create();
}

public function persistEntity(EntityManagerInterface $entityManager, $entityInstance): void

+ 3
- 2
Controller/Merchant/MerchantAdminController.php View File

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

namespace Lc\CaracoleBundle\Controller\Merchant;

use App\Entity\Merchant\Merchant;
use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
use EasyCorp\Bundle\EasyAdminBundle\Field\FormField;
use EasyCorp\Bundle\EasyAdminBundle\Field\NumberField;
@@ -45,8 +46,8 @@ abstract class MerchantAdminController extends AbstractAdminController

public function createEntity(string $entityFqcn)
{
$factory = new MerchantFactory();
return $factory->create();
$merchantFactory = new MerchantFactory();
return $merchantFactory->create();
}

}

+ 5
- 3
Controller/Newsletter/NewsletterAdminController.php View File

@@ -4,6 +4,7 @@ namespace Lc\CaracoleBundle\Controller\Newsletter;

use Lc\CaracoleBundle\Controller\AdminControllerTrait;
use Lc\CaracoleBundle\Factory\Newsletter\NewsletterFactory;
use Lc\CaracoleBundle\Resolver\MerchantResolver;
use Lc\SovBundle\Controller\Newsletter\NewsletterAdminController as SovNewsletterAdminController;

abstract class NewsletterAdminController extends SovNewsletterAdminController
@@ -12,8 +13,9 @@ abstract class NewsletterAdminController extends SovNewsletterAdminController

public function createEntity(string $entityFqcn)
{
$factory = new NewsletterFactory();
$factory->setMerchant($this->get('merchant_resolver')->getCurrent());
return $factory->create();
$newsletterFactory = new NewsletterFactory();
return $newsletterFactory
->setMerchant($this->get(MerchantResolver::class)->getCurrent())
->create();
}
}

+ 5
- 3
Controller/PointSale/PointSaleAdminController.php View File

@@ -8,6 +8,7 @@ use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use Lc\CaracoleBundle\Controller\AdminControllerTrait;
use Lc\CaracoleBundle\Factory\PointSale\PointSaleFactory;
use Lc\CaracoleBundle\Field\Address\AddressField;
use Lc\CaracoleBundle\Resolver\MerchantResolver;
use Lc\SovBundle\Controller\AbstractAdminController;
use Lc\SovBundle\Field\BooleanField;
use Lc\SovBundle\Field\StatusField;
@@ -44,8 +45,9 @@ abstract class PointSaleAdminController extends AbstractAdminController

public function createEntity(string $entityFqcn)
{
$factory = new PointSaleFactory();
$currentMerchant = $this->get('merchant_resolver')->getCurrent();
return $factory->create($currentMerchant);
$pointSaleFactory = new PointSaleFactory();
return $pointSaleFactory
->setMerchant($this->get(MerchantResolver::class)->getCurrent())
->create();
}
}

+ 3
- 0
Controller/Product/ProductCategoryAdminController.php View File

@@ -7,12 +7,15 @@ use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
use EasyCorp\Bundle\EasyAdminBundle\Field\FormField;
use EasyCorp\Bundle\EasyAdminBundle\Field\NumberField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use Lc\CaracoleBundle\Container\Order\OrderShopContainer;
use Lc\CaracoleBundle\Controller\AdminControllerTrait;
use Lc\CaracoleBundle\Field\Address\AddressField;
use Lc\CaracoleBundle\Repository\Reduction\ReductionCatalogStore;
use Lc\SovBundle\Controller\AbstractAdminController;
use Lc\SovBundle\Field\BooleanField;
use Lc\SovBundle\Field\CKEditorField;
use Lc\SovBundle\Field\StatusField;
use Lc\SovBundle\Translation\TranslatorAdmin;

abstract class ProductCategoryAdminController extends AbstractAdminController
{

+ 7
- 4
Controller/Reminder/ReminderAdminController.php View File

@@ -2,8 +2,11 @@

namespace Lc\CaracoleBundle\Controller\Reminder;

use App\Entity\Reminder\Reminder;
use Lc\CaracoleBundle\Controller\AdminControllerTrait;
use Lc\CaracoleBundle\Factory\Reminder\ReminderFactory;
use Lc\CaracoleBundle\Resolver\MerchantResolver;
use Lc\CaracoleBundle\Resolver\SectionResolver;
use Lc\SovBundle\Controller\Reminder\ReminderAdminController as SovReminderAdminController;

class ReminderAdminController extends SovReminderAdminController
@@ -12,10 +15,10 @@ class ReminderAdminController extends SovReminderAdminController

public function createEntity(string $crudAction = null, string $crudControllerFqcn = null, int $entityId = null)
{
$factory = new ReminderFactory();
return $factory
->setMerchant($this->get('merchant_resolver')->getCurrent())
->setSection($this->get('section_resolver')->getCurrent())
$reminderFactory = new ReminderFactory();
return $reminderFactory
->setMerchant($this->get(MerchantResolver::class)->getCurrent())
->setSection($this->get(SectionResolver::class)->getCurrent())
->create($crudAction, $crudControllerFqcn, $entityId);
}
}

+ 5
- 3
Controller/Section/OpeningAdminController.php View File

@@ -8,6 +8,7 @@ use EasyCorp\Bundle\EasyAdminBundle\Field\ChoiceField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TimeField;
use Lc\CaracoleBundle\Controller\AdminControllerTrait;
use Lc\CaracoleBundle\Factory\Section\OpeningFactory;
use Lc\CaracoleBundle\Resolver\SectionResolver;
use Lc\SovBundle\Controller\AbstractAdminController;

abstract class OpeningAdminController extends AbstractAdminController
@@ -56,9 +57,10 @@ abstract class OpeningAdminController extends AbstractAdminController

public function createEntity(string $entityFqcn)
{
$factory = new OpeningFactory();
$currentSection = $this->get('section_resolver')->getCurrent();
return $factory->create($currentSection);
$openingFactory = new OpeningFactory();
return $openingFactory
->setSection($this->get(SectionResolver::class)->getCurrent())
->create();
}

}

+ 6
- 3
Controller/Section/SectionAdminController.php View File

@@ -10,11 +10,13 @@ use Lc\CaracoleBundle\Controller\AdminControllerTrait;
use Lc\CaracoleBundle\Factory\Section\SectionFactory;
use Lc\CaracoleBundle\Form\Section\OpeningsFormType;
use Lc\CaracoleBundle\Model\Section\SectionModel;
use Lc\CaracoleBundle\Resolver\MerchantResolver;
use Lc\SovBundle\Controller\AbstractAdminController;
use Lc\SovBundle\Field\BooleanField;
use Lc\SovBundle\Field\CKEditorField;
use Lc\SovBundle\Field\StatusField;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Session\SessionFactory;
use Symfony\Component\Routing\Annotation\Route;

abstract class SectionAdminController extends AbstractAdminController
@@ -56,9 +58,10 @@ abstract class SectionAdminController extends AbstractAdminController

public function createEntity(string $entityFqcn)
{
$factory = new SectionFactory();
$currentMerchant = $this->get('merchant_resolver')->getCurrent();
return $factory->create($currentMerchant);
$sectionFactory = new SectionFactory();
return $sectionFactory
->setMerchant($this->get(MerchantResolver::class)->getCurrent())
->create();
}

}

+ 5
- 4
Controller/Site/NewsAdminController.php View File

@@ -4,6 +4,7 @@ namespace Lc\CaracoleBundle\Controller\Site;

use Lc\CaracoleBundle\Controller\AdminControllerTrait;
use Lc\CaracoleBundle\Factory\Site\NewsFactory;
use Lc\CaracoleBundle\Resolver\MerchantResolver;
use Lc\SovBundle\Controller\Site\NewsAdminController as SovNewsAdminController;

abstract class NewsAdminController extends SovNewsAdminController
@@ -12,9 +13,9 @@ abstract class NewsAdminController extends SovNewsAdminController

public function createEntity(string $entityFqcn)
{
$factory = new NewsFactory();
$currentMerchant = $this->get('merchant_resolver')->getCurrent();
$factory->setMerchant($currentMerchant);
return $factory->create();
$newsFactory = new NewsFactory();
return $newsFactory
->setMerchant($this->get(MerchantResolver::class)->getCurrent())
->create();
}
}

+ 5
- 4
Controller/Site/PageAdminController.php View File

@@ -4,6 +4,7 @@ namespace Lc\CaracoleBundle\Controller\Site;

use Lc\CaracoleBundle\Controller\AdminControllerTrait;
use Lc\CaracoleBundle\Factory\Site\PageFactory;
use Lc\CaracoleBundle\Resolver\SectionResolver;
use Lc\SovBundle\Controller\Site\PageAdminController as SovPageAdminController;

abstract class PageAdminController extends SovPageAdminController
@@ -12,9 +13,9 @@ abstract class PageAdminController extends SovPageAdminController

public function createEntity(string $entityFqcn)
{
$factory = new PageFactory();
$currentSection = $this->get('section_resolver')->getCurrent();
$factory->setSection($currentSection);
return $factory->create();
$pageFactory = new PageFactory();
return $pageFactory
->setSection($this->get(SectionResolver::class)->getCurrent())
->create();
}
}

+ 5
- 4
Controller/Ticket/TicketAdminController.php View File

@@ -3,6 +3,7 @@
namespace Lc\CaracoleBundle\Controller\Ticket;

use Lc\CaracoleBundle\Controller\AdminControllerTrait;
use Lc\CaracoleBundle\Resolver\MerchantResolver;
use Lc\SovBundle\Controller\Ticket\TicketAdminController as SovTicketAdminController;
use Lc\CaracoleBundle\Factory\Ticket\TicketFactory;

@@ -12,10 +13,10 @@ class TicketAdminController extends SovTicketAdminController

public function createEntity(string $entityFqcn)
{
$merchantResolver = $this->get('merchant_resolver');
$factory = new TicketFactory();
$factory->setMerchant($merchantResolver->getCurrent());
return $factory->create();
$ticketFactory = new TicketFactory();
return $ticketFactory
->setMerchant($this->get(MerchantResolver::class)->getCurrent())
->create();
}

}

+ 5
- 4
Controller/User/GroupUserAdminController.php View File

@@ -4,6 +4,7 @@ namespace Lc\CaracoleBundle\Controller\User;

use Lc\CaracoleBundle\Controller\AdminControllerTrait;
use Lc\CaracoleBundle\Factory\User\GroupUserFactory;
use Lc\CaracoleBundle\Resolver\MerchantResolver;
use Lc\SovBundle\Controller\User\GroupUserAdminController as SovGroupUserAdminController;

abstract class GroupUserAdminController extends SovGroupUserAdminController
@@ -12,9 +13,9 @@ abstract class GroupUserAdminController extends SovGroupUserAdminController

public function createEntity(string $entityFqcn)
{
$factory = new GroupUserFactory();
$currentMerchant = $this->get('merchant_resolver')->getCurrent();
$factory->setMerchant($currentMerchant);
return $factory->create();
$groupUserFactory = new GroupUserFactory();
return $groupUserFactory
->setMerchant($this->get(MerchantResolver::class)->getCurrent())
->create();
}
}

+ 10
- 4
Controller/User/UserMerchantAdminController.php View File

@@ -24,9 +24,12 @@ use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProvider;
use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator;
use EasyCorp\Bundle\EasyAdminBundle\Security\Permission;
use Lc\CaracoleBundle\Controller\AdminControllerTrait;
use Lc\CaracoleBundle\Factory\User\UserFactory;
use Lc\CaracoleBundle\Factory\User\UserMerchantFactory;
use Lc\CaracoleBundle\Form\Credit\CreditHistoryFormType;
use Lc\CaracoleBundle\Form\User\UserMerchantFormType;
use Lc\CaracoleBundle\Model\Credit\CreditHistoryInterface;
use Lc\CaracoleBundle\Resolver\MerchantResolver;
use Lc\SovBundle\Controller\AbstractAdminController;
use Lc\SovBundle\Field\BooleanField;
use Lc\SovBundle\Field\ToggleField;
@@ -118,11 +121,12 @@ abstract class UserMerchantAdminController extends AbstractAdminController
public function new(AdminContext $context): Response
{
$entityManager = $this->get('em');
$userFactory = $this->get('user_factory');
$userMerchantFactory = $this->get('user_merchant_factory');
$userRepository = $entityManager->getRepository(UserInterface::class);
$merchantResolver = $this->get('merchant_resolver');
$userMerchant = $userMerchantFactory->create();
$merchantResolver = $this->get(MerchantResolver::class);
$userMerchantFactory = new UserMerchantFactory();
$userMerchant = $userMerchantFactory
->setMerchant($merchantResolver->getCurrent())
->create();

$form = $this->createForm(UserMerchantFormType::class, $userMerchant);

@@ -139,6 +143,8 @@ abstract class UserMerchantAdminController extends AbstractAdminController
$param['lastname'] = $form->get('firstname')->getData();
$param['roles'] = array();

// @TODO : à adapter
$userFactory = new UserFactory();
$user = $userFactory->create($param);

$entityManager->create($user);

+ 4
- 3
Factory/Address/AddressFactory.php View File

@@ -3,18 +3,19 @@
namespace Lc\CaracoleBundle\Factory\Address;

use App\Entity\Address\Address;
use Lc\CaracoleBundle\Factory\MerchantFactoryTrait;
use Lc\CaracoleBundle\Model\Address\AddressInterface;
use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
use Lc\SovBundle\Factory\AbstractFactory;

class AddressFactory extends AbstractFactory
{
use MerchantFactoryTrait;

public function create(MerchantInterface $merchant = null): AddressInterface
public function create(): AddressInterface
{
$address = new Address();

$address->setMerchant($merchant);
$address->setMerchant($this->merchant);

return $address;
}

+ 2
- 1
Factory/File/DocumentFactory.php View File

@@ -6,6 +6,7 @@ use App\Entity\File\Document;
use Lc\CaracoleBundle\Factory\MerchantFactoryTrait;
use Lc\CaracoleBundle\Model\Address\AddressInterface;
use Lc\CaracoleBundle\Model\File\DocumentInterface;
use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
use Lc\SovBundle\Factory\AbstractFactory;
use Lc\SovBundle\Model\User\UserInterface;

@@ -25,4 +26,4 @@ class DocumentFactory extends AbstractFactory
return $document;
}

}
}

+ 1
- 2
Factory/MerchantFactoryTrait.php View File

@@ -6,7 +6,7 @@ use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;

trait MerchantFactoryTrait
{
public ?MerchantInterface $merchant = null;
protected MerchantInterface $merchant;

public function setMerchant(MerchantInterface $merchant)
{
@@ -14,5 +14,4 @@ trait MerchantFactoryTrait

return $this;
}

}

+ 3
- 12
Factory/Order/OrderShopFactory.php View File

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

use App\Entity\Order\OrderShop;
use Lc\CaracoleBundle\Event\Order\OrderShopChangeStatusEvent;
use Lc\CaracoleBundle\Factory\SectionFactoryTrait;
use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
use Lc\CaracoleBundle\Model\Order\OrderShopInterface;
use Lc\CaracoleBundle\Model\Order\OrderStatusModel;
@@ -15,26 +16,16 @@ use Symfony\Component\EventDispatcher\EventDispatcherInterface;

class OrderShopFactory extends AbstractFactory
{
protected EventDispatcherInterface $eventDispatcher;
protected OrderStatusHistoryFactory $orderStatusHistoryFactory;

public function __construct(
EventDispatcherInterface $eventDispatcher,
OrderStatusHistoryFactory $orderStatusHistoryFactory
) {
$this->eventDispatcher = $eventDispatcher;
$this->orderStatusHistoryFactory = $orderStatusHistoryFactory;
}
use SectionFactoryTrait;

public function create(
SectionInterface $section,
UserInterface $user = null,
VisitorInterface $visitor = null
): OrderShopInterface {

$orderShop = new OrderShop();

$orderShop->setSection($section);
$orderShop->setSection($this->section);

$orderShopBelongTo = false;


+ 4
- 2
Factory/PointSale/PointSaleFactory.php View File

@@ -3,18 +3,20 @@
namespace Lc\CaracoleBundle\Factory\PointSale;

use App\Entity\PointSale\PointSale;
use Lc\CaracoleBundle\Factory\MerchantFactoryTrait;
use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
use Lc\CaracoleBundle\Model\PointSale\PointSaleInterface;
use Lc\SovBundle\Factory\AbstractFactory;

class PointSaleFactory extends AbstractFactory
{
use MerchantFactoryTrait;

public function create(MerchantInterface $merchant): PointSaleInterface
public function create(): PointSaleInterface
{
$pointSale = new PointSale();

$pointSale->addMerchant($merchant);
$pointSale->addMerchant($this->merchant);

return $pointSale;
}

+ 7
- 3
Factory/Product/ProductCategoryFactory.php View File

@@ -3,6 +3,8 @@
namespace Lc\CaracoleBundle\Factory\Product;

use App\Entity\Product\ProductCategory;
use Lc\CaracoleBundle\Factory\MerchantFactoryTrait;
use Lc\CaracoleBundle\Factory\SectionFactoryTrait;
use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
use Lc\CaracoleBundle\Model\Product\ProductCategoryInterface;
use Lc\CaracoleBundle\Model\Section\SectionInterface;
@@ -10,13 +12,15 @@ use Lc\SovBundle\Factory\AbstractFactory;

class ProductCategoryFactory extends AbstractFactory
{
use MerchantFactoryTrait;
use SectionFactoryTrait;

public function create(MerchantInterface $merchant, SectionInterface $section): ProductCategoryInterface
public function create(): ProductCategoryInterface
{
$productCategory = new ProductCategory();

$productCategory->setMerchant($merchant);
$productCategory->setSection($section);
$productCategory->setMerchant($this->merchant);
$productCategory->setSection($this->section);

return $productCategory;
}

+ 2
- 7
Factory/Product/ProductFamilyFactory.php View File

@@ -11,18 +11,13 @@ use Lc\SovBundle\Factory\AbstractFactory;

class ProductFamilyFactory extends AbstractFactory
{

use SectionFactoryTrait;

public function create(SectionInterface $section = null): ProductFamilyInterface
public function create(): ProductFamilyInterface
{
$productFamily = new ProductFamily();

if(is_null($section)) {
$productFamily->setSection($this->section);
}else{
$productFamily->setSection($section);
}
$productFamily->setSection($this->section);

return $productFamily;
}

+ 4
- 2
Factory/Reduction/ReductionCartFactory.php View File

@@ -3,18 +3,20 @@
namespace Lc\CaracoleBundle\Factory\Reduction;

use App\Entity\Reduction\ReductionCart;
use Lc\CaracoleBundle\Factory\MerchantFactoryTrait;
use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
use Lc\CaracoleBundle\Model\Reduction\ReductionCartInterface;
use Lc\SovBundle\Factory\AbstractFactory;

class ReductionCartFactory extends AbstractFactory
{
use MerchantFactoryTrait;

public function create(MerchantInterface $merchant): ReductionCartInterface
public function create(): ReductionCartInterface
{
$reductionCart = new ReductionCart();

$reductionCart->setMerchant($merchant);
$reductionCart->setMerchant($this->merchant);

return $reductionCart;
}

+ 4
- 2
Factory/Reduction/ReductionCatalogFactory.php View File

@@ -3,18 +3,20 @@
namespace Lc\CaracoleBundle\Factory\Reduction;

use App\Entity\Reduction\ReductionCatalog;
use Lc\CaracoleBundle\Factory\MerchantFactoryTrait;
use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
use Lc\CaracoleBundle\Model\Reduction\ReductionCatalogInterface;
use Lc\SovBundle\Factory\AbstractFactory;

class ReductionCatalogFactory extends AbstractFactory
{
use MerchantFactoryTrait;

public function create(MerchantInterface $merchant): ReductionCatalogInterface
public function create(): ReductionCatalogInterface
{
$reductionCatalog = new ReductionCatalog();

$reductionCatalog->setMerchant($merchant);
$reductionCatalog->setMerchant($this->merchant);

return $reductionCatalog;
}

+ 4
- 2
Factory/Reduction/ReductionCreditFactory.php View File

@@ -3,18 +3,20 @@
namespace Lc\CaracoleBundle\Factory\Reduction;

use App\Entity\Reduction\ReductionCredit;
use Lc\CaracoleBundle\Factory\MerchantFactoryTrait;
use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
use Lc\CaracoleBundle\Model\Reduction\ReductionCreditInterface;
use Lc\SovBundle\Factory\AbstractFactory;

class ReductionCreditFactory extends AbstractFactory
{
use MerchantFactoryTrait;

public function create(MerchantInterface $merchant): ReductionCreditInterface
public function create(): ReductionCreditInterface
{
$reductionCredit = new ReductionCredit();

$reductionCredit->setMerchant($merchant);
$reductionCredit->setMerchant($this->merchant);

return $reductionCredit;
}

+ 11
- 4
Factory/Reminder/ReminderFactory.php View File

@@ -2,8 +2,11 @@

namespace Lc\CaracoleBundle\Factory\Reminder;

use App\Entity\Merchant\Merchant;
use Lc\CaracoleBundle\Factory\MerchantFactoryTrait;
use Lc\CaracoleBundle\Factory\SectionFactoryTrait;
use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
use Lc\CaracoleBundle\Model\Section\SectionInterface;
use Lc\SovBundle\Factory\Reminder\ReminderFactory as SovReminderFactory;
use Lc\SovBundle\Model\Reminder\ReminderInterface;

@@ -12,12 +15,16 @@ class ReminderFactory extends SovReminderFactory
use MerchantFactoryTrait;
use SectionFactoryTrait;

public function create(string $crudAction = null, string $crudControllerFqcn = null, int $entityId = null): ReminderInterface
{
public function create(
string $crudAction = null,
string $crudControllerFqcn = null,
int $entityId = null
): ReminderInterface {

$reminder = parent::create($crudAction, $crudControllerFqcn, $entityId);

$reminder->setMerchant($this->merchant) ;
$reminder->setSection($this->section) ;
$reminder->setMerchant($this->merchant);
$reminder->setSection($this->section);

return $reminder;
}

+ 4
- 4
Factory/Section/OpeningFactory.php View File

@@ -3,23 +3,23 @@
namespace Lc\CaracoleBundle\Factory\Section;

use App\Entity\Section\Opening;
use Lc\CaracoleBundle\Model\Section\SectionInterface;
use Lc\CaracoleBundle\Factory\SectionFactoryTrait;
use Lc\SovBundle\Factory\AbstractFactory;
use Lc\SovBundle\Model\User\GroupUserInterface;

class OpeningFactory extends AbstractFactory
{
use SectionFactoryTrait;

public function create(
SectionInterface $section,
int $day,
int $day = null,
\DateTime $timeStart = null,
\DateTime $timeEnd = null,
GroupUserInterface $groupUser = null
): Opening {
$opening = new Opening();

$opening->setSection($section);
$opening->setSection($this->section);
$opening->setDay($day);
$opening->setTimeStart($timeStart);
$opening->setTimeEnd($timeEnd);

+ 4
- 3
Factory/Section/SectionFactory.php View File

@@ -3,18 +3,19 @@
namespace Lc\CaracoleBundle\Factory\Section;

use App\Entity\Section\Section;
use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
use Lc\CaracoleBundle\Factory\MerchantFactoryTrait;
use Lc\CaracoleBundle\Model\Section\SectionInterface;
use Lc\SovBundle\Factory\AbstractFactory;

class SectionFactory extends AbstractFactory
{
use MerchantFactoryTrait;

public function create(MerchantInterface $merchant): SectionInterface
public function create(): SectionInterface
{
$section = new Section();

$section->setMerchant($merchant);
$section->setMerchant($this->merchant);

return $section;
}

+ 1
- 2
Factory/SectionFactoryTrait.php View File

@@ -6,7 +6,7 @@ use Lc\CaracoleBundle\Model\Section\SectionInterface;

trait SectionFactoryTrait
{
public ?SectionInterface $section = null;
protected SectionInterface $section;

public function setSection(SectionInterface $section)
{
@@ -14,5 +14,4 @@ trait SectionFactoryTrait

return $this;
}

}

+ 3
- 2
Factory/Setting/MerchantSettingFactory.php View File

@@ -10,12 +10,13 @@ use Lc\SovBundle\Model\File\FileInterface;

class MerchantSettingFactory extends AbstractFactory
{
use MerchantFactoryTrait;

public function create(MerchantInterface $merchant, string $name, string $text = null, \DateTime $date = null, FileInterface $file = null)
public function create(string $name, string $text = null, \DateTime $date = null, FileInterface $file = null)
{
$merchantSetting = new MerchantSetting();

$merchantSetting->setMerchant($merchant);
$merchantSetting->setMerchant($this->merchant);
$merchantSetting->setName($name);
$merchantSetting->setText($text);
$merchantSetting->setDate($date);

+ 3
- 2
Factory/Setting/SectionSettingFactory.php View File

@@ -10,12 +10,13 @@ use Lc\SovBundle\Model\File\FileInterface;

class SectionSettingFactory extends AbstractFactory
{
use SectionFactoryTrait;

public function create(SectionInterface $section, string $name, string $text = null, \DateTime $date = null, FileInterface $file = null)
public function create(string $name, string $text = null, \DateTime $date = null, FileInterface $file = null)
{
$merchantSetting = new SectionSetting();

$merchantSetting->setSection($section);
$merchantSetting->setSection($this->section);
$merchantSetting->setName($name);
$merchantSetting->setText($text);
$merchantSetting->setDate($date);

+ 1
- 0
Factory/Site/NewsFactory.php View File

@@ -3,6 +3,7 @@
namespace Lc\CaracoleBundle\Factory\Site;

use Lc\CaracoleBundle\Factory\MerchantFactoryTrait;
use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
use Lc\SovBundle\Factory\Site\NewsFactory as SovNewsFactory;
use Lc\SovBundle\Model\Site\NewsInterface;


+ 1
- 0
Factory/Site/PageFactory.php View File

@@ -4,6 +4,7 @@ namespace Lc\CaracoleBundle\Factory\Site;

use Lc\CaracoleBundle\Factory\MerchantFactoryTrait;
use Lc\CaracoleBundle\Factory\SectionFactoryTrait;
use Lc\CaracoleBundle\Model\Section\SectionInterface;
use Lc\SovBundle\Factory\Site\PageFactory as SovPageFactory;
use Lc\SovBundle\Model\Site\PageInterface;


+ 1
- 0
Factory/Ticket/TicketFactory.php View File

@@ -4,6 +4,7 @@ namespace Lc\CaracoleBundle\Factory\Ticket;

use Lc\CaracoleBundle\Factory\MerchantFactoryTrait;
use Lc\CaracoleBundle\Factory\SectionFactoryTrait;
use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
use Lc\SovBundle\Factory\Ticket\TicketFactory as SovTicketFactory;
use Lc\SovBundle\Model\Ticket\TicketInterface;


+ 1
- 0
Factory/User/GroupUserFactory.php View File

@@ -3,6 +3,7 @@
namespace Lc\CaracoleBundle\Factory\User;

use Lc\CaracoleBundle\Factory\MerchantFactoryTrait;
use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
use Lc\SovBundle\Model\User\GroupUserInterface;
use Lc\SovBundle\Factory\User\GroupUserFactory as SovGroupUserFactory;


+ 1
- 1
Factory/User/UserMerchantFactory.php View File

@@ -14,7 +14,7 @@ class UserMerchantFactory extends AbstractFactory
use MerchantFactoryTrait;

// createUserMerchant
public function create(UserInterface $user): UserMerchantInterface
public function create(UserInterface $user = null): UserMerchantInterface
{
$userMerchant = new UserMerchant();


+ 1
- 1
Factory/User/VisitorFactory.php View File

@@ -8,7 +8,7 @@ use Lc\SovBundle\Factory\AbstractFactory;

class VisitorFactory extends AbstractFactory
{
public function create(string $cookie, string $ip): VisitorInterface
public static function create(string $cookie, string $ip): VisitorInterface
{
$visitor = new Visitor();


+ 1
- 103
Model/Order/OrderShopModel.php View File

@@ -11,6 +11,7 @@ use Lc\CaracoleBundle\Model\Address\AddressInterface;
use Lc\CaracoleBundle\Model\Credit\CreditHistoryInterface;
use Lc\CaracoleBundle\Model\File\DocumentInterface;
use Lc\CaracoleBundle\Model\File\DocumentModel;
use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface;
use Lc\CaracoleBundle\Model\Product\ProductFamilyModel;
use Lc\CaracoleBundle\Model\Product\ProductInterface;
use Lc\CaracoleBundle\Model\Section\SectionInterface;
@@ -155,85 +156,6 @@ abstract class OrderShopModel extends AbstractLightEntity implements FilterSecti
}
}

public function countQuantities()
{
return self::countQuantitiesByOrderProducts($this->getOrderProducts());
}

public static function countQuantitiesByOrderProducts($orderProducts = [])
{
$count = 0;

foreach ($orderProducts as $orderProduct) {
$count += $orderProduct->getQuantityOrder();
}

return $count;
}

public function getOrderProductsByParentCategory()
{
$categoriesArray = [];

foreach ($this->getOrderProducts() as $orderProduct) {
$productCategories = $orderProduct->getProduct()->getProductFamily()->getProductCategories();
$category = $productCategories[0]->getParentCategory();
$labelCategory = $category->getTitle();
if (!isset($categoriesArray[$labelCategory])) {
$categoriesArray[$labelCategory] = [];
}
$categoriesArray[$labelCategory][] = $orderProduct;
}

return $categoriesArray;
}

public function hasOrderProductAlreadyInCart($orderProductTest)
{
foreach ($this->getOrderProducts() as $orderProduct) {
if ($orderProduct->getProduct() == $orderProductTest->getProduct()) {
return $orderProduct;
}
}

return false;
}

public function getOrderProductsByProductFamily($productFamily)
{
$arrayOrderProducts = [];

foreach ($this->getOrderProducts() as $orderProduct) {
if ($orderProduct->getProduct()->getProductFamily() == $productFamily) {
$arrayOrderProducts[] = $orderProduct;
}
}

return $arrayOrderProducts;
}

public function getQuantityOrderByProduct(ProductInterface $product, $byWeight = false)
{
$quantity = 0;
$productFamily = $product->getProductFamily();
$behaviorCountStock = $productFamily->getBehaviorCountStock();

foreach ($this->getOrderProducts() as $orderProduct) {
if ($orderProduct->getProduct()->getId() == $product->getId()
|| (($behaviorCountStock == ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY || $behaviorCountStock == ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_MEASURE)
&& $orderProduct->getProduct()->getProductFamily()->getId() == $productFamily->getId())) {
if ($byWeight) {
$quantity += $orderProduct->getQuantityOrder() * ($orderProduct->getQuantityProduct(
) / $orderProduct->getProduct()->getUnitInherited()->getCoefficient());
} else {
$quantity += $orderProduct->getQuantityOrder();
}
}
}
return $quantity;
}

public function getValidationDate(): ?\DateTimeInterface
{
return $this->validationDate;
@@ -646,30 +568,6 @@ abstract class OrderShopModel extends AbstractLightEntity implements FilterSecti
return $this;
}

public function isValid()
{
if ($this->getOrderStatus() && in_array(
$this->getOrderStatus()->getAlias(),
OrderStatusModel::$statusAliasAsValid
) > 0) {
return true;
}

return false;
}

public function isCart()
{
if ($this->getOrderStatus() && in_array(
$this->getOrderStatus()->getAlias(),
OrderStatusModel::$statusAliasAsCart
) > 0) {
return true;
}

return false;
}

public function getSection(): ?SectionInterface
{
return $this->section;

+ 0
- 86
Model/Product/ProductModel.php View File

@@ -75,92 +75,6 @@ abstract class ProductModel extends AbstractLightEntity implements SortableInter
return $title;
}

public function isProductSaleStatusOn()
{
if ($this->getProductFamily()->getSaleStatus() != 1) {
return false;
}

$allCategoriesSalesOff = true;
$unavailableSpecificDay = false;

foreach ($this->getProductFamily()->getProductCategories() as $category) {
if ($category->getParent()) {
if ($category->getSaleStatus() && $category->getParent()->getSaleStatus()) {
$allCategoriesSalesOff = false;
}
} else {
if ($category->getSaleStatus()) {
$allCategoriesSalesOff = false;
}
}

// specific day
// @TODO : spécifique pdl ?
$displaySpecificDay = $category->getDisplaySpecificDay();
if ($displaySpecificDay && $displaySpecificDay != date('N')) {
$unavailableSpecificDay = true;
}
}

if ($allCategoriesSalesOff) {
return false;
}

if ($unavailableSpecificDay) {
return false;
}

return true;
}

// isProductAvailable
public function isAvailable($quantityOrder = 0, $checkCart = false, $orderShop = null)
{
if ($this->getStatus() != 1 || $this->getProductFamily()->getStatus() != 1 || !$this->isProductSaleStatusOn()) {
return false;
}

// @TODO : orderShop à définir où est appelé isProductAvailable
if ($checkCart && !$orderShop) {
throw new \Exception("Attention jeune padawan : définir le orderShop à l'endroit où est appelé isProductAvailable");
}

$productFamily = $this->getProductFamily();
$quantityAsked = $quantityOrder;

if ($productFamily->getBehaviorCountStock() == ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_MEASURE) {
if (!$quantityOrder) {
$quantityAsked = $orderShop->getQuantityOrderByProduct($this, true);
} else {
$quantityAsked = ($this->getQuantityInherited() / $this->getUnitInherited()->getCoefficient()) * $quantityOrder;
}

if ($checkCart) {
$quantityAsked += $orderShop->getQuantityOrderByProduct($this, true);
}
}

if (($productFamily->getBehaviorCountStock() == ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY
|| $productFamily->getBehaviorCountStock() == ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT)) {

if (!$quantityOrder) {
$quantityAsked = $orderShop->getQuantityOrderByProduct($this);
}

if ($checkCart) {
$quantityAsked += $orderShop->getQuantityOrderByProduct($this);
}
}

if ($this->getAvailableQuantityInherited() >= $quantityAsked
|| $productFamily->getBehaviorCountStock() == ProductFamilyModel::BEHAVIOR_COUNT_STOCK_UNLIMITED) {
return true;
} else {
return false;
}
}

// getProductQuantityMaxAddCart
public function getQuantityMaxAddCart(OrderShopInterface $orderShop)
{

+ 8
- 9
Repository/Config/TaxRateStore.php View File

@@ -2,32 +2,31 @@

namespace Lc\CaracoleBundle\Repository\Config;

use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
use Lc\CaracoleBundle\Resolver\MerchantResolver;
use Lc\SovBundle\Repository\AbstractStore;

class TaxRateStore extends AbstractStore
{
protected TaxRateRepositoryQuery $query;
protected MerchantResolver $merchantResolver;

public function __construct(TaxRateRepositoryQuery $query, MerchantResolver $merchantResolver)
public function __construct(TaxRateRepositoryQuery $query)
{
$this->query = $query;
$this->merchantResolver = $merchantResolver;
}

public function getAsArray()
public function getAsArray(MerchantInterface $merchant)
{
$query = $this->query->create();
$taxRates = $this->query->create()->find();
$taxRatesList = [];

$taxRatesList = array();
foreach ($query->find() as $taxRate) {
foreach ($taxRates as $taxRate) {
$taxRatesList[$taxRate->getId()]['title'] = $taxRate->getTitle();
$taxRatesList[$taxRate->getId()]['value'] = $taxRate->getValue();
}

$taxRatesList['default']['title'] = $this->merchantResolver->getCurrent()->getTaxRate()->getTitle();
$taxRatesList['default']['value'] = $this->merchantResolver->getCurrent()->getTaxRate()->getValue();
$taxRatesList['default']['title'] = $merchant->getTaxRate()->getTitle();
$taxRatesList['default']['value'] = $merchant->getTaxRate()->getValue();

return $taxRatesList;
}

+ 2
- 1
Repository/Config/UnitStore.php View File

@@ -13,7 +13,8 @@ class UnitStore extends AbstractStore
$this->query = $query;
}

public function getAsArray(){
public function getAsArray()
{
$query = $this->query->create();

foreach ($query->find() as $unit) {

+ 8
- 8
Repository/Credit/CreditHistoryStore.php View File

@@ -18,28 +18,28 @@ class CreditHistoryStore extends AbstractStore
$this->query = $query;
}

//findAllByDateStartEnd
//findAllByDateStartEnd
public function getByDateStartEnd(DateTime $dateStart, DateTime $dateEnd): array
{
$query = $this->query->create();

$query
->filterByJoinUserMerchant($this->merchant)
->filterByDateStart($dateStart)
->filterByDateEnd($dateEnd)
->orderBy('.createdAt');
->filterByJoinUserMerchant($this->merchant)
->filterByDateStart($dateStart)
->filterByDateEnd($dateEnd)
->orderBy('.createdAt');

return $query->find();
}

//findAllByUserMerchant
//findAllByUserMerchant
public function getByUserMerchant(UserMerchant $userMerchant): array
{
$query = $this->query->create();

$query
->filterByUserMerchant($userMerchant)
->orderBy('.createdAt', 'DESC');
->filterByUserMerchant($userMerchant)
->orderBy('.createdAt', 'DESC');

return $query->find();
}

+ 0
- 29
Repository/Order/OrderProductStore.php View File

@@ -14,33 +14,4 @@ class OrderProductStore extends AbstractStore
{
$this->query = $query;
}

// getOrderProductsFormOrderShopsGroupByStorageOrder
public function getByOrderShopsGroupByStorageOrder(array $orderShops): array
{
$orderProductsByStorageOrder = [];

foreach ($orderShops as $orderShop) {
foreach ($orderShop->getOrderProducts() as $orderProduct) {

if ($orderProduct->getProduct() && $orderProduct->getProduct()->getProductFamily()) {

$storageOrder = 0;
if ($orderProduct->getProduct()->getProductFamily()->getStorageOrder()) $storageOrder = $productFamily->getStorageOrder();

if (!isset($orderProductsByStorageOrder[$storageOrder])) {
$orderProductsByStorageOrder[$productFamily->getId()] = [
'order_products' => [],
'total_quantity_weight' => 0,
];
}

$orderProductsByStorageOrder[$storageOrder]['order_products'][] = $orderProduct;
$orderProductsByStorageOrder[$storageOrder]['total_quantity_weight'] += ($orderProduct->getQuantityProduct() / $orderProduct->getUnit()->getCoefficient()) * $orderProduct->getQuantityOrder();
}
}
}

return $orderProductsByStorageOrder;
}
}

+ 59
- 198
Repository/Order/OrderShopStore.php View File

@@ -19,6 +19,7 @@ use Lc\CaracoleBundle\Repository\Section\SectionStore;
use Lc\CaracoleBundle\Resolver\OpeningResolver;
use Lc\CaracoleBundle\Repository\SectionStoreTrait;
use Lc\CaracoleBundle\Resolver\Price\PriceResolver;
use Lc\CaracoleBundle\Solver\Price\PriceSolver;
use Lc\SovBundle\Model\User\UserInterface;
use Lc\SovBundle\Repository\AbstractStore;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
@@ -31,7 +32,7 @@ class OrderShopStore extends AbstractStore

protected OrderShopRepositoryQuery $query;
protected EntityManagerInterface $entityManager;
protected PriceResolver $priceResolver;
protected PriceSolver $priceSolver;
protected DocumentBuilder $documentBuilder;
protected ReductionCreditStore $reductionCreditStore;
protected SectionStore $sectionStore;
@@ -45,7 +46,7 @@ class OrderShopStore extends AbstractStore
public function __construct(
OrderShopRepositoryQuery $query,
EntityManagerInterface $entityManager,
PriceResolver $priceResolver,
PriceSolver $priceSolver,
DocumentBuilder $documentBuilder,
ReductionCreditStore $reductionCreditStore,
SectionStore $sectionStore,
@@ -58,7 +59,7 @@ class OrderShopStore extends AbstractStore
) {
$this->query = $query;
$this->entityManager = $entityManager;
$this->priceResolver = $priceResolver;
$this->priceSolver = $priceSolver;
$this->documentBuilder = $documentBuilder;
$this->reductionCreditStore = $reductionCreditStore;
$this->sectionStore = $sectionStore;
@@ -143,7 +144,7 @@ class OrderShopStore extends AbstractStore

public function getNextIdValidOrder(Section $section)
{
$lastOrder = $this->getOneLastOrderValid($section);
$lastOrder = $this->getOneLastValid($section);

if ($lastOrder) {
return intval($lastOrder->getIdValidOrder() + 1);
@@ -152,146 +153,6 @@ class OrderShopStore extends AbstractStore
}
}

// getOrderDatas
public function getDatas(OrderShopInterface $orderShop, UserInterface $user = null): array
{
$data = [];

$data['order'] = $orderShop;

if ($orderShop) {
$data['count'] = $orderShop->countQuantities();
$data['total_with_tax'] = $this->priceResolver->getTotalWithTax($orderShop);
$data['order_products_by_category'] = $orderShop->getOrderProductsByParentCategory();
$data['total_remaining_to_be_paid'] = $this->getTotalRemainingToBePaid($orderShop);
}
return $data;
}

public function getAsJsonObject(OrderShopInterface $orderShop): array
{
$data['id'] = $orderShop->getId();
$data['user'] = $orderShop->getUser()->getSummary();
$data['orderStatus'] = $orderShop->getOrderStatus()->__toString();
$data['deliveryAddress'] = $orderShop->getDeliveryAddress()->getSummary();
$data['invoiceAddress'] = $orderShop->getInvoiceAddress()->getSummary();
$data['total'] = $this->priceResolver->getTotal($orderShop);
$data['totalWithTax'] = $this->priceResolver->getTotalWithTax($orderShop);
$data['totalWithTaxAndReduction'] = $this->priceResolver->getTotalWithTax($orderShop);
$i = 0;

foreach ($orderShop->getOrderProductsByParentCategory() as $labelCategory => $orderProducts) {
foreach ($orderProducts as $orderProduct) {
$data['orderProducts'][$i]['id'] = $orderProduct->getId();
$data['orderProducts'][$i]['product'] = $orderProduct->getProduct()->getId();
$data['orderProducts'][$i]['quantityOrder'] = $orderProduct->getQuantityOrder();
$data['orderProducts'][$i]['labelCategory'] = $labelCategory;
$data['orderProducts'][$i]['title'] = $orderProduct->getTitle();
$data['orderProducts'][$i]['price'] = $this->priceResolver->getPrice($orderProduct);
$data['orderProducts'][$i]['priceWithTax'] = $this->priceResolver->getPriceWithTax($orderProduct);
$data['orderProducts'][$i]['priceWithTaxAndReduction'] = $this->priceResolver->getPriceWithTaxAndReduction(
$orderProduct
);
$data['orderProducts'][$i]['quantity'] = $orderProduct->getQuantityOrder();
$data['orderProducts'][$i]['totalWithTaxAndReduction'] = $this->priceResolver->getTotalOrderProductsWithTaxAndReduction(
array($orderProduct)
);
$i++;
}
}

return $data;
}

public function groupOrderProductsByProductFamily(array $orderProducts): array
{
$orderProductsByProductFamily = [];
foreach ($orderProducts as $orderProduct) {
if ($orderProduct->getProduct() && $orderProduct->getProduct()->getProductFamily()) {
$productFamily = $orderProduct->getProduct()->getProductFamily();
if (!isset($orderProductsByProductFamily[$productFamily->getId()])) {
$orderProductsByProductFamily[$productFamily->getId()] = [
'order_products' => [],
'total_quantity_weight' => 0,
];
}
$orderProductsByProductFamily[$productFamily->getId()]['order_products'][] = $orderProduct;
$orderProductsByProductFamily[$productFamily->getId(
)]['total_quantity_weight'] += ($orderProduct->getQuantityProduct() / $orderProduct->getUnit(
)->getCoefficient()) * $orderProduct->getQuantityOrder();
}
}

return $orderProductsByProductFamily;
}

// isOrderShopPositiveAmount
public function isPositiveAmount(OrderShopInterface $orderShop)
{
return $this->priceResolver->getTotalWithTax($orderShop) >= 0;
}

public function isPaid(OrderShopInterface $orderShop, $mergeComplementaryOrderShop = false)
{
$totalOrderPayments = $this->getTotalOrderPayments($orderShop, $mergeComplementaryOrderShop);
$totalOrder = $this->priceResolver->getTotalWithTax($orderShop);

if ((abs($totalOrderPayments - $totalOrder) < 0.00001
|| $totalOrderPayments >= $totalOrder)
&& $totalOrder > 0) {
return true;
} else {
return false;
}
}

public function getTotalOrderPayments(OrderShopInterface $orderShop, $mergeComplementaryOrderShop = false): float
{
$totalAmount = floatval(0);
foreach ($orderShop->getOrderPayments() as $orderPayment) {
$totalAmount = $orderPayment->getAmount() + $totalAmount;
}
if ($mergeComplementaryOrderShop) {
foreach ($orderShop->getComplementaryOrderShops() as $complementaryOrderShop) {
foreach ($complementaryOrderShop->getOrderPayments() as $orderPayment) {
$totalAmount = $orderPayment->getAmount() + $totalAmount;
}
}
}
return $totalAmount;
}

public function getTotalRemainingToBePaid(OrderShopInterface $orderShop): float
{
return $this->priceResolver->getTotalWithTax($orderShop) - $this->getTotalOrderPayments($orderShop);
}

// isOrderShopPositiveAmountRemainingToBePaid
public function isPositiveAmountRemainingToBePaid(OrderShopInterface $orderShop): bool
{
return $this->getTotalRemainingToBePaid($orderShop) > 0;
}

public function getCartByUserOrCreateIt($user)
{
$newOrderShop = $this->em->getRepository(OrderShopInterface::class)->findCartCurrent(['user' => $user]);
if ($newOrderShop === null) {
$newOrderShop = $this->createOrderShop(
array(
'user' => $user,
'merchant' => $this->merchantUtils->getMerchantUser()
)
);
}

return $newOrderShop;
}

public function isCartAllowToBeOrder(OrderShopInterface $orderShop)
{
return true;
}

// countValidOrderShopByUserAllMerchant
public function countValidByUserAllMerchant($user)
{
@@ -317,59 +178,6 @@ class OrderShopStore extends AbstractStore
);
}

/*
public function getCartCurrent(SectionInterface $section, UserInterface $user = null, VisitorInterface $visitor = null)
{
$paramsSearchOrderShop = [];

$user = $this->security->getUser();
$visitor = $this->userUtils->getVisitorCurrent();

$orderShop = null;
$orderShopUser = null;
$orderShopVisitor = null;

if ($user) {
$orderShopUser = $this->orderShopRepo->findCartCurrent(
[
'user' => $user
]
);
}

if ($visitor) {
$orderShopVisitor = $this->orderShopRepo->findCartCurrent(
[
'visitor' => $visitor
]
);
}

if ($orderShopUser || $orderShopVisitor) {
// merge
if ($orderShopUser && $orderShopVisitor && $orderShopUser != $orderShopVisitor
&& $orderShopVisitor->getOrderProducts() && count($orderShopVisitor->getOrderProducts())
&& $orderShopUser->getOrderStatus()->getAlias() == OrderStatus::ALIAS_CART) {
$orderShop = $this->mergeOrderShops($orderShopUser, $orderShopVisitor);
$this->utils->addFlash(
'success',
"Votre panier visiteur vient d'être fusionné avec votre panier client."
);
} else {
$orderShop = ($orderShopUser) ? $orderShopUser : $orderShopVisitor;
}
// set user
if ($orderShop && $user && !$orderShop->getUser()) {
$orderShop->setUser($user);
$orderShop->setVisitor(null);
$this->em->persist($orderShop);
$this->em->flush();
}
}

return $orderShop;
}*/

// countValidOrderWithReductionCredit
public function countValidWithReductionCredit(
OrderReductionCreditInterface $reductionCredit,
@@ -392,7 +200,7 @@ class OrderShopStore extends AbstractStore
// countValidOrderWithReductionCart
public function countValidWithReductionCart(
OrderReductionCartInterface $reductionCart
): string {
): int {
$query = $this->query->create();
$query
->selectCount()
@@ -615,4 +423,57 @@ class OrderShopStore extends AbstractStore

return $query->find();
}

/*
public function getCartCurrent(SectionInterface $section, UserInterface $user = null, VisitorInterface $visitor = null)
{
$paramsSearchOrderShop = [];

$user = $this->security->getUser();
$visitor = $this->userUtils->getVisitorCurrent();

$orderShop = null;
$orderShopUser = null;
$orderShopVisitor = null;

if ($user) {
$orderShopUser = $this->orderShopRepo->findCartCurrent(
[
'user' => $user
]
);
}

if ($visitor) {
$orderShopVisitor = $this->orderShopRepo->findCartCurrent(
[
'visitor' => $visitor
]
);
}

if ($orderShopUser || $orderShopVisitor) {
// merge
if ($orderShopUser && $orderShopVisitor && $orderShopUser != $orderShopVisitor
&& $orderShopVisitor->getOrderProducts() && count($orderShopVisitor->getOrderProducts())
&& $orderShopUser->getOrderStatus()->getAlias() == OrderStatus::ALIAS_CART) {
$orderShop = $this->mergeOrderShops($orderShopUser, $orderShopVisitor);
$this->utils->addFlash(
'success',
"Votre panier visiteur vient d'être fusionné avec votre panier client."
);
} else {
$orderShop = ($orderShopUser) ? $orderShopUser : $orderShopVisitor;
}
// set user
if ($orderShop && $user && !$orderShop->getUser()) {
$orderShop->setUser($user);
$orderShop->setVisitor(null);
$this->em->persist($orderShop);
$this->em->flush();
}
}

return $orderShop;
}*/
}

+ 4
- 98
Repository/Product/ProductFamilyStore.php View File

@@ -6,6 +6,7 @@ use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface;
use Lc\CaracoleBundle\Model\Product\ProductFamilyModel;
use Lc\CaracoleBundle\Repository\SectionStoreTrait;
use Lc\CaracoleBundle\Resolver\Price\PriceResolver;
use Lc\CaracoleBundle\Solver\Price\PriceSolver;
use Lc\SovBundle\Repository\AbstractStore;

class ProductFamilyStore extends AbstractStore
@@ -13,106 +14,11 @@ class ProductFamilyStore extends AbstractStore
use SectionStoreTrait;

protected ProductFamilyRepositoryQuery $query;
protected PriceResolver $priceResolver;
protected PriceSolver $priceSolver;

public function __construct(ProductFamilyRepositoryQuery $query, PriceResolver $priceResolver)
public function __construct(ProductFamilyRepositoryQuery $query, PriceSolver $priceSolver)
{
$this->query = $query;
$this->priceResolver = $priceResolver;
}

public function isOneProductAvailableAddCart(array $products): bool
{
foreach ($products as $product) {
if ($product->isAvailable(1, true)) {
return true;
}
}

return false;
}

public function getMultiplyingFactor($productFamily)
{
if ($productFamily->getBehaviorPrice() == ProductFamilyModel::BEHAVIOR_PRICE_BY_PIECE) {
if ($productFamily->getBuyingPrice() > 0) {
return number_format(
$this->priceResolver->getPriceWithTax($productFamily) / $productFamily->getBuyingPrice(),
3
);
}
} elseif ($productFamily->getBehaviorPrice() == ProductFamilyModel::BEHAVIOR_PRICE_BY_REFERENCE_UNIT) {
if ($productFamily->getBuyingPriceByRefUnit() > 0) {
return number_format(
$this->priceResolver->getPriceByRefUnitWithTax(
$productFamily
) / $productFamily->getBuyingPriceByRefUnit(),
3
);
}
}
}

public function getCheapestProduct(ProductFamilyInterface $productFamily)
{
$priceResolver = $this->priceResolver;
return $this->getCheapestOrMostExpensiveProduct(
$productFamily,
function ($a, $b) use ($priceResolver) {
return $priceResolver->getPriceWithTaxAndReduction(
$a
) > $priceResolver->getPriceWithTaxAndReduction($b);
},
true
);
}

public function getCheapestProductByRefUnit(ProductFamilyInterface $productFamily)
{
$priceResolver = $this->priceResolver;
return $this->getCheapestOrMostExpensiveProduct(
$productFamily,
function ($a, $b) use ($priceResolver) {
return $priceResolver->getPriceByRefUnitWithTaxAndReduction(
$a
) > $priceResolver->getPriceByRefUnitWithTaxAndReduction($b);
},
false
);
}

public function getMostExpensiveProductByRefUnit(ProductFamilyInterface $productFamily)
{
$priceResolver = $this->priceResolver;
return $this->getCheapestOrMostExpensiveProduct(
$productFamily,
function ($a, $b) use ($priceResolver) {
return $priceResolver->getPriceByRefUnitWithTaxAndReduction(
$a
) < $priceResolver->getPriceByRefUnitWithTaxAndReduction($b);
},
false
);
}

private function getCheapestOrMostExpensiveProduct(
ProductFamilyInterface $productFamily,
$comparisonFunction,
$returnSelfIfNotActiveProducts
) {
if ($productFamily->getActiveProducts()) {
$products = $productFamily->getProductsOnline()->getValues();
if (count($products) > 0) {
usort($products, $comparisonFunction);
return $products[0];
}
} else {
return $productFamily->getOriginProduct();
}
if ($returnSelfIfNotActiveProducts) {
return $productFamily;
} else {
return false;
}
$this->priceSolver = $priceSolver;
}
}

+ 4
- 6
Repository/Reduction/ReductionCartStore.php View File

@@ -2,11 +2,9 @@

namespace Lc\CaracoleBundle\Repository\Reduction;

use App\Entity\Order\OrderShop;
use App\Entity\Reduction\ReductionCart;
use App\Resolver\Price\PriceResolver;
use Lc\CaracoleBundle\Model\Reduction\ReductionCartInterface;
use Lc\CaracoleBundle\Repository\Order\OrderShopStore;
use Lc\CaracoleBundle\Solver\Price\PriceSolver;
use Lc\SovBundle\Model\User\UserInterface;
use Lc\SovBundle\Repository\AbstractStore;
use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
@@ -15,18 +13,18 @@ class ReductionCartStore extends AbstractStore
{
protected ReductionCartRepositoryQuery $query;
protected OrderShopStore $orderShopStore;
protected PriceResolver $priceResolver;
protected PriceSolver $priceSolver;
protected FlashBagInterface $flashBag;

public function __construct(
ReductionCartRepositoryQuery $query,
OrderShopStore $orderShopStore,
PriceResolver $priceResolver,
PriceSolver $priceSolver,
FlashBagInterface $flashBag
) {
$this->query = $query;
$this->orderShopStore = $orderShopStore;
$this->priceResolver = $priceResolver;
$this->priceSolver = $priceSolver;
$this->flashBag = $flashBag;
}


+ 0
- 28
Repository/Reduction/ReductionCreditStore.php View File

@@ -32,34 +32,6 @@ class ReductionCreditStore extends AbstractStore
return $query->find();
}

public function getReductionCreditsAvailableByUser(UserInterface $user)
{
$reductionCredits = $this->getByTypeAndUser(ReductionCreditModel::TYPE_CREDIT, $user);

$reductionCreditsArray = [];
foreach ($reductionCredits as $reductionCredit) {
if (!$this->orderShopStore->countValidOrderWithReductionCredit($reductionCredit, $user)) {
$reductionCreditsArray[] = $reductionCredit;
}
}

return $reductionCreditsArray;
}

public function getReductionGiftsAvailableByUser($user)
{
$reductionGifts = $this->getByTypeAndUser(ReductionCreditModel::TYPE_GIFT, $user);

$reductionGiftsArray = [];
foreach ($reductionGifts as $reductionGift) {
if (!$this->orderShopStore->countValidOrderWithReductionCredit($reductionGift)) {
$reductionGiftsArray[] = $reductionGift;
}
}

return $reductionGiftsArray;
}

public function isReductionGiftUsed(ReductionCreditInterface $reductionGift)
{
if ($this->orderShopStore->countValidOrderWithReductionCredit($reductionGift)) {

+ 7
- 22
Repository/User/UserMerchantStore.php View File

@@ -5,6 +5,7 @@ namespace Lc\CaracoleBundle\Repository\User;
use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
use Lc\CaracoleBundle\Model\User\UserMerchantInterface;
use Lc\CaracoleBundle\Repository\MerchantStoreTrait;
use Lc\CaracoleBundle\Solver\User\UserMerchantSolver;
use Lc\SovBundle\Model\User\UserInterface;
use Lc\SovBundle\Repository\AbstractStore;

@@ -13,14 +14,16 @@ class UserMerchantStore extends AbstractStore
use MerchantStoreTrait;

protected UserMerchantRepositoryQuery $query;
protected UserMerchantSolver $userMerchantSolver;

public function __construct(UserMerchantRepositoryQuery $query)
public function __construct(UserMerchantRepositoryQuery $query, UserMerchantSolver $userMerchantSolver)
{
$this->query = $query;
$this->userMerchantSolver = $userMerchantSolver;
}

// getUserMerchant
public function getOneByUser(UserInterface $user)
public function getOneByUser(UserInterface $user): UserMerchantInterface
{
$query = $this->query->create();

@@ -31,27 +34,9 @@ class UserMerchantStore extends AbstractStore
return $query->findOne();
}

public function isCreditActive(UserMerchantInterface $userMerchant = null)
{
if (!$userMerchant || ($userMerchant && !$userMerchant->isCreditActive())) {
return false;
}

return true;
}

public function isCreditActiveByUser(UserInterface $user)
public function isCreditActiveByUser(UserInterface $user): bool
{
$userMerchant = $this->getOneByUser($user);
return $this->isCreditActive($userMerchant);
}

public function isCreditSufficientToPay(UserMerchantInterface $userMerchant, float $amount)
{
if ($this->isCreditActive($userMerchant) && $userMerchant->getCredit() >= $amount) {
return true;
}

return false;
return $this->userMerchantSolver->isCreditActive($userMerchant);
}
}

+ 48
- 0
Resolver/ReductionResolver.php View File

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

namespace Lc\CaracoleBundle\Resolver;

use Lc\CaracoleBundle\Model\Reduction\ReductionCreditModel;
use Lc\CaracoleBundle\Repository\Order\OrderShopStore;
use Lc\CaracoleBundle\Repository\Reduction\ReductionCreditStore;
use Lc\SovBundle\Model\User\UserInterface;

class ReductionResolver
{
protected OrderShopStore $orderShopStore;
protected ReductionCreditStore $reductionCreditStore;

public function __construct(OrderShopStore $orderShopStore, ReductionCreditStore $reductionCreditStore)
{
$this->orderShopStore = $orderShopStore;
$this->reductionCreditStore = $reductionCreditStore;
}

public function getReductionCreditsAvailableByUser(UserInterface $user)
{
$reductionCredits = $this->reductionCreditStore->getByTypeAndUser(ReductionCreditModel::TYPE_CREDIT, $user);

$reductionCreditsArray = [];
foreach ($reductionCredits as $reductionCredit) {
if (!$this->orderShopStore->countValidOrderWithReductionCredit($reductionCredit, $user)) {
$reductionCreditsArray[] = $reductionCredit;
}
}

return $reductionCreditsArray;
}

public function getReductionGiftsAvailableByUser($user)
{
$reductionGifts = $this->reductionCreditStore->getByTypeAndUser(ReductionCreditModel::TYPE_GIFT, $user);

$reductionGiftsArray = [];
foreach ($reductionGifts as $reductionGift) {
if (!$this->orderShopStore->countValidOrderWithReductionCredit($reductionGift)) {
$reductionGiftsArray[] = $reductionGift;
}
}

return $reductionGiftsArray;
}
}

+ 61
- 0
Solver/Order/OrderProductSolver.php View File

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

namespace Lc\CaracoleBundle\Solver\Order;

class OrderProductSolver
{
// groupOrderProductsByProductFamily
public function getOrderProductsByProductFamily(array $orderProducts): array
{
$orderProductsByProductFamily = [];
foreach ($orderProducts as $orderProduct) {
if ($orderProduct->getProduct() && $orderProduct->getProduct()->getProductFamily()) {
$productFamily = $orderProduct->getProduct()->getProductFamily();
if (!isset($orderProductsByProductFamily[$productFamily->getId()])) {
$orderProductsByProductFamily[$productFamily->getId()] = [
'order_products' => [],
'total_quantity_weight' => 0,
];
}
$orderProductsByProductFamily[$productFamily->getId()]['order_products'][] = $orderProduct;
$orderProductsByProductFamily[$productFamily->getId(
)]['total_quantity_weight'] += ($orderProduct->getQuantityProduct() / $orderProduct->getUnit(
)->getCoefficient()) * $orderProduct->getQuantityOrder();
}
}

return $orderProductsByProductFamily;
}

// getOrderProductsFormOrderShopsGroupByStorageOrder
public function getOrderProductsByOrderShopsGroupByStorageOrder(array $orderShops): array
{
$orderProductsByStorageOrder = [];

foreach ($orderShops as $orderShop) {
foreach ($orderShop->getOrderProducts() as $orderProduct) {
if ($orderProduct->getProduct() && $orderProduct->getProduct()->getProductFamily()) {
$productFamily = $orderProduct->getProduct()->getProductFamily();
$storageOrder = 0;

if ($productFamily->getStorageOrder()) {
$storageOrder = $productFamily->getStorageOrder();
}

if (!isset($orderProductsByStorageOrder[$storageOrder])) {
$orderProductsByStorageOrder[$productFamily->getId()] = [
'order_products' => [],
'total_quantity_weight' => 0,
];
}

$orderProductsByStorageOrder[$storageOrder]['order_products'][] = $orderProduct;
$orderProductsByStorageOrder[$storageOrder]['total_quantity_weight'] += ($orderProduct->getQuantityProduct(
) / $orderProduct->getUnit()->getCoefficient()) * $orderProduct->getQuantityOrder();
}
}
}

return $orderProductsByStorageOrder;
}
}

+ 116
- 0
Solver/Order/OrderShopSolver.php View File

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

namespace Lc\CaracoleBundle\Solver\Order;

use Lc\CaracoleBundle\Model\Order\OrderShopInterface;
use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface;
use Lc\CaracoleBundle\Model\Product\ProductFamilyModel;
use Lc\CaracoleBundle\Model\Product\ProductInterface;
use Lc\CaracoleBundle\Solver\Price\PriceSolver;

class OrderShopSolver
{
protected PriceSolver $priceSolver;

public function __construct(PriceSolver $priceSolver)
{
$this->priceSolver = $priceSolver;
}

public function countQuantities(OrderShopInterface $orderShop): int
{
return $this->countQuantitiesByOrderProducts($orderShop->getOrderProducts());
}

public function countQuantitiesByOrderProducts($orderProducts = []): int
{
$count = 0;

foreach ($orderProducts as $orderProduct) {
$count += $orderProduct->getQuantityOrder();
}

return $count;
}

public function getOrderProductsByParentCategory(OrderShopInterface $orderShop): array
{
$categoriesArray = [];

foreach ($orderShop->getOrderProducts() as $orderProduct) {
$productCategories = $orderProduct->getProduct()->getProductFamily()->getProductCategories();
$category = $productCategories[0]->getParentCategory();
$labelCategory = $category->getTitle();
if (!isset($categoriesArray[$labelCategory])) {
$categoriesArray[$labelCategory] = [];
}
$categoriesArray[$labelCategory][] = $orderProduct;
}

return $categoriesArray;
}

// getOrderProductsByProductFamily
public function getOrderProductsByProductFamily(
OrderShopInterface $orderShop,
ProductFamilyInterface $productFamily
): array {
$arrayOrderProducts = [];

foreach ($orderShop->getOrderProducts() as $orderProduct) {
if ($orderProduct->getProduct()->getProductFamily() == $productFamily) {
$arrayOrderProducts[] = $orderProduct;
}
}

return $arrayOrderProducts;
}

public function getQuantityOrderByProduct(
OrderShopInterface $orderShop,
ProductInterface $product,
$byWeight = false
): int {
$quantity = 0;
$productFamily = $product->getProductFamily();
$behaviorCountStock = $productFamily->getBehaviorCountStock();

foreach ($orderShop->getOrderProducts() as $orderProduct) {
if ($orderProduct->getProduct()->getId() == $product->getId()
|| (($behaviorCountStock == ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY || $behaviorCountStock == ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_MEASURE)
&& $orderProduct->getProduct()->getProductFamily()->getId() == $productFamily->getId())) {
if ($byWeight) {
$quantity += $orderProduct->getQuantityOrder() * ($orderProduct->getQuantityProduct(
) / $orderProduct->getProduct()->getUnitInherited()->getCoefficient());
} else {
$quantity += $orderProduct->getQuantityOrder();
}
}
}

return $quantity;
}

public function getTotalOrderPayments(OrderShopInterface $orderShop, $mergeComplementaryOrderShop = false): float
{
$totalAmount = floatval(0);
foreach ($orderShop->getOrderPayments() as $orderPayment) {
$totalAmount = $orderPayment->getAmount() + $totalAmount;
}
if ($mergeComplementaryOrderShop) {
foreach ($orderShop->getComplementaryOrderShops() as $complementaryOrderShop) {
foreach ($complementaryOrderShop->getOrderPayments() as $orderPayment) {
$totalAmount = $orderPayment->getAmount() + $totalAmount;
}
}
}

return $totalAmount;
}

public function getTotalRemainingToBePaid(OrderShopInterface $orderShop): float
{
return $this->priceSolver->getTotalWithTax($orderShop) - $this->getTotalOrderPayments($orderShop);
}

}

Resolver/Price/OrderProductPriceResolver.php → Solver/Price/OrderProductPriceSolver.php View File

@@ -1,18 +1,18 @@
<?php

namespace Lc\CaracoleBundle\Resolver\Price;
namespace Lc\CaracoleBundle\Solver\Price;

use Lc\CaracoleBundle\Model\Order\OrderProductInterface;

class OrderProductPriceResolver
class OrderProductPriceSolver
{
use PriceResolverTrait;
use PriceSolverTrait;

protected $ProductPriceResolver;
protected $productPriceResolver;

public function __construct(ProductPriceResolver $ProductPriceResolver)
public function __construct(ProductPriceSolver $ProductPriceResolver)
{
$this->ProductPriceResolver = $ProductPriceResolver;
$this->productPriceResolver = $ProductPriceResolver;
}

public function getPrice(OrderProductInterface $orderProduct, $round = false)

Resolver/Price/OrderShopPriceResolver.php → Solver/Price/OrderShopPriceSolver.php View File

@@ -1,19 +1,19 @@
<?php

namespace Lc\CaracoleBundle\Resolver\Price;
namespace Lc\CaracoleBundle\Solver\Price;

use Lc\CaracoleBundle\Model\Order\OrderReductionCreditInterface;
use Lc\CaracoleBundle\Model\Order\OrderShopInterface;
use Lc\CaracoleBundle\Model\Reduction\ReductionCartModel;
use Lc\CaracoleBundle\Model\Reduction\ReductionCreditModel;

class OrderShopPriceResolver
class OrderShopPriceSolver
{
use PriceResolverTrait;
use PriceSolverTrait;

protected OrderProductPriceResolver $orderProductPriceResolver;
protected OrderProductPriceSolver $orderProductPriceResolver;

public function __construct(OrderProductPriceResolver $orderProductPriceResolver)
public function __construct(OrderProductPriceSolver $orderProductPriceResolver)
{
$this->orderProductPriceResolver = $orderProductPriceResolver;
}

Resolver/Price/PriceResolver.php → Solver/Price/PriceSolver.php View File

@@ -1,25 +1,25 @@
<?php

namespace Lc\CaracoleBundle\Resolver\Price;
namespace Lc\CaracoleBundle\Solver\Price;

use Lc\CaracoleBundle\Doctrine\Extension\ProductPropertyInterface;
use Lc\CaracoleBundle\Model\Order\OrderProductInterface;
use Lc\CaracoleBundle\Model\Order\OrderShopInterface;

class PriceResolver
class PriceSolver
{
protected ProductPriceResolver $productPriceResolver;
protected OrderProductPriceResolver $orderProductPriceResolver;
protected OrderShopPriceResolver $orderShopPriceResolver;
protected ProductPriceSolver $productPriceSolver;
protected OrderProductPriceSolver $orderProductPriceSolver;
protected OrderShopPriceSolver $orderShopPriceSolver;

public function __construct(
ProductPriceResolver $productPriceResolver,
OrderProductPriceResolver $orderProductPriceResolver,
OrderShopPriceResolver $orderShopPriceResolver
ProductPriceSolver $productPriceSolver,
OrderProductPriceSolver $orderProductPriceSolver,
OrderShopPriceSolver $orderShopPriceSolver
) {
$this->productPriceResolver = $productPriceResolver;
$this->orderProductPriceResolver = $orderProductPriceResolver;
$this->orderShopPriceResolver = $orderShopPriceResolver;
$this->productPriceSolver = $productPriceSolver;
$this->orderProductPriceSolver = $orderProductPriceSolver;
$this->orderShopPriceSolver = $orderShopPriceSolver;
}

public function __call($name, $arguments)

Resolver/Price/PriceResolverTrait.php → Solver/Price/PriceSolverTrait.php View File

@@ -1,11 +1,11 @@
<?php

namespace Lc\CaracoleBundle\Resolver\Price;
namespace Lc\CaracoleBundle\Solver\Price;

use Lc\CaracoleBundle\Doctrine\Extension\ProductPropertyInterface;
use Lc\CaracoleBundle\Model\Order\OrderProductInterface;

trait PriceResolverTrait
trait PriceSolverTrait
{
public function applyTax($price, $taxRateValue)
{

Resolver/Price/ProductPriceResolver.php → Solver/Price/ProductPriceSolver.php View File

@@ -1,12 +1,12 @@
<?php

namespace Lc\CaracoleBundle\Resolver\Price;
namespace Lc\CaracoleBundle\Solver\Price;

use Lc\CaracoleBundle\Doctrine\Extension\ProductPropertyInterface;

class ProductPriceResolver
class ProductPriceSolver
{
use PriceResolverTrait;
use PriceSolverTrait;

public function getPrice(ProductPropertyInterface $product)
{

+ 103
- 0
Solver/Product/ProductFamilySolver.php View File

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

namespace Lc\CaracoleBundle\Solver\Product;

use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface;
use Lc\CaracoleBundle\Model\Product\ProductFamilyModel;
use Lc\CaracoleBundle\Solver\Price\PriceSolver;

class ProductFamilySolver
{
protected PriceSolver $priceSolver;

public function __construct(PriceSolver $priceSolver)
{
$this->priceSolver = $priceSolver;
}

public function getMultiplyingFactor(ProductFamilyInterface $productFamily)
{
if ($productFamily->getBehaviorPrice() == ProductFamilyModel::BEHAVIOR_PRICE_BY_PIECE) {
if ($productFamily->getBuyingPrice() > 0) {
return number_format(
$this->priceSolver->getPriceWithTax($productFamily) / $productFamily->getBuyingPrice(),
3
);
}
} elseif ($productFamily->getBehaviorPrice() == ProductFamilyModel::BEHAVIOR_PRICE_BY_REFERENCE_UNIT) {
if ($productFamily->getBuyingPriceByRefUnit() > 0) {
return number_format(
$this->priceSolver->getPriceByRefUnitWithTax(
$productFamily
) / $productFamily->getBuyingPriceByRefUnit(),
3
);
}
}
}

public function getCheapestProduct(ProductFamilyInterface $productFamily)
{
$priceSolver = $this->priceSolver;
return $this->getCheapestOrMostExpensiveProduct(
$productFamily,
function ($a, $b) use ($priceSolver) {
return $priceSolver->getPriceWithTaxAndReduction(
$a
) > $priceSolver->getPriceWithTaxAndReduction($b);
},
true
);
}

public function getCheapestProductByRefUnit(ProductFamilyInterface $productFamily)
{
$priceSolver = $this->priceSolver;
return $this->getCheapestOrMostExpensiveProduct(
$productFamily,
function ($a, $b) use ($priceSolver) {
return $priceSolver->getPriceByRefUnitWithTaxAndReduction(
$a
) > $priceSolver->getPriceByRefUnitWithTaxAndReduction($b);
},
false
);
}

public function getMostExpensiveProductByRefUnit(ProductFamilyInterface $productFamily)
{
$priceSolver = $this->priceSolver;
return $this->getCheapestOrMostExpensiveProduct(
$productFamily,
function ($a, $b) use ($priceSolver) {
return $priceSolver->getPriceByRefUnitWithTaxAndReduction(
$a
) < $priceSolver->getPriceByRefUnitWithTaxAndReduction($b);
},
false
);
}

private function getCheapestOrMostExpensiveProduct(
ProductFamilyInterface $productFamily,
$comparisonFunction,
$returnSelfIfNotActiveProducts
) {
if ($productFamily->getActiveProducts()) {
$products = $productFamily->getProductsOnline()->getValues();
if (count($products) > 0) {
usort($products, $comparisonFunction);
return $products[0];
}
} else {
return $productFamily->getOriginProduct();
}
if ($returnSelfIfNotActiveProducts) {
return $productFamily;
} else {
return false;
}
}
}



+ 110
- 0
Solver/Product/ProductSolver.php View File

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

namespace Lc\CaracoleBundle\Solver\Product;

use Lc\CaracoleBundle\Model\Product\ProductFamilyModel;
use Lc\CaracoleBundle\Model\Product\ProductInterface;

class ProductSolver
{

// isProductAvailable
public function isAvailable(ProductInterface $product, $quantityOrder = 0, $checkCart = false, $orderShop = null)
{
if ($product->getStatus() != 1 || $product->getProductFamily()->getStatus() != 1 || !$this->isProductSaleStatusOn($product)) {
return false;
}

// @TODO : orderShop à définir où est appelé isProductAvailable
if ($checkCart && !$orderShop) {
throw new \Exception("Attention jeune padawan : définir le orderShop à l'endroit où est appelé isProductAvailable");
}

$productFamily = $product->getProductFamily();
$quantityAsked = $quantityOrder;

if ($productFamily->getBehaviorCountStock() == ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_MEASURE) {
if (!$quantityOrder) {
$quantityAsked = $orderShop->getQuantityOrderByProduct($product, true);
} else {
$quantityAsked = ($product->getQuantityInherited() / $product->getUnitInherited()->getCoefficient()) * $quantityOrder;
}

if ($checkCart) {
$quantityAsked += $orderShop->getQuantityOrderByProduct($product, true);
}
}

if (($productFamily->getBehaviorCountStock() == ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY
|| $productFamily->getBehaviorCountStock() == ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT)) {

if (!$quantityOrder) {
$quantityAsked = $orderShop->getQuantityOrderByProduct($product);
}

if ($checkCart) {
$quantityAsked += $orderShop->getQuantityOrderByProduct($product);
}
}

if ($product->getAvailableQuantityInherited() >= $quantityAsked
|| $productFamily->getBehaviorCountStock() == ProductFamilyModel::BEHAVIOR_COUNT_STOCK_UNLIMITED) {
return true;
} else {
return false;
}
}

public function isOneProductAvailableAddCart(array $products): bool
{
foreach ($products as $product) {
if ($product->isAvailable(1, true)) {
return true;
}
}

return false;
}

public function isProductSaleStatusOn(ProductInterface $product)
{
if ($product->getProductFamily()->getSaleStatus() != 1) {
return false;
}

$allCategoriesSalesOff = true;
$unavailableSpecificDay = false;

foreach ($product->getProductFamily()->getProductCategories() as $category) {
if ($category->getParent()) {
if ($category->getSaleStatus() && $category->getParent()->getSaleStatus()) {
$allCategoriesSalesOff = false;
}
} else {
if ($category->getSaleStatus()) {
$allCategoriesSalesOff = false;
}
}

// specific day
// @TODO : spécifique pdl ?
$displaySpecificDay = $category->getDisplaySpecificDay();
if ($displaySpecificDay && $displaySpecificDay != date('N')) {
$unavailableSpecificDay = true;
}
}

if ($allCategoriesSalesOff) {
return false;
}

if ($unavailableSpecificDay) {
return false;
}

return true;
}



}

+ 26
- 0
Solver/User/UserMerchantSolver.php View File

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

namespace Lc\CaracoleBundle\Solver\User;

use Lc\CaracoleBundle\Model\User\UserMerchantInterface;

class UserMerchantSolver
{
public function isCreditActive(UserMerchantInterface $userMerchant = null)
{
if (!$userMerchant || ($userMerchant && !$userMerchant->isCreditActive())) {
return false;
}

return true;
}

public function isCreditSufficientToPay(UserMerchantInterface $userMerchant, float $amount)
{
if ($this->isCreditActive($userMerchant) && $userMerchant->getCredit() >= $amount) {
return true;
}

return false;
}
}

+ 75
- 0
Transformer/Order/OrderShopTransformer.php View File

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

namespace Lc\CaracoleBundle\Transformer\Order;

use Lc\CaracoleBundle\Model\Order\OrderShopInterface;
use Lc\CaracoleBundle\Resolver\ReductionResolver;
use Lc\CaracoleBundle\Solver\Order\OrderShopSolver;
use Lc\CaracoleBundle\Solver\Price\PriceSolver;
use Lc\SovBundle\Model\User\UserInterface;

class OrderShopTransformer
{
protected PriceSolver $priceSolver;
protected OrderShopSolver $orderShopSolver;
protected ReductionResolver $reductionResolver;

public function __construct(PriceSolver $priceSolver, OrderShopSolver $orderShopSolver, ReductionResolver $reductionResolver)
{
$this->priceSolver = $priceSolver;
$this->orderShopSolver = $orderShopSolver;
$this->reductionResolver = $reductionResolver;
}

// getOrderDatas
public function getDatas(OrderShopInterface $orderShop, UserInterface $user = null): array
{
$data = [];

$data['order'] = $orderShop;

if ($orderShop) {
$data['count'] = $this->orderShopSolver->countQuantities($orderShop);
$data['total_with_tax'] = $this->priceSolver->getTotalWithTax($orderShop);
$data['order_products_by_category'] = $this->orderShopSolver->getOrderProductsByParentCategory($orderShop);
$data['total_remaining_to_be_paid'] = $this->orderShopSolver->getTotalRemainingToBePaid($orderShop);
}
return $data;
}

public function getAsJsonObject(OrderShopInterface $orderShop): array
{
$data['id'] = $orderShop->getId();
$data['user'] = $orderShop->getUser()->getSummary();
$data['orderStatus'] = $orderShop->getOrderStatus()->__toString();
$data['deliveryAddress'] = $orderShop->getDeliveryAddress()->getSummary();
$data['invoiceAddress'] = $orderShop->getInvoiceAddress()->getSummary();
$data['total'] = $this->priceSolver->getTotal($orderShop);
$data['totalWithTax'] = $this->priceSolver->getTotalWithTax($orderShop);
$data['totalWithTaxAndReduction'] = $this->priceSolver->getTotalWithTax($orderShop);
$i = 0;

$orderProductsByParentCategory = $this->orderShopSolver->getOrderProductsByParentCategory($orderShop);
foreach ($orderProductsByParentCategory as $labelCategory => $orderProducts) {
foreach ($orderProducts as $orderProduct) {
$data['orderProducts'][$i]['id'] = $orderProduct->getId();
$data['orderProducts'][$i]['product'] = $orderProduct->getProduct()->getId();
$data['orderProducts'][$i]['quantityOrder'] = $orderProduct->getQuantityOrder();
$data['orderProducts'][$i]['labelCategory'] = $labelCategory;
$data['orderProducts'][$i]['title'] = $orderProduct->getTitle();
$data['orderProducts'][$i]['price'] = $this->priceSolver->getPrice($orderProduct);
$data['orderProducts'][$i]['priceWithTax'] = $this->priceSolver->getPriceWithTax($orderProduct);
$data['orderProducts'][$i]['priceWithTaxAndReduction'] = $this->priceSolver->getPriceWithTaxAndReduction(
$orderProduct
);
$data['orderProducts'][$i]['quantity'] = $orderProduct->getQuantityOrder();
$data['orderProducts'][$i]['totalWithTaxAndReduction'] = $this->priceSolver->getTotalOrderProductsWithTaxAndReduction(
array($orderProduct)
);
$i++;
}
}

return $data;
}
}

Loading…
Cancel
Save