Browse Source

Refactoring services

packProduct
Guillaume 2 years ago
parent
commit
4ed14dec1c
30 changed files with 265 additions and 250 deletions
  1. +34
    -0
      Model/Order/OrderShopModel.php
  2. +2
    -2
      Repository/Config/TaxRateStore.php
  3. +2
    -2
      Repository/Config/UnitStore.php
  4. +4
    -4
      Repository/Credit/CreditHistoryStore.php
  5. +7
    -0
      Repository/Merchant/MerchantStore.php
  6. +1
    -1
      Repository/MerchantRepositoryQueryTrait.php
  7. +64
    -29
      Repository/Order/OrderShopRepositoryQuery.php
  8. +80
    -37
      Repository/Order/OrderShopStore.php
  9. +2
    -0
      Repository/Product/ProductCategoryRepository.php
  10. +1
    -5
      Repository/Product/ProductCategoryRepositoryQuery.php
  11. +1
    -41
      Repository/Product/ProductCategoryStore.php
  12. +5
    -5
      Repository/Reduction/ReductionCartStore.php
  13. +0
    -6
      Repository/Reduction/ReductionCatalogRepositoryQuery.php
  14. +1
    -1
      Repository/Reduction/ReductionCatalogStore.php
  15. +0
    -5
      Repository/Reduction/ReductionCreditRepositoryQuery.php
  16. +0
    -30
      Repository/Reduction/ReductionCreditStore.php
  17. +8
    -0
      Repository/Reminder/ReminderStore.php
  18. +1
    -1
      Repository/SectionRepositoryQueryTrait.php
  19. +12
    -0
      Repository/SectionStoreTrait.php
  20. +2
    -2
      Repository/Site/NewsRepositoryQuery.php
  21. +4
    -4
      Repository/Site/NewsStore.php
  22. +1
    -1
      Repository/Site/PageStore.php
  23. +2
    -2
      Repository/Ticket/TicketRepositoryQuery.php
  24. +14
    -31
      Repository/Ticket/TicketStore.php
  25. +5
    -4
      Repository/User/UserMerchantStore.php
  26. +1
    -1
      Repository/User/UserRepositoryQuery.php
  27. +0
    -14
      Repository/User/UserStore.php
  28. +2
    -4
      Repository/User/VisitorStore.php
  29. +1
    -1
      Resolver/MerchantResolver.php
  30. +8
    -17
      Resolver/OpeningResolver.php

+ 34
- 0
Model/Order/OrderShopModel.php View File

*/ */
protected $cycleNumber; protected $cycleNumber;


/**
* @ORM\Column(type="datetime", nullable=true)
*/
protected $orderShopCreatedAt;

/**
* @ORM\Column(type="integer", nullable=true)
*/
protected $idValidOrder;
/** /**
* @ORM\ManyToOne(targetEntity="App\Entity\Address\Address") * @ORM\ManyToOne(targetEntity="App\Entity\Address\Address")
*/ */
return $this; return $this;
} }


public function getOrderShopCreatedAt(): ?\DateTimeInterface
{
return $this->orderShopCreatedAt;
}

public function setOrderShopCreatedAt(?\DateTimeInterface $orderShopCreatedAt): self
{
$this->orderShopCreatedAt = $orderShopCreatedAt;

return $this;
}

public function getIdValidOrder(): ?int
{
return $this->idValidOrder;
}

public function setIdValidOrder(?int $idValidOrder): self
{
$this->idValidOrder = $idValidOrder;

return $this;
}


public function getDeliveryAddress(): ?AddressInterface public function getDeliveryAddress(): ?AddressInterface
{ {
return $this->deliveryAddress; return $this->deliveryAddress;

+ 2
- 2
Repository/Config/TaxRateStore.php View File

$this->query = $query; $this->query = $query;
} }


public function getAsArray(MerchantInterface $merchant)
public function getAsArray(MerchantInterface $merchant, $query = null)
{ {
$taxRates = $this->query->create()->find();
$taxRates = $this->createQuery($query)->find();


$taxRatesList = []; $taxRatesList = [];



+ 2
- 2
Repository/Config/UnitStore.php View File

$this->query = $query; $this->query = $query;
} }


public function getAsArray()
public function getAsArray($query = null)
{ {
$query = $this->query->create();
$query = $this->createQuery($query);


foreach ($query->find() as $unit) { foreach ($query->find() as $unit) {
$unitsList[$unit->getId()]['unit'] = $unit->getUnit(); $unitsList[$unit->getId()]['unit'] = $unit->getUnit();

+ 4
- 4
Repository/Credit/CreditHistoryStore.php View File

} }


//findAllByDateStartEnd //findAllByDateStartEnd
public function getByDateStartEnd(DateTime $dateStart, DateTime $dateEnd): array
public function getByDateStartEnd(DateTime $dateStart, DateTime $dateEnd, $query = null): array
{ {
$query = $this->query->create();
$query = $this->createQuery($query);


$query $query
->filterByJoinUserMerchant($this->merchant) ->filterByJoinUserMerchant($this->merchant)
} }


//findAllByUserMerchant //findAllByUserMerchant
public function getByUserMerchant(UserMerchant $userMerchant): array
public function getByUserMerchant(UserMerchant $userMerchant, $query = null): array
{ {
$query = $this->query->create();
$query = $this->createQuery($query);


$query $query
->filterByUserMerchant($userMerchant) ->filterByUserMerchant($userMerchant)

+ 7
- 0
Repository/Merchant/MerchantStore.php View File

$this->query = $query; $this->query = $query;
} }


public function getOnline($query = null)
{
$query = $this->createQuery($query);
$query->filterIsOnline();
return $query->find();
}

} }

+ 1
- 1
Repository/MerchantRepositoryQueryTrait.php View File

{ {
return $this->andWhereMerchant($this->id, $merchant); return $this->andWhereMerchant($this->id, $merchant);
} }
}
}

+ 64
- 29
Repository/Order/OrderShopRepositoryQuery.php View File

use Lc\CaracoleBundle\Model\Address\AddressInterface; use Lc\CaracoleBundle\Model\Address\AddressInterface;
use Lc\CaracoleBundle\Model\Order\OrderReductionCartInterface; use Lc\CaracoleBundle\Model\Order\OrderReductionCartInterface;
use Lc\CaracoleBundle\Model\Order\OrderReductionCreditInterface; use Lc\CaracoleBundle\Model\Order\OrderReductionCreditInterface;
use Lc\CaracoleBundle\Model\Reduction\ReductionCartInterface;
use Lc\CaracoleBundle\Model\Reduction\ReductionCreditInterface;
use Lc\CaracoleBundle\Model\User\VisitorInterface; use Lc\CaracoleBundle\Model\User\VisitorInterface;
use Lc\CaracoleBundle\Repository\SectionRepositoryQueryTrait; use Lc\CaracoleBundle\Repository\SectionRepositoryQueryTrait;
use Lc\SovBundle\Model\User\UserInterface; use Lc\SovBundle\Model\User\UserInterface;
protected bool $isJoinOrderReductionCredits = false; protected bool $isJoinOrderReductionCredits = false;
protected bool $isJoinOrderReductionCarts = false; protected bool $isJoinOrderReductionCarts = false;
protected bool $isJoinOrderStatus = false; protected bool $isJoinOrderStatus = false;
protected bool $isJoinMerchant = false;
protected bool $isJoinSection = false;
protected bool $isJoinComplementaryOrderShops = false; protected bool $isJoinComplementaryOrderShops = false;
protected bool $isJoinDeliveryPointSale = false; protected bool $isJoinDeliveryPointSale = false;


public function selectParam($select): self public function selectParam($select): self
{ {
return $this return $this
->addSelect($select);
->addSelect($select);
} }


public function selectCount(): self public function selectCount(): self
{ {
return $this return $this
->select('count(r.id) as total');
->select('count(r.id) as total');
} }


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

public function filterIsMerchantOnline(): self
{
$this->joinMerchant();
return $this
->andWhere('merchant.status = :status')
->setParameter(':status', 1);
} }


public function filterByDateStart(string $dateField, DateTime $dateStart): self public function filterByDateStart(string $dateField, DateTime $dateStart): self
{ {
return $this return $this
->andWhere('.' . $dateField . ' >= :dateStart')
->setParameter('dateStart', $dateStart);
->andWhere('.' . $dateField . ' >= :dateStart')
->setParameter('dateStart', $dateStart);
} }


public function filterByDateEnd(string $dateField, DateTime $dateEnd): self public function filterByDateEnd(string $dateField, DateTime $dateEnd): self
{ {
return $this return $this
->andWhere('.' . $dateField . ' <= :dateEnd')
->setParameter('dateEnd', $dateEnd);
->andWhere('.' . $dateField . ' <= :dateEnd')
->setParameter('dateEnd', $dateEnd);
} }


public function filterByVisitor(VisitorInterface $visitor): self public function filterByVisitor(VisitorInterface $visitor): self
{ {
return $this return $this
->andWhere('.visitor = :visitor')
->setParameter('visitor', $visitor);
->andWhere('.visitor = :visitor')
->setParameter('visitor', $visitor);
} }


public function filterByAddress(AddressInterface $address): self public function filterByAddress(AddressInterface $address): self
{ {
return $this return $this
->andWhere('.deliveryAddress = :address OR .invoiceAddress = :address')
->setParameter('address', $address);
->andWhere('.deliveryAddress = :address OR .invoiceAddress = :address')
->setParameter('address', $address);
} }


public function filterByStatus(array $statusArray): self public function filterByStatus(array $statusArray): self
$this->joinOrderStatus(); $this->joinOrderStatus();


return $this return $this
->andWhere('os.alias IN (:alias)')
->setParameter('alias', $statusArray);
->andWhere('os.alias IN (:alias)')
->setParameter('alias', $statusArray);
} }


public function filterByReductionCredit(OrderReductionCreditInterface $reductionCredit): self
public function filterByReductionCredit(ReductionCreditInterface $reductionCredit): self
{ {
$this->joinOrderReductionCredits(); $this->joinOrderReductionCredits();


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


public function filterByReductionCart(OrderReductionCartInterface $reductionCart): self
public function filterByReductionCart(ReductionCartInterface $reductionCart): self
{ {
$this->joinOrderReductionCarts(); $this->joinOrderReductionCarts();


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


public function filterByCycleNumber(int $cycleNumber): self public function filterByCycleNumber(int $cycleNumber): self
{ {
return $this return $this
->andWhere('.cycleNumber = :cycleNumber')
->setParameter('cycleNumber', $cycleNumber);
->andWhere('.cycleNumber = :cycleNumber')
->setParameter('cycleNumber', $cycleNumber);
} }


public function filterIsNotMainOrderShop(): self public function filterIsNotMainOrderShop(): self
{ {
return $this return $this
->andWhere('.mainOrderShop = false OR .mainOrderShop IS NULL');
->andWhere('.mainOrderShop = false OR .mainOrderShop IS NULL');
} }


public function filterIsNullMainOrderShop(): self public function filterIsNullMainOrderShop(): self
{ {
return $this return $this
->andWhere('.mainOrderShop IS NULL');
->andWhere('.mainOrderShop IS NULL');
} }


public function selectOrderReductionCarts(): self public function selectOrderReductionCarts(): self
$this->isJoinOrderReductionCredits = true; $this->isJoinOrderReductionCredits = true;


return $this return $this
->innerJoin('.orderReductionCredits', 'orc');
->innerJoin('.orderReductionCredits', 'orc');
} }
return $this; return $this;
} }
$this->isJoinOrderStatus = true; $this->isJoinOrderStatus = true;


return $this return $this
->leftJoin('.orderStatus', 'os');
->leftJoin('.orderStatus', 'os');
} }
return $this; return $this;
} }
$this->isJoinOrderReductionCarts = true; $this->isJoinOrderReductionCarts = true;


return $this return $this
->leftJoin('.orderReductionCarts', 'orcart');
->leftJoin('.orderReductionCarts', 'orcart');
}
return $this;
}

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

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

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

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


return $this return $this
->leftJoin('.complementaryOrderShops', 'complementaryOrderShops');
->leftJoin('.complementaryOrderShops', 'complementaryOrderShops');
} }
return $this; return $this;
} }
$this->isJoinDeliveryPointSale = true; $this->isJoinDeliveryPointSale = true;


return $this return $this
->leftJoin('.deliveryPointSale', 'pointSale');
->leftJoin('.deliveryPointSale', 'pointSale');
} }
return $this; return $this;
} }

+ 80
- 37
Repository/Order/OrderShopStore.php View File

use Lc\CaracoleBundle\Model\Order\OrderReductionCreditInterface; use Lc\CaracoleBundle\Model\Order\OrderReductionCreditInterface;
use Lc\CaracoleBundle\Model\Order\OrderShopInterface; use Lc\CaracoleBundle\Model\Order\OrderShopInterface;
use Lc\CaracoleBundle\Model\Order\OrderStatusModel; use Lc\CaracoleBundle\Model\Order\OrderStatusModel;
use Lc\CaracoleBundle\Model\Reduction\ReductionCartInterface;
use Lc\CaracoleBundle\Model\Reduction\ReductionCreditInterface;
use Lc\CaracoleBundle\Model\Section\SectionInterface; 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;
} }


// getOrderShopsOfWeek // getOrderShopsOfWeek
public function getByCycle(SectionInterface $section, $params = [])
public function getByCurrentCycle($params = [])
{ {
$orderShops = $this->getBy( $orderShops = $this->getBy(
array_merge( array_merge(
[ [
'section' => $section,
'cycleNumber' => $this->getCycleNumberCurrentOrder($section),
'section' => $this->section,
'cycleNumber' => $this->getCycleNumberCurrentOrder($this->section),
'isValid' => true, 'isValid' => true,
], ],
$params $params
} }


// getOrderShopsOfWeekByUser // getOrderShopsOfWeekByUser
public function getByCycleAndUser(SectionInterface $section, UserInterface $user, array $params = [])
public function getByCurrentCycleAndUser(UserInterface $user, array $params = [])
{ {
return $this->getByCycle(
$section,
return $this->getByCurrentCycle(
array_merge( array_merge(
[ [
'user' => $user, 'user' => $user,
'cycleNumber' => $this->getCycleNumberCurrentOrder($section),
'cycleNumber' => $this->getCycleNumberCurrentOrder($this->section),
'excludeComplementaryOrderShops' => true 'excludeComplementaryOrderShops' => true
], ],
$params $params


//public $countOrderShopsOfWeek = null; //public $countOrderShopsOfWeek = null;


public function countByCycle(SectionInterface $section, bool $excludeComplementaryOrderShops = true)
public function countByCurrentCycle(bool $excludeComplementaryOrderShops = true)
{ {
return $this->getByCycle(
$section,
return $this->getByCurrentCycle(
[ [
'count' => true, 'count' => true,
'excludeComplementaryOrderShops' => $excludeComplementaryOrderShops 'excludeComplementaryOrderShops' => $excludeComplementaryOrderShops


// @TODO : optimisation à remettre en place // @TODO : optimisation à remettre en place
/*if (is_null($this->countOrderShopsOfWeek)) { /*if (is_null($this->countOrderShopsOfWeek)) {
$this->countOrderShopsOfWeek = $this->getByCycle(
$this->countOrderShopsOfWeek = $this->getByCurrentCycle(
$section, $section,
[ [
'count' => true, 'count' => true,
// countValidOrderShopByUserAllMerchant // countValidOrderShopByUserAllMerchant
public function countValidByUserAllMerchant($user): int public function countValidByUserAllMerchant($user): int
{ {
$totalOrder = 0;

foreach ($this->merchantStore->getRepositoryQuery()->findAll() as $merchant) {
$totalOrder += $this->countValidByUser($user, $merchant);
}

return $totalOrder;
return $this->countBy(
[
'user' => $user,
'isValid' => true,
// @TODO : à tester
'isMerchantOnline' => true,
'excludeComplementaryOrderShops' => true
]
);
} }


public function countValidByUser(UserInterface $user, MerchantInterface $merchant = null): int
public function countValidByUser(UserInterface $user): int
{ {
return $this->getBy(
return $this->countBy(
[ [
'user' => $user, 'user' => $user,
'isValid' => true, 'isValid' => true,
'merchant' => $merchant,
'excludeComplementaryOrderShops' => true,
'count' => true
'section' => $this->section,
'excludeComplementaryOrderShops' => true
]
);
}

public function countValidByCurrentCycle(): int
{
return $this->countBy(
[
'cycleNumber' => $this->getCycleNumberCurrentOrder($this->section),
'isValid' => true,
'section' => $this->section,
'excludeComplementaryOrderShops' => true
] ]
); );
} }


// countValidOrderWithReductionCredit // countValidOrderWithReductionCredit
public function countValidWithReductionCredit( public function countValidWithReductionCredit(
OrderReductionCreditInterface $reductionCredit,
ReductionCreditInterface $reductionCredit,
UserInterface $user = null UserInterface $user = null
): string {
): int {
$query = $this->query->create(); $query = $this->query->create();


if ($user) { if ($user) {


// countValidOrderWithReductionCart // countValidOrderWithReductionCart
public function countValidWithReductionCart( public function countValidWithReductionCart(
OrderReductionCartInterface $reductionCart
ReductionCartInterface $reductionCart
): int { ): int {
$query = $this->query->create(); $query = $this->query->create();
$query $query
} }


// countValidOrderWithReductionCartPerUser // countValidOrderWithReductionCartPerUser
public function countValidWithReductionCartPerUser(
OrderReductionCartInterface $reductionCart,
public function countValidWithReductionCartByUser(
ReductionCartInterface $reductionCart,
UserInterface $user UserInterface $user
): string {
): int {
$query = $this->query->create(); $query = $this->query->create();


$query $query
->filterByStatus(OrderStatusModel::$statusAliasAsValid) ->filterByStatus(OrderStatusModel::$statusAliasAsValid)
->filterBySection($this->section); ->filterBySection($this->section);


$results = $query->find();

if ($results) {
return $results[0];
}
return $query->findOne();


return null;
} }


// findLastOrderValidOfWeek // findLastOrderValidOfWeek
public function getOneLastValidOfCycle(int $cycleNumber): ?OrderShopInterface
public function getOneLastValidByCycle(int $cycleNumber): ?OrderShopInterface
{ {
$query = $this->query->create(); $query = $this->query->create();


->filterByCycleNumber($cycleNumber) ->filterByCycleNumber($cycleNumber)
->filterByStatus(OrderStatusModel::$statusAliasAsValid) ->filterByStatus(OrderStatusModel::$statusAliasAsValid)
->filterIsNotMainOrderShop() ->filterIsNotMainOrderShop()
->orderBy('.weekId', 'DESC')
->orderBy('.cycleId', 'DESC')
->filterBySection($this->section); ->filterBySection($this->section);


return $query->findOne(); return $query->findOne();
$query->filterBySection($this->section); $query->filterBySection($this->section);
} }


if (isset($params['isMerchantOnline'])) {
$query->filterIsMerchantOnline();
}

if (isset($params['select'])) { if (isset($params['select'])) {
$query->selectParam($params['select']); $query->selectParam($params['select']);
} }






public function isReductionGiftUsed(ReductionCreditInterface $reductionGift)
{
if ($this->countValidWithReductionCredit($reductionGift)) {
return true;
} else {
return false;
}
}

public function isReductionCreditUsed(ReductionCreditInterface $reductionCredit, UserInterface $user = null)
{
if ($this->countValidWithReductionCredit($reductionCredit, $user)) {
return true;
} else {
return false;
}
}

public function isReductionCreditAddedToOrder(
OrderShopInterface $orderShop,
ReductionCreditInterface $reductionCredit
) {
foreach ($orderShop->getOrderReductionCredits() as $orderReductionCredit) {
if ($orderReductionCredit->getReductionCredit() == $reductionCredit) {
return true;
}
}

return false;
}

/* /*
public function getCartCurrent(SectionInterface $section, UserInterface $user = null, VisitorInterface $visitor = null) public function getCartCurrent(SectionInterface $section, UserInterface $user = null, VisitorInterface $visitor = null)
{ {

+ 2
- 0
Repository/Product/ProductCategoryRepository.php View File

{ {
parent::__construct($registry, ProductCategory::class); parent::__construct($registry, ProductCategory::class);
} }


} }

+ 1
- 5
Repository/Product/ProductCategoryRepositoryQuery.php View File

return $this->andWhere('pf.status = 1'); return $this->andWhere('pf.status = 1');
} }


public function filterByCurrentDay(): self
{
return $this->andWhere('e.displaySpecificDay IS NULL OR e.displaySpecificDay = :dayToday')
->setParameter('dayToday', date('N'));
}

} }

+ 1
- 41
Repository/Product/ProductCategoryStore.php View File

{ {
$this->query = $query; $this->query = $query;
} }

public function getParents()
{
$query = $this->query->create();
if ($this->section) {
$query->filterBySection($this->section);
}
$query->filterIsParent();

return $query->find();
}

//findAllByParent
public function getByParent(
ProductCategoryInterface $parentCategory,
bool $withOffline = false,
bool $withEmptyCategories = true,
bool $filterBySpecificDay = false
): array {

$query = $this->query->create();
$query->filterByParent($parentCategory);

if ($withOffline) {
$query->filterIsOnlineAndOffline();
} else {
$query->filterIsOnline();
}

if (!$withEmptyCategories) {
$query->hasProductFamilyOnline();
}

if ($filterBySpecificDay) {
$query->filterBySpecificDay();
}

$query->orderBy('position', 'asc');

return $query->find();
}


} }

+ 5
- 5
Repository/Reduction/ReductionCartStore.php View File

// getReductionCartRemainingQuantity // getReductionCartRemainingQuantity
public function getRemainingQuantity(ReductionCartInterface $reductionCart): float public function getRemainingQuantity(ReductionCartInterface $reductionCart): float
{ {
return $reductionCart->getAvailableQuantity() - $this->orderShopStore->countValidOrderWithReductionCart(
return $reductionCart->getAvailableQuantity() - $this->orderShopStore->countValidWithReductionCart(
$reductionCart $reductionCart
); );
} }
// getReductionCartUsedQuantityPerUser // getReductionCartUsedQuantityPerUser
public function getUsedQuantityByUser(ReductionCartInterface $reductionCart, UserInterface $user): float public function getUsedQuantityByUser(ReductionCartInterface $reductionCart, UserInterface $user): float
{ {
return $this->orderShopStore->countValidWithReductionCartPerUser($reductionCart, $user);
return $this->orderShopStore->countValidWithReductionCartByUser($reductionCart, $user);
} }


// getReductionCartUsedQuantity // getReductionCartUsedQuantity
public function getUsedQuantity(ReductionCartInterface $reductionCart): float public function getUsedQuantity(ReductionCartInterface $reductionCart): float
{ {
return $this->orderShopStore->countValidWithReductionCartPerUser($reductionCart);
return $this->orderShopStore->countValidWithReductionCart($reductionCart);
} }


// getReductionCartRemainingQuantityPerUser // getReductionCartRemainingQuantityPerUser
{ {
if ($reductionCart->getAvailableQuantityPerUser()) { if ($reductionCart->getAvailableQuantityPerUser()) {
return $reductionCart->getAvailableQuantityPerUser( return $reductionCart->getAvailableQuantityPerUser(
) - $this->orderShopStore->countValidWithReductionCartPerUser($reductionCart, $user);
) - $this->orderShopStore->countValidWithReductionCartByUser($reductionCart, $user);
} }


return false; return false;
} }


// findAllAvailableForUser / getReductionCartsAvailableByUser // findAllAvailableForUser / getReductionCartsAvailableByUser
public function getAvailablesByUser(UserInterface $user)
public function getAvailableByUser(UserInterface $user)
{ {
$reductionCarts = $this->query->find(); $reductionCarts = $this->query->find();



+ 0
- 6
Repository/Reduction/ReductionCatalogRepositoryQuery.php View File

->setParameter(':productFamily', $productFamily); ->setParameter(':productFamily', $productFamily);
} }


public function filterStatus(bool $status)
{
return $this
->andWhere('.status = :status')
->setParameter(':status', $status);
}
} }

+ 1
- 1
Repository/Reduction/ReductionCatalogStore.php View File

public function getByProductFamily($productFamily){ public function getByProductFamily($productFamily){
$query = $this->query->create(); $query = $this->query->create();
$query->filterProductFamily($productFamily); $query->filterProductFamily($productFamily);
$query->filterStatus(true);
$query->filterIsOnline();
return $query->findOne(); return $query->findOne();


} }

+ 0
- 5
Repository/Reduction/ReductionCreditRepositoryQuery.php View File

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


public function filterStatusOnline()
{
return $this->andWhere('.status = 1');
}

public function filterByUser(UserInterface $user) public function filterByUser(UserInterface $user)
{ {
return $this return $this

+ 0
- 30
Repository/Reduction/ReductionCreditStore.php View File

$query = $this->query->create(); $query = $this->query->create();


$query $query
->filterStatusOnline()
->filterByType($type) ->filterByType($type)
->filterByUser($user); ->filterByUser($user);


return $query->find(); return $query->find();
} }


public function isReductionGiftUsed(ReductionCreditInterface $reductionGift)
{
if ($this->orderShopStore->countValidOrderWithReductionCredit($reductionGift)) {
return true;
} else {
return false;
}
}

public function isReductionCreditUsed(ReductionCreditInterface $reductionCredit, UserInterface $user = null)
{
if ($this->orderShopStore->countValidOrderWithReductionCredit($reductionCredit, $user)) {
return true;
} else {
return false;
}
}

public function isReductionCreditAddedToOrder(
OrderShopInterface $orderShop,
ReductionCreditInterface $reductionCredit
) {
foreach ($orderShop->getOrderReductionCredits() as $orderReductionCredit) {
if ($orderReductionCredit->getReductionCredit() == $reductionCredit) {
return true;
}
}


return false;
}
} }

+ 8
- 0
Repository/Reminder/ReminderStore.php View File

$query->filterByMerchant($this->merchant); $query->filterByMerchant($this->merchant);
} }


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

return parent::getByUser($user, $query); return parent::getByUser($user, $query);
} }


$query->filterByMerchant($this->merchant); $query->filterByMerchant($this->merchant);
} }


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

return parent::getByEasyAdminConfigAndUser($crudAction, $crudControllerFqcn, $user, $entityId, $query); return parent::getByEasyAdminConfigAndUser($crudAction, $crudControllerFqcn, $user, $entityId, $query);
} }
} }

+ 1
- 1
Repository/SectionRepositoryQueryTrait.php View File

{ {
return $this->andWhereSection($this->id, $section); return $this->andWhereSection($this->id, $section);
} }
}
}

+ 12
- 0
Repository/SectionStoreTrait.php View File



return $this; return $this;
} }

public function getParents()
{
$query = $this->query->create();
if ($this->section) {
$query->filterBySection($this->section);
}
$query->filterIsParent();

return $query->find();
}

} }

+ 2
- 2
Repository/Site/NewsRepositoryQuery.php View File



namespace Lc\CaracoleBundle\Repository\Site; namespace Lc\CaracoleBundle\Repository\Site;


use Lc\CaracoleBundle\Repository\MerchantRepositoryQueryTrait;
use Lc\CaracoleBundle\Repository\SectionRepositoryQueryTrait;
use Lc\SovBundle\Repository\Site\NewsRepositoryQuery as SovNewsRepositoryQuery; use Lc\SovBundle\Repository\Site\NewsRepositoryQuery as SovNewsRepositoryQuery;


class NewsRepositoryQuery extends SovNewsRepositoryQuery class NewsRepositoryQuery extends SovNewsRepositoryQuery
{ {
use MerchantRepositoryQueryTrait;
use SectionRepositoryQueryTrait;


} }

+ 4
- 4
Repository/Site/NewsStore.php View File



namespace Lc\CaracoleBundle\Repository\Site; namespace Lc\CaracoleBundle\Repository\Site;


use Lc\CaracoleBundle\Repository\MerchantStoreTrait;
use Lc\CaracoleBundle\Repository\SectionStoreTrait;
use Lc\SovBundle\Repository\Site\NewsStore as SovNewsStore; use Lc\SovBundle\Repository\Site\NewsStore as SovNewsStore;


class NewsStore extends SovNewsStore class NewsStore extends SovNewsStore
{ {
use MerchantStoreTrait;
use SectionStoreTrait;


public function getLatests(int $maxResults = 0, $query = null): array public function getLatests(int $maxResults = 0, $query = null): array
{ {
$query = $this->query->create(); $query = $this->query->create();
} }


if ($this->merchant) {
$query->filterByMerchant($this->merchant);
if ($this->section) {
$query->filterBySection($this->section);
} }


return parent::getLatests($maxResults, $query); return parent::getLatests($maxResults, $query);

+ 1
- 1
Repository/Site/PageStore.php View File

} }


// findPage // findPage
public function getOnePage(string $devAlias): ?PageInterface
public function getOneByDevAlias(string $devAlias): ?PageInterface
{ {
$query = $this->query->create(); $query = $this->query->create();



+ 2
- 2
Repository/Ticket/TicketRepositoryQuery.php View File



namespace Lc\CaracoleBundle\Repository\Ticket; namespace Lc\CaracoleBundle\Repository\Ticket;


use Lc\CaracoleBundle\Repository\MerchantRepositoryQueryTrait;
use Lc\CaracoleBundle\Repository\SectionRepositoryQueryTrait;
use Lc\SovBundle\Repository\Ticket\TicketRepositoryQuery as SovTicketRepositoryQuery; use Lc\SovBundle\Repository\Ticket\TicketRepositoryQuery as SovTicketRepositoryQuery;


class TicketRepositoryQuery extends SovTicketRepositoryQuery class TicketRepositoryQuery extends SovTicketRepositoryQuery
{ {
use MerchantRepositoryQueryTrait;
use SectionRepositoryQueryTrait;


} }

+ 14
- 31
Repository/Ticket/TicketStore.php View File



namespace Lc\CaracoleBundle\Repository\Ticket; namespace Lc\CaracoleBundle\Repository\Ticket;


use Lc\CaracoleBundle\Repository\MerchantStoreTrait;
use Lc\CaracoleBundle\Repository\SectionStoreTrait;
use Lc\SovBundle\Model\User\UserInterface;
use Lc\SovBundle\Repository\Ticket\TicketStore as SovTicketStore; use Lc\SovBundle\Repository\Ticket\TicketStore as SovTicketStore;


class TicketStore extends SovTicketStore class TicketStore extends SovTicketStore
{ {
use MerchantStoreTrait;
use SectionStoreTrait;


public function getByUser($user, $query = null): array
public function getByUser(UserInterface $user, $query = null): array
{ {
if (is_null($query)) {
$query = $this->query->create();
}

if ($this->merchant) {
$query->filterByMerchant($this->merchant);
}

$query = $this->createQuery($query);
$query->filterBySection($this->section);
return parent::getByUser($user, $query); return parent::getByUser($user, $query);
} }


public function getAllOpen(int $limit = 0, $query = null): array
public function getOpen(int $limit = 0, $query = null): array
{ {
if (is_null($query)) {
$query = $this->query->create();
}

if ($this->merchant) {
$query->filterByMerchant($this->merchant);
}

return parent::getAllOpen($limit, $query);
$query = $this->createQuery($query);
$query->filterBySection($this->section);
return parent::getOpen($limit, $query);
} }


public function countAllOpen($query = null): string
public function countOpen($query = null): string
{ {
if (is_null($query)) {
$query = $this->query->create();
}

if ($this->merchant) {
$query->filterByMerchant($this->merchant);
}

return parent::countAllOpen($query);
$query = $this->createQuery($query);
$query->filterBySection($this->section);
return parent::countOpen($query);
} }


} }

+ 5
- 4
Repository/User/UserMerchantStore.php View File

} }


// getUserMerchant // getUserMerchant
public function getOneByUser(UserInterface $user): UserMerchantInterface
public function getOneByUser(UserInterface $user, $query = null): UserMerchantInterface
{ {
$query = $this->query->create();
$query = $this->createQuery($query);


$query $query
->filterByMerchant($this->merchant) ->filterByMerchant($this->merchant)
return $query->findOne(); return $query->findOne();
} }


public function isCreditActiveByUser(UserInterface $user): bool
public function isCreditActiveByUser(UserInterface $user, $query = null): bool
{ {
$userMerchant = $this->getOneByUser($user);
$userMerchant = $this->getOneByUser($user, $query);
return $this->userMerchantSolver->isCreditActive($userMerchant); return $this->userMerchantSolver->isCreditActive($userMerchant);
} }
} }

+ 1
- 1
Repository/User/UserRepositoryQuery.php View File

->andWhere('um.active = 1'); ->andWhere('um.active = 1');
} }


public function filterByJoinUserMerchant(Merchant $merchant): self
public function filterByMerchant(Merchant $merchant): self
{ {
$this->joinUserMerchants(); $this->joinUserMerchants();
return $this return $this

+ 0
- 14
Repository/User/UserStore.php View File

{ {
use MerchantStoreTrait; use MerchantStoreTrait;


public function getByNewsletter(Newsletter $newsletter, $query = null): array
{
if (is_null($query)) {
$query = $this->query->create();
}

if ($this->merchant) {
$query
->filterByJoinUserMerchant($this->merchant)
->filterMerchantIsActive();
}

return parent::getByNewsletter($newsletter, $query);
}
} }

+ 2
- 4
Repository/User/VisitorStore.php View File

$this->query = $query; $this->query = $query;
} }


public function getOneByCookie(string $cookie)
public function getOneByCookie(string $cookie, $query = null)
{ {
$query = $this->query->create();

$query = $this->createQuery($query);
$query->filterByCookie($cookie); $query->filterByCookie($cookie);

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

+ 1
- 1
Resolver/MerchantResolver.php View File



public function getMerchantUser(UserInterface $user = null) public function getMerchantUser(UserInterface $user = null)
{ {
$merchants = $this->merchantStore->findAll();
$merchants = $this->merchantStore->getOnline();


if ($user) { if ($user) {
return $user->getMerchant(); return $user->getMerchant();

+ 8
- 17
Resolver/OpeningResolver.php View File

protected array $messages = []; protected array $messages = [];
protected SectionResolver $sectionResolver; protected SectionResolver $sectionResolver;
protected Security $security; protected Security $security;
//protected OrderShopStore $orderShopStore;
protected OrderShopStore $orderShopStore;


public function __construct(SectionResolver $sectionResolver, Security $security /*, OrderShopStore $orderShopStore*/)
public function __construct(SectionResolver $sectionResolver, Security $security, OrderShopStore $orderShopStore)
{ {
$this->sectionResolver = $sectionResolver; $this->sectionResolver = $sectionResolver;
$this->security = $security; $this->security = $security;
//$this->orderShopStore = $orderShopStore;
$this->orderShopStore = $orderShopStore;
} }


public function isOpenSale( public function isOpenSale(
SectionInterface $section = null,
SectionInterface $section,
UserInterface $user = null, UserInterface $user = null,
\DateTime $date = null, \DateTime $date = null,
string $context = null string $context = null
// Initialisation // Initialisation
$this->messages = []; $this->messages = [];


if (is_null($section)) {
$section = $this->sectionResolver->getCurrent();
}

if (is_null($user)) {
$user = $this->security->getUser();
}

if (is_null($date)) { if (is_null($date)) {
$date = new \DateTime(); $date = new \DateTime();
} }
} }


// Période de fermeture des commandes issue de la configuration de la section (congés) // Période de fermeture des commandes issue de la configuration de la section (congés)
if($this->isClosingPeriod($section)) {
if($this->isClosingPeriod($section, $date)) {
$this->addMessage( $this->addMessage(
'Les commandes sont fermées (période de fermeture des commandes dans la configuration de la section).' 'Les commandes sont fermées (période de fermeture des commandes dans la configuration de la section).'
); );
} }


// isHolidays // isHolidays
public function isClosingPeriod(Section $section, \DateTime $date)
public function isClosingPeriod(SectionInterface $section, \DateTime $date)
{ {
$orderClosedStart = $section->getSettingValue(SectionSettingDefinition::SETTING_ORDER_CLOSED_START); $orderClosedStart = $section->getSettingValue(SectionSettingDefinition::SETTING_ORDER_CLOSED_START);
$orderClosedEnd = $section->getSettingValue(SectionSettingDefinition::SETTING_ORDER_CLOSED_END); $orderClosedEnd = $section->getSettingValue(SectionSettingDefinition::SETTING_ORDER_CLOSED_END);
// isMaximumOrderWeekAchieved // isMaximumOrderWeekAchieved
public function isMaximumOrderCycleAchieved(SectionInterface $section) public function isMaximumOrderCycleAchieved(SectionInterface $section)
{ {
// @TODO : countValidByCycle
//$countOrderShopCycle = $this->orderShopStore->countValidByCycle($section);
$countOrderShopCycle = 0 ;

$countOrderShopCycle = $this->orderShopStore->countValidByCurrentCycle();
$orderMaximumPerCycle = $section->getSettingValue(SectionSettingDefinition::SETTING_ORDER_MAXIMUM_PER_CYCLE); $orderMaximumPerCycle = $section->getSettingValue(SectionSettingDefinition::SETTING_ORDER_MAXIMUM_PER_CYCLE);
if ($orderMaximumPerCycle && $countOrderShopCycle >= $orderMaximumPerCycle) { if ($orderMaximumPerCycle && $countOrderShopCycle >= $orderMaximumPerCycle) {
return true; return true;

Loading…
Cancel
Save