Browse Source

Refactoring services

packProduct
Guillaume 3 years ago
parent
commit
3313e0e0ea
12 changed files with 283 additions and 50 deletions
  1. +11
    -8
      EventSubscriber/SettingEventSubscriber.php
  2. +1
    -1
      Generator/DocumentReferenceGenerator.php
  3. +5
    -5
      Generator/OrderReferenceGenerator.php
  4. +9
    -9
      Model/Section/SectionModel.php
  5. +3
    -0
      Repository/Address/AddressStore.php
  6. +1
    -0
      Repository/Order/OrderProductStore.php
  7. +31
    -5
      Repository/Order/OrderShopStore.php
  8. +44
    -0
      Repository/PointSale/PointSaleRepositoryQuery.php
  9. +46
    -21
      Repository/Product/ProductFamilyRepositoryQuery.php
  10. +29
    -0
      Repository/Product/ProductFamilyStore.php
  11. +101
    -1
      Repository/Reduction/ReductionCatalogRepositoryQuery.php
  12. +2
    -0
      Repository/Reduction/ReductionCatalogStore.php

+ 11
- 8
EventSubscriber/SettingEventSubscriber.php View File



public function initSettings() public function initSettings()
{ {
$merchants = $this->merchantStore->get();

$this->initSettingsGeneric( $this->initSettingsGeneric(
'merchant', 'merchant',
$this->merchantSettingDefinition->getSettings(), $this->merchantSettingDefinition->getSettings(),
//TODO vérifier que ce soit bien les online que l'on souhaite //TODO vérifier que ce soit bien les online que l'on souhaite
$this->merchantStore->getOnline(),
$merchants,
$this->merchantSettingFactory $this->merchantSettingFactory
); );


$this->initSettingsGeneric(
'section',
$this->sectionSettingDefinition->getSettings(),
//TODOJ'en suis là !!! Et je sais pas ce que je dois mettre, tout les sections ? et les sections d'un merchant ?
$this->sectionStore->getOnline(),
$this->sectionSettingFactory
);
foreach($merchants as $merchant) {
$this->initSettingsGeneric(
'section',
$this->sectionSettingDefinition->getSettings(),
$merchant->getSections(),
$this->sectionSettingFactory
);
}
} }


public function initSettingsGeneric($type, $settings, $entities, $factory) public function initSettingsGeneric($type, $settings, $entities, $factory)

Generator/Reference/DocumentReferenceGenerator.php → Generator/DocumentReferenceGenerator.php View File

<?php <?php


namespace Lc\CaracoleBundle\Generator\Reference;
namespace Lc\CaracoleBundle\Generator;


use Lc\CaracoleBundle\Definition\SectionSettingDefinition; use Lc\CaracoleBundle\Definition\SectionSettingDefinition;
use Lc\CaracoleBundle\Model\File\DocumentModel; use Lc\CaracoleBundle\Model\File\DocumentModel;

Generator/Reference/OrderReferenceGenerator.php → Generator/OrderReferenceGenerator.php View File

<?php <?php


namespace Lc\CaracoleBundle\Generator\Reference;
namespace Lc\CaracoleBundle\Generator;


use Lc\CaracoleBundle\Definition\SectionSettingDefinition; use Lc\CaracoleBundle\Definition\SectionSettingDefinition;
use Lc\CaracoleBundle\Model\Order\OrderShopInterface; use Lc\CaracoleBundle\Model\Order\OrderShopInterface;
public function buildReference(OrderShopInterface $orderShop, \DateTime $distributionDate = null): string public function buildReference(OrderShopInterface $orderShop, \DateTime $distributionDate = null): string
{ {
switch ($orderShop->getSection()->getCycle()) { switch ($orderShop->getSection()->getCycle()) {
case SectionModel::CYCLE_DAY:
case SectionModel::CYCLE_TYPE_DAY:
return $this->buildReferenceCycleDay($orderShop); return $this->buildReferenceCycleDay($orderShop);
case SectionModel::CYCLE_WEEK:
case SectionModel::CYCLE_TYPE_WEEK:
return $this->buildReferenceCycleWeek($orderShop, $distributionDate); return $this->buildReferenceCycleWeek($orderShop, $distributionDate);
case SectionModel::CYCLE_MONTH:
case SectionModel::CYCLE_TYPE_MONTH:
return $this->buildReferenceCycleMonth($orderShop, $distributionDate); return $this->buildReferenceCycleMonth($orderShop, $distributionDate);
case SectionModel::CYCLE_YEAR:
case SectionModel::CYCLE_TYPE_YEAR:
return $this->buildReferenceCycleYear($orderShop, $distributionDate); return $this->buildReferenceCycleYear($orderShop, $distributionDate);
} }



+ 9
- 9
Model/Section/SectionModel.php View File

/** /**
* @ORM\Column(type="string", length=32) * @ORM\Column(type="string", length=32)
*/ */
protected $cycle;
protected $cycleType;


const CYCLE_DAY = 'day';
const CYCLE_WEEK = 'week';
const CYCLE_MONTH = 'month';
const CYCLE_YEAR = 'year';
const CYCLE_TYPE_DAY = 'day';
const CYCLE_TYPE_WEEK = 'week';
const CYCLE_TYPE_MONTH = 'month';
const CYCLE_TYPE_YEAR = 'year';


/** /**
* @ORM\Column(type="boolean", nullable=true) * @ORM\Column(type="boolean", nullable=true)
return $this; return $this;
} }


public function getCycle(): ?string
public function getCycleType(): ?string
{ {
return $this->cycle;
return $this->cycleType;
} }


public function setCycle(string $cycle): self
public function setCycleType(string $cycleType): self
{ {
$this->cycle = $cycle;
$this->cycleType = $cycleType;


return $this; return $this;
} }

+ 3
- 0
Repository/Address/AddressStore.php View File



namespace Lc\CaracoleBundle\Repository\Address; namespace Lc\CaracoleBundle\Repository\Address;


use Lc\CaracoleBundle\Repository\MerchantStoreTrait;
use Lc\SovBundle\Repository\AbstractStore; use Lc\SovBundle\Repository\AbstractStore;
use Lc\SovBundle\Repository\RepositoryQueryInterface; use Lc\SovBundle\Repository\RepositoryQueryInterface;


class AddressStore extends AbstractStore class AddressStore extends AbstractStore
{ {
use MerchantStoreTrait;

protected AddressRepositoryQuery $query; protected AddressRepositoryQuery $query;


public function __construct(AddressRepositoryQuery $query) public function __construct(AddressRepositoryQuery $query)

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

$query = $this->createDefaultQuery($query); $query = $this->createDefaultQuery($query);
$query->filterByProduct($product); $query->filterByProduct($product);
$query->filterByOrderStatus(OrderStatusModel::$statusAliasAsValid); $query->filterByOrderStatus(OrderStatusModel::$statusAliasAsValid);
return $query->find();
} }
} }

+ 31
- 5
Repository/Order/OrderShopStore.php View File



use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Lc\CaracoleBundle\Builder\File\DocumentBuilder; use Lc\CaracoleBundle\Builder\File\DocumentBuilder;
use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
use Lc\CaracoleBundle\Model\Order\OrderReductionCartInterface;
use Lc\CaracoleBundle\Model\Order\OrderReductionCreditInterface;
use Lc\CaracoleBundle\Model\Order\OrderShopInterface; use Lc\CaracoleBundle\Model\Order\OrderShopInterface;
use Lc\CaracoleBundle\Model\Order\OrderStatusModel; use Lc\CaracoleBundle\Model\Order\OrderStatusModel;
use Lc\CaracoleBundle\Model\Reduction\ReductionCartInterface; use Lc\CaracoleBundle\Model\Reduction\ReductionCartInterface;
use Lc\CaracoleBundle\Model\Reduction\ReductionCreditInterface; use Lc\CaracoleBundle\Model\Reduction\ReductionCreditInterface;
use Lc\CaracoleBundle\Model\Reduction\ReductionCreditModel; use Lc\CaracoleBundle\Model\Reduction\ReductionCreditModel;
use Lc\CaracoleBundle\Model\Section\SectionInterface;
use Lc\CaracoleBundle\Repository\Merchant\MerchantStore; use Lc\CaracoleBundle\Repository\Merchant\MerchantStore;
use Lc\CaracoleBundle\Repository\Reduction\ReductionCreditStore; use Lc\CaracoleBundle\Repository\Reduction\ReductionCreditStore;
use Lc\CaracoleBundle\Repository\Section\SectionStore; use Lc\CaracoleBundle\Repository\Section\SectionStore;
use Lc\CaracoleBundle\Solver\Order\OrderShopSolver; use Lc\CaracoleBundle\Solver\Order\OrderShopSolver;
use Lc\CaracoleBundle\Solver\Price\PriceSolver; use Lc\CaracoleBundle\Solver\Price\PriceSolver;
use Lc\CaracoleBundle\Solver\Reduction\ReductionCartSolver; use Lc\CaracoleBundle\Solver\Reduction\ReductionCartSolver;
use Lc\CaracoleBundle\Statistic\Product\ProductsSalesStatistic;
use Lc\SovBundle\Model\User\UserInterface; use Lc\SovBundle\Model\User\UserInterface;
use Lc\SovBundle\Repository\AbstractStore; use Lc\SovBundle\Repository\AbstractStore;
use Lc\SovBundle\Repository\RepositoryQueryInterface; use Lc\SovBundle\Repository\RepositoryQueryInterface;
} }
return null; return null;
} }

public function isReductionCreditAllowAddToOrder(
OrderShopInterface $orderShop,
ReductionCreditInterface $reductionCredit
) {
$user = $orderShop->getUser();

// appartient à l'utilisateur
if (!$reductionCredit->getUsers()->contains($user)) {
// @TODO : déplacer la gestion du flash message
//$this->flashBag->add('error', 'error.reductionCredit.userNotAllow');
return false;
}

// n'a pas été utilisé
if ($reductionCredit->getType() == ReductionCreditModel::TYPE_CREDIT) {
if ($this->countValidWithReductionCredit($reductionCredit, $user) > 0) {
// @TODO : déplacer la gestion du flash message
//$this->flashBah->add('error', 'error.reductionCredit.alreadyUse');
return false;
}
} else {
if ($this->countValidWithReductionCredit($reductionCredit) > 0) {
// @TODO : déplacer la gestion du flash message
//$this->flashBah->add('error', 'error.reductionCredit.alreadyUse');
return false;
}
}

return true;
}
} }

+ 44
- 0
Repository/PointSale/PointSaleRepositoryQuery.php View File



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


class PointSaleRepositoryQuery extends AbstractRepositoryQuery class PointSaleRepositoryQuery extends AbstractRepositoryQuery
{ {
protected $isJoinUserPointSales = false;


public function __construct(PointSaleRepository $repository, PaginatorInterface $paginator) public function __construct(PointSaleRepository $repository, PaginatorInterface $paginator)
{ {
parent::__construct($repository, 'r', $paginator); parent::__construct($repository, 'r', $paginator);
} }


public function filterByUser(UserInterface $user): self
{
$this->joinUserPointSales();

return $this
->andWhere('userPointSales.user = :user')
->setParameter('user', $user);
}

public function filterByMerchant(MerchantInterface $merchant) public function filterByMerchant(MerchantInterface $merchant)
{ {
return $this return $this
->andWhere(':merchant MEMBER OF .merchants') ->andWhere(':merchant MEMBER OF .merchants')
->setParameter(':merchant', $merchant); ->setParameter(':merchant', $merchant);
} }

public function filterIsNotPublic(): self
{
return $this->andWhere('.isPublic = 0');
}

public function filterIsPublic(): self
{
return $this->andWhere('.isPublic = 1');
}

public function filterByIsPublic(int $isPublic): self
{
return $this->andWhere('.isPublic = ' . $isPublic);
}

public function filterLikeCode(string $code): self
{
return $this
->andWhere('.code LIKE :code')
->setParameter('code', $code);
}

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

return $this
->innerJoin('.userPointSales', 'userPointSales');
}
return $this;
}
} }

+ 46
- 21
Repository/Product/ProductFamilyRepositoryQuery.php View File

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


public function joinProductCategories(): self
public function selectCount(): self
{ {
if (!$this->isJoinProductCategories) {
$this->isJoinProductCategories = true;

return $this
->leftJoin('.productCategories', 'cat');
//$query->addSelect('cat') ; ???
}
return $this;
return $this->select('count(r.id)');
} }



public function joinProducts(): self
public function selectProductCategories(): self
{ {
if (!$this->isJoinProducts) {
$this->isJoinProducts = true;
$this->joinProductCategories();


return $this
->innerJoin('.products', 'pfp');
// $query->addSelect('pfp') ; ?????
}
return $this;
return $this->addSelect('pCategories');
} }


public function orderByPosition(): self
public function filterLikeBehaviorStockCycle(string $behaviorStockCycle): self
{ {
$this->orderBy('e.position', 'ASC');
return $this;
return $this
->andWhere('.behaviorStockCycle LIKE :behaviorStockCycle')
->setParameter('behaviorStockCycle', $behaviorStockCycle);
} }


public function filterByProductCategory(ProductCategoryInterface $category): self public function filterByProductCategory(ProductCategoryInterface $category): self
return $this; return $this;
} }


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

return $this
->leftJoin('.productCategories', 'cat');
//$query->addSelect('cat') ; ???
}
return $this;
}

public function selectProducts(): self
{
$this->joinProducts();

return $this->addSelect('products');
}

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

return $this
->innerJoin('.products', 'pfp');
// $query->addSelect('pfp') ; ?????
}
return $this;
}

public function orderByPosition(): self
{
$this->orderBy('e.position', 'ASC');
return $this;
}

} }

+ 29
- 0
Repository/Product/ProductFamilyStore.php View File

namespace Lc\CaracoleBundle\Repository\Product; namespace Lc\CaracoleBundle\Repository\Product;


use Lc\CaracoleBundle\Model\Product\ProductCategoryInterface; use Lc\CaracoleBundle\Model\Product\ProductCategoryInterface;
use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface;
use Lc\CaracoleBundle\Model\Reduction\ReductionCatalogInterface;
use Lc\CaracoleBundle\Repository\SectionStoreTrait; use Lc\CaracoleBundle\Repository\SectionStoreTrait;
use Lc\CaracoleBundle\Solver\Price\PriceSolver; use Lc\CaracoleBundle\Solver\Price\PriceSolver;
use Lc\SovBundle\Repository\AbstractStore; use Lc\SovBundle\Repository\AbstractStore;
return $query->find(); return $query->find();
} }


public function getBestReductionCatalog(
ProductFamilyInterface $productFamily,
ReductionCatalogInterface $reductionCatalog1,
ReductionCatalogInterface $reductionCatalog2
) {
$price1 = $this->priceSolver->applyReductionCatalog(
$productFamily,
$this->priceSolver->getPrice($productFamily),
$this->priceSolver->getPriceWithTax($productFamily),
1,
$reductionCatalog1
);

$price2 = $this->priceSolver->applyReductionCatalog(
$productFamily,
$this->priceSolver->getPrice($productFamily),
$this->priceSolver->getPriceWithTax($productFamily),
1,
$reductionCatalog2
);

if ($price1 > $price2) {
return $reductionCatalog2;
} else {
return $reductionCatalog1;
}
}




} }

+ 101
- 1
Repository/Reduction/ReductionCatalogRepositoryQuery.php View File

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


class ReductionCatalogRepositoryQuery extends AbstractRepositoryQuery class ReductionCatalogRepositoryQuery extends AbstractRepositoryQuery
{ {
use MerchantRepositoryQueryTrait;
protected bool $isJoinProductFamilies;
protected bool $isJoinProductFamily;
protected bool $isJoinProductCategories;
use SectionRepositoryQueryTrait;


public function __construct(ReductionCatalogRepository $repository, PaginatorInterface $paginator) public function __construct(ReductionCatalogRepository $repository, PaginatorInterface $paginator)
{ {
parent::__construct($repository, 'r', $paginator); parent::__construct($repository, 'r', $paginator);
} }


public function joinProductFamilies()
{
if (!$this->isJoinProductFamilies) {
$this->isJoinProductFamilies = true;

return $this
->leftJoin('.productFamilies', 'pfs');
//->addSelect('pfs') ;
}
return $this;
}

public function joinProductFamily()
{
if (!$this->isJoinProductFamily) {
$this->isJoinProductFamily = true;

return $this
->leftJoin('.productFamily', 'pf');
//->addSelect('pf') ;
}
return $this;
}

public function joinProductCategories()
{
if (!$this->isJoinProductCategories) {
$this->isJoinProductCategories = true;

return $this
->leftJoin('.productCategories', 'pcs');
//->addSelect('pcs') ;
}
return $this;
}


public function filterProductFamily(ProductFamilyInterface $productFamily) public function filterProductFamily(ProductFamilyInterface $productFamily)
{ {
return $this return $this
->setParameter(':productFamily', $productFamily); ->setParameter(':productFamily', $productFamily);
} }


public function filterConditionDate()
{
return $this
->andWhere('e.permanent = 1 OR (e.dateStart <= :now AND e.dateEnd >= :now)')
->setParameter(':now', new \DateTime());
}

public function filterConditionUser(UserInterface $user = null)
{
if ($user) {
return $this
->andWhere(':user MEMBER OF e.users OR e.users is empty')
->setParameter('user', $user);
} else {
return $this
->andWhere('e.users is empty');
}
}

public function filterConditionGroupUser(UserInterface $user = null)
{
if ($user) {
return $this
->andWhere(':groupUser MEMBER OF e.groupUsers OR e.groupUsers is empty')
->setParameter('groupUser', $user->getGroupUsers());
} else {
return $this
->andWhere('e.groupUsers is empty');
}
}

public function filterConditionProductFamilies(array $productFamilies)
{
$this->joinProductFamilies();
$this->joinProductFamily();
return $this
->andWhere(':productFamily MEMBER OF e.productFamilies OR e.productFamilies is empty')
->setParameter('productFamily', $productFamilies);
}

public function filterConditionProductFamily(ProductFamilyInterface $productFamily)
{
$this->joinProductFamilies();
$this->joinProductFamily();
return $this
->andWhere(':productFamily MEMBER OF e.productFamilies OR e.productFamilies is empty')
->setParameter('productFamily', $productFamily);
}

public function filterConditionProductCategories(array $productCategories)
{
$this->joinProductCategories();
return $this
->andWhere(':productCategory MEMBER OF e.productCategories OR e.productCategories is empty')
->setParameter('productCategory', $productCategories);
}


} }

+ 2
- 0
Repository/Reduction/ReductionCatalogStore.php View File

return $query; return $query;
} }


/*
public function getByProductFamily(ProductFamilyInterface $productFamily, $query = null) public function getByProductFamily(ProductFamilyInterface $productFamily, $query = null)
{ {
$query = $this->createDefaultQuery($query); $query = $this->createDefaultQuery($query);


return $query->findOne(); return $query->findOne();
} }
*/
} }

Loading…
Cancel
Save