Browse Source

Refactoring repos

packProduct
Guillaume 3 years ago
parent
commit
5f5e3113c6
4 changed files with 121 additions and 137 deletions
  1. +0
    -9
      Repository/Merchant/MerchantStore.php
  2. +3
    -3
      Repository/Order/OrderShopRepositoryQuery.php
  3. +115
    -118
      Repository/Order/OrderShopStore.php
  4. +3
    -7
      Repository/Site/PageStore.php

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

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


//TODO pas de merchant_configs

// public function findAllWithConfigs()
// {
// $qb = $this->createQueryBuilder('hub');
// $qb->innerJoin('hub.merchantConfigs', 'merchant_configs');
// return $qb->getQuery()->getResult();
// }

} }

+ 3
- 3
Repository/Order/OrderShopRepositoryQuery.php View File

->setParameter('deliveryAvailabilityPointSale', $deliveryAvailabilityPointSale); ->setParameter('deliveryAvailabilityPointSale', $deliveryAvailabilityPointSale);
} }


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


public function filterIsNotMainOrderShop(): self public function filterIsNotMainOrderShop(): self

+ 115
- 118
Repository/Order/OrderShopStore.php View File

protected UrlGeneratorInterface $router; protected UrlGeneratorInterface $router;


public function __construct( public function __construct(
OrderShopRepositoryQuery $query,
EntityManagerInterface $entityManager,
PriceResolver $priceResolver,
DocumentBuilder $documentBuilder,
ReductionCreditStore $reductionCreditStore,
SectionStore $sectionStore,
OrderProductStore $orderProductStore,
MerchantStore $merchantStore,
FlashBagInterface $flashBag,
OpeningResolver $openingResolver,
ParameterBagInterface $parameterBag,
UrlGeneratorInterface $router
OrderShopRepositoryQuery $query,
EntityManagerInterface $entityManager,
PriceResolver $priceResolver,
DocumentBuilder $documentBuilder,
ReductionCreditStore $reductionCreditStore,
SectionStore $sectionStore,
OrderProductStore $orderProductStore,
MerchantStore $merchantStore,
FlashBagInterface $flashBag,
OpeningResolver $openingResolver,
ParameterBagInterface $parameterBag,
UrlGeneratorInterface $router
) { ) {
$this->query = $query; $this->query = $query;
$this->entityManager = $entityManager; $this->entityManager = $entityManager;
$this->router = $router; $this->router = $router;
} }


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


return $orderShops; return $orderShops;
} }


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


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


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


]
]
); );


// @TODO : optimisation à remettre en place // @TODO : optimisation à remettre en place
return $this->countOrderShopsOfWeek;*/ return $this->countOrderShopsOfWeek;*/
} }


// getNextWeekId
// getNextWeekId
public function getNextCycleId(SectionInterface $section, int $cycleNumber): int public function getNextCycleId(SectionInterface $section, int $cycleNumber): int
{ {
$lastOrder = $this->getOneLastOrderValidOfCycle($section, $cycleNumber); $lastOrder = $this->getOneLastOrderValidOfCycle($section, $cycleNumber);
} }
} }


// getOrderDatas
// getOrderDatas
public function getDatas(OrderShopInterface $orderShop, UserInterface $user = null): array public function getDatas(OrderShopInterface $orderShop, UserInterface $user = null): array
{ {
$data = []; $data = [];
$data['orderProducts'][$i]['price'] = $this->priceResolver->getPrice($orderProduct); $data['orderProducts'][$i]['price'] = $this->priceResolver->getPrice($orderProduct);
$data['orderProducts'][$i]['priceWithTax'] = $this->priceResolver->getPriceWithTax($orderProduct); $data['orderProducts'][$i]['priceWithTax'] = $this->priceResolver->getPriceWithTax($orderProduct);
$data['orderProducts'][$i]['priceWithTaxAndReduction'] = $this->priceResolver->getPriceWithTaxAndReduction( $data['orderProducts'][$i]['priceWithTaxAndReduction'] = $this->priceResolver->getPriceWithTaxAndReduction(
$orderProduct
$orderProduct
); );
$data['orderProducts'][$i]['quantity'] = $orderProduct->getQuantityOrder(); $data['orderProducts'][$i]['quantity'] = $orderProduct->getQuantityOrder();
$data['orderProducts'][$i]['totalWithTaxAndReduction'] = $this->priceResolver->getTotalOrderProductsWithTaxAndReduction( $data['orderProducts'][$i]['totalWithTaxAndReduction'] = $this->priceResolver->getTotalOrderProductsWithTaxAndReduction(
array($orderProduct)
array($orderProduct)
); );
$i++; $i++;
} }
$productFamily = $orderProduct->getProduct()->getProductFamily(); $productFamily = $orderProduct->getProduct()->getProductFamily();
if (!isset($orderProductsByProductFamily[$productFamily->getId()])) { if (!isset($orderProductsByProductFamily[$productFamily->getId()])) {
$orderProductsByProductFamily[$productFamily->getId()] = [ $orderProductsByProductFamily[$productFamily->getId()] = [
'order_products' => [],
'total_quantity_weight' => 0,
'order_products' => [],
'total_quantity_weight' => 0,
]; ];
} }
$orderProductsByProductFamily[$productFamily->getId()]['order_products'][] = $orderProduct; $orderProductsByProductFamily[$productFamily->getId()]['order_products'][] = $orderProduct;
$orderProductsByProductFamily[$productFamily->getId( $orderProductsByProductFamily[$productFamily->getId(
)]['total_quantity_weight'] += ($orderProduct->getQuantityProduct() / $orderProduct->getUnit( )]['total_quantity_weight'] += ($orderProduct->getQuantityProduct() / $orderProduct->getUnit(
)->getCoefficient()) * $orderProduct->getQuantityOrder();
)->getCoefficient()) * $orderProduct->getQuantityOrder();
} }
} }


return $orderProductsByProductFamily; return $orderProductsByProductFamily;
} }


// isOrderShopPositiveAmount
// isOrderShopPositiveAmount
public function isPositiveAmount(OrderShopInterface $orderShop) public function isPositiveAmount(OrderShopInterface $orderShop)
{ {
return $this->priceResolver->getTotalWithTax($orderShop) >= 0; return $this->priceResolver->getTotalWithTax($orderShop) >= 0;
$totalOrder = $this->priceResolver->getTotalWithTax($orderShop); $totalOrder = $this->priceResolver->getTotalWithTax($orderShop);


if ((abs($totalOrderPayments - $totalOrder) < 0.00001 if ((abs($totalOrderPayments - $totalOrder) < 0.00001
|| $totalOrderPayments >= $totalOrder)
&& $totalOrder > 0) {
|| $totalOrderPayments >= $totalOrder)
&& $totalOrder > 0) {
return true; return true;
} else { } else {
return false; return false;
return $totalAmount; return $totalAmount;
} }


public
function getTotalRemainingToBePaid(
OrderShopInterface $orderShop
): float {
public function getTotalRemainingToBePaid(OrderShopInterface $orderShop): float
{
return $this->priceResolver->getTotalWithTax($orderShop) - $this->getTotalOrderPayments($orderShop); return $this->priceResolver->getTotalWithTax($orderShop) - $this->getTotalOrderPayments($orderShop);
} }


// isOrderShopPositiveAmountRemainingToBePaid
// isOrderShopPositiveAmountRemainingToBePaid
public function isPositiveAmountRemainingToBePaid(OrderShopInterface $orderShop): bool public function isPositiveAmountRemainingToBePaid(OrderShopInterface $orderShop): bool
{ {
return $this->getTotalRemainingToBePaid($orderShop) > 0; return $this->getTotalRemainingToBePaid($orderShop) > 0;
$newOrderShop = $this->em->getRepository(OrderShopInterface::class)->findCartCurrent(['user' => $user]); $newOrderShop = $this->em->getRepository(OrderShopInterface::class)->findCartCurrent(['user' => $user]);
if ($newOrderShop === null) { if ($newOrderShop === null) {
$newOrderShop = $this->createOrderShop( $newOrderShop = $this->createOrderShop(
array(
'user' => $user,
'merchant' => $this->merchantUtils->getMerchantUser()
)
array(
'user' => $user,
'merchant' => $this->merchantUtils->getMerchantUser()
)
); );
} }


return true; return true;
} }


// countValidOrderShopByUserAllMerchant
// countValidOrderShopByUserAllMerchant
public function countValidByUserAllMerchant($user) public function countValidByUserAllMerchant($user)
{ {
$totalOrder = 0; $totalOrder = 0;
public function countValidByUser(UserInterface $user, MerchantInterface $merchant = null) public function countValidByUser(UserInterface $user, MerchantInterface $merchant = null)
{ {
return $this->getBy( return $this->getBy(
[
'user' => $user,
'isValid' => true,
'merchant' => $merchant,
'excludeComplementaryOrderShops' => true,
'count' => true
]
[
'user' => $user,
'isValid' => true,
'merchant' => $merchant,
'excludeComplementaryOrderShops' => true,
'count' => true
]
); );
} }


return $orderShop; return $orderShop;
}*/ }*/


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


$query->filterByUser($user); $query->filterByUser($user);
} }
$query $query
->selectCount()
->filterByReductionCredit($reductionCredit)
->filterByStatus(OrderStatus::$statusAliasAsValid)
->filterBySection($this->section);
->selectCount()
->filterByReductionCredit($reductionCredit)
->filterByStatus(OrderStatus::$statusAliasAsValid)
->filterBySection($this->section);


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


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

$query $query
->selectCount()
->filterByReductionCart($reductionCart)
->filterByStatus(OrderStatus::$statusAliasAsValid)
->filterBySection($this->section);
->selectCount()
->filterByReductionCart($reductionCart)
->filterByStatus(OrderStatus::$statusAliasAsValid)
->filterBySection($this->section);


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


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


$query $query
->selectCount()
->filterByUser($user)
->filterByReductionCart($reductionCart)
->filterByStatus(OrderStatus::$statusAliasAsValid)
->filterBySection($this->section);
->selectCount()
->filterByUser($user)
->filterByReductionCart($reductionCart)
->filterByStatus(OrderStatus::$statusAliasAsValid)
->filterBySection($this->section);


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


//findCartCurrent
// findCartCurrent
public function getCartCurrent(array $params): ?OrderShopInterface public function getCartCurrent(array $params): ?OrderShopInterface
{ {
$query = $this->query->create(); $query = $this->query->create();


if (isset($params['user'])) { if (isset($params['user'])) {
$query $query
->filterByUser($params['user']);
->filterByUser($params['user']);
} }
if (isset($params['visitor'])) { if (isset($params['visitor'])) {
$query $query
->filterByVisitor($params['visitor']);
->filterByVisitor($params['visitor']);
} }


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


$results = $query->find(); $results = $query->find();


return null; return null;
} }


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


$query $query
->filterByWeekNumber($weekNumber)
->filterByStatus(OrderStatus::$statusAliasAsValid)
->filterIsNotMainOrderShop()
->orderBy('.weekId', 'DESC')
->filterBySection($this->section);
->filterByCycleNumber($cycleNumber)
->filterByStatus(OrderStatus::$statusAliasAsValid)
->filterIsNotMainOrderShop()
->orderBy('.weekId', 'DESC')
->filterBySection($this->section);


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


//findLastOrderValid
public function getOneLastOrderValid(): ?OrderShopInterface
//findLastOrderValid
public function getOneLastValid(): ?OrderShopInterface
{ {
$query = $this->query->create(); $query = $this->query->create();


$query $query
->filterByStatus(OrderStatus::$statusAliasAsValid)
->filterIsNotMainOrderShop()
->orderBy('.idValidOrder', 'DESC')
->filterBySection($this->section);
->filterByStatus(OrderStatus::$statusAliasAsValid)
->filterIsNotMainOrderShop()
->orderBy('.idValidOrder', 'DESC')
->filterBySection($this->section);


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


//TODO Fonction à tester
// @TODO : Fonction à tester


// findAllBy
public function getAllBy(array $params = [])
// findAllBy
public function getBy(array $params = [])
{ {
$query = $this->query->create(); $query = $this->query->create();


$query->filterByDateEnd($params['dateField'], $params['dateEnd']); $query->filterByDateEnd($params['dateField'], $params['dateEnd']);
} }


if (isset($params['weekNumber'])) {
$query->filterByWeekNumber($params['weekNumber']);
if (isset($params['cycleNumber'])) {
$query->filterByCycleNumber($params['cycleNumber']);
} }


if (isset($params['isCart'])) { if (isset($params['isCart'])) {
if (isset($params['estimatedDeliveryDateTime'])) { if (isset($params['estimatedDeliveryDateTime'])) {
$date = clone $params['estimatedDeliveryDateTime']; $date = clone $params['estimatedDeliveryDateTime'];
$query $query
->filterByEstimatedDeliveryDateStart($date->format('Y-m-d 00:00:00'))
->filterByEstimatedDeliveryDateEnd($date->modify('+1 day')->format('Y-m-d 00:00:00'));
->filterByEstimatedDeliveryDateStart($date->format('Y-m-d 00:00:00'))
->filterByEstimatedDeliveryDateEnd($date->modify('+1 day')->format('Y-m-d 00:00:00'));
} }



if (isset($params['deliveryDate'])) { if (isset($params['deliveryDate'])) {
$date = clone $params['deliveryDate']; $date = clone $params['deliveryDate'];
$query $query
->filterByDeliveryDateStart($date->format('Y-m-d 00:00:00'))
->filterByDeliveryDateEnd($date->modify('+1 day')->format('Y-m-d 00:00:00'));
->filterByDeliveryDateStart($date->format('Y-m-d 00:00:00'))
->filterByDeliveryDateEnd($date->modify('+1 day')->format('Y-m-d 00:00:00'));
} }


if (isset($params['mergeComplementaryOrderShops'])) { if (isset($params['mergeComplementaryOrderShops'])) {
//TODO jointure peut être pas utile
$query $query
->joinComplementaryOrderShops();
->joinComplementaryOrderShops();
} }


if (isset($params['excludeComplementaryOrderShops']) || isset($params['mergeComplementaryOrderShops'])) { if (isset($params['excludeComplementaryOrderShops']) || isset($params['mergeComplementaryOrderShops'])) {

+ 3
- 7
Repository/Site/PageStore.php View File

parent::__construct($query); parent::__construct($query);
} }


// TODO Vérifier si c'est good avec la section
// findPage
public function getOnePage(string $devAlias, SectionInterface $section = null): ?PageInterface
// findPage
public function getOnePage(string $devAlias): ?PageInterface
{ {
$query = $this->query->create(); $query = $this->query->create();


if ($section == null) {
$section = $this->section;
}
$query $query
->filterIsOnline() ->filterIsOnline()
->filterByDevAlias($devAlias) ->filterByDevAlias($devAlias)
->filterBySection($section);
->filterBySection($this->section);


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

Loading…
Cancel
Save