Browse Source

Refactoring services frontend

packProduct
Guillaume 2 years ago
parent
commit
eaa7985ef6
30 changed files with 688 additions and 980 deletions
  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 View File

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

+ 16
- 9
Builder/Order/OrderShopBuilder.php View File

@@ -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()));


+ 10
- 1
Container/Product/ProductFamilyContainer.php View File

@@ -5,6 +5,7 @@ namespace Lc\CaracoleBundle\Container\Product;
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
@@ -13,17 +14,20 @@ class ProductFamilyContainer
protected ProductFamilySolver $solver;
protected ProductFamilyRepositoryQuery $repositoryQuery;
protected ProductFamilyStore $store;
protected ProductFamilyResolver $resolver;

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

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

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

}

+ 1
- 1
Controller/ControllerTrait.php View File

@@ -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

+ 0
- 15
Doctrine/Extension/ProductPropertyTrait.php View File

@@ -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 View File

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

+ 3
- 1
Factory/Order/OrderStatusHistoryFactory.php View File

@@ -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 View File

@@ -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 View File

@@ -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
]);
}
}
}

+ 3
- 53
Model/Order/OrderProductModel.php View File

@@ -59,57 +59,6 @@ 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()
{
@@ -117,11 +66,12 @@ abstract class OrderProductModel implements PriceInterface
}

// 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 View File

@@ -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 View File

@@ -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 View File

@@ -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 View File

@@ -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 View File

@@ -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
Repository/Order/OrderShopStore.php View File

@@ -110,7 +110,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(

+ 5
- 0
Repository/Order/OrderStatusRepositoryQuery.php View File

@@ -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 View File

@@ -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();
}
}

+ 53
- 0
Resolver/OrderShopResolver.php View File

@@ -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 View File

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

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

@@ -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 View File

@@ -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 View File

@@ -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 View File

@@ -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 View File

@@ -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 View File

@@ -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 View File

@@ -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 View File

@@ -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 View File

@@ -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 View File

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

Loading…
Cancel
Save