浏览代码

Refactoring services

packProduct
Guillaume 3 年前
父节点
当前提交
efdb8f8359
共有 19 个文件被更改,包括 135 次插入57 次删除
  1. +8
    -5
      Builder/File/DocumentBuilder.php
  2. +16
    -4
      Builder/Order/OrderShopBuilder.php
  3. +9
    -0
      Container/Order/OrderProductContainer.php
  4. +11
    -10
      Controller/Credit/CreditHistoryAdminController.php
  5. +1
    -1
      Form/Order/OrderProductsType.php
  6. +1
    -3
      Model/Order/OrderShopModel.php
  7. +5
    -0
      Repository/File/DocumentRepositoryQuery.php
  8. +19
    -3
      Repository/File/DocumentStore.php
  9. +0
    -12
      Repository/Order/OrderShopRepositoryQuery.php
  10. +2
    -2
      Repository/Order/OrderShopStore.php
  11. +1
    -0
      Repository/Product/ProductFamilyRepositoryQuery.php
  12. +10
    -1
      Repository/Product/ProductFamilyStore.php
  13. +7
    -0
      Repository/Reduction/ReductionCreditRepositoryQuery.php
  14. +10
    -2
      Repository/Reduction/ReductionCreditStore.php
  15. +21
    -0
      Repository/SectionRepositoryQueryTrait.php
  16. +1
    -2
      Solver/Order/OrderProductReductionCatalogSolver.php
  17. +1
    -1
      Solver/Order/OrderShopSolver.php
  18. +12
    -1
      Solver/Product/ProductFamilySolver.php
  19. +0
    -10
      Solver/Product/ProductSolver.php

+ 8
- 5
Builder/File/DocumentBuilder.php 查看文件

@@ -5,26 +5,29 @@ namespace Lc\CaracoleBundle\Builder\File;
use Lc\CaracoleBundle\Model\File\DocumentInterface;
use Lc\CaracoleBundle\Model\Order\OrderShopInterface;
use Lc\CaracoleBundle\Generator\DocumentReferenceGenerator;
use Lc\CaracoleBundle\Solver\Address\AddressSolver;

class DocumentBuilder
{
protected DocumentReferenceGenerator $documentReferenceGenerator;
protected AddressSolver $addressSolver;

public function __construct(DocumentReferenceGenerator $documentReferenceGenerator)
public function __construct(DocumentReferenceGenerator $documentReferenceGenerator, AddressSolver $addressSolver)
{
$this->documentReferenceGenerator = $documentReferenceGenerator;
$this->addressSolver = $addressSolver;
}

public function initFromOrderShop(DocumentInterface $document, OrderShopInterface $orderShop) :DocumentInterface
{
$merchantAddress = $orderShop->getMerchant()->getAddress();
$merchantAddress = $orderShop->getSection()->getMerchant()->getAddress();
$buyerAddress = $orderShop->getInvoiceAddress();

$document->setReference($this->documentReferenceGenerator->buildReference($orderShop->getMerchant())) ;
$document->setReference($this->documentReferenceGenerator->buildReference($orderShop->getSection()->getMerchant(), $document->getType())) ;
$document->setMerchantAddress($merchantAddress);
$document->setBuyerAddress($buyerAddress);
$document->setMerchantAddressText($merchantAddress->getSummary());
$document->setBuyerAddressText($buyerAddress->getSummary());
$document->setMerchantAddressText($this->addressSolver->getSummary($merchantAddress));
$document->setBuyerAddressText($this->addressSolver->getSummary($buyerAddress));
$document->addOrderShop($orderShop);
$document->setCreatedBy($orderShop->getUser());


+ 16
- 4
Builder/Order/OrderShopBuilder.php 查看文件

@@ -35,6 +35,7 @@ use Lc\CaracoleBundle\Repository\Order\OrderStatusStore;
use Lc\CaracoleBundle\Repository\Product\ProductFamilyStore;
use Lc\CaracoleBundle\Resolver\OpeningResolver;
use Lc\CaracoleBundle\Resolver\OrderShopResolver;
use Lc\CaracoleBundle\Solver\Order\OrderProductReductionCatalogSolver;
use Lc\CaracoleBundle\Solver\Order\OrderShopSolver;
use Lc\CaracoleBundle\Solver\Price\PriceSolver;
use Lc\CaracoleBundle\Solver\Product\ProductSolver;
@@ -59,6 +60,7 @@ class OrderShopBuilder
protected OpeningResolver $openingResolver;
protected ProductSolver $productSolver;
protected OrderShopResolver $orderShopResolver;
protected OrderProductReductionCatalogSolver $orderProductReductionCatalogSolver;

public function __construct(
EntityManagerInterface $entityManager,
@@ -74,7 +76,8 @@ class OrderShopBuilder
FlashBagInterface $flashBag,
OpeningResolver $openingResolver,
ProductSolver $productSolver,
OrderShopResolver $orderShopResolver
OrderShopResolver $orderShopResolver,
OrderProductReductionCatalogSolver $orderProductReductionCatalogSolver
) {
$this->entityManager = $entityManager;
$this->orderShopStore = $orderShopStore;
@@ -90,6 +93,7 @@ class OrderShopBuilder
$this->openingResolver = $openingResolver;
$this->productSolver = $productSolver;
$this->orderShopResolver = $orderShopResolver;
$this->orderProductReductionCatalogSolver = $orderProductReductionCatalogSolver;
}

public function create(
@@ -202,7 +206,10 @@ class OrderShopBuilder
&& $orderProduct->getRedelivery() == $orderProductAdd->getRedelivery()
&& (string)$this->priceSolver->getPrice($orderProduct)
== (string)$this->priceSolver->getPrice($orderProductAdd)
&& $orderProduct->getOrderProductReductionCatalog()->compare(
&& $orderProduct->getOrderProductReductionCatalog()
&& $orderProductAdd->getOrderProductReductionCatalog()
&& $this->orderProductReductionCatalogSolver->compare(
$orderProduct->getOrderProductReductionCatalog(),
$orderProductAdd->getOrderProductReductionCatalog()
)) {
$orderProduct->setQuantityOrder(
@@ -372,7 +379,7 @@ class OrderShopBuilder
public function createDocumentInvoice(OrderShopInterface $orderShop): DocumentInterface
{
$documentFactory = new DocumentFactory();
$document = $documentFactory->create(DocumentModel::TYPE_INVOICE);
$document = $documentFactory->create($orderShop->getSection(), DocumentModel::TYPE_INVOICE);
$this->documentBuilder->initFromOrderShop($document, $orderShop);
return $document;
}
@@ -586,7 +593,12 @@ class OrderShopBuilder

public function getProductsSalesStatistic(SectionInterface $section, $entity, $nbWeek = 2)
{
$productsSalesStatistic = new ProductsSalesStatistic($this->entityManager, $entity, $nbWeek, $this->productSolver);
$productsSalesStatistic = new ProductsSalesStatistic(
$this->entityManager,
$entity,
$nbWeek,
$this->productSolver
);

$productsSalesStatistic->init($section, $this->orderShopSolver, $this->openingResolver);
$productsSalesStatistic->populateProperties($this->orderShopStore);

+ 9
- 0
Container/Order/OrderProductContainer.php 查看文件

@@ -6,21 +6,25 @@ use Lc\CaracoleBundle\Builder\Order\OrderProductBuilder;
use Lc\CaracoleBundle\Factory\Order\OrderProductFactory;
use Lc\CaracoleBundle\Repository\Order\OrderProductRepositoryQuery;
use Lc\CaracoleBundle\Repository\Order\OrderProductStore;
use Lc\CaracoleBundle\Solver\Order\OrderProductSolver;

class OrderProductContainer
{
protected OrderProductFactory $factory;
protected OrderProductSolver $solver;
protected OrderProductBuilder $builder;
protected OrderProductRepositoryQuery $repositoryQuery;
protected OrderProductStore $store;

public function __construct(
OrderProductFactory $factory,
OrderProductSolver $solver,
OrderProductBuilder $builder,
OrderProductRepositoryQuery $repositoryQuery,
OrderProductStore $store
) {
$this->factory = $factory;
$this->solver = $solver;
$this->builder = $builder;
$this->repositoryQuery = $repositoryQuery;
$this->store = $store;
@@ -31,6 +35,11 @@ class OrderProductContainer
return $this->factory;
}

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

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

+ 11
- 10
Controller/Credit/CreditHistoryAdminController.php 查看文件

@@ -25,6 +25,7 @@ use Lc\CaracoleBundle\Controller\AdminControllerTrait;
use Lc\CaracoleBundle\Factory\Credit\CreditHistoryFactory;
use Lc\CaracoleBundle\Model\Credit\CreditHistoryInterface;
use Lc\CaracoleBundle\Model\Credit\CreditHistoryModel;
use Lc\CaracoleBundle\Model\Order\OrderPaymentModel;
use Lc\CaracoleBundle\Model\User\UserMerchantInterface;
use Lc\SovBundle\Controller\AbstractAdminController;
use Lc\SovBundle\Translation\TranslatorAdmin;
@@ -111,29 +112,29 @@ abstract class CreditHistoryAdminController extends AbstractAdminController
ChoiceField::new('meanPayment')->setChoices(
array(
$translatorAdmin->transField(
'meanPaymentOptions.' . CreditHistoryModel::MEAN_PAYMENT_CASH,
'meanPaymentOptions.' . OrderPaymentModel::MEAN_PAYMENT_CASH,
'CreditHistory'
) => CreditHistoryModel::MEAN_PAYMENT_CASH,
) => OrderPaymentModel::MEAN_PAYMENT_CASH,

$translatorAdmin->transField(
'meanPaymentOptions.' . CreditHistoryModel::MEAN_PAYMENT_CHEQUE,
'meanPaymentOptions.' . OrderPaymentModel::MEAN_PAYMENT_CHEQUE,
'CreditHistory'
) => CreditHistoryModel::MEAN_PAYMENT_CHEQUE,
) => OrderPaymentModel::MEAN_PAYMENT_CHEQUE,

$translatorAdmin->transField(
'meanPaymentOptions.' . CreditHistoryModel::MEAN_PAYMENT_CREDIT,
'meanPaymentOptions.' . OrderPaymentModel::MEAN_PAYMENT_CREDIT,
'CreditHistory'
) => CreditHistoryModel::MEAN_PAYMENT_CREDIT,
) => OrderPaymentModel::MEAN_PAYMENT_CREDIT,

$translatorAdmin->transField(
'meanPaymentOptions.' . CreditHistoryModel::MEAN_PAYMENT_CREDIT_CARD,
'meanPaymentOptions.' . OrderPaymentModel::MEAN_PAYMENT_CREDIT_CARD,
'CreditHistory'
) => CreditHistoryModel::MEAN_PAYMENT_CREDIT_CARD,
) => OrderPaymentModel::MEAN_PAYMENT_CREDIT_CARD,

$translatorAdmin->transField(
'meanPaymentOptions.' . CreditHistoryModel::MEAN_PAYMENT_TRANSFER,
'meanPaymentOptions.' . OrderPaymentModel::MEAN_PAYMENT_TRANSFER,
'CreditHistory'
) => CreditHistoryModel::MEAN_PAYMENT_TRANSFER,
) => OrderPaymentModel::MEAN_PAYMENT_TRANSFER,
)
),
TextField::new('reference'),

+ 1
- 1
Form/Order/OrderProductsType.php 查看文件

@@ -55,7 +55,7 @@ class OrderProductsType extends AbstractType
} else {
$product = null;
if ($productFamily->getActiveProducts()) {
$products = $productFamily->getProductsOnline();
$products = $this->productFamilySolver->getProductsOnline($productFamily);
if ($products && count($products) > 0) {
$product = $products[0];
}

+ 1
- 3
Model/Order/OrderShopModel.php 查看文件

@@ -22,8 +22,6 @@ abstract class OrderShopModel extends AbstractLightEntity implements FilterSecti
const DELIVERY_TYPE_HOME = 'home';
const DELIVERY_TYPE_POINTSALE = 'point-sale';



/**
* @ORM\ManyToOne(targetEntity="Lc\SovBundle\Model\User\UserInterface", inversedBy="orderShops", fetch="EAGER")
*/
@@ -96,7 +94,7 @@ abstract class OrderShopModel extends AbstractLightEntity implements FilterSecti
protected $orderReductionCredits;

/**
* @ORM\ManyToMany(targetEntity="Lc\CaracoleBundle\Model\File\DocumentInterface", inversedBy="orderShops")
* @ORM\ManyToMany(targetEntity="Lc\CaracoleBundle\Model\File\DocumentInterface", inversedBy="orderShops", cascade={"persist"})
*/
protected $documents;


+ 5
- 0
Repository/File/DocumentRepositoryQuery.php 查看文件

@@ -17,6 +17,11 @@ class DocumentRepositoryQuery extends AbstractRepositoryQuery
parent::__construct($repository, 'r', $paginator);
}

public function filterByType($type)
{
return $this->andWhereEqual('type', $type);
}

public function filterByBuyerAddress(AddressInterface $buyerAddress)
{
return $this

+ 19
- 3
Repository/File/DocumentStore.php 查看文件

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

use App\Entity\Address\Address;
use Lc\CaracoleBundle\Model\File\DocumentInterface;
use Lc\CaracoleBundle\Repository\MerchantStoreTrait;
use Lc\CaracoleBundle\Repository\SectionStoreTrait;
use Lc\SovBundle\Repository\AbstractStore;
@@ -11,6 +12,7 @@ use Lc\SovBundle\Repository\RepositoryQueryInterface;
class DocumentStore extends AbstractStore
{
use SectionStoreTrait;
use MerchantStoreTrait;

protected DocumentRepositoryQuery $query;

@@ -28,7 +30,15 @@ class DocumentStore extends AbstractStore
public function filtersDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
{
$query->filterIsOnlineAndOffline();
$query->filterBySection($this->section);

if(isset($this->section) && $this->section) {
$query->filterBySection($this->section);
}

if(isset($this->merchant) && $this->merchant) {
$query->filterByMerchantViaSection($this->merchant);
}

return $query;
}

@@ -38,9 +48,15 @@ class DocumentStore extends AbstractStore
}


public function getOneLatestByType(string $documentType, $query = null)
public function getOneLatestByType(string $documentType, $query = null): DocumentInterface
{
// @TODO : à écrire
$query = $this->createDefaultQuery($query);

$query
->filterByType($documentType)
->orderBy('createdAt', 'DESC');

return $query->findOne();
}

// findLastInvoice

+ 0
- 12
Repository/Order/OrderShopRepositoryQuery.php 查看文件

@@ -28,7 +28,6 @@ class OrderShopRepositoryQuery extends AbstractRepositoryQuery
protected bool $isJoinOrderReductionCarts = false;
protected bool $isJoinOrderStatus = false;
protected bool $isJoinMerchant = false;
protected bool $isJoinSection = false;
protected bool $isJoinComplementaryOrderShops = false;
protected bool $isJoinDeliveryPointSale = false;

@@ -209,17 +208,6 @@ class OrderShopRepositoryQuery extends AbstractRepositoryQuery
return $this;
}

public function joinSection(): self
{
if (!$this->isJoinSection) {
$this->isJoinSection = true;

return $this
->leftJoin('.section', 's');
}
return $this;
}

public function joinComplementaryOrderShops(): self
{
if (!$this->isJoinComplementaryOrderShops) {

+ 2
- 2
Repository/Order/OrderShopStore.php 查看文件

@@ -391,7 +391,7 @@ class OrderShopStore extends AbstractStore
}

if (isset($params['orderStatus'])) {
$query->filterByStatus($params['orderStatus']);
$query->filterByStatus([$params['orderStatus']]);
}

if (isset($params['user'])) {
@@ -452,7 +452,7 @@ class OrderShopStore extends AbstractStore
$reductionCreditsArray = [];
foreach ($reductionCredits as $reductionCredit) {
if (!$this->countValidWithReductionCredit($reductionCredit, $user)
&& (!$this->merchant || $reductionCredit->getSection()->getMerchant() == $this->merchant)) {
&& ($reductionCredit->getSection()->getMerchant() == $this->merchant)) {
$reductionCreditsArray[] = $reductionCredit;
}
}

+ 1
- 0
Repository/Product/ProductFamilyRepositoryQuery.php 查看文件

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

use Knp\Component\Pager\PaginatorInterface;
use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
use Lc\CaracoleBundle\Model\Product\ProductCategoryInterface;
use Lc\CaracoleBundle\Repository\SectionRepositoryQueryTrait;
use Lc\SovBundle\Repository\AbstractRepositoryQuery;

+ 10
- 1
Repository/Product/ProductFamilyStore.php 查看文件

@@ -5,6 +5,7 @@ namespace Lc\CaracoleBundle\Repository\Product;
use Lc\CaracoleBundle\Model\Product\ProductCategoryInterface;
use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface;
use Lc\CaracoleBundle\Model\Reduction\ReductionCatalogInterface;
use Lc\CaracoleBundle\Repository\MerchantStoreTrait;
use Lc\CaracoleBundle\Repository\SectionStoreTrait;
use Lc\CaracoleBundle\Solver\Price\PriceSolver;
use Lc\SovBundle\Model\User\UserInterface;
@@ -14,6 +15,7 @@ use Lc\SovBundle\Repository\RepositoryQueryInterface;
class ProductFamilyStore extends AbstractStore
{
use SectionStoreTrait;
use MerchantStoreTrait;

protected ProductFamilyRepositoryQuery $query;
protected PriceSolver $priceSolver;
@@ -32,7 +34,14 @@ class ProductFamilyStore extends AbstractStore

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

if(isset($this->merchant) && $this->merchant) {
$query->filterByMerchantViaSection($this->merchant);
}

return $query;
}


+ 7
- 0
Repository/Reduction/ReductionCreditRepositoryQuery.php 查看文件

@@ -25,6 +25,13 @@ class ReductionCreditRepositoryQuery extends AbstractRepositoryQuery
->setParameter('user', $user);
}

public function filterByOwner(UserInterface $user)
{
return $this
->andWhere('.owner = :user')
->setParameter('user', $user);
}

public function filterByType(string $type = ReductionCreditModel::TYPE_CREDIT)
{
return $this

+ 10
- 2
Repository/Reduction/ReductionCreditStore.php 查看文件

@@ -5,6 +5,7 @@ namespace Lc\CaracoleBundle\Repository\Reduction;
use Lc\CaracoleBundle\Model\Order\OrderShopInterface;
use Lc\CaracoleBundle\Model\Reduction\ReductionCreditInterface;
use Lc\CaracoleBundle\Model\Reduction\ReductionCreditModel;
use Lc\CaracoleBundle\Repository\MerchantStoreTrait;
use Lc\CaracoleBundle\Repository\Order\OrderShopStore;
use Lc\CaracoleBundle\Repository\SectionStoreTrait;
use Lc\SovBundle\Model\User\UserInterface;
@@ -14,6 +15,7 @@ use Lc\SovBundle\Repository\RepositoryQueryInterface;
class ReductionCreditStore extends AbstractStore
{
use SectionStoreTrait;
use MerchantStoreTrait;

protected ReductionCreditRepositoryQuery $query;

@@ -34,7 +36,13 @@ class ReductionCreditStore extends AbstractStore
if($this->section) {
$query->filterBySection($this->section);
}

if(isset($this->merchant) && $this->merchant) {
$query->filterByMerchantViaSection($this->merchant);
}

$query->filterIsOnlineAndOffline();

return $query;
}

@@ -69,7 +77,7 @@ class ReductionCreditStore extends AbstractStore
{
/// @TODO : à écrire
$query = $this->createDefaultQuery($query);
$query->filterByUser($user);
$query->filterByOwner($user);
return $query->find();
}

@@ -78,7 +86,7 @@ class ReductionCreditStore extends AbstractStore
{
/// @TODO : à écrire
$query = $this->createDefaultQuery($query);
$query->filterByUser($user);
$query->filterByOwner($user);
return $query->find();
}


+ 21
- 0
Repository/SectionRepositoryQueryTrait.php 查看文件

@@ -2,12 +2,33 @@

namespace Lc\CaracoleBundle\Repository;

use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
use Lc\CaracoleBundle\Model\Section\SectionInterface;

trait SectionRepositoryQueryTrait
{
protected bool $isJoinSection = false;

public function filterBySection(SectionInterface $section)
{
return $this->andWhereSection($this->id, $section);
}

public function filterByMerchantViaSection(MerchantInterface $merchant)
{
$this->joinSection();
return $this->andWhere('s.merchant = :merchant')
->setParameter('merchant', $merchant);
}

public function joinSection(): self
{
if (!$this->isJoinSection) {
$this->isJoinSection = true;

return $this
->leftJoin('.section', 's');
}
return $this;
}
}

+ 1
- 2
Solver/Order/OrderProductReductionCatalogSolver.php 查看文件

@@ -27,8 +27,7 @@ class OrderProductReductionCatalogSolver
OrderProductReductionCatalogInterface $orderProductReductionCatalog,
OrderProductReductionCatalogInterface $orderProductReductionCatalogCompare
): bool {
return $orderProductReductionCatalogCompare
&& $orderProductReductionCatalog->getUnit() == $orderProductReductionCatalogCompare->getUnit()
return $orderProductReductionCatalog->getUnit() == $orderProductReductionCatalogCompare->getUnit()
&& (string)$orderProductReductionCatalog->getValue(
) == (string)$orderProductReductionCatalogCompare->getValue()
&& $orderProductReductionCatalog->getBehaviorTaxRate(

+ 1
- 1
Solver/Order/OrderShopSolver.php 查看文件

@@ -347,7 +347,7 @@ class OrderShopSolver
}

// getProductQuantityMaxAddCart
public function getProductQuantityMaxAddCart(ProductInterface $product, OrderShopInterface $orderShop)
public function getProductQuantityMaxAddCart(OrderShopInterface $orderShop, ProductInterface $product)
{
$productFamily = $product->getProductFamily();


+ 12
- 1
Solver/Product/ProductFamilySolver.php 查看文件

@@ -174,7 +174,7 @@ class ProductFamilySolver

foreach ($products as $product) {
if ($product->getStatus() == 1) {
$titleProduct = $product->getTitleInherited();
$titleProduct = $this->productSolver->getTitleInherited($product);
if (!isset($arrayProductsGroupByTitle[$titleProduct])) {
$arrayProductsGroupByTitle[$titleProduct] = [];
}
@@ -185,6 +185,17 @@ class ProductFamilySolver
return $arrayProductsGroupByTitle;
}

public function getQuantityTitle(ProductFamilyInterface $productFamily, ProductInterface $product)
{
$title = $this->productSolver->getQuantityLabelInherited($product);

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

return $title;
}

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

+ 0
- 10
Solver/Product/ProductSolver.php 查看文件

@@ -142,16 +142,6 @@ class ProductSolver
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()) {

正在加载...
取消
保存