Bladeren bron

Intégration app product édition avancé

packProduct
Fabien Normand 3 jaren geleden
bovenliggende
commit
c16c9a2f71
55 gewijzigde bestanden met toevoegingen van 1118 en 1214 verwijderingen
  1. +17
    -5
      Builder/Order/OrderProductBuilder.php
  2. +17
    -10
      Builder/Order/OrderShopBuilder.php
  3. +9
    -0
      Container/Credit/CreditHistoryContainer.php
  4. +14
    -0
      Container/Product/ProductFamilyContainer.php
  5. +1
    -1
      Controller/ControllerTrait.php
  6. +37
    -5
      Definition/MerchantSettingDefinition.php
  7. +1
    -1
      Definition/SectionSettingDefinition.php
  8. +0
    -10
      Definition/SectionSettingDefinitionInterface.php
  9. +0
    -15
      Doctrine/Extension/ProductPropertyTrait.php
  10. +1
    -1
      Event/Order/CartChangeEvent.php
  11. +2
    -14
      EventSubscriber/OpeningEventSubscriber.php
  12. +3
    -5
      EventSubscriber/SettingEventSubscriber.php
  13. +3
    -1
      Factory/Order/OrderStatusHistoryFactory.php
  14. +9
    -13
      Form/Order/OrderProductType.php
  15. +68
    -18
      Form/Order/OrderProductsType.php
  16. +5
    -14
      Form/Setting/BaseSettingType.php
  17. +180
    -0
      Form/Ticket/TicketFormType.php
  18. +0
    -4
      Model/Address/AddressInterface.php
  19. +0
    -68
      Model/Credit/CreditHistoryInterface.php
  20. +0
    -70
      Model/Credit/CreditHistoryModel.php
  21. +7
    -56
      Model/Order/OrderProductModel.php
  22. +1
    -1
      Model/Order/OrderShopModel.php
  23. +0
    -235
      Model/Product/ProductFamilyInterface.php
  24. +0
    -230
      Model/Product/ProductFamilyModel.php
  25. +0
    -33
      Model/Product/ProductInterface.php
  26. +0
    -182
      Model/Product/ProductModel.php
  27. +1
    -1
      Model/Ticket/TicketModel.php
  28. +16
    -12
      Notification/MailMailjetNotification.php
  29. +6
    -0
      Repository/Address/AddressRepositoryQuery.php
  30. +9
    -0
      Repository/Address/AddressStore.php
  31. +3
    -1
      Repository/Order/OrderProductStore.php
  32. +18
    -12
      Repository/Order/OrderShopStore.php
  33. +5
    -0
      Repository/Order/OrderStatusRepositoryQuery.php
  34. +7
    -0
      Repository/Order/OrderStatusStore.php
  35. +4
    -1
      Repository/Product/ProductFamilyStore.php
  36. +2
    -1
      Repository/Reduction/ReductionCartRepositoryQuery.php
  37. +3
    -1
      Repository/Reduction/ReductionCartStore.php
  38. +3
    -1
      Repository/Reduction/ReductionCatalogStore.php
  39. +2
    -1
      Repository/Reduction/ReductionCreditRepositoryQuery.php
  40. +3
    -1
      Repository/Reduction/ReductionCreditStore.php
  41. +53
    -0
      Resolver/OrderShopResolver.php
  42. +107
    -0
      Resolver/ProductFamilyResolver.php
  43. +34
    -8
      Resolver/SectionResolver.php
  44. +3
    -1
      Resources/translations/admin.fr.yaml
  45. +78
    -0
      Solver/Credit/CreditHistorySolver.php
  46. +65
    -0
      Solver/Order/OrderProductSolver.php
  47. +41
    -41
      Solver/Order/OrderShopSolver.php
  48. +14
    -5
      Solver/Price/OrderProductPriceSolver.php
  49. +11
    -3
      Solver/Price/OrderShopPriceSolver.php
  50. +2
    -2
      Solver/Price/PriceSolver.php
  51. +13
    -7
      Solver/Price/PriceSolverTrait.php
  52. +52
    -22
      Solver/Price/ProductPriceSolver.php
  53. +35
    -99
      Solver/Product/ProductFamilySolver.php
  54. +148
    -0
      Solver/Product/ProductSolver.php
  55. +5
    -2
      Transformer/Order/OrderShopTransformer.php

+ 17
- 5
Builder/Order/OrderProductBuilder.php Bestand weergeven

@@ -6,32 +6,44 @@ 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\Order\OrderProductSolver;
use Lc\CaracoleBundle\Solver\Price\PriceSolver;
use Lc\CaracoleBundle\Solver\Product\ProductFamilySolver;
use Lc\CaracoleBundle\Solver\Product\ProductSolver;

class OrderProductBuilder
{
protected EntityManagerInterface $entityManager;
protected PriceSolver $priceSolver;
protected OrderProductStore $orderProductStore;
protected ProductSolver $productSolver;
protected ProductFamilySolver $productFamilySolver;
protected OrderProductSolver $orderProductSolver;

public function __construct(
EntityManagerInterface $entityManager,
PriceSolver $priceSolver,
OrderProductStore $orderProductStore
OrderProductStore $orderProductStore,
ProductSolver $productSolver,
OrderProductSolver $orderProductSolver,
ProductFamilySolver $productFamilySolver
) {
$this->entityManager = $entityManager;
$this->priceSolver = $priceSolver;
$this->orderProductStore = $orderProductStore;
$this->productSolver = $productSolver;
$this->orderProductSolver = $orderProductSolver;
$this->productFamilySolver = $productFamilySolver;
}

public function init(OrderProductInterface $orderProduct) :OrderProductInterface
{
$orderProduct->setTitle($orderProduct->getTitleOrderShop());
$orderProduct->setTitle($this->orderProductSolver->getTitleOrderShop($orderProduct));
$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());
$orderProduct->setUnit($this->productSolver->getUnitInherited($orderProduct->getProduct()));
$orderProduct->setTaxRate($this->productFamilySolver->getTaxRateInherited($orderProduct->getProduct()));
$orderProduct->setQuantityProduct($this->productSolver->getQuantityInherited($orderProduct->getProduct()));

return $orderProduct;
}

+ 17
- 10
Builder/Order/OrderShopBuilder.php Bestand weergeven

@@ -38,6 +38,7 @@ use Lc\CaracoleBundle\Resolver\OpeningResolver;
use Lc\CaracoleBundle\Resolver\Price\PriceResolver;
use Lc\CaracoleBundle\Solver\Order\OrderShopSolver;
use Lc\CaracoleBundle\Solver\Price\PriceSolver;
use Lc\CaracoleBundle\Solver\Product\ProductSolver;
use Lc\CaracoleBundle\Statistic\Product\ProductsSalesStatistic;
use Lc\SovBundle\Model\User\UserInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
@@ -57,6 +58,7 @@ class OrderShopBuilder
protected EventDispatcherInterface $eventDispatcher;
protected FlashBagInterface $flashBag;
protected OpeningResolver $openingResolver;
protected ProductSolver $productSolver;

public function __construct(
EntityManagerInterface $entityManager,
@@ -70,7 +72,8 @@ class OrderShopBuilder
PriceSolver $priceSolver,
EventDispatcherInterface $eventDispatcher,
FlashBagInterface $flashBag,
OpeningResolver $openingResolver
OpeningResolver $openingResolver,
ProductSolver $productSolver
) {
$this->entityManager = $entityManager;
$this->orderShopStore = $orderShopStore;
@@ -84,6 +87,7 @@ class OrderShopBuilder
$this->eventDispatcher = $eventDispatcher;
$this->flashBag = $flashBag;
$this->openingResolver = $openingResolver;
$this->productSolver = $productSolver;
}

public function create(
@@ -91,12 +95,14 @@ class OrderShopBuilder
UserInterface $user = null,
VisitorInterface $visitor = null
): OrderShopInterface {

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

$this->setOrderStatus($orderShop, OrderStatusModel::ALIAS_CART);

//TODO flush ???
$this->entityManager->create($orderShop);
$this->entityManager->flush();

return $orderShop;
}
@@ -106,7 +112,7 @@ class OrderShopBuilder
UserInterface $user = null,
VisitorInterface $visitor = null
): OrderShopInterface {
$cart = $this->orderShopStore->getCartBy(
$cart = $this->orderShopStore->getOneCartCurrent(
[
'section' => $section,
'user' => $user,
@@ -126,7 +132,8 @@ class OrderShopBuilder
string $alias,
bool $forceByAdmin = false
): OrderShopInterface {
$orderStatus = $this->orderStatusStore->getRepositoryQuery()->findOneByAlias($alias);

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

if ($orderStatus) {
if ($orderShop->getOrderStatus() === null
@@ -170,7 +177,7 @@ class OrderShopBuilder
): bool {
$return = false;

if ($this->orderProductStore->isOrderProductAvailableAddCart($orderProductAdd, $orderShop)) {
if ($this->orderShopSolver->isOrderProductAvailableAddCart($orderProductAdd, $orderShop)) {
if ($orderProductAdd->getQuantityOrder() > 0) {
$updated = false;
$this->orderProductBuilder->init($orderProductAdd);
@@ -197,8 +204,8 @@ class OrderShopBuilder
foreach ($orderShop->getOrderProducts() as $orderProduct) {
if ($orderProduct->getProduct()->getId() == $orderProductAdd->getProduct()->getId()
&& $orderProduct->getRedelivery() == $orderProductAdd->getRedelivery()
&& (string)$this->priceResolver->getPrice($orderProduct)
== (string)$this->priceResolver->getPrice($orderProductAdd)
&& (string)$this->priceSolver->getPrice($orderProduct)
== (string)$this->priceSolver->getPrice($orderProductAdd)
&& $orderProduct->getOrderProductReductionCatalog()->compare(
$orderProductAdd->getOrderProductReductionCatalog()
)) {
@@ -225,7 +232,7 @@ class OrderShopBuilder
$this->entityManager->create($orderProductReductionCatalog);
}
//TODO est-ce un update ou un create ???
$this->entityManager->update($orderProductAdd);
$this->entityManager->persist($orderProductAdd);
$this->entityManager->update($orderShop);
}

@@ -434,7 +441,7 @@ class OrderShopBuilder
case ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_MEASURE :

//Disponibilité par unité de référence
$oldAvailability = $orderProduct->getProduct()->getAvailableQuantityInherited();
$oldAvailability = $this->productSolver->getAvailableQuantityInherited($orderProduct->getProduct());
$newAvailability = $oldAvailability - ($orderProduct->getQuantityOrder(
) * ($orderProduct->getQuantityProduct() / $orderProduct->getUnit()->getCoefficient()));

@@ -560,7 +567,7 @@ class OrderShopBuilder
}

// setDeliveryAddress
public function initDeliveryAddress(OrderShopInterface $orderShop, AddressInterface $address):void
public function initDeliveryAddress(OrderShopInterface $orderShop, AddressInterface $address = null):void
{
$orderShop->setDeliveryAddress($address);
$orderShop->setDeliveryInfos($address ? $address->getDeliveryInfos() : null);

+ 9
- 0
Container/Credit/CreditHistoryContainer.php Bestand weergeven

@@ -6,6 +6,7 @@ use Lc\CaracoleBundle\Builder\Credit\CreditHistoryBuilder;
use Lc\CaracoleBundle\Factory\Credit\CreditHistoryFactory;
use Lc\CaracoleBundle\Repository\Credit\CreditHistoryRepositoryQuery;
use Lc\CaracoleBundle\Repository\Credit\CreditHistoryStore;
use Lc\CaracoleBundle\Solver\Credit\CreditHistorySolver;

class CreditHistoryContainer
{
@@ -13,15 +14,18 @@ class CreditHistoryContainer
protected CreditHistoryRepositoryQuery $repositoryQuery;
protected CreditHistoryStore $store;
protected CreditHistoryBuilder $builder;
protected CreditHistorySolver $solver;

public function __construct(
CreditHistoryFactory $factory,
CreditHistoryRepositoryQuery $repositoryQuery,
CreditHistorySolver $solver,
CreditHistoryStore $store,
CreditHistoryBuilder $builder
) {
$this->factory = $factory;
$this->repositoryQuery = $repositoryQuery;
$this->solver = $solver;
$this->store = $store;
$this->builder = $builder;
}
@@ -36,6 +40,11 @@ class CreditHistoryContainer
return $this->repositoryQuery;
}

public function getSolver(): CreditHistorySolver
{
return $this->solver;
}

public function getStore(): CreditHistoryStore
{
return $this->store;

+ 14
- 0
Container/Product/ProductFamilyContainer.php Bestand weergeven

@@ -6,6 +6,7 @@ use Lc\CaracoleBundle\Builder\Product\ProductFamilyBuilder;
use Lc\CaracoleBundle\Factory\Product\ProductFamilyFactory;
use Lc\CaracoleBundle\Repository\Product\ProductFamilyRepositoryQuery;
use Lc\CaracoleBundle\Repository\Product\ProductFamilyStore;
use Lc\CaracoleBundle\Resolver\ProductFamilyResolver;
use Lc\CaracoleBundle\Solver\Product\ProductFamilySolver;

class ProductFamilyContainer
@@ -15,6 +16,7 @@ class ProductFamilyContainer
protected ProductFamilyRepositoryQuery $repositoryQuery;
protected ProductFamilyStore $store;
protected ProductFamilyBuilder $builder;
protected ProductFamilyResolver $resolver;

public function __construct(
ProductFamilyFactory $factory,
@@ -22,12 +24,14 @@ class ProductFamilyContainer
ProductFamilyRepositoryQuery $repositoryQuery,
ProductFamilyStore $store,
ProductFamilyBuilder $builder
ProductFamilyResolver $resolver
) {
$this->factory = $factory;
$this->solver = $solver;
$this->repositoryQuery = $repositoryQuery;
$this->store = $store;
$this->builder = $builder;
$this->resolver = $resolver;
}

public function getFactory(): ProductFamilyFactory
@@ -50,4 +54,14 @@ class ProductFamilyContainer
return $this->store;
}

public function getResolver(): ProductFamilyResolver
{
return $this->resolver;
}

public function getBuilder(): ProductFamilyBuilder
{
return $this->builder;
}

}

+ 1
- 1
Controller/ControllerTrait.php Bestand weergeven

@@ -105,7 +105,7 @@ trait ControllerTrait

public function getVisitorCurrent(): VisitorInterface
{
return $this->get(VisitorResolver::class)->getCurrent();
return $this->getVisitorContainer()->getResolver()->getCurrent();
}

public function getMerchantCurrent(): MerchantInterface

+ 37
- 5
Definition/MerchantSettingDefinition.php Bestand weergeven

@@ -7,23 +7,55 @@ use Lc\SovBundle\Definition\AbstractSettingDefinition;
class MerchantSettingDefinition extends AbstractSettingDefinition implements MerchantSettingDefinitionInterface
{
const CATEGORY_GENERAL = 'general';
const CATEGORY_EMAIL = 'email';

const SETTING_URL = 'url';
const SETTING_EMAIL_SUBJECT_PREFIX = 'emailSubjectPrefix';
const SETTING_EMAIL_FROM = 'emailFrom';
const SETTING_EMAIL_FROM_NAME = 'emailFromName';
const SETTING_EMAIL_CONTACT = 'emailContact';

public function __construct()
{
$this
->addSettingText(
->addSettingText(
[
'name' => self::SETTING_URL,
'category' => self::CATEGORY_GENERAL,
]
);

$this->addSettingText(
[
'category' => self::CATEGORY_EMAIL,
'name' => self::SETTING_EMAIL_SUBJECT_PREFIX,
]
);
$this->addSettingText(
[
'category' => self::CATEGORY_EMAIL,
'name' => self::SETTING_EMAIL_FROM,
]
);
$this->addSettingText(
[
'category' => self::CATEGORY_EMAIL,
'name' => self::SETTING_EMAIL_FROM_NAME,
]
);
$this->addSettingText(
[
'name' => self::SETTING_URL,
'category' => self::CATEGORY_GENERAL,
'category' => self::CATEGORY_EMAIL,
'name' => self::SETTING_EMAIL_CONTACT,
]
);
);
}

public function getCategories()
{
return [
self::CATEGORY_GENERAL,
self::CATEGORY_GENERAL,
self::CATEGORY_EMAIL,
];
}


+ 1
- 1
Definition/SectionSettingDefinition.php Bestand weergeven

@@ -4,7 +4,7 @@ namespace Lc\CaracoleBundle\Definition;

use Lc\SovBundle\Definition\AbstractSettingDefinition;

class SectionSettingDefinition extends AbstractSettingDefinition implements SectionSettingDefinitionInterface
class SectionSettingDefinition extends AbstractSettingDefinition
{
const CATEGORY_GENERAL = 'general';


+ 0
- 10
Definition/SectionSettingDefinitionInterface.php Bestand weergeven

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


namespace Lc\CaracoleBundle\Definition;


interface SectionSettingDefinitionInterface
{

}

+ 0
- 15
Doctrine/Extension/ProductPropertyTrait.php Bestand weergeven

@@ -44,11 +44,6 @@ trait ProductPropertyTrait
return $this->buyingPriceByRefUnit;
}

public function getBuyingPriceByRefUnitInherited(): ?float
{
return $this->getBuyingPriceByRefUnit();
}

public function setBuyingPriceByRefUnit(?float $buyingPriceByRefUnit): self
{
$this->buyingPriceByRefUnit = $buyingPriceByRefUnit;
@@ -61,11 +56,6 @@ trait ProductPropertyTrait
return $this->priceByRefUnit;
}

public function getPriceByRefUnitInherited(): ?float
{
return $this->getPriceByRefUnit();
}

public function setPriceByRefUnit(?float $priceByRefUnit): self
{
$this->priceByRefUnit = $priceByRefUnit;
@@ -85,11 +75,6 @@ trait ProductPropertyTrait
return $this;
}

public function getQuantityInherited(): ?float
{
return $this->getQuantity();
}

public function getAvailableQuantity(): ?float
{
return $this->availableQuantity;

+ 1
- 1
Event/Order/CartChangeEvent.php Bestand weergeven

@@ -13,7 +13,7 @@ class CartChangeEvent extends Event

protected OrderShopInterface $orderShop;

public function __construct(OrderShopInterface $orderShop, OrderStatusInterface $orderStatus, bool $forceByAdmin)
public function __construct(OrderShopInterface $orderShop)
{
$this->orderShop = $orderShop;
}

+ 2
- 14
EventSubscriber/OpeningEventSubscriber.php Bestand weergeven

@@ -3,28 +3,17 @@
namespace Lc\CaracoleBundle\EventSubscriber;

use Doctrine\ORM\EntityManagerInterface;
use Lc\CaracoleBundle\Definition\MerchantSettingDefinitionInterface;
use Lc\CaracoleBundle\Factory\Setting\MerchantSettingFactory;
use Lc\CaracoleBundle\Factory\Setting\SectionSettingFactory;
use Lc\CaracoleBundle\Model\Section\SectionInterface;
use Lc\CaracoleBundle\Definition\SectionSettingDefinitionInterface;
use Lc\CaracoleBundle\Repository\Merchant\MerchantRepository;
use Lc\CaracoleBundle\Repository\Section\OpeningRepositoryQuery;
use Lc\CaracoleBundle\Repository\Section\SectionRepository;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\KernelEvents;

class OpeningEventSubscriber implements EventSubscriberInterface
{
protected $entityManager;
protected $openingRepositoryQuery;
protected EntityManagerInterface $entityManager;

public function __construct(
EntityManagerInterface $entityManager,
OpeningRepositoryQuery $openingRepositoryQuery
EntityManagerInterface $entityManager
) {
$this->entityManager = $entityManager;
$this->openingRepositoryQuery = $openingRepositoryQuery;
}

public static function getSubscribedEvents()
@@ -36,7 +25,6 @@ class OpeningEventSubscriber implements EventSubscriberInterface

public function initOpenings()
{

}

}

+ 3
- 5
EventSubscriber/SettingEventSubscriber.php Bestand weergeven

@@ -4,13 +4,11 @@ namespace Lc\CaracoleBundle\EventSubscriber;

use Doctrine\ORM\EntityManagerInterface;
use Lc\CaracoleBundle\Definition\MerchantSettingDefinitionInterface;
use Lc\CaracoleBundle\Definition\SectionSettingDefinition;
use Lc\CaracoleBundle\Factory\Setting\MerchantSettingFactory;
use Lc\CaracoleBundle\Factory\Setting\SectionSettingFactory;
use Lc\CaracoleBundle\Model\Section\SectionInterface;
use Lc\CaracoleBundle\Definition\SectionSettingDefinitionInterface;
use Lc\CaracoleBundle\Repository\Merchant\MerchantRepository;
use Lc\CaracoleBundle\Repository\Merchant\MerchantStore;
use Lc\CaracoleBundle\Repository\Section\SectionRepository;
use Lc\CaracoleBundle\Repository\Section\SectionStore;
use Lc\SovBundle\Solver\Setting\SettingSolver;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
@@ -20,7 +18,7 @@ class SettingEventSubscriber implements EventSubscriberInterface
{
protected EntityManagerInterface $entityManager;
protected MerchantSettingDefinitionInterface $merchantSettingDefinition;
protected SectionSettingDefinitionInterface $sectionSettingDefinition;
protected SectionSettingDefinition $sectionSettingDefinition;
protected MerchantStore $merchantStore;
protected SectionStore $sectionStore;
protected MerchantSettingFactory $merchantSettingFactory;
@@ -30,7 +28,7 @@ class SettingEventSubscriber implements EventSubscriberInterface
public function __construct(
EntityManagerInterface $entityManager,
MerchantSettingDefinitionInterface $merchantSettingDefinition,
SectionSettingDefinitionInterface $sectionSettingDefinition,
SectionSettingDefinition $sectionSettingDefinition,
MerchantStore $merchantStore,
SectionStore $sectionStore,
MerchantSettingFactory $merchantSettingFactory,

+ 3
- 1
Factory/Order/OrderStatusHistoryFactory.php Bestand weergeven

@@ -6,17 +6,19 @@ use App\Entity\Order\OrderStatusHistory;
use Lc\CaracoleBundle\Model\Order\OrderShopInterface;
use Lc\CaracoleBundle\Model\Order\OrderStatusHistoryInterface;
use Lc\CaracoleBundle\Model\Order\OrderStatusHistoryModel;
use Lc\CaracoleBundle\Model\Order\OrderStatusInterface;
use Lc\SovBundle\Factory\AbstractFactory;

class OrderStatusHistoryFactory extends AbstractFactory
{
public function create(OrderShopInterface $orderShop, string $status, string $origin = OrderStatusHistoryModel::ORIGIN_USER): OrderStatusHistoryInterface
public function create(OrderShopInterface $orderShop, OrderStatusInterface $status, string $origin = OrderStatusHistoryModel::ORIGIN_USER): OrderStatusHistoryInterface
{
$orderStatusHistory = new OrderStatusHistory();

$orderStatusHistory->setOrderShop($orderShop);
$orderStatusHistory->setOrderStatus($status);
$orderStatusHistory->setOrigin($origin);
$orderStatusHistory->setCreatedAt(new \DateTime());

return $orderStatusHistory;
}

+ 9
- 13
Form/Order/OrderProductType.php Bestand weergeven

@@ -3,13 +3,13 @@
namespace Lc\CaracoleBundle\Form\Order;

use Doctrine\ORM\EntityManagerInterface;
use Lc\CaracoleBundle\Form\Product\ProductToIdTransformer;
use Lc\CaracoleBundle\Model\Order\OrderProductInterface;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\NumberType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Lc\CaracoleBundle\Form\Product\ProductToIdTransformer;

class OrderProductType extends AbstractType
{
@@ -24,14 +24,10 @@ class OrderProductType extends AbstractType

public function buildForm(FormBuilderInterface $builder, array $options)
{
$data = $options['data'];

$builder
->add(
'quantityOrder',
NumberType::class,
array(
'html5' => true
)
)
->add('quantityOrder', NumberType::class)
->add('product', HiddenType::class);

$builder->get('product')->addModelTransformer($this->productTransformer);
@@ -39,10 +35,10 @@ class OrderProductType extends AbstractType

public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(
[
'data_class' => $this->entityManager->getEntityName(OrderProductInterface::class),
]
);
$resolver->setDefaults([
'data_class' => $this->entityManager->getEntityName(
OrderProductInterface::class
),
]);
}
}

+ 68
- 18
Form/Order/OrderProductsType.php Bestand weergeven

@@ -2,34 +2,84 @@

namespace Lc\CaracoleBundle\Form\Order;

use App\Repository\Product\ProductFamilyStore;
use Doctrine\ORM\EntityManagerInterface;
use Lc\CaracoleBundle\Factory\Order\OrderProductFactory;
use Lc\CaracoleBundle\Solver\Product\ProductFamilySolver;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class OrderProductsType extends AbstractType
{
protected EntityManagerInterface $entityManager;
protected ProductFamilyStore $productFamilyStore;
protected OrderProductFactory $orderProductFactory;
protected ProductFamilySolver $productFamilySolver;

public function __construct(
EntityManagerInterface $entityManager,
ProductFamilyStore $productFamilyStore,
OrderProductFactory $orderProductFactory,
ProductFamilySolver $productFamilySolver
) {
$this->entityManager = $entityManager;
$this->productFamilyStore = $productFamilyStore;
$this->orderProductFactory = $orderProductFactory;
$this->productFamilySolver = $productFamilySolver;
}

public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add(
'orderProducts',
CollectionType::class,
array(
'label' => false,
'entry_type' => OrderProductType::class,
'entry_options' => ['label' => false],
'allow_add' => true,
'allow_delete' => true,
'required' => true
)
);
if (isset($options['data']['id_product_family'])) {
$idProductFamily = $options['data']['id_product_family'];
$productFamily = $this->productFamilyStore->getOneById($idProductFamily);

$builder->add('id_product_family', HiddenType::class, [
'data' => $productFamily->getId()
]);

if ($productFamily) {
if ($productFamily->getActiveProducts()
&& $productFamily->getBehaviorAddToCart() == 'multiple') {
$cpt = 0;

foreach ($this->productFamilySolver->getProductsGroupByTitle($productFamily) as $key => $product) {
$orderProduct = $this->orderProductFactory->create($product[0], 0);
$builder->add('order_product_' . $cpt, OrderProductType::class, [
'data' => $orderProduct
]);
$cpt++;
}
} else {
$product = null;
if ($productFamily->getActiveProducts()) {
$products = $productFamily->getProductsOnline();
if ($products && count($products) > 0) {
$product = $products[0];
}
} else {
$originProduct = $this->productFamilySolver->getOriginProduct($productFamily);
if ($originProduct && $originProduct->getStatus() == 1) {
$product = $originProduct;
}
}

$orderProduct = $this->orderProductFactory->create($product, 1);

$builder->add('order_product_0', OrderProductType::class, [
'data' => $orderProduct
]);
}
}
}
}

public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(
[
]
);
$resolver->setDefaults([
// Configure your form options here
]);
}
}
}

+ 5
- 14
Form/Setting/BaseSettingType.php Bestand weergeven

@@ -2,36 +2,27 @@

namespace Lc\CaracoleBundle\Form\Setting;

use FOS\CKEditorBundle\Form\Type\CKEditorType;
use Lc\CaracoleBundle\Definition\MerchantSettingDefinitionInterface;
use Lc\CaracoleBundle\Definition\SectionSettingDefinition;
use Lc\CaracoleBundle\Model\Setting\MerchantSettingInterface;
use Lc\CaracoleBundle\Model\Setting\SectionSettingInterface;
use Lc\CaracoleBundle\Definition\SectionSettingDefinitionInterface;
use Lc\SovBundle\Form\Common\FileManagerType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\DateType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\TimeType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Lc\SovBundle\Form\Setting\BaseSettingType as SovBaseSettingType;

abstract class BaseSettingType extends SovBaseSettingType
{
protected $em;
protected $merchantSettingDefinition;
protected $sectionSettingDefinition;
protected EntityManagerInterface $em;
protected MerchantSettingDefinitionInterface $merchantSettingDefinition;
protected SectionSettingDefinition $sectionSettingDefinition;

public function __construct(
EntityManagerInterface $entityManager,
MerchantSettingDefinitionInterface $merchantSettingDefinition,
SectionSettingDefinitionInterface $sectionSettingDefinition
SectionSettingDefinition $sectionSettingDefinition
) {
$this->em = $entityManager;
$this->merchantSettingDefinition = $merchantSettingDefinition;

+ 180
- 0
Form/Ticket/TicketFormType.php Bestand weergeven

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

namespace Lc\CaracoleBundle\Form\Ticket;

use Lc\CaracoleBundle\Model\Order\OrderShopInterface;
use Lc\CaracoleBundle\Repository\Order\OrderShopStore;
use Lc\CaracoleBundle\Solver\Price\PriceSolver;
use Lc\SovBundle\Component\FormComponent;
use Lc\SovBundle\Doctrine\EntityManager;
use Lc\SovBundle\Model\Ticket\TicketInterface;
use Lc\SovBundle\Model\User\UserInterface;
use Lc\SovBundle\Solver\Ticket\TicketSolver;
use Lc\SovBundle\Translation\TranslatorAdmin;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\FileType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\Validator\Constraints\File;

class TicketFormType extends AbstractType
{
protected Security $security;
protected EntityManager $entityManager;
protected TranslatorAdmin $translatorAdmin;
protected TicketSolver $ticketSolver;
protected FormComponent $formComponent;
protected OrderShopStore $orderShopStore;
protected PriceSolver $priceSolver;

public function __construct(
Security $security,
EntityManager $entityManager,
TranslatorAdmin $translatorAdmin,
TicketSolver $ticketSolver,
FormComponent $formComponent,
OrderShopStore $orderShopStore,
PriceSolver $priceSolver
) {
$this->security = $security;
$this->entityManager = $entityManager;
$this->translatorAdmin = $translatorAdmin;
$this->ticketSolver = $ticketSolver;
$this->formComponent = $formComponent;
$this->orderShopStore = $orderShopStore;
$this->priceSolver = $priceSolver;
}

public function buildForm(FormBuilderInterface $builder, array $options)
{
$isConnected = $this->security->getUser();
$entityName = $this->entityManager->getEntityName(TicketInterface::class);

if (!$isConnected) {
$builder->add(
'visitorFirstname',
TextType::class,
[
'label' => 'Prénom'
]
)
->add(
'visitorLastname',
TextType::class,
[
'label' => 'Nom'
]
)
->add(
'visitorEmail',
EmailType::class,
[
'label' => 'Email'
]
);
}

$builder->add(
'type',
ChoiceType::class,
[
'label' => 'Type',
'choices' => $this->translatorAdmin->transChoices(
$this->ticketSolver->getTypeChoices(),
'Ticket',
'type'
),
]
);

if ($isConnected) {
$builder->add(
'orderShop',
EntityType::class,
[
'class' => $this->entityManager->getEntityName(OrderShopInterface::class),
'multiple' => false,
'expanded' => false,
'choices' => $this->orderShopStore->getBy(
[
'user' => $this->security->getUser(),
'isValid' => true
]
),
'label' => 'field.default.order',
'placeholder' => '-- Choisissez une commande --',
'required' => false,
'choice_label' => function ($orderShop, $key, $value) {
return 'Commande du ' . $orderShop->getValidationDate()->format(
'd/m/Y'
) . ' (' . number_format(
$this->priceSolver->getTotalWithTax($orderShop),
2
) . ' €)';
},
'translation_domain' => 'admin',
]
);
} else {
$this->formComponent->addCaptchaType($builder);
}

$builder->add(
'subject',
TextType::class
);

$builder->add(
'message',
TextareaType::class,
[
'mapped' => false,
'label' => 'Message'
]
);

$builder->add(
'image',
FileType::class,
[
'label' => 'Photo',
'mapped' => false,
'required' => false,
'constraints' => [
new File(
[
'maxSize' => '2048k',
'mimeTypes' => [
'image/png',
'image/jpeg',
'image/jpg',
'image/gif',
],
'mimeTypesMessage' => "Mauvais format d'image (formats acceptés : jpeg, png, gif)",
]
)
],
]
);
}

/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(
[
'data_class' => $this->entityManager->getEntityName(TicketInterface::class),
]
);
}
}

+ 0
- 4
Model/Address/AddressInterface.php Bestand weergeven

@@ -2,14 +2,10 @@

namespace Lc\CaracoleBundle\Model\Address;


use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
use Lc\CaracoleBundle\Model\PointSale\PointSaleInterface;
use Lc\SovBundle\Model\User\UserInterface;

/**
* @ORM\MappedSuperclass()
*/
interface AddressInterface
{
public function getUser(): ?UserInterface;

+ 0
- 68
Model/Credit/CreditHistoryInterface.php Bestand weergeven

@@ -20,73 +20,5 @@ use Lc\SovBundle\Model\User\UserInterface;
*/
interface CreditHistoryInterface
{
public function getCreatedBy(): ?UserInterface;

public function setCreatedBy(?UserInterface $createdBy);

public function getUpdatedBy(): ?UserInterface;

public function setUpdatedBy(?UserInterface $updatedBy);

public function __toString();

public function getAmount(): ?float;

public function setAmount(?float $amount);

public function getAmountInherited(): float;

public function getMeanPaymentInherited(): string;

public function getPaidAtInherited(): ?\DateTimeInterface;

public function getReferenceInherited(): ?string;

public function getCommentInherited(): ?string;

public function getMeanPaymentInheritedLabel(): string;

public function getType(): ?string;

public function setType(string $type): CreditHistoryModel;

public function getUserMerchant(): ?UserMerchantInterface;

public function setUserMerchant(?UserMerchantInterface $userMerchant): CreditHistoryModel;

public function getOrderPayment(): ?OrderPaymentInterface;

public function setOrderPayment(?OrderPaymentInterface $orderPayment): CreditHistoryModel;

public function getOrderRefund(): ?OrderRefundInterface;

public function setOrderRefund(?OrderRefundInterface $orderRefund): CreditHistoryModel;

public function getDevAlias(): ?string;

public function setDevAlias(?string $devAlias);

public function setMeanPayment(?string $meanPayment): CreditHistoryModel;

public function getMeanPayment(): ?string;

public function getReference(): ?string;

public function setReference(?string $reference): CreditHistoryModel;

public function getPaidAt(): ?\DateTimeInterface;

public function setPaidAt(?\DateTimeInterface $paidAt): CreditHistoryModel;

public function getComment(): ?string;

public function setComment(?string $comment): CreditHistoryModel;

public function getCreatedAt(): ?\DateTimeInterface;

public function setCreatedAt(\DateTimeInterface $createdAt);

public function getUpdatedAt(): ?\DateTimeInterface;

public function setUpdatedAt(\DateTimeInterface $updatedAt);
}

+ 0
- 70
Model/Credit/CreditHistoryModel.php Bestand weergeven

@@ -73,76 +73,6 @@ abstract class CreditHistoryModel extends AbstractLightEntity implements PayoffI
return $this;
}

public function getAmountInherited(): float
{
if ($this->getOrderPayment() !== null) {
return $this->getOrderPayment()->getAmount();
} else {
if ($this->getOrderRefund() !== null) {
return $this->getOrderRefund()->getAmount();
} else {
return $this->getAmount();
}
}
}

public function getMeanPaymentInherited(): string
{
if ($this->getOrderPayment() !== null) {
return $this->getOrderPayment()->getMeanPayment();
} else {
if ($this->getOrderRefund() !== null) {
return $this->getOrderRefund()->getMeanPayment();
} else {
return $this->getMeanPayment();
}
}
}

public function getPaidAtInherited(): ?\DateTimeInterface
{
if ($this->getOrderPayment() !== null) {
return $this->getOrderPayment()->getPaidAt();
} else {
if ($this->getOrderRefund() !== null) {
return $this->getOrderRefund()->getPaidAt();
} else {
return $this->getPaidAt();
}
}
}

public function getReferenceInherited(): ?string
{
if ($this->getOrderPayment() !== null) {
return $this->getOrderPayment()->getReference();
} else {
if ($this->getOrderRefund() !== null) {
return $this->getOrderRefund()->getReference();
} else {
return $this->getReference();
}
}
}

public function getCommentInherited(): ?string
{
if ($this->getOrderPayment() !== null) {
return $this->getOrderPayment()->getComment();
} else {
if ($this->getOrderRefund() !== null) {
return $this->getOrderRefund()->getComment();
} else {
return $this->getComment();
}
}
}

public function getMeanPaymentInheritedLabel(): string
{
return 'field.default.meanPaymentOptions.' . $this->getMeanPaymentInherited();
}

public function getType(): ?string
{
return $this->type;

+ 7
- 56
Model/Order/OrderProductModel.php Bestand weergeven

@@ -6,11 +6,12 @@ use Lc\CaracoleBundle\Doctrine\Extension\PriceTrait;
use Doctrine\ORM\Mapping as ORM;
use Lc\CaracoleBundle\Doctrine\Extension\PriceInterface;
use Lc\CaracoleBundle\Model\Product\ProductInterface;
use Lc\SovBundle\Doctrine\EntityInterface;

/**
* @ORM\MappedSuperclass()
*/
abstract class OrderProductModel implements PriceInterface
abstract class OrderProductModel implements PriceInterface, EntityInterface
{
use PriceTrait;

@@ -59,69 +60,19 @@ abstract class OrderProductModel implements PriceInterface
}
}

public function getTitleOrderShop()
{
$product = $this->getProduct();
$productFamily = $product->getProductFamily();

$titleProduct = $product->getTitle();
$titleProductFamily = $productFamily->getTitle();

if (strlen($titleProduct) > 0 && strlen($titleProductFamily) > 0) {
$title = $titleProductFamily . ' - ' . $titleProduct;
} else {
$title = strlen($titleProduct) ? $titleProduct : $titleProductFamily;
}

if ($productFamily->hasProductsWithVariousWeight()) {
$title .= ' - ' . $product->getQuantityLabelInherited();
}

return $title;
}

public function getTitleSummaryAfterAddCart()
{
$title = '';

$product = $this->getProduct();
$productFamily = $product->getProductFamily();
$titleProduct = $product->getTitleInherited();
$titleProductFamily = $productFamily->getTitle();

// multiple
if ($productFamily->getActiveProducts() && $productFamily->getBehaviorAddToCart() == 'multiple') {
$title .= $titleProduct;
if ($productFamily->hasProductsWithVariousWeight()) {
$title .= ' - ' . $product->getQuantityLabelInherited();
}
}

// simple
if ($productFamily->getBehaviorAddToCart() == 'simple') {
if ($productFamily->getActiveProducts()) {
$title .= $titleProduct;
if ($productFamily->hasProductsWithVariousWeight()) {
$title .= ' - ' . $product->getQuantityLabelInherited();
}
}
}

return $title;
}

// isOrderProductAvailable
public function isAvailable()
/*public function isAvailable()
{
return $this->getProduct()->isAvailable($this->getQuantityOrder());
}
}*/

// isOrderProductAvailableAddCart
public function isAvailableAddCart(OrderShopInterface $orderShop = null)
// @TODO : à remettre en place si nécessaire
/*public function isAvailableAddCart(OrderShopInterface $orderShop = null)
{
$product = $this->getProduct();
return $this->isProductAvailable($product, $this->getQuantityOrder(), true, $orderShop);
}
}*/

public function getOrderShop(): ?OrderShopInterface
{

+ 1
- 1
Model/Order/OrderShopModel.php Bestand weergeven

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

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


+ 0
- 235
Model/Product/ProductFamilyInterface.php Bestand weergeven

@@ -2,245 +2,10 @@

namespace Lc\CaracoleBundle\Model\Product;


use Doctrine\Common\Collections\Collection;
use Lc\CaracoleBundle\Model\Reduction\ReductionCatalogInterface;
use Lc\CaracoleBundle\Model\Section\SectionInterface;
use Lc\SovBundle\Model\File\FileInterface;

/**
* @ORM\MappedSuperclass()
*/
interface ProductFamilyInterface
{
public function getBehaviorCountStockChoices(): array;

public function getBehaviorDisplaySaleChoices(): array;

public function getBehaviorStockCycleChoices(): array;

public function getWaringMessageTypeChoices(): array;

public function getBehaviorAddToCartChoices(): array;

public function getBehaviorPriceChoices(): array;

public function getPropertyOrganicLabelChoices(): array;

public function getTypeExpirationDateChoices(): array;

public function getBehaviorExpirationDateChoices(): array;

public function getSection(): SectionInterface;

public function setSection(SectionInterface $section): ProductFamilyModel;

public function getAvailableQuantityInherited();

public function getTaxRateInherited();

public function getActiveProducts(): ?bool;

public function setActiveProducts(bool $activeProducts): ProductFamilyModel;

public function getProductsQuantityAsTitle(): ?bool;

public function setProductsQuantityAsTitle(bool $productsQuantityAsTitle
): ProductFamilyModel;

public function getProductsType(): ?string;

public function setProductsType(?string $productsType): ProductFamilyModel;

public function getQuantityLabel(): ?string;

public function setQuantityLabel(?string $quantityLabel): ProductFamilyModel;

/**
* @return Collection|ProductInterface[]
*/
public function getProducts(): Collection;

public function getProductsOnline(): Collection;

public function addProduct(ProductInterface $product): ProductFamilyModel;

public function removeProduct(ProductInterface $product): ProductFamilyModel;

public function getReductionCatalog(): ?ReductionCatalogInterface;

public function getReductionCatalogInherited(): ?ReductionCatalogInterface;

public function setReductionCatalog(?ReductionCatalogInterface $reductionCatalog
): ProductFamilyModel;

/**
* @return Collection|ProductCategoryInterface[]
*/
public function getProductCategories(): Collection;

public function initProductCategories();

public function addProductCategory(ProductCategoryInterface $productCategory
): ProductFamilyModel;

public function removeProductCategory(ProductCategoryInterface $productCategory
): ProductFamilyModel;

public function getProductCategoryParent();

public function getProductCategoryChild();

public function getSubtitle(): ?string;

public function setSubtitle(?string $subtitle): ProductFamilyModel;

public function getWarningMessage(): ?string;

public function setWarningMessage(?string $warningMessage): ProductFamilyModel;

public function getWarningMessageType(): ?string;

public function setWarningMessageType(?string $warningMessageType
): ProductFamilyModel;

public function getNote(): ?string;

public function setNote(?string $note): ProductFamilyModel;

public function getBehaviorOutOfStock(): ?string;

public function setBehaviorOutOfStock(?string $behaviorOutOfStock
): ProductFamilyModel;

public function getBehaviorCountStock(): ?string;

public function setBehaviorCountStock(string $behaviorCountStock
): ProductFamilyModel;

public function getExportTitle(): ?string;

public function setExportTitle(?string $exportTitle): ProductFamilyModel;

public function getExportNote(): ?string;

public function setExportNote(?string $exportNote): ProductFamilyModel;

public function getBehaviorStockCycle(): ?string;

public function setBehaviorStockCycle(string $behaviorStockWeek
): ProductFamilyModel;

public function getAvailabilityRenewedThisWeek(): ?bool;

public function setAvailabilityRenewedThisWeek(?bool $availabilityRenewedThisWeek
): ProductFamilyModel;

public function getBehaviorDisplaySale(): ?string;

public function setBehaviorDisplaySale(string $behaviorDisplaySale
): ProductFamilyModel;

public function isPropertyNoveltyOnline(): ?bool;

public function getPropertyNoveltyExpirationDate(): ?\DateTimeInterface;

public function setPropertyNoveltyExpirationDate(?\DateTimeInterface $propertyNoveltyExpirationDate
): ProductFamilyModel;

public function getPropertyOrganicLabel(): ?string;

public function setPropertyOrganicLabel(?string $propertyOrganicLabel
): ProductFamilyModel;

public function getPropertyAllergens(): ?string;

public function setPropertyAllergens(?string $propertyAllergens
): ProductFamilyModel;

public function getPropertyComposition(): ?string;

public function setPropertyComposition(?string $propertyComposition
): ProductFamilyModel;

public function getPropertyFragrances(): ?string;

public function setPropertyFragrances(?string $propertyFragrances
): ProductFamilyModel;

public function countProperties(): bool;

public function getBehaviorExpirationDate(): ?string;

public function setBehaviorExpirationDate(?string $behaviorExpirationDate
): ProductFamilyModel;

public function getTypeExpirationDate(): ?string;

public function setTypeExpirationDate(?string $typeExpirationDate
): ProductFamilyModel;

public function getPropertyWeight(): ?string;

public function setPropertyWeight(?string $propertyWeight): ProductFamilyModel;

public function getPropertyQuantity(): ?string;

public function setPropertyQuantity(?string $propertyQuantity): ProductFamilyModel;

public function getPropertyVariety(): ?string;

public function setPropertyVariety(?string $propertyVariety): ProductFamilyModel;

public function getPropertyFeature(): ?string;

public function setPropertyFeature(?string $propertyFeature): ProductFamilyModel;

public function getPropertyAlcoholLevel(): ?string;

public function setPropertyAlcoholLevel(?string $propertyAlcoholLevel
): ProductFamilyModel;

public function getPropertyPackaging(): ?string;

public function setPropertyPackaging(?string $propertyPackaging
): ProductFamilyModel;

public function getPropertyCharacteristics(): ?string;

public function setPropertyCharacteristics(?string $propertyCharacteristics
): ProductFamilyModel;

public function getBehaviorAddToCart(): ?string;

public function setBehaviorAddToCart(?string $behaviorAddToCart
): ProductFamilyModel;

public function getBehaviorPrice(): ?string;

public function getBehaviorPriceInherited();

public function setBehaviorPrice(?string $behaviorPrice): ProductFamilyModel;

public function hasProductsWithVariousWeight();

public function getProductsGroupByTitle();

public function getOriginProduct();

public function getOriginProductOnline();

public function hasOneProductOnline();

public function getSaleStatus(): ?bool;

public function setSaleStatus(bool $saleStatus): ProductFamilyModel;

public function getFieldBuyingPrice();

public function getFieldPrice();

public function getImage(): ?FileInterface;

public function setImage(?FileInterface $image): ProductFamilyModel;
}

+ 0
- 230
Model/Product/ProductFamilyModel.php Bestand weergeven

@@ -25,7 +25,6 @@ abstract class ProductFamilyModel extends AbstractFullEntity implements ProductP
{
use ProductPropertyTrait;


const BEHAVIOR_COUNT_STOCK_UNLIMITED = 'unlimited';
const BEHAVIOR_COUNT_STOCK_BY_MEASURE = 'by-measure';
const BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY = 'by-product-family';
@@ -350,43 +349,6 @@ abstract class ProductFamilyModel extends AbstractFullEntity implements ProductP
return $this;
}

//TODO move
public function getAvailableQuantityInherited()
{
$availableQuantity = 0;

switch ($this->getBehaviorCountStock()) {
case self::BEHAVIOR_COUNT_STOCK_BY_MEASURE :
case self::BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY :

$availableQuantity = $this->getAvailableQuantity();
break;

case self::BEHAVIOR_COUNT_STOCK_BY_PRODUCT :

foreach ($this->getProductsOnline() as $product) {
$availableQuantity += $product->getAvailableQuantityInherited();
}
break;

case self::BEHAVIOR_COUNT_STOCK_UNLIMITED :
$availableQuantity = false;
break;
}

return $availableQuantity;
}

//TODO move
public function getTaxRateInherited()
{
if ($this->getTaxRate()) {
return $this->getTaxRate();
} else {
return $this->getSection()->getMerchant()->getTaxRate();
}
}

public function getActiveProducts(): ?bool
{
return $this->activeProducts;
@@ -443,21 +405,6 @@ abstract class ProductFamilyModel extends AbstractFullEntity implements ProductP
return $this->products;
}

//TODO move
public function getProductsOnline(): Collection
{
$products = $this->getProducts();
$productsOnlineArray = new ArrayCollection();

foreach ($products as $product) {
if ($product->getStatus() == 1 && $product->getOriginProduct() != true) {
$productsOnlineArray[] = $product;
}
}

return $productsOnlineArray;
}

public function addProduct(ProductInterface $product): self
{
if (!$this->products->contains($product)) {
@@ -486,12 +433,6 @@ abstract class ProductFamilyModel extends AbstractFullEntity implements ProductP
return $this->reductionCatalog;
}

//TODO move
public function getReductionCatalogInherited(): ?ReductionCatalogInterface
{
return $this->getReductionCatalog();
}

public function setReductionCatalog(?ReductionCatalogInterface $reductionCatalog): self
{
$this->reductionCatalog = $reductionCatalog;
@@ -530,33 +471,6 @@ abstract class ProductFamilyModel extends AbstractFullEntity implements ProductP
return $this;
}

//TODO move
public function getProductCategoryParent()
{
$productCategories = $this->getProductCategories();

if (count($productCategories) > 0) {
return $productCategories[0]->getParent();
}

return false;
}


//TODO move
public function getProductCategoryChild()
{
$productCategories = $this->getProductCategories();

foreach ($productCategories as $productCategory) {
if ($productCategory->getParent()) {
return $productCategory;
}
}

return false;
}

public function getSubtitle(): ?string
{
return $this->subtitle;
@@ -690,19 +604,6 @@ abstract class ProductFamilyModel extends AbstractFullEntity implements ProductP
return $this;
}

//TODO move
public function isPropertyNoveltyOnline(): ?bool
{
if ($this->getPropertyNoveltyExpirationDate()) {
$now = new \DateTime();
if ($now <= $this->getPropertyNoveltyExpirationDate()) {
return true;
}
}

return false;
}

public function getPropertyNoveltyExpirationDate(): ?\DateTimeInterface
{
return $this->propertyNoveltyExpirationDate;
@@ -763,27 +664,6 @@ abstract class ProductFamilyModel extends AbstractFullEntity implements ProductP
return $this;
}

//TODO move
public function countProperties(): bool
{
$count = 0;

$count += (int)strlen($this->getPropertyOrganicLabel()) > 0;
$count += (int)strlen($this->getPropertyWeight()) > 0;
$count += (int)strlen($this->getPropertyFragrances()) > 0;
$count += (int)strlen($this->getPropertyComposition()) > 0;
$count += (int)strlen($this->getPropertyAllergens()) > 0;
$count += (int)strlen($this->getPropertyAlcoholLevel()) > 0;
$count += (int)strlen($this->getPropertyCharacteristics()) > 0;
$count += (int)strlen($this->getPropertyFeature()) > 0;
$count += (int)strlen($this->getPropertyPackaging()) > 0;
$count += (int)strlen($this->getPropertyQuantity()) > 0;
$count += (int)strlen($this->getPropertyVariety()) > 0;
$count += (int)($this->getPropertyExpirationDate() != null);

return $count;
}

public function getBehaviorExpirationDate(): ?string
{
return $this->behaviorExpirationDate;
@@ -808,7 +688,6 @@ abstract class ProductFamilyModel extends AbstractFullEntity implements ProductP
return $this;
}


public function getPropertyWeight(): ?string
{
return $this->propertyWeight;
@@ -821,7 +700,6 @@ abstract class ProductFamilyModel extends AbstractFullEntity implements ProductP
return $this;
}


public function getPropertyQuantity(): ?string
{
return $this->propertyQuantity;
@@ -870,7 +748,6 @@ abstract class ProductFamilyModel extends AbstractFullEntity implements ProductP
return $this;
}


public function getPropertyPackaging(): ?string
{
return $this->propertyPackaging;
@@ -913,12 +790,6 @@ abstract class ProductFamilyModel extends AbstractFullEntity implements ProductP
return $this->behaviorPrice;
}

//TODO move
public function getBehaviorPriceInherited()
{
return $this->getBehaviorPrice();
}

public function setBehaviorPrice(?string $behaviorPrice): self
{
$this->behaviorPrice = $behaviorPrice;
@@ -926,86 +797,6 @@ abstract class ProductFamilyModel extends AbstractFullEntity implements ProductP
return $this;
}

//TODO move
public function hasProductsWithVariousWeight()
{
if ($this->getActiveProducts()) {
$arrayCountProducts = [];
$products = $this->getProductsOnline();

foreach ($products as $product) {
$titleProduct = $product->getTitleInherited();
if (!isset($arrayCountProducts[$titleProduct])) {
$arrayCountProducts[$titleProduct] = [];
}

if (!in_array($product->getQuantityLabelInherited(), $arrayCountProducts[$titleProduct])) {
$arrayCountProducts[$titleProduct][] = $product->getQuantityLabelInherited();
}

if (count($arrayCountProducts[$titleProduct]) > 1) {
return true;
}
}
}

return false;
}

//TODO move
public function getProductsGroupByTitle()
{
$arrayProductsGroupByTitle = [];
$products = $this->getProductsOnline();

foreach ($products as $product) {
if ($product->getStatus() == 1) {
$titleProduct = $product->getTitleInherited();
if (!isset($arrayProductsGroupByTitle[$titleProduct])) {
$arrayProductsGroupByTitle[$titleProduct] = [];
}
$arrayProductsGroupByTitle[$titleProduct][] = $product;
}
}

return $arrayProductsGroupByTitle;
}

//TODO move
public function getOriginProduct()
{
$products = $this->getProducts();

foreach ($products as $product) {
if ($product->getOriginProduct()) {
return $product;
}
}
}

//TODO move
public function getOriginProductOnline()
{
$originProduct = $this->getOriginProduct();

if ($originProduct->getStatus() == 1) {
return $originProduct;
} else {
return false;
}
}

//TODO move
public function hasOneProductOnline()
{
if (($this->getActiveProducts() && count($this->getProductsOnline()) > 0)
|| (!$this->getActiveProducts() && $this->getOriginProduct())) {
return true;
}

return false;
}

public function getSaleStatus(): ?bool
{
return $this->saleStatus;
@@ -1018,27 +809,6 @@ abstract class ProductFamilyModel extends AbstractFullEntity implements ProductP
return $this;
}

//TODO move
public function getFieldBuyingPrice()
{
if ($this->getBehaviorPrice() === self::BEHAVIOR_PRICE_BY_PIECE) {
return 'buyingPrice';
} elseif ($this->getBehaviorPrice() === self::BEHAVIOR_PRICE_BY_REFERENCE_UNIT) {
return 'buyingPriceByRefUnit';
}
}

//TODO move
public function getFieldPrice()
{
if ($this->getBehaviorPrice() === self::BEHAVIOR_PRICE_BY_PIECE) {
return 'price';
} elseif ($this->getBehaviorPrice() === self::BEHAVIOR_PRICE_BY_REFERENCE_UNIT) {
return 'priceByRefUnit';
}
}


public function getImage(): ?FileInterface
{
return $this->image;

+ 0
- 33
Model/Product/ProductInterface.php Bestand weergeven

@@ -10,35 +10,6 @@ use Lc\CaracoleBundle\Model\Order\OrderShopInterface;
*/
interface ProductInterface
{
public function getQuantityMaxAddCart(OrderShopInterface $orderShop);

public function getProductQuantity();

public function getBuyingPriceInherited();

public function getBuyingPriceByRefUnitInherited();

public function getPriceInherited();

public function getPriceByRefUnitInherited();

public function getBehaviorPriceInherited();

public function getReductionCatalogInherited();

public function getUnitInherited();

public function getTitleInherited();

public function getQuantityInherited();

public function getQuantityLabelInherited();

public function getQuantityTitle($productFamily);

public function getAvailableQuantityInherited();

public function getTaxRateInherited();

public function getProductFamily(): ?ProductFamilyInterface;

@@ -55,13 +26,9 @@ interface ProductInterface

public function getExportTitle(): ?string;

public function getExportTitleInherited(): ?string;

public function setExportTitle(?string $exportTitle): \Lc\CaracoleBundle\Model\Product\ProductModel;

public function getExportNote(): ?string;

public function getExportNoteInherited(): ?string;

public function setExportNote(?string $exportNote): \Lc\CaracoleBundle\Model\Product\ProductModel;
}

+ 0
- 182
Model/Product/ProductModel.php Bestand weergeven

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

// @TODO : move
// getProductQuantityMaxAddCart
public function getQuantityMaxAddCart(OrderShopInterface $orderShop)
{
$productFamily = $this->getProductFamily();

$byWeight = false;
if ($productFamily->getBehaviorCountStock() == ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_MEASURE) {
$byWeight = true;
}

return $this->getAvailableQuantityInherited() - $orderShop->getQuantityOrderByProduct($this, $byWeight);
}

// @TODO : move
// getProductQuantity
public function getProductQuantity()
{
$productFamily = $this->getProductFamily();

if ($productFamily->getBehaviorCountStock() == ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_MEASURE) {
return $this->getQuantityInherited() / $this->getUnitInherited()->getCoefficient();
} else {
return 1;
}
}

// @TODO : move
public function getBuyingPriceInherited()
{
if ($this->getBuyingPrice()) {
return $this->getBuyingPrice();
} else {
return $this->getProductFamily()->getBuyingPrice();
}
}

// @TODO : move
public function getBuyingPriceByRefUnitInherited()
{
if ($this->getBuyingPriceByRefUnit()) {
return $this->getBuyingPriceByRefUnit();
} else {
return $this->getProductFamily()->getBuyingPriceByRefUnit();
}
}

// @TODO : move
public function getPriceInherited()
{
if ($this->getPrice()) {
return $this->getPrice();
} else {
return $this->getProductFamily()->getPrice();
}
}

// @TODO : move
public function getPriceByRefUnitInherited()
{
if ($this->getPriceByRefUnit()) {
return $this->getPriceByRefUnit();
} else {
return $this->getProductFamily()->getPriceByRefUnit();
}
}

// @TODO : move
public function getBehaviorPriceInherited()
{
return $this->getProductFamily()->getBehaviorPrice();
}

// @TODO : move
public function getReductionCatalogInherited()
{
return $this->getProductFamily()->getReductionCatalog();
}

// @TODO : move
public function getUnitInherited()
{
if ($this->getUnit()) {
return $this->getUnit();
} else {
return $this->getProductFamily()->getUnit();
}
}

// @TODO : move
public function getTitleInherited()
{
if ($this->getTitle()) {
return $this->getTitle();
} else {
return $this->getProductFamily()->getTitle();
}
}

// @TODO : move
public function getQuantityInherited()
{
if ($this->getQuantity()) {
return $this->getQuantity();
} else {
return $this->getProductFamily()->getQuantity();
}
}

// @TODO : move
public function getQuantityLabelInherited()
{
$quantity = $this->getQuantityInherited();
$unit = $this->getUnitInherited();
return $quantity . $unit->getWordingShort();
}

// @TODO : move
public function getQuantityTitle($productFamily)
{
$title = $this->getQuantityLabelInherited();
if ($productFamily->hasProductsWithVariousWeight()) {
$title .= ', ' . $this->getTitleInherited();
}
return $title;
}

// @TODO : move
public function getAvailableQuantityInherited()
{
switch ($this->getProductFamily()->getBehaviorCountStock()) {
case ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY :
case ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_MEASURE :
return $this->getProductFamily()->getAvailableQuantity();
break;
case ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT :
return $this->getAvailableQuantity();
break;
case ProductFamilyModel::BEHAVIOR_COUNT_STOCK_UNLIMITED :
return false;
break;
}
}

// @TODO : move
public function getTaxRateInherited()
{
return $this->getProductFamily()->getTaxRateInherited();
}

public function getProductFamily(): ?ProductFamilyInterface
{
return $this->productFamily;
@@ -259,26 +109,10 @@ abstract class ProductModel extends AbstractLightEntity implements SortableInter
return $this;
}


public function getExportTitle(): ?string
{
return $this->exportTitle;
}
//TODO move
public function getExportTitleInherited(): ?string
{
$exportTitle = $this->getExportTitle();
if ($exportTitle && strlen($exportTitle)) {
return $exportTitle;
} else {
$productFamily = $this->getProductFamily();
if ($productFamily) {
return $productFamily->getExportTitle();
}
}

return null;
}

public function setExportTitle(?string $exportTitle): self
{
@@ -292,22 +126,6 @@ abstract class ProductModel extends AbstractLightEntity implements SortableInter
return $this->exportNote;
}

//TODO move
public function getExportNoteInherited(): ?string
{
$exportNote = $this->getExportNote();
if ($exportNote && strlen($exportNote)) {
return $exportNote;
} else {
$productFamily = $this->getProductFamily();
if ($productFamily) {
return $productFamily->getExportNote();
}
}

return null;
}

public function setExportNote(?string $exportNote): self
{
$this->exportNote = $exportNote;

+ 1
- 1
Model/Ticket/TicketModel.php Bestand weergeven

@@ -40,7 +40,7 @@ abstract class TicketModel extends SovTicketModel implements FilterSectionInterf
return $this;
}

public function getOrderShop(): OrderShopInterface
public function getOrderShop(): ?OrderShopInterface
{
return $this->orderShop;
}

+ 16
- 12
Notification/MailMailjetNotification.php Bestand weergeven

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

use Lc\CaracoleBundle\Definition\MerchantSettingDefinition;
use Lc\CaracoleBundle\Resolver\MerchantResolver;
use Lc\SovBundle\Solver\Setting\SettingSolver;
use Mailjet\MailjetSwiftMailer\SwiftMailer\MailjetTransport;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Twig\Environment;
@@ -26,35 +27,38 @@ class MailMailjetNotification
const ATTACHMENT_CONTENT_TYPE = 'attachment-content-type';
//const DISPOSITION_NOTIFICATION_TO = 'disposition-notification-to' ;

protected $transport;
protected $templating;
protected $parameterBag;
protected $merchantResolver;
protected MailjetTransport $transport;
protected Environment $templating;
protected ParameterBagInterface $parameterBag;
protected MerchantResolver $merchantResolver;
protected SettingSolver $settingSolver;

public function __construct(
MailjetTransport $mailjetTransport,
Environment $templating,
ParameterBagInterface $parameterBag,
MerchantResolver $merchantResolver
MerchantResolver $merchantResolver,
SettingSolver $settingSolver
) {
$this->transport = $mailjetTransport;
$this->templating = $templating;
$this->parameterBag = $parameterBag;
$this->merchantResolver = $merchantResolver;
$this->settingSolver = $settingSolver;
}

public function send($params = [])
{
$merchantCurrent = $this->merchantResolver->getCurrent();

$merchantConfigEmailFrom = $merchantCurrent->getSettingValue(MerchantSettingDefinition::EMAIL_FROM);
$merchantConfigEmailFrom = $this->settingSolver->getSettingValue($merchantCurrent, MerchantSettingDefinition::SETTING_EMAIL_FROM);
$emailFrom = (isset($params[self::FROM_EMAIL]) && $params[self::FROM_EMAIL] && strlen($params[self::FROM_EMAIL])) ? $params[self::FROM_EMAIL] : $merchantConfigEmailFrom;

$merchantConfigEmailFromName = $merchantCurrent->getSettingValue(MerchantSettingDefinition::EMAIL_FROM_NAME);
$emailFromName = isset($params[self::FROM_NAME]) ? $params[self::FROM_NAME] : $merchantConfigEmailFromName;
$merchantConfigEmailFromName = $this->settingSolver->getSettingValue($merchantCurrent, MerchantSettingDefinition::SETTING_EMAIL_FROM_NAME);
$emailFromName = isset($params[self::FROM_NAME]) ?? $merchantConfigEmailFromName;

$merchantConfigEmailSubjectPrefix = $merchantCurrent->getSettingValue(MerchantSettingDefinition::EMAIL_SUBJECT_PREFIX);
$emailSubjectPrefix = isset($params[self::SUBJECT_PREFIX]) ? $params[self::SUBJECT_PREFIX] : $merchantConfigEmailSubjectPrefix;
$merchantConfigEmailSubjectPrefix = $this->settingSolver->getSettingValue($merchantCurrent, MerchantSettingDefinition::SETTING_EMAIL_SUBJECT_PREFIX);
$emailSubjectPrefix = isset($params[self::SUBJECT_PREFIX]) ?? $merchantConfigEmailSubjectPrefix;
if ($emailSubjectPrefix && strlen($emailSubjectPrefix)) {
$emailSubjectPrefix .= ' ';
}
@@ -64,11 +68,11 @@ class MailMailjetNotification

if ($this->parameterBag->get('mailjet.dev.redirect.active')==1) {
$message->addTo($this->parameterBag->get('mailjet.dev.redirect.email'),
isset($params[self::TO_NAME]) ? $params[self::TO_NAME] : null);
isset($params[self::TO_NAME]) ?? null);
} else {
$message->addTo(
$params[self::TO_EMAIL],
isset($params[self::TO_NAME]) ? $params[self::TO_NAME] : null);
isset($params[self::TO_NAME]) ?? null);
}

$contentData = [] ;

+ 6
- 0
Repository/Address/AddressRepositoryQuery.php Bestand weergeven

@@ -4,6 +4,7 @@ namespace Lc\CaracoleBundle\Repository\Address;

use Knp\Component\Pager\PaginatorInterface;
use Lc\CaracoleBundle\Repository\MerchantRepositoryQueryTrait;
use Lc\SovBundle\Model\User\UserInterface;
use Lc\SovBundle\Repository\AbstractRepositoryQuery;

class AddressRepositoryQuery extends AbstractRepositoryQuery
@@ -14,4 +15,9 @@ class AddressRepositoryQuery extends AbstractRepositoryQuery
{
parent::__construct($repository, 'r', $paginator);
}

public function filterByUser(UserInterface $user)
{
return $this->andWhereEqual('user', $user);
}
}

+ 9
- 0
Repository/Address/AddressStore.php Bestand weergeven

@@ -3,6 +3,7 @@
namespace Lc\CaracoleBundle\Repository\Address;

use Lc\CaracoleBundle\Repository\MerchantStoreTrait;
use Lc\SovBundle\Model\User\UserInterface;
use Lc\SovBundle\Repository\AbstractStore;
use Lc\SovBundle\Repository\RepositoryQueryInterface;

@@ -32,4 +33,12 @@ class AddressStore extends AbstractStore
{
return $query;
}

public function getByUser(UserInterface $user)
{
$query = $this->createDefaultQuery();
$query->filterByUser($user);
return $query->find();
}

}

+ 3
- 1
Repository/Order/OrderProductStore.php Bestand weergeven

@@ -27,7 +27,9 @@ class OrderProductStore extends AbstractStore

public function filtersDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
{
$query->filterBySection($this->section);
if($this->section) {
$query->filterBySection($this->section);
}
return $query;
}


+ 18
- 12
Repository/Order/OrderShopStore.php Bestand weergeven

@@ -10,6 +10,7 @@ use Lc\CaracoleBundle\Model\Reduction\ReductionCartInterface;
use Lc\CaracoleBundle\Model\Reduction\ReductionCreditInterface;
use Lc\CaracoleBundle\Model\Reduction\ReductionCreditModel;
use Lc\CaracoleBundle\Repository\Merchant\MerchantStore;
use Lc\CaracoleBundle\Repository\Reduction\ReductionCartStore;
use Lc\CaracoleBundle\Repository\Reduction\ReductionCreditStore;
use Lc\CaracoleBundle\Repository\Section\SectionStore;
use Lc\CaracoleBundle\Resolver\OpeningResolver;
@@ -42,6 +43,7 @@ class OrderShopStore extends AbstractStore
protected ParameterBagInterface $parameterBag;
protected UrlGeneratorInterface $router;
protected OrderShopSolver $orderShopSolver;
protected ReductionCartStore $reductionCartStore;

public function __construct(
OrderShopRepositoryQuery $query,
@@ -56,7 +58,8 @@ class OrderShopStore extends AbstractStore
FlashBagInterface $flashBag,
ParameterBagInterface $parameterBag,
UrlGeneratorInterface $router,
OrderShopSolver $orderShopSolver
OrderShopSolver $orderShopSolver,
ReductionCartStore $reductionCartStore
) {
$this->query = $query;
$this->entityManager = $entityManager;
@@ -71,6 +74,7 @@ class OrderShopStore extends AbstractStore
$this->parameterBag = $parameterBag;
$this->router = $router;
$this->orderShopSolver = $orderShopSolver;
$this->reductionCartStore = $reductionCartStore;
}

public function orderByDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
@@ -110,7 +114,7 @@ class OrderShopStore extends AbstractStore
}

// getOrderShopsOfWeekByUser
public function getByCurrentCycleAndUser(UserInterface $user, array $params = [], $query = null)
public function getByCurrentCycleAndUser(UserInterface $user = null, array $params = [], $query = null)
{
return $this->getByCurrentCycle(
array_merge(
@@ -130,10 +134,13 @@ class OrderShopStore extends AbstractStore
public function countByCurrentCycle(array $params, $query = null)
{
return $this->countBy(
[
'cycleNumber' => $this->orderShopSolver->getCycleNumberCurrentOrder($this->section),
'excludeComplementaryOrderShops' => isset($params['excludeComplementaryOrderShops']) ?? true,
],
array_merge(
[
'cycleNumber' => $this->orderShopSolver->getCycleNumberCurrentOrder($this->section),
'excludeComplementaryOrderShops' => isset($params['excludeComplementaryOrderShops']) ?? true,
],
$params
),
$query
);

@@ -188,7 +195,7 @@ class OrderShopStore extends AbstractStore
);
}

public function countValidByUser(UserInterface $user, $query = null): int
public function countValidByUser(UserInterface $user = null, $query = null): int
{
return $this->countBy(
[
@@ -498,14 +505,13 @@ class OrderShopStore extends AbstractStore
// findAllAvailableForUser / getReductionCartsAvailableByUser
public function getReductionCartAvailableByUser(UserInterface $user, $query = null)
{
$query = $this->createQuery($query);
$reductionCarts = $query->find();
$reductionCarts = $this->reductionCartStore->getOnline();

$reductionCartsArray = [];
foreach ($reductionCarts as $reductionCart) {
if ($this->reductionCartSolver->matchWithUser($user)
&& $this->reductionCartSolver->matchWithGroupUser($user)
&& $this->getRemainingQuantityByUser($reductionCart, $user)
if ($this->reductionCartSolver->matchWithUser($reductionCart, $user)
&& $this->reductionCartSolver->matchWithGroupUser($reductionCart, $user)
&& $this->getReductionCartRemainingQuantityByUser($reductionCart, $user)
&& ($reductionCart->getUsers()->count() > 0 || $reductionCart->getGroupUsers()->count() > 0)) {
$reductionCartsArray[] = $reductionCart;
}

+ 5
- 0
Repository/Order/OrderStatusRepositoryQuery.php Bestand weergeven

@@ -11,4 +11,9 @@ class OrderStatusRepositoryQuery extends AbstractRepositoryQuery
{
parent::__construct($repository, 'r', $paginator);
}

public function filterByAlias(string $alias)
{
return $this->andWhereEqual('alias', $alias);
}
}

+ 7
- 0
Repository/Order/OrderStatusStore.php Bestand weergeven

@@ -29,4 +29,11 @@ class OrderStatusStore extends AbstractStore
{
return $query;
}

public function getOneByAlias(string $alias, $query = null)
{
$query = $this->createDefaultQuery($query);
$query->filterByAlias($alias);
return $query->findOne();
}
}

+ 4
- 1
Repository/Product/ProductFamilyStore.php Bestand weergeven

@@ -32,7 +32,10 @@ class ProductFamilyStore extends AbstractStore

public function filtersDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
{
$query->filterBySection($this->section);
if($this->section) {
$query->filterBySection($this->section);
}

return $query;
}


+ 2
- 1
Repository/Reduction/ReductionCartRepositoryQuery.php Bestand weergeven

@@ -4,11 +4,12 @@ namespace Lc\CaracoleBundle\Repository\Reduction;

use Knp\Component\Pager\PaginatorInterface;
use Lc\CaracoleBundle\Repository\MerchantRepositoryQueryTrait;
use Lc\CaracoleBundle\Repository\SectionRepositoryQueryTrait;
use Lc\SovBundle\Repository\AbstractRepositoryQuery;

class ReductionCartRepositoryQuery extends AbstractRepositoryQuery
{
use MerchantRepositoryQueryTrait;
use SectionRepositoryQueryTrait;

public function __construct(ReductionCartRepository $repository, PaginatorInterface $paginator)
{

+ 3
- 1
Repository/Reduction/ReductionCartStore.php Bestand weergeven

@@ -38,7 +38,9 @@ class ReductionCartStore extends AbstractStore

public function filtersDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
{
$query->filterBySection($this->section);
if($this->section) {
$query->filterBySection($this->section);
}
$query->filterIsOnlineAndOffline();
return $query;
}

+ 3
- 1
Repository/Reduction/ReductionCatalogStore.php Bestand weergeven

@@ -26,7 +26,9 @@ class ReductionCatalogStore extends AbstractStore

public function filtersDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
{
$query->filterBySection($this->section);
if($this->section) {
$query->filterBySection($this->section);
}
$query->filterIsOnlineAndOffline();
return $query;
}

+ 2
- 1
Repository/Reduction/ReductionCreditRepositoryQuery.php Bestand weergeven

@@ -5,12 +5,13 @@ namespace Lc\CaracoleBundle\Repository\Reduction;
use Knp\Component\Pager\PaginatorInterface;
use Lc\CaracoleBundle\Model\Reduction\ReductionCreditModel;
use Lc\CaracoleBundle\Repository\MerchantRepositoryQueryTrait;
use Lc\CaracoleBundle\Repository\SectionRepositoryQueryTrait;
use Lc\SovBundle\Model\User\UserInterface;
use Lc\SovBundle\Repository\AbstractRepositoryQuery;

class ReductionCreditRepositoryQuery extends AbstractRepositoryQuery
{
use MerchantRepositoryQueryTrait;
use SectionRepositoryQueryTrait;

public function __construct(ReductionCreditRepository $repository, PaginatorInterface $paginator)
{

+ 3
- 1
Repository/Reduction/ReductionCreditStore.php Bestand weergeven

@@ -31,7 +31,9 @@ class ReductionCreditStore extends AbstractStore

public function filtersDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
{
$query->filterBySection($this->section);
if($this->section) {
$query->filterBySection($this->section);
}
$query->filterIsOnlineAndOffline();
return $query;
}

+ 53
- 0
Resolver/OrderShopResolver.php Bestand weergeven

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

namespace Lc\CaracoleBundle\Resolver;

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

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

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

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

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

public function isPaid(OrderShopInterface $orderShop, $mergeComplementaryOrderShop = false): bool
{
$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->getTotalRemainingToBePaid($orderShop) > 0;
}

}

+ 107
- 0
Resolver/ProductFamilyResolver.php Bestand weergeven

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

namespace Lc\CaracoleBundle\Resolver;

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

class ProductFamilyResolver
{
protected PriceSolver $priceSolver;
protected ProductFamilySolver $productFamilySolver;

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

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 = $this->productFamilySolver->getProductsOnline($productFamily)->getValues();
if (count($products) > 0) {
usort($products, $comparisonFunction);
return $products[0];
}
} else {
return $this->productFamilySolver->getOriginProduct($productFamily);
}
if ($returnSelfIfNotActiveProducts) {
return $productFamily;
} else {
return false;
}
}
}

+ 34
- 8
Resolver/SectionResolver.php Bestand weergeven

@@ -19,13 +19,20 @@ class SectionResolver
protected MerchantResolver $merchantResolver;
protected SectionStore $sectionStore;
protected RequestStack $requestStack;
protected UrlResolver $urlResolver;

public function __construct(EntityManagerInterface $entityManager, MerchantResolver $merchantResolver, SectionStore $sectionStore, RequestStack $requestStack)
{
public function __construct(
EntityManagerInterface $entityManager,
MerchantResolver $merchantResolver,
SectionStore $sectionStore,
RequestStack $requestStack,
UrlResolver $urlResolver
) {
$this->entityManager = $entityManager;
$this->merchantResolver = $merchantResolver;
$this->sectionStore = $sectionStore;
$this->requestStack = $requestStack;
$this->urlResolver = $urlResolver;
}

public function getCurrent()
@@ -33,7 +40,7 @@ class SectionResolver
$requestAttributesArray = $this->requestStack->getMainRequest()->attributes->all();

// admin
if(isset($requestAttributesArray['easyadmin_context'])) {
if (isset($requestAttributesArray['easyadmin_context'])) {
$currentAdminSection = null;
$userMerchant = $this->merchantResolver->getUserMerchant();

@@ -52,12 +59,31 @@ class SectionResolver
}

return $currentAdminSection;
}
// front
} // front
else {
return $this->sectionStore
->setMerchant($this->merchantResolver->getCurrent())
->getOneDefault();
$sectionCurrent = null;
$isCli = php_sapi_name() === 'cli';

// local
if ($isCli || $this->urlResolver->isServerLocalhost()) {
$sectionArray = $this->sectionStore
->setMerchant($this->merchantResolver->getCurrent())
->getOnline();

foreach ($sectionArray as $section) {
if ($section->getDevAlias() == $_ENV['CURRENT_SECTION_LOCAL']) {
$sectionCurrent = $section;
}
}
}
// distant
else {
$sectionCurrent = $this->sectionStore
->setMerchant($this->merchantResolver->getCurrent())
->getOneDefault();
}

return $sectionCurrent;
}
}


+ 3
- 1
Resources/translations/admin.fr.yaml Bestand weergeven

@@ -59,6 +59,7 @@ entity:
behaviorTaxRateChoices:
tax-excluded: TVA exclue
tax-included: Tva incluse

PointSale:
label: Point de vente
label_plurial: Points de vente
@@ -73,12 +74,13 @@ entity:
individual: Particulier
civility: Civilité
zip: Code postal
city: Ville
city: Commune
address: Adresse
phone: Téléphone
company: Entreprise
siret: SIRET
tva: Numero de TVA

Merchant:
label: Marchand
label_plurial: Marchands

+ 78
- 0
Solver/Credit/CreditHistorySolver.php Bestand weergeven

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

namespace Lc\CaracoleBundle\Solver\Credit;

use Lc\CaracoleBundle\Model\Credit\CreditHistoryInterface;

class CreditHistorySolver
{
public function getMeanPaymentInheritedLabel(CreditHistoryInterface $creditHistory): string
{
return 'entity.CreditHistory.fields.meanPaymentOptions.' . $this->getMeanPaymentInherited($creditHistory);
}

public function getAmountInherited(CreditHistoryInterface $creditHistory): float
{
if ($creditHistory->getOrderPayment() !== null) {
return $creditHistory->getOrderPayment()->getAmount();
} else {
if ($creditHistory->getOrderRefund() !== null) {
return $creditHistory->getOrderRefund()->getAmount();
} else {
return $creditHistory->getAmount();
}
}
}

public function getMeanPaymentInherited(CreditHistoryInterface $creditHistory): string
{
if ($creditHistory->getOrderPayment() !== null) {
return $creditHistory->getOrderPayment()->getMeanPayment();
} else {
if ($creditHistory->getOrderRefund() !== null) {
return $creditHistory->getOrderRefund()->getMeanPayment();
} else {
return $creditHistory->getMeanPayment();
}
}
}

public function getPaidAtInherited(CreditHistoryInterface $creditHistory): ?\DateTimeInterface
{
if ($creditHistory->getOrderPayment() !== null) {
return $creditHistory->getOrderPayment()->getPaidAt();
} else {
if ($creditHistory->getOrderRefund() !== null) {
return $creditHistory->getOrderRefund()->getPaidAt();
} else {
return $creditHistory->getPaidAt();
}
}
}

public function getReferenceInherited(CreditHistoryInterface $creditHistory): ?string
{
if ($creditHistory->getOrderPayment() !== null) {
return $creditHistory->getOrderPayment()->getReference();
} else {
if ($creditHistory->getOrderRefund() !== null) {
return $creditHistory->getOrderRefund()->getReference();
} else {
return $creditHistory->getReference();
}
}
}

public function getCommentInherited(CreditHistoryInterface $creditHistory): ?string
{
if ($creditHistory->getOrderPayment() !== null) {
return $creditHistory->getOrderPayment()->getComment();
} else {
if ($creditHistory->getOrderRefund() !== null) {
return $creditHistory->getOrderRefund()->getComment();
} else {
return $creditHistory->getComment();
}
}
}
}

+ 65
- 0
Solver/Order/OrderProductSolver.php Bestand weergeven

@@ -2,8 +2,22 @@

namespace Lc\CaracoleBundle\Solver\Order;

use Lc\CaracoleBundle\Model\Order\OrderProductInterface;
use Lc\CaracoleBundle\Model\Order\OrderShopInterface;
use Lc\CaracoleBundle\Solver\Product\ProductFamilySolver;
use Lc\CaracoleBundle\Solver\Product\ProductSolver;

class OrderProductSolver
{
protected ProductSolver $productSolver;
protected ProductFamilySolver $productFamilySolver;

public function __construct(ProductSolver $productSolver, ProductFamilySolver $productFamilySolver)
{
$this->productSolver = $productSolver;
$this->productFamilySolver = $productFamilySolver;
}

// groupOrderProductsByProductFamily
public function getOrderProductsByProductFamily(array $orderProducts): array
{
@@ -58,4 +72,55 @@ class OrderProductSolver

return $orderProductsByStorageOrder;
}

public function getTitleOrderShop(OrderProductInterface $orderProduct)
{
$product = $orderProduct->getProduct();
$productFamily = $product->getProductFamily();

$titleProduct = $product->getTitle();
$titleProductFamily = $productFamily->getTitle();

if (strlen($titleProduct) > 0 && strlen($titleProductFamily) > 0) {
$title = $titleProductFamily . ' - ' . $titleProduct;
} else {
$title = strlen($titleProduct) ? $titleProduct : $titleProductFamily;
}

if ($this->productFamilySolver->hasProductsWithVariousWeight($productFamily)) {
$title .= ' - ' . $this->productSolver->getQuantityLabelInherited($product);
}

return $title;
}

public function getTitleSummaryAfterAddCart(OrderProductInterface $orderProduct)
{
$title = '';

$product = $orderProduct->getProduct();
$productFamily = $product->getProductFamily();
$titleProduct = $this->productSolver->getTitleInherited($product);
$titleProductFamily = $productFamily->getTitle();

// multiple
if ($productFamily->getActiveProducts() && $productFamily->getBehaviorAddToCart() == 'multiple') {
$title .= $titleProduct;
if ($this->productFamilySolver->hasProductsWithVariousWeight($productFamily)) {
$title .= ' - ' . $this->productSolver->getQuantityLabelInherited($product);
}
}

// simple
if ($productFamily->getBehaviorAddToCart() == 'simple') {
if ($productFamily->getActiveProducts()) {
$title .= $titleProduct;
if ($this->productFamilySolver->hasProductsWithVariousWeight($productFamily)) {
$title .= ' - ' . $this->productSolver->getQuantityLabelInherited($product);
}
}
}

return $title;
}
}

+ 41
- 41
Solver/Order/OrderShopSolver.php Bestand weergeven

@@ -14,18 +14,17 @@ use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface;
use Lc\CaracoleBundle\Model\Product\ProductFamilyModel;
use Lc\CaracoleBundle\Model\Product\ProductInterface;
use Lc\CaracoleBundle\Model\Reduction\ReductionCreditInterface;
use Lc\CaracoleBundle\Solver\Price\PriceSolver;
use Lc\CaracoleBundle\Solver\Product\ProductSolver;

class OrderShopSolver
{
protected PriceSolver $priceSolver;
protected EntityManagerInterface $entityManager;
protected ProductSolver $productSolver;

public function __construct(PriceSolver $priceSolver, EntityManagerInterface $entityManager, ProductSolver $productSolver)
{
$this->priceSolver = $priceSolver;
public function __construct(
EntityManagerInterface $entityManager,
ProductSolver $productSolver
) {
$this->entityManager = $entityManager;
$this->productSolver = $productSolver;
}
@@ -105,13 +104,17 @@ class OrderShopSolver
}

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

// @TODO : orderShop à définir où est appelé isAvailable
if ($checkCart && !$orderShop) {
throw new \Exception("Attention : définir le orderShop à l'endroit où est appelé isAvailable");
}
@@ -123,7 +126,10 @@ class OrderShopSolver
if (!$quantityOrder) {
$quantityAsked = $this->getQuantityOrderByProduct($orderShop, $product, true);
} else {
$quantityAsked = ($product->getQuantityInherited() / $product->getUnitInherited()->getCoefficient()) * $quantityOrder;
$quantityAsked = ($this->productSolver->getQuantityInherited(
$product
) / $this->productSolver->getUnitInherited($product)->getCoefficient(
)) * $quantityOrder;
}

if ($checkCart) {
@@ -133,7 +139,6 @@ class OrderShopSolver

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

if (!$quantityOrder) {
$quantityAsked = $this->getQuantityOrderByProduct($orderShop, $product);
}
@@ -143,7 +148,7 @@ class OrderShopSolver
}
}

if ($product->getAvailableQuantityInherited() >= $quantityAsked
if ($this->productSolver->getAvailableQuantityInherited($product) >= $quantityAsked
|| $productFamily->getBehaviorCountStock() == ProductFamilyModel::BEHAVIOR_COUNT_STOCK_UNLIMITED) {
return true;
} else {
@@ -162,6 +167,16 @@ class OrderShopSolver
return false;
}

public function isOrderProductAvailableAddCart(OrderProductInterface $orderProduct, OrderShopInterface $orderShop)
{
return $this->isProductAvailable(
$orderProduct->getProduct(),
$orderProduct->getQuantityOrder(),
true,
$orderShop
);
}

public function getTotalOrderPayments(OrderShopInterface $orderShop, $mergeComplementaryOrderShop = false): float
{
$totalAmount = floatval(0);
@@ -181,11 +196,6 @@ class OrderShopSolver
return $totalAmount;
}

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

public function getOrderStatusHistory(OrderShopInterface $orderShop, OrderStatusInterface $status)
{
$orderStatusHistories = $orderShop->getOrderStatusHistories();
@@ -224,7 +234,7 @@ class OrderShopSolver

public function isComplementaryOrderShop(OrderShopInterface $orderShop): bool
{
return (bool) $orderShop->getMainOrderShop();
return (bool)$orderShop->getMainOrderShop();
}

public function mergeComplentaryOrderShops(
@@ -277,7 +287,6 @@ class OrderShopSolver
}



public function hasOrderProductAlreadyInCart(
OrderShopInterface $orderShop,
OrderProductInterface $orderProductTest
@@ -315,34 +324,25 @@ class OrderShopSolver
return false;
}

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

public function isPaid(OrderShopInterface $orderShop, $mergeComplementaryOrderShop = false): bool
// getProductQuantityMaxAddCart
public function getProductQuantityMaxAddCart(ProductInterface $product, OrderShopInterface $orderShop)
{
$totalOrderPayments = $this->getTotalOrderPayments($orderShop, $mergeComplementaryOrderShop);
$totalOrder = $this->priceSolver->getTotalWithTax($orderShop);
$productFamily = $product->getProductFamily();

if ((abs($totalOrderPayments - $totalOrder) < 0.00001
|| $totalOrderPayments >= $totalOrder)
&& $totalOrder > 0) {
return true;
} else {
return false;
$byWeight = false;
if ($productFamily->getBehaviorCountStock() == ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_MEASURE) {
$byWeight = true;
}
}

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

public function isCartAllowToBeOrder(OrderShopInterface $orderShop): bool
{
return true;
return $this->productSolver->getAvailableQuantityInherited($product) - $this->getQuantityOrderByProduct(
$orderShop,
$product,
$byWeight
);
}
}

+ 14
- 5
Solver/Price/OrderProductPriceSolver.php Bestand weergeven

@@ -3,16 +3,25 @@
namespace Lc\CaracoleBundle\Solver\Price;

use Lc\CaracoleBundle\Model\Order\OrderProductInterface;
use Lc\CaracoleBundle\Solver\Product\ProductFamilySolver;
use Lc\CaracoleBundle\Solver\Product\ProductSolver;

class OrderProductPriceSolver
{
use PriceSolverTrait;

protected $productPriceResolver;

public function __construct(ProductPriceSolver $ProductPriceResolver)
{
$this->productPriceResolver = $ProductPriceResolver;
protected ProductSolver $productSolver;
protected ProductFamilySolver $productFamilySolver;
protected ProductPriceSolver $productPriceSolver;

public function __construct(
ProductPriceSolver $productPriceSolver,
ProductSolver $productSolver,
ProductFamilySolver $productFamilySolver
) {
$this->productPriceSolver = $productPriceSolver;
$this->productSolver = $productSolver;
$this->productFamilySolver = $productFamilySolver;
}

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

+ 11
- 3
Solver/Price/OrderShopPriceSolver.php Bestand weergeven

@@ -5,17 +5,25 @@ 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;
use Lc\CaracoleBundle\Solver\Product\ProductFamilySolver;
use Lc\CaracoleBundle\Solver\Product\ProductSolver;

class OrderShopPriceSolver
{
use PriceSolverTrait;

protected OrderProductPriceSolver $orderProductPriceResolver;
protected ProductSolver $productSolver;
protected ProductFamilySolver $productFamilySolver;

public function __construct(OrderProductPriceSolver $orderProductPriceResolver)
{
public function __construct(
OrderProductPriceSolver $orderProductPriceResolver,
ProductSolver $productSolver,
ProductFamilySolver $productFamilySolver
) {
$this->orderProductPriceResolver = $orderProductPriceResolver;
$this->productSolver = $productSolver;
$this->productFamilySolver = $productFamilySolver;
}

//Inclus les ReductionCatalog des OrderProducts

+ 2
- 2
Solver/Price/PriceSolver.php Bestand weergeven

@@ -52,11 +52,11 @@ class PriceSolver
}
} else {
if (!strlen($service)) {
throw new \ErrorException("PriceResolver : le type d'entité n'est pas géré");
throw new \ErrorException("PriceSolver : le type d'entité n'est pas géré");
} else {
if (!method_exists($this->$service, $name)) {
throw new \ErrorException(
"PriceResolver : la méthode " . $name . " du service " . $service . " n'existe pas."
"PriceSolver : la méthode " . $name . " du service " . $service . " n'existe pas."
);
}
}

+ 13
- 7
Solver/Price/PriceSolverTrait.php Bestand weergeven

@@ -4,6 +4,8 @@ namespace Lc\CaracoleBundle\Solver\Price;

use Lc\CaracoleBundle\Doctrine\Extension\ProductPropertyInterface;
use Lc\CaracoleBundle\Model\Order\OrderProductInterface;
use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface;
use Lc\CaracoleBundle\Model\Product\ProductInterface;

trait PriceSolverTrait
{
@@ -56,14 +58,18 @@ trait PriceSolverTrait
$reductionCatalogUnit = $reductionCatalog->getUnit();
$reductionCatalogBehaviorTaxRate = $reductionCatalog->getBehaviorTaxRate();
} else {
if ($entity instanceof ProductPropertyInterface) {
$reductionCatalog = $entity->getReductionCatalogInherited();
if ($entity instanceof ProductInterface) {
$reductionCatalog = $this->productSolver->getReductionCatalogInherited($entity);
}

if ($reductionCatalog) {
$reductionCatalogValue = $reductionCatalog->getValue();
$reductionCatalogUnit = $reductionCatalog->getUnit();
$reductionCatalogBehaviorTaxRate = $reductionCatalog->getBehaviorTaxRate();
}
if ($entity instanceof ProductFamilyInterface) {
$reductionCatalog = $this->productFamilySolver->getReductionCatalogInherited($entity);
}

if ($reductionCatalog) {
$reductionCatalogValue = $reductionCatalog->getValue();
$reductionCatalogUnit = $reductionCatalog->getUnit();
$reductionCatalogBehaviorTaxRate = $reductionCatalog->getBehaviorTaxRate();
}

if ($entity instanceof OrderProductInterface) {

+ 52
- 22
Solver/Price/ProductPriceSolver.php Bestand weergeven

@@ -3,19 +3,45 @@
namespace Lc\CaracoleBundle\Solver\Price;

use Lc\CaracoleBundle\Doctrine\Extension\ProductPropertyInterface;
use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface;
use Lc\CaracoleBundle\Model\Product\ProductInterface;
use Lc\CaracoleBundle\Solver\Product\ProductFamilySolver;
use Lc\CaracoleBundle\Solver\Product\ProductSolver;

class ProductPriceSolver
{
use PriceSolverTrait;

protected ProductSolver $productSolver;
protected ProductFamilySolver $productFamilySolver;

public function __construct(ProductSolver $productSolver, ProductFamilySolver $productFamilySolver)
{
$this->productSolver = $productSolver;
$this->productFamilySolver = $productFamilySolver;
}

public function getSolver(ProductPropertyInterface $product)
{
if($product instanceof ProductFamilyInterface) {
return $this->productFamilySolver;
}

if($product instanceof ProductInterface) {
return $this->productSolver;
}
}

public function getPrice(ProductPropertyInterface $product)
{
if ($product->getBehaviorPriceInherited() == 'by-piece') {
return $product->getPriceInherited();
} elseif ($product->getBehaviorPriceInherited() == 'by-reference-unit') {
if ($product->getQuantityInherited() > 0) {
return $product->getPriceByRefUnitInherited() * ($product->getQuantityInherited(
) / $product->getUnitInherited()->getCoefficient());
$solver = $this->getSolver($product);

if ($solver->getBehaviorPriceInherited($product) == 'by-piece') {
return $solver->getPriceInherited($product);
} elseif ($solver->getBehaviorPriceInherited($product) == 'by-reference-unit') {
if ($solver->getQuantityInherited($product) > 0) {
return $solver->getPriceByRefUnitInherited($product) * ($solver->getQuantityInherited($product
) / $solver->getUnitInherited($product)->getCoefficient());
} else {
return 0;
}
@@ -26,18 +52,20 @@ class ProductPriceSolver
{
return $this->applyTax(
$this->getPrice($product),
$product->getTaxRateInherited()->getValue()
$this->productFamilySolver->getTaxRateInherited($product)->getValue()
);
}


public function getPriceByRefUnit(ProductPropertyInterface $product)
{
if ($product->getBehaviorPriceInherited() == 'by-piece') {
return ($this->getPrice($product) * $product->getUnitInherited()->getCoefficient(
)) / $product->getQuantityInherited();
} elseif ($product->getBehaviorPriceInherited() == 'by-reference-unit') {
return $product->getPriceByRefUnitInherited();
$solver = $this->getSolver($product);

if ($solver->getBehaviorPriceInherited($product) == 'by-piece') {
return ($this->getPrice($product) * $solver->getUnitInherited($product)->getCoefficient(
)) / $solver->getQuantityInherited($product);
} elseif ($solver->getBehaviorPriceInherited($product) == 'by-reference-unit') {
return $solver->getPriceByRefUnitInherited($product);
}
}

@@ -45,7 +73,7 @@ class ProductPriceSolver
{
return $this->applyTax(
$this->getPriceByRefUnit($product),
$product->getTaxRateInherited()->getValue()
$this->productFamilySolver->getTaxRateInherited($product)->getValue()
);
}

@@ -68,12 +96,14 @@ class ProductPriceSolver

public function getBuyingPrice(ProductPropertyInterface $product)
{
if ($product->getBehaviorPriceInherited() == 'by-piece') {
return $product->getBuyingPriceInherited();
} elseif ($product->getBehaviorPriceInherited() == 'by-reference-unit') {
if ($product->getQuantityInherited() > 0) {
return $product->getBuyingPriceByRefUnitInherited() * ($product->getQuantityInherited(
) / $product->getUnitInherited()->getCoefficient());
$solver = $this->getSolver($product);

if ($solver->getBehaviorPriceInherited($product) == 'by-piece') {
return $solver->getBuyingPriceInherited($product);
} elseif ($solver->getBehaviorPriceInherited($product) == 'by-reference-unit') {
if ($solver->getQuantityInherited($product) > 0) {
return $solver->getBuyingPriceByRefUnitInherited($product) * ($solver->getQuantityInherited($product
) / $solver->getUnitInherited($product)->getCoefficient());
} else {
return 0;
}
@@ -84,20 +114,20 @@ class ProductPriceSolver
{
return $this->applyTax(
$this->getBuyingPrice($product),
$product->getTaxRateInherited()->getValue()
$this->productFamilySolver->getTaxRateInherited($product)->getValue()
);
}

public function getBuyingPriceByRefUnit(ProductPropertyInterface $product)
{
return $product->getBuyingPriceByRefUnitInherited();
return $this->getSolver($product)->getBuyingPriceByRefUnitInherited($product);
}

public function getBuyingPriceByRefUnitWithTax(ProductPropertyInterface $product)
{
return $this->applyTax(
$this->getBuyingPriceByRefUnit($product),
$product->getTaxRateInherited()->getValue()
$this->productFamilySolver->getTaxRateInherited($product)->getValue()
);
}


+ 35
- 99
Solver/Product/ProductFamilySolver.php Bestand weergeven

@@ -4,6 +4,7 @@ namespace Lc\CaracoleBundle\Solver\Product;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Lc\CaracoleBundle\Doctrine\Extension\ProductPropertyInterface;
use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface;
use Lc\CaracoleBundle\Model\Product\ProductFamilyModel;
use Lc\CaracoleBundle\Model\Product\ProductInterface;
@@ -12,101 +13,14 @@ 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
);
}
protected ProductSolver $productSolver;

public function getMostExpensiveProductByRefUnit(ProductFamilyInterface $productFamily)
public function __construct(ProductSolver $productSolver)
{
$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 = $this->getProductsOnline($productFamily)->getValues();
if (count($products) > 0) {
usort($products, $comparisonFunction);
return $products[0];
}
} else {
return $this->getOriginProduct($productFamily);
}
if ($returnSelfIfNotActiveProducts) {
return $productFamily;
} else {
return false;
}
$this->productSolver = $productSolver;
}


public function getAvailableQuantityInherited(ProductFamilyInterface $productFamily)
{
$availableQuantity = 0;
@@ -121,7 +35,7 @@ class ProductFamilySolver
case ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT :

foreach ($this->getProductsOnline($productFamily) as $product) {
$availableQuantity += $product->getAvailableQuantityInherited();
$availableQuantity += $this->productSolver->getAvailableQuantityInherited($product);
}
break;

@@ -133,9 +47,12 @@ class ProductFamilySolver
return $availableQuantity;
}


public function getTaxRateInherited(ProductFamilyInterface $productFamily)
public function getTaxRateInherited(ProductPropertyInterface $productFamily)
{
if($productFamily instanceof ProductInterface) {
$productFamily = $productFamily->getProductFamily();
}

if ($productFamily->getTaxRate()) {
return $productFamily->getTaxRate();
} else {
@@ -143,7 +60,6 @@ class ProductFamilySolver
}
}


public function getProductsOnline(ProductFamilyInterface $productFamily): Collection
{
$products = $productFamily->getProducts();
@@ -269,7 +185,6 @@ class ProductFamilySolver
return $arrayProductsGroupByTitle;
}


public function getOriginProduct(ProductFamilyInterface $productFamily): ?ProductInterface
{
$products = $productFamily->getProducts();
@@ -283,7 +198,6 @@ class ProductFamilySolver
return null;
}


public function getOriginProductOnline(ProductFamilyInterface $productFamily): ?ProductInterface
{
$originProduct = $this->getOriginProduct($productFamily);
@@ -295,7 +209,6 @@ class ProductFamilySolver
}
}


public function hasOneProductOnline(ProductFamilyInterface $productFamily)
{
if (($productFamily->getActiveProducts() && count($this->getProductsOnline($productFamily)) > 0)
@@ -306,7 +219,6 @@ class ProductFamilySolver
return false;
}


public function getFieldBuyingPrice(ProductFamilyInterface $productFamily): string
{
if ($productFamily->getBehaviorPrice() === ProductFamilyModel::BEHAVIOR_PRICE_BY_PIECE) {
@@ -316,7 +228,6 @@ class ProductFamilySolver
}
}


public function getFieldPrice(ProductFamilyInterface $productFamily): string
{
if ($productFamily->getBehaviorPrice() === ProductFamilyModel::BEHAVIOR_PRICE_BY_PIECE) {
@@ -413,5 +324,30 @@ class ProductFamilySolver
];
}

public function getBuyingPriceByRefUnitInherited(ProductFamilyInterface $productFamily): ?float
{
return $productFamily->getBuyingPriceByRefUnit();
}

public function getPriceByRefUnitInherited(ProductFamilyInterface $productFamily): ?float
{
return $productFamily->getPriceByRefUnit();
}

public function getQuantityInherited(ProductFamilyInterface $productFamily): ?float
{
return $productFamily->getQuantity();
}

public function getUnitInherited(ProductFamilyInterface $productFamily)
{
return $productFamily->getUnit();
}

public function getPriceInherited(ProductFamilyInterface $productFamily)
{
return $productFamily->getPrice();
}

}


+ 148
- 0
Solver/Product/ProductSolver.php Bestand weergeven

@@ -4,6 +4,7 @@ namespace Lc\CaracoleBundle\Solver\Product;

use Doctrine\Common\Collections\ArrayCollection;
use Lc\CaracoleBundle\Model\Order\OrderShopInterface;
use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface;
use Lc\CaracoleBundle\Model\Product\ProductFamilyModel;
use Lc\CaracoleBundle\Model\Product\ProductInterface;

@@ -49,6 +50,153 @@ class ProductSolver
return true;
}

// getProductQuantity
public function getProductQuantity(ProductInterface $product)
{
$productFamily = $product->getProductFamily();

if ($productFamily->getBehaviorCountStock() == ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_MEASURE) {
return $this->getQuantityInherited($product) / $this->getUnitInherited($product)->getCoefficient();
} else {
return 1;
}
}

public function getBuyingPriceInherited(ProductInterface $product)
{
if ($product->getBuyingPrice()) {
return $product->getBuyingPrice();
} else {
return $product->getProductFamily()->getBuyingPrice();
}
}

public function getBuyingPriceByRefUnitInherited(ProductInterface $product)
{
if ($product->getBuyingPriceByRefUnit()) {
return $product->getBuyingPriceByRefUnit();
} else {
return $product->getProductFamily()->getBuyingPriceByRefUnit();
}
}

public function getPriceInherited(ProductInterface $product)
{
if ($product->getPrice()) {
return $product->getPrice();
} else {
return $product->getProductFamily()->getPrice();
}
}

public function getPriceByRefUnitInherited(ProductInterface $product)
{
if ($product->getPriceByRefUnit()) {
return $product->getPriceByRefUnit();
} else {
return $product->getProductFamily()->getPriceByRefUnit();
}
}

public function getBehaviorPriceInherited(ProductInterface $product)
{
return $product->getProductFamily()->getBehaviorPrice();
}

public function getReductionCatalogInherited(ProductInterface $product)
{
return $product->getProductFamily()->getReductionCatalog();
}

public function getUnitInherited(ProductInterface $product)
{
if ($product->getUnit()) {
return $product->getUnit();
} else {
return $product->getProductFamily()->getUnit();
}
}

public function getTitleInherited(ProductInterface $product)
{
if ($product->getTitle()) {
return $product->getTitle();
} else {
return $product->getProductFamily()->getTitle();
}
}

public function getQuantityInherited(ProductInterface $product)
{
if ($product->getQuantity()) {
return $product->getQuantity();
} else {
return $product->getProductFamily()->getQuantity();
}
}

public function getQuantityLabelInherited(ProductInterface $product)
{
$quantity = $product->getQuantityInherited();
$unit = $product->getUnitInherited();
return $quantity . $unit->getWordingShort();
}

// @TODO : si besoin, à remettre en place
/*public function getQuantityTitle(ProductInterface $product, ProductFamilyInterface $productFamily)
{
$title = $product->getQuantityLabelInherited();
if ($this->productFamilySolver->hasProductsWithVariousWeight($productFamily)) {
$title .= ', ' . $product->getTitleInherited();
}
return $title;
}*/

public function getAvailableQuantityInherited(ProductInterface $product)
{
switch ($product->getProductFamily()->getBehaviorCountStock()) {
case ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY :
case ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_MEASURE :
return $product->getProductFamily()->getAvailableQuantity();
case ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT :
return $product->getAvailableQuantity();
case ProductFamilyModel::BEHAVIOR_COUNT_STOCK_UNLIMITED :
return false;
}
}

/*public function getTaxRateInherited(ProductInterface $product)
{
return $product->getProductFamily()->getTaxRateInherited();
}*/

public function getExportTitleInherited(ProductInterface $product): ?string
{
$exportTitle = $product->getExportTitle();
if ($exportTitle && strlen($exportTitle)) {
return $exportTitle;
} else {
$productFamily = $product->getProductFamily();
if ($productFamily) {
return $productFamily->getExportTitle();
}
}

return null;
}

public function getExportNoteInherited(ProductInterface $product): ?string
{
$exportNote = $product->getExportNote();
if ($exportNote && strlen($exportNote)) {
return $exportNote;
} else {
$productFamily = $product->getProductFamily();
if ($productFamily) {
return $productFamily->getExportNote();
}
}

return null;
}
}

+ 5
- 2
Transformer/Order/OrderShopTransformer.php Bestand weergeven

@@ -3,6 +3,7 @@
namespace Lc\CaracoleBundle\Transformer\Order;

use Lc\CaracoleBundle\Model\Order\OrderShopInterface;
use Lc\CaracoleBundle\Resolver\OrderShopResolver;
use Lc\CaracoleBundle\Resolver\ReductionResolver;
use Lc\CaracoleBundle\Solver\Order\OrderShopSolver;
use Lc\CaracoleBundle\Solver\Price\PriceSolver;
@@ -12,11 +13,13 @@ class OrderShopTransformer
{
protected PriceSolver $priceSolver;
protected OrderShopSolver $orderShopSolver;
protected OrderShopResolver $orderShopResolver;
public function __construct(PriceSolver $priceSolver, OrderShopSolver $orderShopSolver)
public function __construct(PriceSolver $priceSolver, OrderShopSolver $orderShopSolver, OrderShopResolver $orderShopResolver)
{
$this->priceSolver = $priceSolver;
$this->orderShopSolver = $orderShopSolver;
$this->orderShopResolver = $orderShopResolver;
}

// getOrderDatas
@@ -30,7 +33,7 @@ class OrderShopTransformer
$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);
$data['total_remaining_to_be_paid'] = $this->orderShopResolver->getTotalRemainingToBePaid($orderShop);
}
return $data;
}

Laden…
Annuleren
Opslaan