Ver código fonte

Correctif reductionCatalog

packProduct
Fabien Normand 3 anos atrás
pai
commit
157898c388
3 arquivos alterados com 156 adições e 147 exclusões
  1. +153
    -145
      Repository/Order/OrderShopStore.php
  2. +1
    -1
      Repository/User/UserRepositoryQuery.php
  3. +2
    -1
      Repository/User/UserStore.php

+ 153
- 145
Repository/Order/OrderShopStore.php Ver arquivo

@@ -28,8 +28,8 @@ use Lc\CaracoleBundle\Solver\Reduction\ReductionCartSolver;
use Lc\SovBundle\Model\User\UserInterface;
use Lc\CaracoleBundle\Repository\AbstractStore;
use Lc\SovBundle\Repository\RepositoryQueryInterface;
use Lc\SovBundle\Translation\FlashBagTranslator;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;

class OrderShopStore extends AbstractStore
@@ -46,7 +46,7 @@ class OrderShopStore extends AbstractStore
protected SectionStore $sectionStore;
protected OrderProductStore $orderProductStore;
protected MerchantStore $merchantStore;
protected FlashBagInterface $flashBag;
protected FlashBagTranslator $flashBagTranslator;
protected OpeningResolver $openingResolver;
protected ParameterBagInterface $parameterBag;
protected UrlGeneratorInterface $router;
@@ -55,22 +55,23 @@ class OrderShopStore extends AbstractStore
protected DistributionBuilder $distributionBuilder;

public function __construct(
OrderShopRepositoryQuery $query,
EntityManagerInterface $entityManager,
PriceSolver $priceSolver,
DocumentBuilder $documentBuilder,
ReductionCreditStore $reductionCreditStore,
ReductionCartSolver $reductionCartSolver,
SectionStore $sectionStore,
OrderProductStore $orderProductStore,
MerchantStore $merchantStore,
FlashBagInterface $flashBag,
ParameterBagInterface $parameterBag,
UrlGeneratorInterface $router,
OrderShopSolver $orderShopSolver,
ReductionCartStore $reductionCartStore,
DistributionBuilder $distributionBuilder
) {
OrderShopRepositoryQuery $query,
EntityManagerInterface $entityManager,
PriceSolver $priceSolver,
DocumentBuilder $documentBuilder,
ReductionCreditStore $reductionCreditStore,
ReductionCartSolver $reductionCartSolver,
SectionStore $sectionStore,
OrderProductStore $orderProductStore,
MerchantStore $merchantStore,
FlashBagTranslator $flashBagTranslator,
ParameterBagInterface $parameterBag,
UrlGeneratorInterface $router,
OrderShopSolver $orderShopSolver,
ReductionCartStore $reductionCartStore,
DistributionBuilder $distributionBuilder
)
{
$this->query = $query;
$this->entityManager = $entityManager;
$this->priceSolver = $priceSolver;
@@ -80,7 +81,7 @@ class OrderShopStore extends AbstractStore
$this->sectionStore = $sectionStore;
$this->orderProductStore = $orderProductStore;
$this->merchantStore = $merchantStore;
$this->flashBag = $flashBag;
$this->flashBagTranslator = $flashBagTranslator;
$this->parameterBag = $parameterBag;
$this->router = $router;
$this->orderShopSolver = $orderShopSolver;
@@ -114,14 +115,14 @@ class OrderShopStore extends AbstractStore
public function getByCurrentDistribution($params = [], $query = null)
{
return $this->getBy(
array_merge(
[
'distribution' => $this->distributionBuilder->guessCurrentDistributionOrder($this->section),
'isValid' => true,
],
$params
),
$query
array_merge(
[
'distribution' => $this->distributionBuilder->guessCurrentDistributionOrder($this->section),
'isValid' => true,
],
$params
),
$query
);
}

@@ -130,14 +131,14 @@ class OrderShopStore extends AbstractStore
public function getByCurrentDistributionAndUser(UserInterface $user = null, array $params = [], $query = null)
{
return $this->getByCurrentDistribution(
array_merge(
[
'user' => $user,
'excludeComplementaryOrderShops' => true
],
$params
),
$query
array_merge(
[
'user' => $user,
'excludeComplementaryOrderShops' => true
],
$params
),
$query
);
}

@@ -147,14 +148,14 @@ class OrderShopStore extends AbstractStore
public function countByCurrentDistribution(array $params, $query = null)
{
return $this->countBy(
array_merge(
[
'distribution' => $this->distributionBuilder->guessCurrentDistributionOrder($this->section),
'excludeComplementaryOrderShops' => isset($params['excludeComplementaryOrderShops']) ?? true,
],
$params
),
$query
array_merge(
[
'distribution' => $this->distributionBuilder->guessCurrentDistributionOrder($this->section),
'excludeComplementaryOrderShops' => isset($params['excludeComplementaryOrderShops']) ?? true,
],
$params
),
$query
);

// @TODO : optimisation à remettre en place
@@ -197,26 +198,26 @@ class OrderShopStore extends AbstractStore
public function countValidByUserAllMerchant($user, $query = null): int
{
return $this->countBy(
[
'user' => $user,
'isValid' => true,
// @TODO : à tester
'isMerchantOnline' => true,
'excludeComplementaryOrderShops' => true
],
$query
[
'user' => $user,
'isValid' => true,
// @TODO : à tester
'isMerchantOnline' => true,
'excludeComplementaryOrderShops' => true
],
$query
);
}

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

@@ -224,21 +225,22 @@ class OrderShopStore extends AbstractStore
public function countValidByCurrentDistribution($query = null): int
{
return $this->countBy(
[
'distribution' => $this->distributionBuilder->guessCurrentDistributionOrder($this->section),
'isValid' => true,
'excludeComplementaryOrderShops' => true
],
$query
[
'distribution' => $this->distributionBuilder->guessCurrentDistributionOrder($this->section),
'isValid' => true,
'excludeComplementaryOrderShops' => true
],
$query
);
}

// countValidOrderWithReductionCredit
public function countValidWithReductionCredit(
ReductionCreditInterface $reductionCredit,
UserInterface $user = null,
$query = null
): int {
ReductionCreditInterface $reductionCredit,
UserInterface $user = null,
$query = null
): int
{

//TODO vérifier que ne pas utiliser createDefaultQuery est pertinent
$query = $this->createQuery($query);
@@ -248,41 +250,43 @@ class OrderShopStore extends AbstractStore
}

$query
->selectCount()
->filterByReductionCredit($reductionCredit)
->filterByStatus(OrderStatusModel::$statusAliasAsValid);
->selectCount()
->filterByReductionCredit($reductionCredit)
->filterByStatus(OrderStatusModel::$statusAliasAsValid);

return $query->count();
}

// countValidOrderWithReductionCart
public function countValidWithReductionCart(
ReductionCartInterface $reductionCart,
$query = null
): int {
ReductionCartInterface $reductionCart,
$query = null
): int
{
$query = $this->createQuery($query);

$query
->selectCount()
->filterByReductionCart($reductionCart)
->filterByStatus(OrderStatusModel::$statusAliasAsValid);
->selectCount()
->filterByReductionCart($reductionCart)
->filterByStatus(OrderStatusModel::$statusAliasAsValid);

return $query->count();
}

// countValidOrderWithReductionCartPerUser
public function countValidWithReductionCartByUser(
ReductionCartInterface $reductionCart,
UserInterface $user,
$query = null
): int {
ReductionCartInterface $reductionCart,
UserInterface $user,
$query = null
): int
{
$query = $this->createDefaultQuery($query);

$query
->selectCount()
->filterByUser($user)
->filterByReductionCart($reductionCart)
->filterByStatus(OrderStatusModel::$statusAliasAsValid);
->selectCount()
->filterByUser($user)
->filterByReductionCart($reductionCart)
->filterByStatus(OrderStatusModel::$statusAliasAsValid);

return $query->count();
}
@@ -290,7 +294,7 @@ class OrderShopStore extends AbstractStore
// findCartCurrent
public function getOneCartCurrent(UserInterface $user = null, VisitorInterface $visitor = null, $query = null): ?OrderShopInterface
{
if(is_null($user) && is_null($visitor)) {
if (is_null($user) && is_null($visitor)) {
return null;
}

@@ -298,16 +302,15 @@ class OrderShopStore extends AbstractStore

if (!is_null($user)) {
$query->filterByUser($user);
}
else {
} else {
if (!is_null($visitor)) {
$query->filterByVisitor($visitor);
}
}

$query
->selectOrderReductionCarts()
->filterByStatus(OrderStatusModel::$statusAliasAsCart);
->selectOrderReductionCarts()
->filterByStatus(OrderStatusModel::$statusAliasAsCart);

return $query->findOne();
}
@@ -319,10 +322,10 @@ class OrderShopStore extends AbstractStore
$query = $this->createDefaultQuery($query);

$query
->filterByDistribution($distribution)
->filterByStatus(OrderStatusModel::$statusAliasAsValid)
->filterIsNotComplementaryOrderShop()
->orderBy('.cycleId', 'DESC');
->filterByDistribution($distribution)
->filterByStatus(OrderStatusModel::$statusAliasAsValid)
->filterIsNotComplementaryOrderShop()
->orderBy('.cycleId', 'DESC');

return $query->findOne();
}
@@ -333,9 +336,9 @@ class OrderShopStore extends AbstractStore
$query = $this->createDefaultQuery($query);

$query
->filterByStatus(OrderStatusModel::$statusAliasAsValid)
->filterIsNotComplementaryOrderShop()
->orderBy('.idValidOrder', 'DESC');
->filterByStatus(OrderStatusModel::$statusAliasAsValid)
->filterIsNotComplementaryOrderShop()
->orderBy('.idValidOrder', 'DESC');

return $query->findOne();
}
@@ -422,13 +425,13 @@ class OrderShopStore extends AbstractStore
$query->filterByAddress($params['address']);
}

if(isset($params['minimumTomorrowDelivery'])) {
if (isset($params['minimumTomorrowDelivery'])) {
$query->filterMinimumTomorrowDelivery();
}

if (isset($params['mergeComplementaryOrderShops'])) {
$query
->joinComplementaryOrderShops();
->joinComplementaryOrderShops();
}

if (isset($params['excludeComplementaryOrderShops']) || isset($params['mergeComplementaryOrderShops'])) {
@@ -463,10 +466,11 @@ class OrderShopStore extends AbstractStore
}

public function isReductionCreditUsed(
ReductionCreditInterface $reductionCredit,
UserInterface $user = null,
$query = null
) {
ReductionCreditInterface $reductionCredit,
UserInterface $user = null,
$query = null
)
{
if ($this->countValidWithReductionCredit($reductionCredit, $user, $query)) {
return true;
} else {
@@ -477,8 +481,8 @@ class OrderShopStore extends AbstractStore
public function getReductionCreditsAvailableByUser(UserInterface $user): array
{
$reductionCredits = $this->reductionCreditStore
->setMerchant($this->merchant)
->getByTypeAndUser(ReductionCreditModel::TYPE_CREDIT, $user);
->setMerchant($this->merchant)
->getByTypeAndUser(ReductionCreditModel::TYPE_CREDIT, $user);

$reductionCreditsArray = [];
foreach ($reductionCredits as $reductionCredit) {
@@ -493,8 +497,8 @@ class OrderShopStore extends AbstractStore
public function getReductionGiftsAvailableByUser(UserInterface $user): array
{
$reductionGifts = $this->reductionCreditStore
->setMerchant($this->merchant)
->getByTypeAndUser(ReductionCreditModel::TYPE_GIFT, $user);
->setMerchant($this->merchant)
->getByTypeAndUser(ReductionCreditModel::TYPE_GIFT, $user);

$reductionGiftsArray = [];
foreach ($reductionGifts as $reductionGift) {
@@ -510,15 +514,16 @@ class OrderShopStore extends AbstractStore
public function getReductionCartRemainingQuantity(ReductionCartInterface $reductionCart): float
{
return $reductionCart->getAvailableQuantity() - $this->countValidWithReductionCart(
$reductionCart
);
$reductionCart
);
}

// getReductionCartUsedQuantityPerUser
public function getReductionCartUsedQuantityByUser(
ReductionCartInterface $reductionCart,
UserInterface $user
): float {
ReductionCartInterface $reductionCart,
UserInterface $user
): float
{
return $this->countValidWithReductionCartByUser($reductionCart, $user);
}

@@ -530,14 +535,15 @@ class OrderShopStore extends AbstractStore

// getReductionCartRemainingQuantityPerUser
public function getReductionCartRemainingQuantityByUser(
ReductionCartInterface $reductionCart,
UserInterface $user
): float {
ReductionCartInterface $reductionCart,
UserInterface $user
): float
{
if ($reductionCart->getAvailableQuantityPerUser()) {
return $reductionCart->getAvailableQuantityPerUser() - $this->countValidWithReductionCartByUser(
$reductionCart,
$user
);
$reductionCart,
$user
);
}

return false;
@@ -547,18 +553,18 @@ class OrderShopStore extends AbstractStore
public function getReductionCartAvailableByUser(UserInterface $user, $query = null)
{
$reductionCarts = $this->reductionCartStore
->setMerchant($this->merchant)
->getOnline();
->setMerchant($this->merchant)
->getOnline();

$reductionCartsArray = [];
foreach ($reductionCarts as $reductionCart) {
if ($this->reductionCartSolver->matchWithUser($reductionCart, $user)
&& $this->reductionCartSolver->matchWithGroupUser($reductionCart, $user)
&& $this->getReductionCartRemainingQuantityByUser($reductionCart, $user)
&& ($reductionCart->getUsers()->count() > 0 || $reductionCart->getGroupUsers()->count() > 0)
&& (!$this->merchant || $reductionCart->getMerchant() == $this->merchant)) {
&& $this->reductionCartSolver->matchWithGroupUser($reductionCart, $user)
&& $this->getReductionCartRemainingQuantityByUser($reductionCart, $user)
&& ($reductionCart->getUsers()->count() > 0 || $reductionCart->getGroupUsers()->count() > 0)
&& (!$this->merchant || $reductionCart->getMerchant() == $this->merchant)) {

$reductionCartsArray[] = $reductionCart;
$reductionCartsArray[] = $reductionCart;
}
}

@@ -567,17 +573,18 @@ class OrderShopStore extends AbstractStore

//countValidOrderProductsOfCyclesByProducts
public function countValidOrderProductsOfDistributionsByProducts(
array $distributions,
array $products,
$query = null
): array {
array $distributions,
array $products,
$query = null
): array
{
$query = $this->createDefaultQuery($query);
$query
->filterByAlias(OrderStatusModel::$statusAliasAsValid)
->filterByDistributions($distributions)
->filterByProducts($products)
->selectSum()
->groupBy('distribution.cycleNumber, product.id');
->filterByAlias(OrderStatusModel::$statusAliasAsValid)
->filterByDistributions($distributions)
->filterByProducts($products)
->selectSum()
->groupBy('distribution.cycleNumber, product.id');


return $query->find();
@@ -590,12 +597,12 @@ class OrderShopStore extends AbstractStore
$query = $this->createQuery($query);

$query
->filterByAlias(OrderStatusModel::$statusAliasAsValid)
->filterByDistribution($distribution)
->filterByProduct($product)
->selectSumQuantityOrder()
->joinDistribution()
->groupBy('distribution.cycleNumber, product.id');
->filterByAlias(OrderStatusModel::$statusAliasAsValid)
->filterByDistribution($distribution)
->filterByProduct($product)
->selectSumQuantityOrder()
->joinDistribution()
->groupBy('distribution.cycleNumber, product.id');

$result = $query->findOne();

@@ -606,15 +613,16 @@ class OrderShopStore extends AbstractStore
}

public function isReductionCreditAllowAddToOrder(
OrderShopInterface $orderShop,
ReductionCreditInterface $reductionCredit
) {
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');
$this->flashBagTranslator->add('error', 'userNotAllow', 'ReductionCredit');
return false;
}

@@ -622,13 +630,13 @@ class OrderShopStore extends AbstractStore
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');
$this->flashBagTranslator->add('error', 'alreadyUse', 'ReductionCredit');
return false;
}
} else {
if ($this->countValidWithReductionCredit($reductionCredit) > 0) {
// @TODO : déplacer la gestion du flash message
//$this->flashBah->add('error', 'error.reductionCredit.alreadyUse');
$this->flashBagTranslator->add('error', 'alreadyUse', 'ReductionCredit');
return false;
}
}

+ 1
- 1
Repository/User/UserRepositoryQuery.php Ver arquivo

@@ -20,7 +20,7 @@ class UserRepositoryQuery extends SovUserRepositoryQuery
$this->isJoinUserMerchants = true;

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

+ 2
- 1
Repository/User/UserStore.php Ver arquivo

@@ -25,8 +25,9 @@ class UserStore extends SovUserStore
}

public function getJoinGroupUsers(){
$query = $this->createDefaultQuery();
$query = $this->createQuery();
$query->joinGroupUsers(true);
$query->orderBy('id');
return $query->find();

}

Carregando…
Cancelar
Salvar