Charly преди 2 години
родител
ревизия
de147795fb
променени са 8 файла, в които са добавени 194 реда и са изтрити 156 реда
  1. +3
    -2
      Builder/Order/OrderShopBuilder.php
  2. +6
    -3
      Controller/Order/CartController.php
  3. +1
    -1
      Repository/Credit/CreditHistoryStore.php
  4. +153
    -145
      Repository/Order/OrderShopStore.php
  5. +1
    -1
      Repository/User/UserRepositoryQuery.php
  6. +2
    -1
      Repository/User/UserStore.php
  7. +13
    -2
      Solver/Price/PriceSolverTrait.php
  8. +15
    -1
      Solver/Section/OpeningSolver.php

+ 3
- 2
Builder/Order/OrderShopBuilder.php Целия файл

@@ -478,8 +478,9 @@ class OrderShopBuilder

$orderShop->addOrderReductionCredit($orderReductionCredit);

if ($this->isOrderShopPositiveAmount($orderShop)
&& $this->isOrderShopPositiveAmountRemainingToBePaid($orderShop)) {
if ($this->orderShopResolver->isPositiveAmount($orderShop)
&& $this->orderShopResolver->isPositiveAmountRemainingToBePaid($orderShop)) {

$this->entityManager->create($orderReductionCredit);
$this->entityManager->flush();


+ 6
- 3
Controller/Order/CartController.php Целия файл

@@ -11,6 +11,9 @@ use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;

/**
* @Route("/{section}/panier", name="frontend_cart_")
*/
class CartController extends AbstractController
{
protected ProductFamilyInterface $productFamily;
@@ -79,7 +82,7 @@ class CartController extends AbstractController
}

/**
* @Route("/order-reduction-cart/delete/{id}", name="frontend_cart_delete_reduction_cart")
* @Route("/order-reduction-cart/delete/{id}", name="delete_reduction_cart")
*/
public function deleteReductionCart(Request $request): RedirectResponse
{
@@ -102,7 +105,7 @@ class CartController extends AbstractController
}

/**
* @Route("/reduction-credit/add/{id}", name="frontend_order_cart_reduction_credit")
* @Route("/reduction-credit/add/{id}", name="order_reduction_credit")
*/
public function addReductionCredit(Request $request): RedirectResponse
{
@@ -133,7 +136,7 @@ class CartController extends AbstractController
}

/**
* @Route("/order-reduction-credit/delete/{id}", name="frontend_cart_delete_reduction_credit")
* @Route("/order-reduction-credit/delete/{id}", name="delete_reduction_credit")
*/
public function deleteReductionCredit(Request $request): RedirectResponse
{

+ 1
- 1
Repository/Credit/CreditHistoryStore.php Целия файл

@@ -21,7 +21,7 @@ class CreditHistoryStore extends AbstractStore

public function orderByDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
{
$query->orderBy('createdAt');
//$query->orderBy('createdAt');
return $query;
}


+ 153
- 145
Repository/Order/OrderShopStore.php Целия файл

@@ -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 Целия файл

@@ -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 Целия файл

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

}

+ 13
- 2
Solver/Price/PriceSolverTrait.php Целия файл

@@ -54,6 +54,16 @@ trait PriceSolverTrait
$round = true
): ?float {


if($entity instanceof ProductFamilyInterface) {
$taxRate = $this->productFamilySolver->getTaxRateInherited($entity)->getValue();
}else if ($entity instanceof ProductInterface) {
$taxRate = $this->productFamilySolver->getTaxRateInherited($entity->getProductFamily())->getValue();
}else{
$taxRate = $entity->getTaxRate()->getValue();
}


if ($reductionCatalog) {
$reductionCatalogValue = $reductionCatalog->getValue();
$reductionCatalogUnit = $reductionCatalog->getUnit();
@@ -96,7 +106,7 @@ trait PriceSolverTrait
$price,
$reductionCatalogValue * $quantity
),
$this->productFamilySolver->getTaxRateInherited($entity)->getValue()
$taxRate
);
} elseif ($reductionCatalogBehaviorTaxRate == 'tax-included') {
$priceWithTax = $this->applyReductionAmount(
@@ -110,7 +120,8 @@ trait PriceSolverTrait
if ($withTax) {
$priceReturn = $priceWithTax;
} else {
$priceReturn = $this->applyPercentNegative($priceWithTax, $this->productFamilySolver->getTaxRateInherited($entity)->getValue());

$priceReturn = $this->applyPercentNegative($priceWithTax, $taxRate);
}
if ($round) {
return $this->round($priceReturn);

+ 15
- 1
Solver/Section/OpeningSolver.php Целия файл

@@ -44,7 +44,21 @@ class OpeningSolver

protected function isOpeningDay(int $weekDay, array $openings): bool
{
return (bool) $this->getOpeningByWeekday($weekDay, $openings);
$opening = $this->getOpeningByWeekday($weekDay, $openings);

if($opening) {
$now = new \DateTime();
if($weekDay == $now->format('N')) {
if($now < $opening->getTimeEnd()) {
return true;
}
}
else {
return true;
}
}

return false;
}

protected function isClosingDay(int $weekDay, array $openings): bool

Loading…
Отказ
Запис