|
|
|
|
|
|
|
|
use Lc\SovBundle\Model\User\UserInterface; |
|
|
use Lc\SovBundle\Model\User\UserInterface; |
|
|
use Lc\CaracoleBundle\Repository\AbstractStore; |
|
|
use Lc\CaracoleBundle\Repository\AbstractStore; |
|
|
use Lc\SovBundle\Repository\RepositoryQueryInterface; |
|
|
use Lc\SovBundle\Repository\RepositoryQueryInterface; |
|
|
|
|
|
use Lc\SovBundle\Translation\FlashBagTranslator; |
|
|
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; |
|
|
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; |
|
|
use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface; |
|
|
|
|
|
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; |
|
|
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; |
|
|
|
|
|
|
|
|
class OrderShopStore extends AbstractStore |
|
|
class OrderShopStore extends AbstractStore |
|
|
|
|
|
|
|
|
protected SectionStore $sectionStore; |
|
|
protected SectionStore $sectionStore; |
|
|
protected OrderProductStore $orderProductStore; |
|
|
protected OrderProductStore $orderProductStore; |
|
|
protected MerchantStore $merchantStore; |
|
|
protected MerchantStore $merchantStore; |
|
|
protected FlashBagInterface $flashBag; |
|
|
|
|
|
|
|
|
protected FlashBagTranslator $flashBagTranslator; |
|
|
protected OpeningResolver $openingResolver; |
|
|
protected OpeningResolver $openingResolver; |
|
|
protected ParameterBagInterface $parameterBag; |
|
|
protected ParameterBagInterface $parameterBag; |
|
|
protected UrlGeneratorInterface $router; |
|
|
protected UrlGeneratorInterface $router; |
|
|
|
|
|
|
|
|
protected DistributionBuilder $distributionBuilder; |
|
|
protected DistributionBuilder $distributionBuilder; |
|
|
|
|
|
|
|
|
public function __construct( |
|
|
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->query = $query; |
|
|
$this->entityManager = $entityManager; |
|
|
$this->entityManager = $entityManager; |
|
|
$this->priceSolver = $priceSolver; |
|
|
$this->priceSolver = $priceSolver; |
|
|
|
|
|
|
|
|
$this->sectionStore = $sectionStore; |
|
|
$this->sectionStore = $sectionStore; |
|
|
$this->orderProductStore = $orderProductStore; |
|
|
$this->orderProductStore = $orderProductStore; |
|
|
$this->merchantStore = $merchantStore; |
|
|
$this->merchantStore = $merchantStore; |
|
|
$this->flashBag = $flashBag; |
|
|
|
|
|
|
|
|
$this->flashBagTranslator = $flashBagTranslator; |
|
|
$this->parameterBag = $parameterBag; |
|
|
$this->parameterBag = $parameterBag; |
|
|
$this->router = $router; |
|
|
$this->router = $router; |
|
|
$this->orderShopSolver = $orderShopSolver; |
|
|
$this->orderShopSolver = $orderShopSolver; |
|
|
|
|
|
|
|
|
public function getByCurrentDistribution($params = [], $query = null) |
|
|
public function getByCurrentDistribution($params = [], $query = null) |
|
|
{ |
|
|
{ |
|
|
return $this->getBy( |
|
|
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 |
|
|
); |
|
|
); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function getByCurrentDistributionAndUser(UserInterface $user = null, array $params = [], $query = null) |
|
|
public function getByCurrentDistributionAndUser(UserInterface $user = null, array $params = [], $query = null) |
|
|
{ |
|
|
{ |
|
|
return $this->getByCurrentDistribution( |
|
|
return $this->getByCurrentDistribution( |
|
|
array_merge( |
|
|
|
|
|
[ |
|
|
|
|
|
'user' => $user, |
|
|
|
|
|
'excludeComplementaryOrderShops' => true |
|
|
|
|
|
], |
|
|
|
|
|
$params |
|
|
|
|
|
), |
|
|
|
|
|
$query |
|
|
|
|
|
|
|
|
array_merge( |
|
|
|
|
|
[ |
|
|
|
|
|
'user' => $user, |
|
|
|
|
|
'excludeComplementaryOrderShops' => true |
|
|
|
|
|
], |
|
|
|
|
|
$params |
|
|
|
|
|
), |
|
|
|
|
|
$query |
|
|
); |
|
|
); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function countByCurrentDistribution(array $params, $query = null) |
|
|
public function countByCurrentDistribution(array $params, $query = null) |
|
|
{ |
|
|
{ |
|
|
return $this->countBy( |
|
|
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 |
|
|
// @TODO : optimisation à remettre en place |
|
|
|
|
|
|
|
|
public function countValidByUserAllMerchant($user, $query = null): int |
|
|
public function countValidByUserAllMerchant($user, $query = null): int |
|
|
{ |
|
|
{ |
|
|
return $this->countBy( |
|
|
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 |
|
|
public function countValidByUser(UserInterface $user = null, $query = null): int |
|
|
{ |
|
|
{ |
|
|
return $this->countBy( |
|
|
return $this->countBy( |
|
|
[ |
|
|
|
|
|
'user' => $user, |
|
|
|
|
|
'isValid' => true, |
|
|
|
|
|
'excludeComplementaryOrderShops' => true |
|
|
|
|
|
], |
|
|
|
|
|
$query |
|
|
|
|
|
|
|
|
[ |
|
|
|
|
|
'user' => $user, |
|
|
|
|
|
'isValid' => true, |
|
|
|
|
|
'excludeComplementaryOrderShops' => true |
|
|
|
|
|
], |
|
|
|
|
|
$query |
|
|
); |
|
|
); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function countValidByCurrentDistribution($query = null): int |
|
|
public function countValidByCurrentDistribution($query = null): int |
|
|
{ |
|
|
{ |
|
|
return $this->countBy( |
|
|
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 |
|
|
// countValidOrderWithReductionCredit |
|
|
public function countValidWithReductionCredit( |
|
|
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 |
|
|
//TODO vérifier que ne pas utiliser createDefaultQuery est pertinent |
|
|
$query = $this->createQuery($query); |
|
|
$query = $this->createQuery($query); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
$query |
|
|
$query |
|
|
->selectCount() |
|
|
|
|
|
->filterByReductionCredit($reductionCredit) |
|
|
|
|
|
->filterByStatus(OrderStatusModel::$statusAliasAsValid); |
|
|
|
|
|
|
|
|
->selectCount() |
|
|
|
|
|
->filterByReductionCredit($reductionCredit) |
|
|
|
|
|
->filterByStatus(OrderStatusModel::$statusAliasAsValid); |
|
|
|
|
|
|
|
|
return $query->count(); |
|
|
return $query->count(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// countValidOrderWithReductionCart |
|
|
// countValidOrderWithReductionCart |
|
|
public function countValidWithReductionCart( |
|
|
public function countValidWithReductionCart( |
|
|
ReductionCartInterface $reductionCart, |
|
|
|
|
|
$query = null |
|
|
|
|
|
): int { |
|
|
|
|
|
|
|
|
ReductionCartInterface $reductionCart, |
|
|
|
|
|
$query = null |
|
|
|
|
|
): int |
|
|
|
|
|
{ |
|
|
$query = $this->createQuery($query); |
|
|
$query = $this->createQuery($query); |
|
|
|
|
|
|
|
|
$query |
|
|
$query |
|
|
->selectCount() |
|
|
|
|
|
->filterByReductionCart($reductionCart) |
|
|
|
|
|
->filterByStatus(OrderStatusModel::$statusAliasAsValid); |
|
|
|
|
|
|
|
|
->selectCount() |
|
|
|
|
|
->filterByReductionCart($reductionCart) |
|
|
|
|
|
->filterByStatus(OrderStatusModel::$statusAliasAsValid); |
|
|
|
|
|
|
|
|
return $query->count(); |
|
|
return $query->count(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// countValidOrderWithReductionCartPerUser |
|
|
// countValidOrderWithReductionCartPerUser |
|
|
public function countValidWithReductionCartByUser( |
|
|
public function countValidWithReductionCartByUser( |
|
|
ReductionCartInterface $reductionCart, |
|
|
|
|
|
UserInterface $user, |
|
|
|
|
|
$query = null |
|
|
|
|
|
): int { |
|
|
|
|
|
|
|
|
ReductionCartInterface $reductionCart, |
|
|
|
|
|
UserInterface $user, |
|
|
|
|
|
$query = null |
|
|
|
|
|
): int |
|
|
|
|
|
{ |
|
|
$query = $this->createDefaultQuery($query); |
|
|
$query = $this->createDefaultQuery($query); |
|
|
|
|
|
|
|
|
$query |
|
|
$query |
|
|
->selectCount() |
|
|
|
|
|
->filterByUser($user) |
|
|
|
|
|
->filterByReductionCart($reductionCart) |
|
|
|
|
|
->filterByStatus(OrderStatusModel::$statusAliasAsValid); |
|
|
|
|
|
|
|
|
->selectCount() |
|
|
|
|
|
->filterByUser($user) |
|
|
|
|
|
->filterByReductionCart($reductionCart) |
|
|
|
|
|
->filterByStatus(OrderStatusModel::$statusAliasAsValid); |
|
|
|
|
|
|
|
|
return $query->count(); |
|
|
return $query->count(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// findCartCurrent |
|
|
// findCartCurrent |
|
|
public function getOneCartCurrent(UserInterface $user = null, VisitorInterface $visitor = null, $query = null): ?OrderShopInterface |
|
|
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; |
|
|
return null; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!is_null($user)) { |
|
|
if (!is_null($user)) { |
|
|
$query->filterByUser($user); |
|
|
$query->filterByUser($user); |
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
|
|
|
} else { |
|
|
if (!is_null($visitor)) { |
|
|
if (!is_null($visitor)) { |
|
|
$query->filterByVisitor($visitor); |
|
|
$query->filterByVisitor($visitor); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
$query |
|
|
$query |
|
|
->selectOrderReductionCarts() |
|
|
|
|
|
->filterByStatus(OrderStatusModel::$statusAliasAsCart); |
|
|
|
|
|
|
|
|
->selectOrderReductionCarts() |
|
|
|
|
|
->filterByStatus(OrderStatusModel::$statusAliasAsCart); |
|
|
|
|
|
|
|
|
return $query->findOne(); |
|
|
return $query->findOne(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
$query = $this->createDefaultQuery($query); |
|
|
$query = $this->createDefaultQuery($query); |
|
|
|
|
|
|
|
|
$query |
|
|
$query |
|
|
->filterByDistribution($distribution) |
|
|
|
|
|
->filterByStatus(OrderStatusModel::$statusAliasAsValid) |
|
|
|
|
|
->filterIsNotComplementaryOrderShop() |
|
|
|
|
|
->orderBy('.cycleId', 'DESC'); |
|
|
|
|
|
|
|
|
->filterByDistribution($distribution) |
|
|
|
|
|
->filterByStatus(OrderStatusModel::$statusAliasAsValid) |
|
|
|
|
|
->filterIsNotComplementaryOrderShop() |
|
|
|
|
|
->orderBy('.cycleId', 'DESC'); |
|
|
|
|
|
|
|
|
return $query->findOne(); |
|
|
return $query->findOne(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
$query = $this->createDefaultQuery($query); |
|
|
$query = $this->createDefaultQuery($query); |
|
|
|
|
|
|
|
|
$query |
|
|
$query |
|
|
->filterByStatus(OrderStatusModel::$statusAliasAsValid) |
|
|
|
|
|
->filterIsNotComplementaryOrderShop() |
|
|
|
|
|
->orderBy('.idValidOrder', 'DESC'); |
|
|
|
|
|
|
|
|
->filterByStatus(OrderStatusModel::$statusAliasAsValid) |
|
|
|
|
|
->filterIsNotComplementaryOrderShop() |
|
|
|
|
|
->orderBy('.idValidOrder', 'DESC'); |
|
|
|
|
|
|
|
|
return $query->findOne(); |
|
|
return $query->findOne(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
$query->filterByAddress($params['address']); |
|
|
$query->filterByAddress($params['address']); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if(isset($params['minimumTomorrowDelivery'])) { |
|
|
|
|
|
|
|
|
if (isset($params['minimumTomorrowDelivery'])) { |
|
|
$query->filterMinimumTomorrowDelivery(); |
|
|
$query->filterMinimumTomorrowDelivery(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (isset($params['mergeComplementaryOrderShops'])) { |
|
|
if (isset($params['mergeComplementaryOrderShops'])) { |
|
|
$query |
|
|
$query |
|
|
->joinComplementaryOrderShops(); |
|
|
|
|
|
|
|
|
->joinComplementaryOrderShops(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (isset($params['excludeComplementaryOrderShops']) || isset($params['mergeComplementaryOrderShops'])) { |
|
|
if (isset($params['excludeComplementaryOrderShops']) || isset($params['mergeComplementaryOrderShops'])) { |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function isReductionCreditUsed( |
|
|
public function isReductionCreditUsed( |
|
|
ReductionCreditInterface $reductionCredit, |
|
|
|
|
|
UserInterface $user = null, |
|
|
|
|
|
$query = null |
|
|
|
|
|
) { |
|
|
|
|
|
|
|
|
ReductionCreditInterface $reductionCredit, |
|
|
|
|
|
UserInterface $user = null, |
|
|
|
|
|
$query = null |
|
|
|
|
|
) |
|
|
|
|
|
{ |
|
|
if ($this->countValidWithReductionCredit($reductionCredit, $user, $query)) { |
|
|
if ($this->countValidWithReductionCredit($reductionCredit, $user, $query)) { |
|
|
return true; |
|
|
return true; |
|
|
} else { |
|
|
} else { |
|
|
|
|
|
|
|
|
public function getReductionCreditsAvailableByUser(UserInterface $user): array |
|
|
public function getReductionCreditsAvailableByUser(UserInterface $user): array |
|
|
{ |
|
|
{ |
|
|
$reductionCredits = $this->reductionCreditStore |
|
|
$reductionCredits = $this->reductionCreditStore |
|
|
->setMerchant($this->merchant) |
|
|
|
|
|
->getByTypeAndUser(ReductionCreditModel::TYPE_CREDIT, $user); |
|
|
|
|
|
|
|
|
->setMerchant($this->merchant) |
|
|
|
|
|
->getByTypeAndUser(ReductionCreditModel::TYPE_CREDIT, $user); |
|
|
|
|
|
|
|
|
$reductionCreditsArray = []; |
|
|
$reductionCreditsArray = []; |
|
|
foreach ($reductionCredits as $reductionCredit) { |
|
|
foreach ($reductionCredits as $reductionCredit) { |
|
|
|
|
|
|
|
|
public function getReductionGiftsAvailableByUser(UserInterface $user): array |
|
|
public function getReductionGiftsAvailableByUser(UserInterface $user): array |
|
|
{ |
|
|
{ |
|
|
$reductionGifts = $this->reductionCreditStore |
|
|
$reductionGifts = $this->reductionCreditStore |
|
|
->setMerchant($this->merchant) |
|
|
|
|
|
->getByTypeAndUser(ReductionCreditModel::TYPE_GIFT, $user); |
|
|
|
|
|
|
|
|
->setMerchant($this->merchant) |
|
|
|
|
|
->getByTypeAndUser(ReductionCreditModel::TYPE_GIFT, $user); |
|
|
|
|
|
|
|
|
$reductionGiftsArray = []; |
|
|
$reductionGiftsArray = []; |
|
|
foreach ($reductionGifts as $reductionGift) { |
|
|
foreach ($reductionGifts as $reductionGift) { |
|
|
|
|
|
|
|
|
public function getReductionCartRemainingQuantity(ReductionCartInterface $reductionCart): float |
|
|
public function getReductionCartRemainingQuantity(ReductionCartInterface $reductionCart): float |
|
|
{ |
|
|
{ |
|
|
return $reductionCart->getAvailableQuantity() - $this->countValidWithReductionCart( |
|
|
return $reductionCart->getAvailableQuantity() - $this->countValidWithReductionCart( |
|
|
$reductionCart |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
$reductionCart |
|
|
|
|
|
); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// getReductionCartUsedQuantityPerUser |
|
|
// getReductionCartUsedQuantityPerUser |
|
|
public function getReductionCartUsedQuantityByUser( |
|
|
public function getReductionCartUsedQuantityByUser( |
|
|
ReductionCartInterface $reductionCart, |
|
|
|
|
|
UserInterface $user |
|
|
|
|
|
): float { |
|
|
|
|
|
|
|
|
ReductionCartInterface $reductionCart, |
|
|
|
|
|
UserInterface $user |
|
|
|
|
|
): float |
|
|
|
|
|
{ |
|
|
return $this->countValidWithReductionCartByUser($reductionCart, $user); |
|
|
return $this->countValidWithReductionCartByUser($reductionCart, $user); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// getReductionCartRemainingQuantityPerUser |
|
|
// getReductionCartRemainingQuantityPerUser |
|
|
public function getReductionCartRemainingQuantityByUser( |
|
|
public function getReductionCartRemainingQuantityByUser( |
|
|
ReductionCartInterface $reductionCart, |
|
|
|
|
|
UserInterface $user |
|
|
|
|
|
): float { |
|
|
|
|
|
|
|
|
ReductionCartInterface $reductionCart, |
|
|
|
|
|
UserInterface $user |
|
|
|
|
|
): float |
|
|
|
|
|
{ |
|
|
if ($reductionCart->getAvailableQuantityPerUser()) { |
|
|
if ($reductionCart->getAvailableQuantityPerUser()) { |
|
|
return $reductionCart->getAvailableQuantityPerUser() - $this->countValidWithReductionCartByUser( |
|
|
return $reductionCart->getAvailableQuantityPerUser() - $this->countValidWithReductionCartByUser( |
|
|
$reductionCart, |
|
|
|
|
|
$user |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
$reductionCart, |
|
|
|
|
|
$user |
|
|
|
|
|
); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return false; |
|
|
return false; |
|
|
|
|
|
|
|
|
public function getReductionCartAvailableByUser(UserInterface $user, $query = null) |
|
|
public function getReductionCartAvailableByUser(UserInterface $user, $query = null) |
|
|
{ |
|
|
{ |
|
|
$reductionCarts = $this->reductionCartStore |
|
|
$reductionCarts = $this->reductionCartStore |
|
|
->setMerchant($this->merchant) |
|
|
|
|
|
->getOnline(); |
|
|
|
|
|
|
|
|
->setMerchant($this->merchant) |
|
|
|
|
|
->getOnline(); |
|
|
|
|
|
|
|
|
$reductionCartsArray = []; |
|
|
$reductionCartsArray = []; |
|
|
foreach ($reductionCarts as $reductionCart) { |
|
|
foreach ($reductionCarts as $reductionCart) { |
|
|
if ($this->reductionCartSolver->matchWithUser($reductionCart, $user) |
|
|
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; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//countValidOrderProductsOfCyclesByProducts |
|
|
//countValidOrderProductsOfCyclesByProducts |
|
|
public function countValidOrderProductsOfDistributionsByProducts( |
|
|
public function countValidOrderProductsOfDistributionsByProducts( |
|
|
array $distributions, |
|
|
|
|
|
array $products, |
|
|
|
|
|
$query = null |
|
|
|
|
|
): array { |
|
|
|
|
|
|
|
|
array $distributions, |
|
|
|
|
|
array $products, |
|
|
|
|
|
$query = null |
|
|
|
|
|
): array |
|
|
|
|
|
{ |
|
|
$query = $this->createDefaultQuery($query); |
|
|
$query = $this->createDefaultQuery($query); |
|
|
$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(); |
|
|
return $query->find(); |
|
|
|
|
|
|
|
|
$query = $this->createQuery($query); |
|
|
$query = $this->createQuery($query); |
|
|
|
|
|
|
|
|
$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(); |
|
|
$result = $query->findOne(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function isReductionCreditAllowAddToOrder( |
|
|
public function isReductionCreditAllowAddToOrder( |
|
|
OrderShopInterface $orderShop, |
|
|
|
|
|
ReductionCreditInterface $reductionCredit |
|
|
|
|
|
) { |
|
|
|
|
|
|
|
|
OrderShopInterface $orderShop, |
|
|
|
|
|
ReductionCreditInterface $reductionCredit |
|
|
|
|
|
) |
|
|
|
|
|
{ |
|
|
$user = $orderShop->getUser(); |
|
|
$user = $orderShop->getUser(); |
|
|
|
|
|
|
|
|
// appartient à l'utilisateur |
|
|
// appartient à l'utilisateur |
|
|
if (!$reductionCredit->getUsers()->contains($user)) { |
|
|
if (!$reductionCredit->getUsers()->contains($user)) { |
|
|
// @TODO : déplacer la gestion du flash message |
|
|
// @TODO : déplacer la gestion du flash message |
|
|
//$this->flashBag->add('error', 'error.reductionCredit.userNotAllow'); |
|
|
|
|
|
|
|
|
$this->flashBagTranslator->add('error', 'userNotAllow', 'ReductionCredit'); |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($reductionCredit->getType() == ReductionCreditModel::TYPE_CREDIT) { |
|
|
if ($reductionCredit->getType() == ReductionCreditModel::TYPE_CREDIT) { |
|
|
if ($this->countValidWithReductionCredit($reductionCredit, $user) > 0) { |
|
|
if ($this->countValidWithReductionCredit($reductionCredit, $user) > 0) { |
|
|
// @TODO : déplacer la gestion du flash message |
|
|
// @TODO : déplacer la gestion du flash message |
|
|
//$this->flashBah->add('error', 'error.reductionCredit.alreadyUse'); |
|
|
|
|
|
|
|
|
$this->flashBagTranslator->add('error', 'alreadyUse', 'ReductionCredit'); |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
} else { |
|
|
} else { |
|
|
if ($this->countValidWithReductionCredit($reductionCredit) > 0) { |
|
|
if ($this->countValidWithReductionCredit($reductionCredit) > 0) { |
|
|
// @TODO : déplacer la gestion du flash message |
|
|
// @TODO : déplacer la gestion du flash message |
|
|
//$this->flashBah->add('error', 'error.reductionCredit.alreadyUse'); |
|
|
|
|
|
|
|
|
$this->flashBagTranslator->add('error', 'alreadyUse', 'ReductionCredit'); |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |