Procházet zdrojové kódy

Refactoring services

packProduct
Guillaume před 3 roky
rodič
revize
3313e0e0ea
12 změnil soubory, kde provedl 283 přidání a 50 odebrání
  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 Zobrazit soubor

@@ -56,21 +56,24 @@ class SettingEventSubscriber implements EventSubscriberInterface

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

$this->initSettingsGeneric(
'merchant',
$this->merchantSettingDefinition->getSettings(),
//TODO vérifier que ce soit bien les online que l'on souhaite
$this->merchantStore->getOnline(),
$merchants,
$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)

Generator/Reference/DocumentReferenceGenerator.php → Generator/DocumentReferenceGenerator.php Zobrazit soubor

@@ -1,6 +1,6 @@
<?php

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

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

Generator/Reference/OrderReferenceGenerator.php → Generator/OrderReferenceGenerator.php Zobrazit soubor

@@ -1,6 +1,6 @@
<?php

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

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


+ 9
- 9
Model/Section/SectionModel.php Zobrazit soubor

@@ -33,12 +33,12 @@ abstract class SectionModel extends AbstractFullEntity implements FilterMerchant
/**
* @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)
@@ -131,14 +131,14 @@ abstract class SectionModel extends AbstractFullEntity implements FilterMerchant
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;
}

+ 3
- 0
Repository/Address/AddressStore.php Zobrazit soubor

@@ -2,11 +2,14 @@

namespace Lc\CaracoleBundle\Repository\Address;

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

class AddressStore extends AbstractStore
{
use MerchantStoreTrait;

protected AddressRepositoryQuery $query;

public function __construct(AddressRepositoryQuery $query)

+ 1
- 0
Repository/Order/OrderProductStore.php Zobrazit soubor

@@ -42,5 +42,6 @@ class OrderProductStore extends AbstractStore
$query = $this->createDefaultQuery($query);
$query->filterByProduct($product);
$query->filterByOrderStatus(OrderStatusModel::$statusAliasAsValid);
return $query->find();
}
}

+ 31
- 5
Repository/Order/OrderShopStore.php Zobrazit soubor

@@ -4,15 +4,11 @@ namespace Lc\CaracoleBundle\Repository\Order;

use Doctrine\ORM\EntityManagerInterface;
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\OrderStatusModel;
use Lc\CaracoleBundle\Model\Reduction\ReductionCartInterface;
use Lc\CaracoleBundle\Model\Reduction\ReductionCreditInterface;
use Lc\CaracoleBundle\Model\Reduction\ReductionCreditModel;
use Lc\CaracoleBundle\Model\Section\SectionInterface;
use Lc\CaracoleBundle\Repository\Merchant\MerchantStore;
use Lc\CaracoleBundle\Repository\Reduction\ReductionCreditStore;
use Lc\CaracoleBundle\Repository\Section\SectionStore;
@@ -21,7 +17,6 @@ use Lc\CaracoleBundle\Repository\SectionStoreTrait;
use Lc\CaracoleBundle\Solver\Order\OrderShopSolver;
use Lc\CaracoleBundle\Solver\Price\PriceSolver;
use Lc\CaracoleBundle\Solver\Reduction\ReductionCartSolver;
use Lc\CaracoleBundle\Statistic\Product\ProductsSalesStatistic;
use Lc\SovBundle\Model\User\UserInterface;
use Lc\SovBundle\Repository\AbstractStore;
use Lc\SovBundle\Repository\RepositoryQueryInterface;
@@ -545,4 +540,35 @@ class OrderShopStore extends AbstractStore
}
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 Zobrazit soubor

@@ -4,20 +4,64 @@ namespace Lc\CaracoleBundle\Repository\PointSale;

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

class PointSaleRepositoryQuery extends AbstractRepositoryQuery
{
protected $isJoinUserPointSales = false;

public function __construct(PointSaleRepository $repository, PaginatorInterface $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)
{
return $this
->andWhere(':merchant MEMBER OF .merchants')
->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 Zobrazit soubor

@@ -16,35 +16,23 @@ class ProductFamilyRepositoryQuery extends AbstractRepositoryQuery
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
@@ -78,4 +66,41 @@ class ProductFamilyRepositoryQuery extends AbstractRepositoryQuery
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 Zobrazit soubor

@@ -3,6 +3,8 @@
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\SectionStoreTrait;
use Lc\CaracoleBundle\Solver\Price\PriceSolver;
use Lc\SovBundle\Repository\AbstractStore;
@@ -89,6 +91,33 @@ class ProductFamilyStore extends AbstractStore
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 Zobrazit soubor

@@ -5,17 +5,59 @@ namespace Lc\CaracoleBundle\Repository\Reduction;
use Knp\Component\Pager\PaginatorInterface;
use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface;
use Lc\CaracoleBundle\Repository\MerchantRepositoryQueryTrait;
use Lc\CaracoleBundle\Repository\SectionRepositoryQueryTrait;
use Lc\SovBundle\Model\User\UserInterface;
use Lc\SovBundle\Repository\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)
{
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)
{
return $this
@@ -23,4 +65,62 @@ class ReductionCatalogRepositoryQuery extends AbstractRepositoryQuery
->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 Zobrazit soubor

@@ -36,6 +36,7 @@ class ReductionCatalogStore extends AbstractStore
return $query;
}

/*
public function getByProductFamily(ProductFamilyInterface $productFamily, $query = null)
{
$query = $this->createDefaultQuery($query);
@@ -46,4 +47,5 @@ class ReductionCatalogStore extends AbstractStore

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

Načítá se…
Zrušit
Uložit