Просмотр исходного кода

Refactoring services frontend

packProduct
Guillaume 2 лет назад
Родитель
Сommit
eaa7985ef6
30 измененных файлов: 688 добавлений и 980 удалений
  1. +17
    -5
      Builder/Order/OrderProductBuilder.php
  2. +16
    -9
      Builder/Order/OrderShopBuilder.php
  3. +10
    -1
      Container/Product/ProductFamilyContainer.php
  4. +1
    -1
      Controller/ControllerTrait.php
  5. +0
    -15
      Doctrine/Extension/ProductPropertyTrait.php
  6. +1
    -1
      Event/Order/CartChangeEvent.php
  7. +3
    -1
      Factory/Order/OrderStatusHistoryFactory.php
  8. +9
    -13
      Form/Order/OrderProductType.php
  9. +68
    -18
      Form/Order/OrderProductsType.php
  10. +3
    -53
      Model/Order/OrderProductModel.php
  11. +1
    -1
      Model/Order/OrderShopModel.php
  12. +0
    -235
      Model/Product/ProductFamilyInterface.php
  13. +0
    -230
      Model/Product/ProductFamilyModel.php
  14. +0
    -33
      Model/Product/ProductInterface.php
  15. +0
    -182
      Model/Product/ProductModel.php
  16. +1
    -1
      Repository/Order/OrderShopStore.php
  17. +5
    -0
      Repository/Order/OrderStatusRepositoryQuery.php
  18. +7
    -0
      Repository/Order/OrderStatusStore.php
  19. +53
    -0
      Resolver/OrderShopResolver.php
  20. +107
    -0
      Resolver/ProductFamilyResolver.php
  21. +65
    -0
      Solver/Order/OrderProductSolver.php
  22. +41
    -41
      Solver/Order/OrderShopSolver.php
  23. +14
    -5
      Solver/Price/OrderProductPriceSolver.php
  24. +11
    -3
      Solver/Price/OrderShopPriceSolver.php
  25. +2
    -2
      Solver/Price/PriceSolver.php
  26. +13
    -7
      Solver/Price/PriceSolverTrait.php
  27. +52
    -22
      Solver/Price/ProductPriceSolver.php
  28. +35
    -99
      Solver/Product/ProductFamilySolver.php
  29. +148
    -0
      Solver/Product/ProductSolver.php
  30. +5
    -2
      Transformer/Order/OrderShopTransformer.php

+ 17
- 5
Builder/Order/OrderProductBuilder.php Просмотреть файл

use Lc\CaracoleBundle\Model\Order\OrderProductInterface; use Lc\CaracoleBundle\Model\Order\OrderProductInterface;
use Lc\CaracoleBundle\Repository\Order\OrderProductStore; use Lc\CaracoleBundle\Repository\Order\OrderProductStore;
use Lc\CaracoleBundle\Resolver\Price\PriceResolver; use Lc\CaracoleBundle\Resolver\Price\PriceResolver;
use Lc\CaracoleBundle\Solver\Order\OrderProductSolver;
use Lc\CaracoleBundle\Solver\Price\PriceSolver; use Lc\CaracoleBundle\Solver\Price\PriceSolver;
use Lc\CaracoleBundle\Solver\Product\ProductFamilySolver;
use Lc\CaracoleBundle\Solver\Product\ProductSolver;


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


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


public function init(OrderProductInterface $orderProduct) :OrderProductInterface public function init(OrderProductInterface $orderProduct) :OrderProductInterface
{ {
$orderProduct->setTitle($orderProduct->getTitleOrderShop());
$orderProduct->setTitle($this->orderProductSolver->getTitleOrderShop($orderProduct));
$orderProduct->setPrice($this->priceSolver->getPrice($orderProduct->getProduct())); $orderProduct->setPrice($this->priceSolver->getPrice($orderProduct->getProduct()));
$orderProduct->setBuyingPrice($this->priceSolver->getBuyingPrice($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; return $orderProduct;
} }

+ 16
- 9
Builder/Order/OrderShopBuilder.php Просмотреть файл

use Lc\CaracoleBundle\Resolver\Price\PriceResolver; use Lc\CaracoleBundle\Resolver\Price\PriceResolver;
use Lc\CaracoleBundle\Solver\Order\OrderShopSolver; use Lc\CaracoleBundle\Solver\Order\OrderShopSolver;
use Lc\CaracoleBundle\Solver\Price\PriceSolver; use Lc\CaracoleBundle\Solver\Price\PriceSolver;
use Lc\CaracoleBundle\Solver\Product\ProductSolver;
use Lc\CaracoleBundle\Statistic\Product\ProductsSalesStatistic; use Lc\CaracoleBundle\Statistic\Product\ProductsSalesStatistic;
use Lc\SovBundle\Model\User\UserInterface; use Lc\SovBundle\Model\User\UserInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface;
protected EventDispatcherInterface $eventDispatcher; protected EventDispatcherInterface $eventDispatcher;
protected FlashBagInterface $flashBag; protected FlashBagInterface $flashBag;
protected OpeningResolver $openingResolver; protected OpeningResolver $openingResolver;
protected ProductSolver $productSolver;


public function __construct( public function __construct(
EntityManagerInterface $entityManager, EntityManagerInterface $entityManager,
PriceSolver $priceSolver, PriceSolver $priceSolver,
EventDispatcherInterface $eventDispatcher, EventDispatcherInterface $eventDispatcher,
FlashBagInterface $flashBag, FlashBagInterface $flashBag,
OpeningResolver $openingResolver
OpeningResolver $openingResolver,
ProductSolver $productSolver
) { ) {
$this->entityManager = $entityManager; $this->entityManager = $entityManager;
$this->orderShopStore = $orderShopStore; $this->orderShopStore = $orderShopStore;
$this->eventDispatcher = $eventDispatcher; $this->eventDispatcher = $eventDispatcher;
$this->flashBag = $flashBag; $this->flashBag = $flashBag;
$this->openingResolver = $openingResolver; $this->openingResolver = $openingResolver;
$this->productSolver = $productSolver;
} }


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

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


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


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


return $orderShop; return $orderShop;
} }
UserInterface $user = null, UserInterface $user = null,
VisitorInterface $visitor = null VisitorInterface $visitor = null
): OrderShopInterface { ): OrderShopInterface {
$cart = $this->orderShopStore->getCartBy(
$cart = $this->orderShopStore->getOneCartCurrent(
[ [
'section' => $section, 'section' => $section,
'user' => $user, 'user' => $user,
string $alias, string $alias,
bool $forceByAdmin = false bool $forceByAdmin = false
): OrderShopInterface { ): OrderShopInterface {
$orderStatus = $this->orderStatusStore->getRepositoryQuery()->findOneByAlias($alias);

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


if ($orderStatus) { if ($orderStatus) {
if ($orderShop->getOrderStatus() === null if ($orderShop->getOrderStatus() === null
): bool { ): bool {
$return = false; $return = false;


if ($this->orderProductStore->isOrderProductAvailableAddCart($orderProductAdd, $orderShop)) {
if ($this->orderShopSolver->isOrderProductAvailableAddCart($orderProductAdd, $orderShop)) {
if ($orderProductAdd->getQuantityOrder() > 0) { if ($orderProductAdd->getQuantityOrder() > 0) {
$updated = false; $updated = false;
$this->orderProductBuilder->init($orderProductAdd); $this->orderProductBuilder->init($orderProductAdd);
foreach ($orderShop->getOrderProducts() as $orderProduct) { foreach ($orderShop->getOrderProducts() as $orderProduct) {
if ($orderProduct->getProduct()->getId() == $orderProductAdd->getProduct()->getId() if ($orderProduct->getProduct()->getId() == $orderProductAdd->getProduct()->getId()
&& $orderProduct->getRedelivery() == $orderProductAdd->getRedelivery() && $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( && $orderProduct->getOrderProductReductionCatalog()->compare(
$orderProductAdd->getOrderProductReductionCatalog() $orderProductAdd->getOrderProductReductionCatalog()
)) { )) {
$this->entityManager->create($orderProductReductionCatalog); $this->entityManager->create($orderProductReductionCatalog);
} }
//TODO est-ce un update ou un create ??? //TODO est-ce un update ou un create ???
$this->entityManager->update($orderProductAdd);
$this->entityManager->persist($orderProductAdd);
$this->entityManager->update($orderShop); $this->entityManager->update($orderShop);
} }


case ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_MEASURE : case ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_MEASURE :


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



+ 10
- 1
Container/Product/ProductFamilyContainer.php Просмотреть файл

use Lc\CaracoleBundle\Factory\Product\ProductFamilyFactory; use Lc\CaracoleBundle\Factory\Product\ProductFamilyFactory;
use Lc\CaracoleBundle\Repository\Product\ProductFamilyRepositoryQuery; use Lc\CaracoleBundle\Repository\Product\ProductFamilyRepositoryQuery;
use Lc\CaracoleBundle\Repository\Product\ProductFamilyStore; use Lc\CaracoleBundle\Repository\Product\ProductFamilyStore;
use Lc\CaracoleBundle\Resolver\ProductFamilyResolver;
use Lc\CaracoleBundle\Solver\Product\ProductFamilySolver; use Lc\CaracoleBundle\Solver\Product\ProductFamilySolver;


class ProductFamilyContainer class ProductFamilyContainer
protected ProductFamilySolver $solver; protected ProductFamilySolver $solver;
protected ProductFamilyRepositoryQuery $repositoryQuery; protected ProductFamilyRepositoryQuery $repositoryQuery;
protected ProductFamilyStore $store; protected ProductFamilyStore $store;
protected ProductFamilyResolver $resolver;


public function __construct( public function __construct(
ProductFamilyFactory $factory, ProductFamilyFactory $factory,
ProductFamilySolver $solver, ProductFamilySolver $solver,
ProductFamilyRepositoryQuery $repositoryQuery, ProductFamilyRepositoryQuery $repositoryQuery,
ProductFamilyStore $store
ProductFamilyStore $store,
ProductFamilyResolver $resolver
) { ) {
$this->factory = $factory; $this->factory = $factory;
$this->solver = $solver; $this->solver = $solver;
$this->repositoryQuery = $repositoryQuery; $this->repositoryQuery = $repositoryQuery;
$this->store = $store; $this->store = $store;
$this->resolver = $resolver;
} }


public function getFactory(): ProductFamilyFactory public function getFactory(): ProductFamilyFactory
return $this->store; return $this->store;
} }


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

} }

+ 1
- 1
Controller/ControllerTrait.php Просмотреть файл



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


public function getMerchantCurrent(): MerchantInterface public function getMerchantCurrent(): MerchantInterface

+ 0
- 15
Doctrine/Extension/ProductPropertyTrait.php Просмотреть файл

return $this->buyingPriceByRefUnit; return $this->buyingPriceByRefUnit;
} }


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

public function setBuyingPriceByRefUnit(?float $buyingPriceByRefUnit): self public function setBuyingPriceByRefUnit(?float $buyingPriceByRefUnit): self
{ {
$this->buyingPriceByRefUnit = $buyingPriceByRefUnit; $this->buyingPriceByRefUnit = $buyingPriceByRefUnit;
return $this->priceByRefUnit; return $this->priceByRefUnit;
} }


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

public function setPriceByRefUnit(?float $priceByRefUnit): self public function setPriceByRefUnit(?float $priceByRefUnit): self
{ {
$this->priceByRefUnit = $priceByRefUnit; $this->priceByRefUnit = $priceByRefUnit;
return $this; return $this;
} }


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

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

+ 1
- 1
Event/Order/CartChangeEvent.php Просмотреть файл



protected OrderShopInterface $orderShop; protected OrderShopInterface $orderShop;


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

+ 3
- 1
Factory/Order/OrderStatusHistoryFactory.php Просмотреть файл

use Lc\CaracoleBundle\Model\Order\OrderShopInterface; use Lc\CaracoleBundle\Model\Order\OrderShopInterface;
use Lc\CaracoleBundle\Model\Order\OrderStatusHistoryInterface; use Lc\CaracoleBundle\Model\Order\OrderStatusHistoryInterface;
use Lc\CaracoleBundle\Model\Order\OrderStatusHistoryModel; use Lc\CaracoleBundle\Model\Order\OrderStatusHistoryModel;
use Lc\CaracoleBundle\Model\Order\OrderStatusInterface;
use Lc\SovBundle\Factory\AbstractFactory; use Lc\SovBundle\Factory\AbstractFactory;


class OrderStatusHistoryFactory extends 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 = new OrderStatusHistory();


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


return $orderStatusHistory; return $orderStatusHistory;
} }

+ 9
- 13
Form/Order/OrderProductType.php Просмотреть файл

namespace Lc\CaracoleBundle\Form\Order; namespace Lc\CaracoleBundle\Form\Order;


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


class OrderProductType extends AbstractType class OrderProductType extends AbstractType
{ {


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

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


$builder->get('product')->addModelTransformer($this->productTransformer); $builder->get('product')->addModelTransformer($this->productTransformer);


public function configureOptions(OptionsResolver $resolver) 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 Просмотреть файл



namespace Lc\CaracoleBundle\Form\Order; 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\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\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\OptionsResolver\OptionsResolver;


class OrderProductsType extends AbstractType 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) 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) public function configureOptions(OptionsResolver $resolver)
{ {
$resolver->setDefaults(
[
]
);
$resolver->setDefaults([
// Configure your form options here
]);
} }
}
}

+ 3
- 53
Model/Order/OrderProductModel.php Просмотреть файл

} }
} }


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 // isOrderProductAvailable
public function isAvailable() public function isAvailable()
{ {
} }


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


public function getOrderShop(): ?OrderShopInterface public function getOrderShop(): ?OrderShopInterface
{ {

+ 1
- 1
Model/Order/OrderShopModel.php Просмотреть файл

protected $meanPayment; 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; protected $orderStatusHistories;



+ 0
- 235
Model/Product/ProductFamilyInterface.php Просмотреть файл



namespace Lc\CaracoleBundle\Model\Product; 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() * @ORM\MappedSuperclass()
*/ */
interface ProductFamilyInterface 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 Просмотреть файл

{ {
use ProductPropertyTrait; use ProductPropertyTrait;



const BEHAVIOR_COUNT_STOCK_UNLIMITED = 'unlimited'; const BEHAVIOR_COUNT_STOCK_UNLIMITED = 'unlimited';
const BEHAVIOR_COUNT_STOCK_BY_MEASURE = 'by-measure'; const BEHAVIOR_COUNT_STOCK_BY_MEASURE = 'by-measure';
const BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY = 'by-product-family'; const BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY = 'by-product-family';
return $this; 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 public function getActiveProducts(): ?bool
{ {
return $this->activeProducts; return $this->activeProducts;
return $this->products; 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 public function addProduct(ProductInterface $product): self
{ {
if (!$this->products->contains($product)) { if (!$this->products->contains($product)) {
return $this->reductionCatalog; return $this->reductionCatalog;
} }


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

public function setReductionCatalog(?ReductionCatalogInterface $reductionCatalog): self public function setReductionCatalog(?ReductionCatalogInterface $reductionCatalog): self
{ {
$this->reductionCatalog = $reductionCatalog; $this->reductionCatalog = $reductionCatalog;
return $this; 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 public function getSubtitle(): ?string
{ {
return $this->subtitle; return $this->subtitle;
return $this; 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 public function getPropertyNoveltyExpirationDate(): ?\DateTimeInterface
{ {
return $this->propertyNoveltyExpirationDate; return $this->propertyNoveltyExpirationDate;
return $this; 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 public function getBehaviorExpirationDate(): ?string
{ {
return $this->behaviorExpirationDate; return $this->behaviorExpirationDate;
return $this; return $this;
} }



public function getPropertyWeight(): ?string public function getPropertyWeight(): ?string
{ {
return $this->propertyWeight; return $this->propertyWeight;
return $this; return $this;
} }



public function getPropertyQuantity(): ?string public function getPropertyQuantity(): ?string
{ {
return $this->propertyQuantity; return $this->propertyQuantity;
return $this; return $this;
} }



public function getPropertyPackaging(): ?string public function getPropertyPackaging(): ?string
{ {
return $this->propertyPackaging; return $this->propertyPackaging;
return $this->behaviorPrice; return $this->behaviorPrice;
} }


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

public function setBehaviorPrice(?string $behaviorPrice): self public function setBehaviorPrice(?string $behaviorPrice): self
{ {
$this->behaviorPrice = $behaviorPrice; $this->behaviorPrice = $behaviorPrice;
return $this; 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 public function getSaleStatus(): ?bool
{ {
return $this->saleStatus; return $this->saleStatus;
return $this; 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 public function getImage(): ?FileInterface
{ {
return $this->image; return $this->image;

+ 0
- 33
Model/Product/ProductInterface.php Просмотреть файл

*/ */
interface ProductInterface 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; public function getProductFamily(): ?ProductFamilyInterface;




public function getExportTitle(): ?string; public function getExportTitle(): ?string;


public function getExportTitleInherited(): ?string;

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


public function getExportNote(): ?string; public function getExportNote(): ?string;


public function getExportNoteInherited(): ?string;

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

+ 0
- 182
Model/Product/ProductModel.php Просмотреть файл

return $title; 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 public function getProductFamily(): ?ProductFamilyInterface
{ {
return $this->productFamily; return $this->productFamily;
return $this; return $this;
} }



public function getExportTitle(): ?string public function getExportTitle(): ?string
{ {
return $this->exportTitle; 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 public function setExportTitle(?string $exportTitle): self
{ {
return $this->exportNote; 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 public function setExportNote(?string $exportNote): self
{ {
$this->exportNote = $exportNote; $this->exportNote = $exportNote;

+ 1
- 1
Repository/Order/OrderShopStore.php Просмотреть файл

} }


// getOrderShopsOfWeekByUser // getOrderShopsOfWeekByUser
public function getByCurrentCycleAndUser(UserInterface $user, array $params = [], $query = null)
public function getByCurrentCycleAndUser(UserInterface $user = null, array $params = [], $query = null)
{ {
return $this->getByCurrentCycle( return $this->getByCurrentCycle(
array_merge( array_merge(

+ 5
- 0
Repository/Order/OrderStatusRepositoryQuery.php Просмотреть файл

{ {
parent::__construct($repository, 'r', $paginator); parent::__construct($repository, 'r', $paginator);
} }

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

+ 7
- 0
Repository/Order/OrderStatusStore.php Просмотреть файл

{ {
return $query; return $query;
} }

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

+ 53
- 0
Resolver/OrderShopResolver.php Просмотреть файл

<?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 Просмотреть файл

<?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;
}
}
}

+ 65
- 0
Solver/Order/OrderProductSolver.php Просмотреть файл



namespace Lc\CaracoleBundle\Solver\Order; 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 class OrderProductSolver
{ {
protected ProductSolver $productSolver;
protected ProductFamilySolver $productFamilySolver;

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

// groupOrderProductsByProductFamily // groupOrderProductsByProductFamily
public function getOrderProductsByProductFamily(array $orderProducts): array public function getOrderProductsByProductFamily(array $orderProducts): array
{ {


return $orderProductsByStorageOrder; 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 Просмотреть файл

use Lc\CaracoleBundle\Model\Product\ProductFamilyModel; use Lc\CaracoleBundle\Model\Product\ProductFamilyModel;
use Lc\CaracoleBundle\Model\Product\ProductInterface; use Lc\CaracoleBundle\Model\Product\ProductInterface;
use Lc\CaracoleBundle\Model\Reduction\ReductionCreditInterface; use Lc\CaracoleBundle\Model\Reduction\ReductionCreditInterface;
use Lc\CaracoleBundle\Solver\Price\PriceSolver;
use Lc\CaracoleBundle\Solver\Product\ProductSolver; use Lc\CaracoleBundle\Solver\Product\ProductSolver;


class OrderShopSolver class OrderShopSolver
{ {
protected PriceSolver $priceSolver;
protected EntityManagerInterface $entityManager; protected EntityManagerInterface $entityManager;
protected ProductSolver $productSolver; 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->entityManager = $entityManager;
$this->productSolver = $productSolver; $this->productSolver = $productSolver;
} }
} }


// isProductAvailable // 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; return false;
} }


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


if ($checkCart) { if ($checkCart) {


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

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


if ($product->getAvailableQuantityInherited() >= $quantityAsked
if ($this->productSolver->getAvailableQuantityInherited($product) >= $quantityAsked
|| $productFamily->getBehaviorCountStock() == ProductFamilyModel::BEHAVIOR_COUNT_STOCK_UNLIMITED) { || $productFamily->getBehaviorCountStock() == ProductFamilyModel::BEHAVIOR_COUNT_STOCK_UNLIMITED) {
return true; return true;
} else { } else {
return false; 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 public function getTotalOrderPayments(OrderShopInterface $orderShop, $mergeComplementaryOrderShop = false): float
{ {
$totalAmount = floatval(0); $totalAmount = floatval(0);
return $totalAmount; return $totalAmount;
} }


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

public function getOrderStatusHistory(OrderShopInterface $orderShop, OrderStatusInterface $status) public function getOrderStatusHistory(OrderShopInterface $orderShop, OrderStatusInterface $status)
{ {
$orderStatusHistories = $orderShop->getOrderStatusHistories(); $orderStatusHistories = $orderShop->getOrderStatusHistories();


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


public function mergeComplentaryOrderShops( public function mergeComplentaryOrderShops(
} }





public function hasOrderProductAlreadyInCart( public function hasOrderProductAlreadyInCart(
OrderShopInterface $orderShop, OrderShopInterface $orderShop,
OrderProductInterface $orderProductTest OrderProductInterface $orderProductTest
return false; 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 Просмотреть файл

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


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


class OrderProductPriceSolver class OrderProductPriceSolver
{ {
use PriceSolverTrait; 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) public function getPrice(OrderProductInterface $orderProduct, $round = false)

+ 11
- 3
Solver/Price/OrderShopPriceSolver.php Просмотреть файл

use Lc\CaracoleBundle\Model\Order\OrderReductionCreditInterface; use Lc\CaracoleBundle\Model\Order\OrderReductionCreditInterface;
use Lc\CaracoleBundle\Model\Order\OrderShopInterface; use Lc\CaracoleBundle\Model\Order\OrderShopInterface;
use Lc\CaracoleBundle\Model\Reduction\ReductionCartModel; 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 class OrderShopPriceSolver
{ {
use PriceSolverTrait; use PriceSolverTrait;


protected OrderProductPriceSolver $orderProductPriceResolver; 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->orderProductPriceResolver = $orderProductPriceResolver;
$this->productSolver = $productSolver;
$this->productFamilySolver = $productFamilySolver;
} }


//Inclus les ReductionCatalog des OrderProducts //Inclus les ReductionCatalog des OrderProducts

+ 2
- 2
Solver/Price/PriceSolver.php Просмотреть файл

} }
} else { } else {
if (!strlen($service)) { 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 { } else {
if (!method_exists($this->$service, $name)) { if (!method_exists($this->$service, $name)) {
throw new \ErrorException( 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 Просмотреть файл



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


trait PriceSolverTrait trait PriceSolverTrait
{ {
$reductionCatalogUnit = $reductionCatalog->getUnit(); $reductionCatalogUnit = $reductionCatalog->getUnit();
$reductionCatalogBehaviorTaxRate = $reductionCatalog->getBehaviorTaxRate(); $reductionCatalogBehaviorTaxRate = $reductionCatalog->getBehaviorTaxRate();
} else { } 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) { if ($entity instanceof OrderProductInterface) {

+ 52
- 22
Solver/Price/ProductPriceSolver.php Просмотреть файл

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


use Lc\CaracoleBundle\Doctrine\Extension\ProductPropertyInterface; 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 class ProductPriceSolver
{ {
use PriceSolverTrait; 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) 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 { } else {
return 0; return 0;
} }
{ {
return $this->applyTax( return $this->applyTax(
$this->getPrice($product), $this->getPrice($product),
$product->getTaxRateInherited()->getValue()
$this->productFamilySolver->getTaxRateInherited($product)->getValue()
); );
} }




public function getPriceByRefUnit(ProductPropertyInterface $product) 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);
} }
} }


{ {
return $this->applyTax( return $this->applyTax(
$this->getPriceByRefUnit($product), $this->getPriceByRefUnit($product),
$product->getTaxRateInherited()->getValue()
$this->productFamilySolver->getTaxRateInherited($product)->getValue()
); );
} }




public function getBuyingPrice(ProductPropertyInterface $product) 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 { } else {
return 0; return 0;
} }
{ {
return $this->applyTax( return $this->applyTax(
$this->getBuyingPrice($product), $this->getBuyingPrice($product),
$product->getTaxRateInherited()->getValue()
$this->productFamilySolver->getTaxRateInherited($product)->getValue()
); );
} }


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


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



+ 35
- 99
Solver/Product/ProductFamilySolver.php Просмотреть файл



use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection; use Doctrine\Common\Collections\Collection;
use Lc\CaracoleBundle\Doctrine\Extension\ProductPropertyInterface;
use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface; use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface;
use Lc\CaracoleBundle\Model\Product\ProductFamilyModel; use Lc\CaracoleBundle\Model\Product\ProductFamilyModel;
use Lc\CaracoleBundle\Model\Product\ProductInterface; use Lc\CaracoleBundle\Model\Product\ProductInterface;


class ProductFamilySolver 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) public function getAvailableQuantityInherited(ProductFamilyInterface $productFamily)
{ {
$availableQuantity = 0; $availableQuantity = 0;
case ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT : case ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT :


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


return $availableQuantity; return $availableQuantity;
} }



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

if ($productFamily->getTaxRate()) { if ($productFamily->getTaxRate()) {
return $productFamily->getTaxRate(); return $productFamily->getTaxRate();
} else { } else {
} }
} }



public function getProductsOnline(ProductFamilyInterface $productFamily): Collection public function getProductsOnline(ProductFamilyInterface $productFamily): Collection
{ {
$products = $productFamily->getProducts(); $products = $productFamily->getProducts();
return $arrayProductsGroupByTitle; return $arrayProductsGroupByTitle;
} }



public function getOriginProduct(ProductFamilyInterface $productFamily): ?ProductInterface public function getOriginProduct(ProductFamilyInterface $productFamily): ?ProductInterface
{ {
$products = $productFamily->getProducts(); $products = $productFamily->getProducts();
return null; return null;
} }



public function getOriginProductOnline(ProductFamilyInterface $productFamily): ?ProductInterface public function getOriginProductOnline(ProductFamilyInterface $productFamily): ?ProductInterface
{ {
$originProduct = $this->getOriginProduct($productFamily); $originProduct = $this->getOriginProduct($productFamily);
} }
} }



public function hasOneProductOnline(ProductFamilyInterface $productFamily) public function hasOneProductOnline(ProductFamilyInterface $productFamily)
{ {
if (($productFamily->getActiveProducts() && count($this->getProductsOnline($productFamily)) > 0) if (($productFamily->getActiveProducts() && count($this->getProductsOnline($productFamily)) > 0)
return false; return false;
} }



public function getFieldBuyingPrice(ProductFamilyInterface $productFamily): string public function getFieldBuyingPrice(ProductFamilyInterface $productFamily): string
{ {
if ($productFamily->getBehaviorPrice() === ProductFamilyModel::BEHAVIOR_PRICE_BY_PIECE) { if ($productFamily->getBehaviorPrice() === ProductFamilyModel::BEHAVIOR_PRICE_BY_PIECE) {
} }
} }



public function getFieldPrice(ProductFamilyInterface $productFamily): string public function getFieldPrice(ProductFamilyInterface $productFamily): string
{ {
if ($productFamily->getBehaviorPrice() === ProductFamilyModel::BEHAVIOR_PRICE_BY_PIECE) { if ($productFamily->getBehaviorPrice() === ProductFamilyModel::BEHAVIOR_PRICE_BY_PIECE) {
]; ];
} }


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 Просмотреть файл



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


return true; 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 Просмотреть файл

namespace Lc\CaracoleBundle\Transformer\Order; namespace Lc\CaracoleBundle\Transformer\Order;


use Lc\CaracoleBundle\Model\Order\OrderShopInterface; use Lc\CaracoleBundle\Model\Order\OrderShopInterface;
use Lc\CaracoleBundle\Resolver\OrderShopResolver;
use Lc\CaracoleBundle\Resolver\ReductionResolver; use Lc\CaracoleBundle\Resolver\ReductionResolver;
use Lc\CaracoleBundle\Solver\Order\OrderShopSolver; use Lc\CaracoleBundle\Solver\Order\OrderShopSolver;
use Lc\CaracoleBundle\Solver\Price\PriceSolver; use Lc\CaracoleBundle\Solver\Price\PriceSolver;
{ {
protected PriceSolver $priceSolver; protected PriceSolver $priceSolver;
protected OrderShopSolver $orderShopSolver; 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->priceSolver = $priceSolver;
$this->orderShopSolver = $orderShopSolver; $this->orderShopSolver = $orderShopSolver;
$this->orderShopResolver = $orderShopResolver;
} }


// getOrderDatas // getOrderDatas
$data['count'] = $this->orderShopSolver->countQuantities($orderShop); $data['count'] = $this->orderShopSolver->countQuantities($orderShop);
$data['total_with_tax'] = $this->priceSolver->getTotalWithTax($orderShop); $data['total_with_tax'] = $this->priceSolver->getTotalWithTax($orderShop);
$data['order_products_by_category'] = $this->orderShopSolver->getOrderProductsByParentCategory($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; return $data;
} }

Загрузка…
Отмена
Сохранить