Pārlūkot izejas kodu

Refactoring repos

packProduct
Guillaume pirms 3 gadiem
vecāks
revīzija
5f5e3113c6
4 mainītis faili ar 121 papildinājumiem un 137 dzēšanām
  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 Parādīt failu

@@ -23,13 +23,4 @@ class MerchantStore extends AbstractStore
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 Parādīt failu

@@ -159,11 +159,11 @@ class OrderShopRepositoryQuery extends AbstractRepositoryQuery
->setParameter('deliveryAvailabilityPointSale', $deliveryAvailabilityPointSale);
}

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

public function filterIsNotMainOrderShop(): self

+ 115
- 118
Repository/Order/OrderShopStore.php Parādīt failu

@@ -43,18 +43,18 @@ class OrderShopStore extends AbstractStore
protected UrlGeneratorInterface $router;

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->entityManager = $entityManager;
@@ -70,50 +70,50 @@ class OrderShopStore extends AbstractStore
$this->router = $router;
}

// getOrderShopsOfWeek
// getOrderShopsOfWeek
public function getByCycle(SectionInterface $section, $params = [])
{
$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;
}

// getOrderShopsOfWeekByUser
// getOrderShopsOfWeekByUser
public function getByCycleAndUser(SectionInterface $section, UserInterface $user, array $params = [])
{
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)
{
return $this->getByCycle(
$section,
[
'count' => true,
'excludeComplementaryOrderShops' => $excludeComplementaryOrderShops
$section,
[
'count' => true,
'excludeComplementaryOrderShops' => $excludeComplementaryOrderShops

]
]
);

// @TODO : optimisation à remettre en place
@@ -130,7 +130,7 @@ class OrderShopStore extends AbstractStore
return $this->countOrderShopsOfWeek;*/
}

// getNextWeekId
// getNextWeekId
public function getNextCycleId(SectionInterface $section, int $cycleNumber): int
{
$lastOrder = $this->getOneLastOrderValidOfCycle($section, $cycleNumber);
@@ -152,7 +152,7 @@ class OrderShopStore extends AbstractStore
}
}

// getOrderDatas
// getOrderDatas
public function getDatas(OrderShopInterface $orderShop, UserInterface $user = null): array
{
$data = [];
@@ -190,11 +190,11 @@ class OrderShopStore extends AbstractStore
$data['orderProducts'][$i]['price'] = $this->priceResolver->getPrice($orderProduct);
$data['orderProducts'][$i]['priceWithTax'] = $this->priceResolver->getPriceWithTax($orderProduct);
$data['orderProducts'][$i]['priceWithTaxAndReduction'] = $this->priceResolver->getPriceWithTaxAndReduction(
$orderProduct
$orderProduct
);
$data['orderProducts'][$i]['quantity'] = $orderProduct->getQuantityOrder();
$data['orderProducts'][$i]['totalWithTaxAndReduction'] = $this->priceResolver->getTotalOrderProductsWithTaxAndReduction(
array($orderProduct)
array($orderProduct)
);
$i++;
}
@@ -211,21 +211,21 @@ class OrderShopStore extends AbstractStore
$productFamily = $orderProduct->getProduct()->getProductFamily();
if (!isset($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(
)]['total_quantity_weight'] += ($orderProduct->getQuantityProduct() / $orderProduct->getUnit(
)->getCoefficient()) * $orderProduct->getQuantityOrder();
)->getCoefficient()) * $orderProduct->getQuantityOrder();
}
}

return $orderProductsByProductFamily;
}

// isOrderShopPositiveAmount
// isOrderShopPositiveAmount
public function isPositiveAmount(OrderShopInterface $orderShop)
{
return $this->priceResolver->getTotalWithTax($orderShop) >= 0;
@@ -237,8 +237,8 @@ class OrderShopStore extends AbstractStore
$totalOrder = $this->priceResolver->getTotalWithTax($orderShop);

if ((abs($totalOrderPayments - $totalOrder) < 0.00001
|| $totalOrderPayments >= $totalOrder)
&& $totalOrder > 0) {
|| $totalOrderPayments >= $totalOrder)
&& $totalOrder > 0) {
return true;
} else {
return false;
@@ -261,14 +261,12 @@ class OrderShopStore extends AbstractStore
return $totalAmount;
}

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

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

@@ -294,7 +292,7 @@ class OrderShopStore extends AbstractStore
return true;
}

// countValidOrderShopByUserAllMerchant
// countValidOrderShopByUserAllMerchant
public function countValidByUserAllMerchant($user)
{
$totalOrder = 0;
@@ -309,13 +307,13 @@ class OrderShopStore extends AbstractStore
public function countValidByUser(UserInterface $user, MerchantInterface $merchant = null)
{
return $this->getBy(
[
'user' => $user,
'isValid' => true,
'merchant' => $merchant,
'excludeComplementaryOrderShops' => true,
'count' => true
]
[
'user' => $user,
'isValid' => true,
'merchant' => $merchant,
'excludeComplementaryOrderShops' => true,
'count' => true
]
);
}

@@ -372,10 +370,10 @@ class OrderShopStore extends AbstractStore
return $orderShop;
}*/

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

@@ -383,62 +381,63 @@ class OrderShopStore extends AbstractStore
$query->filterByUser($user);
}
$query
->selectCount()
->filterByReductionCredit($reductionCredit)
->filterByStatus(OrderStatus::$statusAliasAsValid)
->filterBySection($this->section);
->selectCount()
->filterByReductionCredit($reductionCredit)
->filterByStatus(OrderStatus::$statusAliasAsValid)
->filterBySection($this->section);

return $query->count();
}

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

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

return $query->count();
}

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

$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();
}

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

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

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

$results = $query->find();

@@ -449,39 +448,39 @@ class OrderShopStore extends AbstractStore
return null;
}

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

$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();
}

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

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

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();

@@ -511,8 +510,8 @@ class OrderShopStore extends AbstractStore
$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'])) {
@@ -546,22 +545,20 @@ class OrderShopStore extends AbstractStore
if (isset($params['estimatedDeliveryDateTime'])) {
$date = clone $params['estimatedDeliveryDateTime'];
$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'])) {
$date = clone $params['deliveryDate'];
$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'])) {
//TODO jointure peut être pas utile
$query
->joinComplementaryOrderShops();
->joinComplementaryOrderShops();
}

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

+ 3
- 7
Repository/Site/PageStore.php Parādīt failu

@@ -16,19 +16,15 @@ class PageStore extends SovPageStore
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();

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

return $query->findOne();
}

Notiek ielāde…
Atcelt
Saglabāt