Browse Source

Merge branch 'develop' of https://forge.laclic.fr/Laclic/CaracoleBundle into develop

packProduct
Fab 3 years ago
parent
commit
590cf7340c
21 changed files with 383 additions and 104 deletions
  1. +36
    -2
      Builder/Credit/CreditHistoryBuilder.php
  2. +1
    -1
      Builder/Order/OrderShopBuilder.php
  3. +20
    -0
      Builder/Ticket/TicketBuilder.php
  4. +2
    -2
      Builder/User/UserBuilder.php
  5. +18
    -20
      Builder/User/UserMerchantBuilder.php
  6. +10
    -1
      Container/Address/AddressContainer.php
  7. +10
    -1
      Container/Credit/CreditHistoryContainer.php
  8. +38
    -20
      Container/Order/OrderShopContainer.php
  9. +19
    -1
      Container/User/UserMerchantContainer.php
  10. +43
    -0
      Form/Reduction/EditGiftVoucherType.php
  11. +31
    -0
      Form/Reduction/ReductionCartType.php
  12. +26
    -0
      Form/Reduction/SendGiftVoucherType.php
  13. +1
    -0
      Model/Credit/CreditHistoryModel.php
  14. +26
    -20
      Repository/Order/OrderShopStore.php
  15. +1
    -0
      Repository/Product/ProductCategoryStore.php
  16. +26
    -0
      Repository/Reduction/ReductionCreditStore.php
  17. +1
    -3
      Resolver/MerchantResolver.php
  18. +38
    -7
      Resolver/OpeningResolver.php
  19. +27
    -21
      Resolver/SectionResolver.php
  20. +1
    -1
      Statistic/Product/ProductsSalesStatistic.php
  21. +8
    -4
      Twig/StoreTwigExtension.php

+ 36
- 2
Builder/Credit/CreditHistoryBuilder.php View File

@@ -3,25 +3,56 @@
namespace Lc\CaracoleBundle\Builder\Credit;

use Lc\CaracoleBundle\Builder\User\UserMerchantBuilder;
use Lc\CaracoleBundle\Factory\Credit\CreditHistoryFactory;
use Lc\CaracoleBundle\Model\Credit\CreditHistoryInterface;
use Lc\CaracoleBundle\Model\Credit\CreditHistoryModel;
use Lc\CaracoleBundle\Model\User\UserMerchantInterface;
use Lc\CaracoleBundle\Repository\User\UserMerchantStore;

class CreditHistoryBuilder
{
protected CreditHistoryFactory $creditHistoryFactory;
protected UserMerchantStore $userMerchantStore;
protected UserMerchantBuilder $userMerchantBuilder;

public function __construct(
CreditHistoryFactory $creditHistoryFactory,
UserMerchantStore $userMerchantStore,
UserMerchantBuilder $userMerchantBuilder
) {
$this->creditHistoryFactory = $creditHistoryFactory;
$this->userMerchantStore = $userMerchantStore;
$this->userMerchantBuilder = $userMerchantBuilder;
}

public function create(
string $type,
UserMerchantInterface $userMerchant,
array $params = []
): CreditHistoryInterface {
$creditHistory = $this->creditHistoryFactory->create($type, $userMerchant);

$amount = isset($params['amount']) ?? null ;
$meanPayment = isset($params['meanPayment']) ?? null ;
$reference = isset($params['reference']) ?? null ;
$comment = isset($params['comment']) ?? null ;
$orderPayment = isset($params['orderPayment']) ?? null ;
$orderRefund = isset($params['orderRefund']) ?? null ;

$creditHistory->setType($type);
$creditHistory->setUserMerchant($userMerchant);
$creditHistory->setAmount($amount);
$creditHistory->setMeanPayment($meanPayment);
$creditHistory->setReference($reference);
$creditHistory->setComment($comment);
$creditHistory->setOrderPayment($orderPayment);
$creditHistory->setOrderRefund($orderRefund);

return $creditHistory;
}

// saveCreditHistory
public function save(CreditHistoryInterface $creditHistory) :bool
public function save(CreditHistoryInterface $creditHistory): bool
{
if ($creditHistory) {
$userMerchant = $creditHistory->getUserMerchant();
@@ -33,7 +64,10 @@ class CreditHistoryBuilder
$this->userMerchantBuilder->updateCredit($userMerchant, $creditHistory, $userMerchantAmount);
return true;
} elseif ($creditHistory->getType() == CreditHistoryModel::TYPE_DEBIT) {
if ($this->userMerchantStore->isCreditSufficientToPay($userMerchant, $creditHistory->getAmountInherited())) {
if ($this->userMerchantStore->isCreditSufficientToPay(
$userMerchant,
$creditHistory->getAmountInherited()
)) {
$userMerchantAmount = $userMerchant->getCredit() - $creditHistory->getAmountInherited();
$this->userMerchantBuilder->updateCredit($userMerchant, $creditHistory, $userMerchantAmount);
return true;

+ 1
- 1
Builder/Order/OrderShopBuilder.php View File

@@ -476,7 +476,7 @@ class OrderShopBuilder
public function updatePriceByProductFamily(ProductFamilyInterface $productFamily)
{
// @TODO : faire la vérification isOpenSale depuis la méthode appelante
if (!$this->openingResolver->isOpenSale($productFamily->getSection(), null,null, OpeningResolver::OPENING_CONTEXT_BACKEND)) {
if (!$this->openingResolver->isOpenSale($productFamily->getSection(), null, OpeningResolver::OPENING_CONTEXT_BACKEND)) {
$countOrderProductUpdated = 0;

foreach ($productFamily->getProducts() as $product) {

+ 20
- 0
Builder/Ticket/TicketBuilder.php View File

@@ -0,0 +1,20 @@
<?php

namespace Lc\CaracoleBundle\Builder\Ticket;

use Lc\SovBundle\Model\Ticket\TicketInterface;
use Lc\SovBundle\Builder\Ticket\TicketBuilder as SovTicketBuilder;

class TicketBuilder extends SovTicketBuilder
{

public function init(TicketInterface $ticket, array $params = []): void
{
parent::init($ticket, $params);

$ticket->setSection($params['section']);
if(isset($data['orderShop'])) {
$ticket->setOrderShop($data['orderShop']);
}
}
}

+ 2
- 2
Builder/User/UserBuilder.php View File

@@ -2,7 +2,6 @@

namespace Lc\CaracoleBundle\Builder\User;

use Doctrine\ORM\EntityManagerInterface;
use Lc\CaracoleBundle\Factory\User\UserPointSaleFactory;
use Lc\CaracoleBundle\Model\PointSale\PointSaleInterface;
use Lc\SovBundle\Model\User\UserInterface;
@@ -11,9 +10,10 @@ use Lc\SovBundle\Builder\User\UserBuilder as SovUserBuilder;
class UserBuilder extends SovUserBuilder
{

// linkUserToPointSale
public function linkToPointSale(UserInterface $user, PointSaleInterface $pointSale):bool
{
if (!$user->isLinkedToPointSale($pointSale)) {
if (!$this->userSolver->isLinkedToPointSale($user, $pointSale)) {
$userPointSaleFactory = new UserPointSaleFactory();
$userPointSale = $userPointSaleFactory->create($user, $pointSale);


+ 18
- 20
Builder/User/UserMerchantBuilder.php View File

@@ -60,30 +60,14 @@ class UserMerchantBuilder
return $userMerchant;
}

public function updateCreditActive(
UserInterface $user,
MerchantInterface $merchant,
$creditActive = true
): UserMerchantInterface {
$userMerchant = $this->createIfNotExist($user, $merchant);

$userMerchant->setCreditActive($creditActive);

//TODO create ou update ???
$this->entityManager->persist($userMerchant);
$this->entityManager->flush();

return $userMerchant;
}

public function activeCredit(UserInterface $user, MerchantInterface $merchant): UserMerchantInterface
public function activeCredit(UserMerchantInterface $userMerchant): UserMerchantInterface
{
return $this->updateCreditActive($user, $merchant, true);
return $this->updateCreditActive($userMerchant, true);
}

public function unactiveCredit(UserInterface $user, MerchantInterface $merchant): UserMerchantInterface
public function unactiveCredit(UserMerchantInterface $userMerchant): UserMerchantInterface
{
return $this->updateCreditActive($user, $merchant, false);
return $this->updateCreditActive($userMerchant, false);
}

public function updateCredit(
@@ -100,5 +84,19 @@ class UserMerchantBuilder
return $userMerchant;
}

public function updateCreditActive(
UserMerchantInterface $userMerchant,
$creditActive = true
): UserMerchantInterface {

$userMerchant->setCreditActive($creditActive);

//TODO create ou update ???
$this->entityManager->persist($userMerchant);
$this->entityManager->flush();

return $userMerchant;
}

}


+ 10
- 1
Container/Address/AddressContainer.php View File

@@ -2,6 +2,7 @@

namespace Lc\CaracoleBundle\Container\Address;

use Lc\CaracoleBundle\Builder\Address\AddressBuilder;
use Lc\CaracoleBundle\Factory\Address\AddressFactory;
use Lc\CaracoleBundle\Repository\Address\AddressRepositoryQuery;
use Lc\CaracoleBundle\Repository\Address\AddressStore;
@@ -11,15 +12,18 @@ class AddressContainer
protected AddressFactory $factory;
protected AddressRepositoryQuery $repositoryQuery;
protected AddressStore $store;
protected AddressBuilder $builder;

public function __construct(
AddressFactory $factory,
AddressRepositoryQuery $repositoryQuery,
AddressStore $store
AddressStore $store,
AddressBuilder $builder
) {
$this->factory = $factory;
$this->repositoryQuery = $repositoryQuery;
$this->store = $store;
$this->builder = $builder;
}

public function getFactory(): AddressFactory
@@ -36,4 +40,9 @@ class AddressContainer
{
return $this->store;
}

public function getBuilder(): AddressBuilder
{
return $this->builder;
}
}

+ 10
- 1
Container/Credit/CreditHistoryContainer.php View File

@@ -2,6 +2,7 @@

namespace Lc\CaracoleBundle\Container\Credit;

use Lc\CaracoleBundle\Builder\Credit\CreditHistoryBuilder;
use Lc\CaracoleBundle\Factory\Credit\CreditHistoryFactory;
use Lc\CaracoleBundle\Repository\Credit\CreditHistoryRepositoryQuery;
use Lc\CaracoleBundle\Repository\Credit\CreditHistoryStore;
@@ -11,15 +12,18 @@ class CreditHistoryContainer
protected CreditHistoryFactory $factory;
protected CreditHistoryRepositoryQuery $repositoryQuery;
protected CreditHistoryStore $store;
protected CreditHistoryBuilder $builder;

public function __construct(
CreditHistoryFactory $factory,
CreditHistoryRepositoryQuery $repositoryQuery,
CreditHistoryStore $store
CreditHistoryStore $store,
CreditHistoryBuilder $builder
) {
$this->factory = $factory;
$this->repositoryQuery = $repositoryQuery;
$this->store = $store;
$this->builder = $builder;
}

public function getFactory(): CreditHistoryFactory
@@ -36,4 +40,9 @@ class CreditHistoryContainer
{
return $this->store;
}

public function getBuilder(): CreditHistoryBuilder
{
return $this->builder;
}
}

+ 38
- 20
Container/Order/OrderShopContainer.php View File

@@ -2,57 +2,75 @@

namespace Lc\CaracoleBundle\Container\Order;

use App\Resolver\OrderResolver;
use Lc\CaracoleBundle\Builder\Order\OrderShopBuilder;
use Lc\CaracoleBundle\Factory\Order\OrderShopFactory;
use Lc\CaracoleBundle\Repository\Order\OrderShopRepositoryQuery;
use Lc\CaracoleBundle\Repository\Order\OrderShopStore;
use Lc\CaracoleBundle\Solver\Order\OrderShopSolver;
use Lc\CaracoleBundle\Transformer\Order\OrderShopTransformer;

class OrderShopContainer
{
protected OrderShopFactory $orderShopFactory;
protected OrderShopSolver $orderShopSolver;
protected OrderShopRepositoryQuery $orderShopRepositoryQuery;
protected OrderShopStore $orderShopStore;
protected OrderShopBuilder $orderShopBuilder;
protected OrderShopFactory $factory;
protected OrderShopSolver $solver;
protected OrderShopRepositoryQuery $repositoryQuery;
protected OrderShopStore $store;
protected OrderShopBuilder $builder;
protected OrderResolver $resolver;
protected OrderShopTransformer $transformer;

public function __construct(
OrderShopFactory $orderShopFactory,
OrderShopSolver $orderShopSolver,
OrderShopRepositoryQuery $orderShopRepositoryQuery,
OrderShopStore $orderShopStore,
OrderShopBuilder $orderShopBuilder
OrderShopFactory $factory,
OrderShopSolver $solver,
OrderShopRepositoryQuery $repositoryQuery,
OrderShopStore $store,
OrderResolver $resolver,
OrderShopBuilder $builder,
OrderShopTransformer $transformer
) {
$this->orderShopFactory = $orderShopFactory;
$this->orderShopSolver = $orderShopSolver;
$this->orderShopRepositoryQuery = $orderShopRepositoryQuery;
$this->orderShopStore = $orderShopStore;
$this->orderShopBuilder = $orderShopBuilder;
$this->factory = $factory;
$this->solver = $solver;
$this->repositoryQuery = $repositoryQuery;
$this->store = $store;
$this->resolver = $resolver;
$this->builder = $builder;
$this->transformer = $transformer;
}

public function getFactory(): OrderShopFactory
{
return $this->orderShopFactory;
return $this->factory;
}

public function getSolver(): OrderShopSolver
{
return $this->orderShopSolver;
return $this->solver;
}

public function getRepositoryQuery(): OrderShopRepositoryQuery
{
return $this->orderShopRepositoryQuery;
return $this->repositoryQuery;
}

public function getStore(): OrderShopStore
{
return $this->orderShopStore;
return $this->store;
}

public function getResolver(): OrderResolver
{
return $this->resolver;
}

public function getBuilder(): OrderShopBuilder
{
return $this->orderShopBuilder;
return $this->builder;
}

public function getTransformer(): OrderShopTransformer
{
return $this->transformer;
}

}

+ 19
- 1
Container/User/UserMerchantContainer.php View File

@@ -2,24 +2,32 @@

namespace Lc\CaracoleBundle\Container\User;

use Lc\CaracoleBundle\Builder\User\UserMerchantBuilder;
use Lc\CaracoleBundle\Factory\User\UserMerchantFactory;
use Lc\CaracoleBundle\Repository\User\UserMerchantRepositoryQuery;
use Lc\CaracoleBundle\Repository\User\UserMerchantStore;
use Lc\CaracoleBundle\Solver\User\UserMerchantSolver;

class UserMerchantContainer
{
protected UserMerchantFactory $factory;
protected UserMerchantSolver $solver;
protected UserMerchantRepositoryQuery $repositoryQuery;
protected UserMerchantStore $store;
protected UserMerchantBuilder $builder;

public function __construct(
UserMerchantFactory $factory,
UserMerchantSolver $solver,
UserMerchantRepositoryQuery $repositoryQuery,
UserMerchantStore $store
UserMerchantStore $store,
UserMerchantBuilder $builder
) {
$this->factory = $factory;
$this->solver = $solver;
$this->repositoryQuery = $repositoryQuery;
$this->store = $store;
$this->builder = $builder;
}

public function getFactory(): UserMerchantFactory
@@ -27,6 +35,11 @@ class UserMerchantContainer
return $this->factory;
}

public function getSolver(): UserMerchantSolver
{
return $this->solver;
}

public function getRepositoryQuery(): UserMerchantRepositoryQuery
{
return $this->repositoryQuery;
@@ -37,4 +50,9 @@ class UserMerchantContainer
return $this->store;
}

public function getBuilder(): UserMerchantBuilder
{
return $this->builder;
}

}

+ 43
- 0
Form/Reduction/EditGiftVoucherType.php View File

@@ -0,0 +1,43 @@
<?php

namespace Lc\CaracoleBundle\Form\Reduction;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\DateType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class EditGiftVoucherType extends AbstractType
{

public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('activationDate', DateType::class, [
'label' => 'Date d\'activation de votre bon cadeau :',
'widget'=> 'single_text',
'help'=> 'Date à partir de laquelle la personne pourra utiliser ce bon cadeau.'
//'format'=> 'dd/MM/yyyy'
])
->add('title', TextType::class, [
'label' => 'Message personnalisé affiché dans le bon cadeau :',
'help'=> 'Exemple "Joyeux Noël Tata Suzanne !"'
])
->add('email', EmailType::class, [
'label' => 'Email de la personne à qui vous souhaitez offrir ce bon cadeau :',
'help'=> 'Le bon ne sera utilisable qu\'avec cet adresse e-mail'
])
->add('ownerName', TextType::class,[
'label' => 'Offert par :',
'help'=> 'Sera affiché dans le bon cadeau'
]);
}

public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
// Configure your form options here
]);
}
}

+ 31
- 0
Form/Reduction/ReductionCartType.php View File

@@ -0,0 +1,31 @@
<?php

namespace Lc\CaracoleBundle\Form\Reduction;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class ReductionCartType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add(
'code',
TextType::class,
[
'label' => 'Bon de réduction :'
]
);
}

public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(
[

]
);
}
}

+ 26
- 0
Form/Reduction/SendGiftVoucherType.php View File

@@ -0,0 +1,26 @@
<?php

namespace Lc\CaracoleBundle\Form\Reduction;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class SendGiftVoucherType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{

$builder->add('message', TextareaType::class, [
'label' => 'Message personnalisé',
]);
}

public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
// Configure your form options here
]);
}
}

+ 1
- 0
Model/Credit/CreditHistoryModel.php View File

@@ -28,6 +28,7 @@ abstract class CreditHistoryModel extends AbstractLightEntity implements PayoffI
const MEAN_PAYMENT_CREDIT = 'credit';
const MEAN_PAYMENT_TRANSFER = 'transfer';
const MEAN_PAYMENT_CASH = 'cash';
const MEAN_PAYMENT_GIFT = 'transfer-gift';

/**
* @ORM\Column(type="float", nullable=true)

+ 26
- 20
Repository/Order/OrderShopStore.php View File

@@ -122,13 +122,13 @@ class OrderShopStore extends AbstractStore
}

//public $countOrderShopsOfWeek = null;
public function countByCurrentCycle(bool $excludeComplementaryOrderShops = true, $query = null)
// public function countByCurrentCycle(bool $excludeComplementaryOrderShops = true, $query = null)
public function countByCurrentCycle(array $params, $query = null)
{
return $this->getByCurrentCycle(
return $this->countBy(
[
'count' => true,
'excludeComplementaryOrderShops' => $excludeComplementaryOrderShops

'cycleNumber' => $this->orderShopSolver->getCycleNumberCurrentOrder($this->section),
'excludeComplementaryOrderShops' => isset($params['excludeComplementaryOrderShops']) ?? true,
],
$query
);
@@ -150,7 +150,7 @@ class OrderShopStore extends AbstractStore
// getNextWeekId
public function getNextCycleId(int $cycleNumber, $query = null): int
{
$lastOrder = $this->getOneLastValidOfCycle($cycleNumber, $query);
$lastOrder = $this->getOneLastValidByCycle($cycleNumber, $query);
if ($lastOrder) {
return intval($lastOrder->getCycleId() + 1);
} else {
@@ -310,11 +310,8 @@ class OrderShopStore extends AbstractStore
public function countBy(array $params = [], $query = null)
{
$query = $this->createDefaultQuery($query);

$query
->selectCount()
->applyGetByFilters($query);

$query->selectCount();
$this->applyGetByFilters($query);
return $query->count();
}

@@ -465,8 +462,10 @@ class OrderShopStore extends AbstractStore
}

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

@@ -477,11 +476,15 @@ class OrderShopStore extends AbstractStore
}

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

return false;
@@ -506,8 +509,11 @@ class OrderShopStore extends AbstractStore
return $reductionCartsArray;
}

public function countValidOrderProductsOfCyclesByProducts(array $cycleNumbers, array $products, $query =null): array
{
public function countValidOrderProductsOfCyclesByProducts(
array $cycleNumbers,
array $products,
$query = null
): array {
$query = $this->createDefaultQuery($query);

$query
@@ -520,7 +526,7 @@ class OrderShopStore extends AbstractStore
return $query->find();
}

public function countValidOrderProductsOfCycleByProduct(int $cycleNumber, int $productId, $query =null): ?string
public function countValidOrderProductsOfCycleByProduct(int $cycleNumber, int $productId, $query = null): ?string
{
$query = $this->createDefaultQuery($query);


+ 1
- 0
Repository/Product/ProductCategoryStore.php View File

@@ -21,6 +21,7 @@ class ProductCategoryStore extends AbstractStore
public function orderByDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
{
$query->orderBy('position');
return $query;
}

public function filtersDefault(RepositoryQueryInterface $query): RepositoryQueryInterface

+ 26
- 0
Repository/Reduction/ReductionCreditStore.php View File

@@ -53,5 +53,31 @@ class ReductionCreditStore extends AbstractStore
return $query->find();
}

// findReductionGiftToUseByUser
public function getReductionGiftToUseByUser(UserInterface $user, $query = null)
{
/// @TODO : à écrire
$query = $this->createDefaultQuery($query);
$query->filterByUser($user);
return $query->find();
}

// findReductionGiftOwnedByUser
public function getReductionGiftOwnedByUser(UserInterface $user, $query = null)
{
/// @TODO : à écrire
$query = $this->createDefaultQuery($query);
$query->filterByUser($user);
return $query->find();
}

// findReductionGiftOwnedActiveByUser
public function getReductionGiftOwnedActiveByUser(UserInterface $user, $query = null)
{
/// @TODO : à écrire
$query = $this->createDefaultQuery($query);
$query->filterByUser($user);
return $query->find();
}

}

+ 1
- 3
Resolver/MerchantResolver.php View File

@@ -1,12 +1,11 @@
<?php

/**
* @author La clic ! <contact@laclic.fr>
*/


namespace Lc\CaracoleBundle\Resolver;


use Doctrine\ORM\EntityManagerInterface;
use Lc\CaracoleBundle\Definition\MerchantSettingDefinition;
use Lc\CaracoleBundle\Definition\MerchantSettingDefinitionInterface;
@@ -101,7 +100,6 @@ class MerchantResolver
}
}


public function getUserMerchant(
UserInterface $user = null,
MerchantInterface $merchant = null

+ 38
- 7
Resolver/OpeningResolver.php View File

@@ -6,6 +6,7 @@ use App\Entity\Section\Section;
use Lc\CaracoleBundle\Definition\SectionSettingDefinition;
use Lc\CaracoleBundle\Model\Section\OpeningInterface;
use Lc\CaracoleBundle\Model\Section\SectionInterface;
use Lc\CaracoleBundle\Model\Section\SectionModel;
use Lc\CaracoleBundle\Repository\Order\OrderShopStore;
use Lc\SovBundle\Model\User\UserInterface;
use Lc\SovBundle\Solver\Setting\SettingSolver;
@@ -35,18 +36,19 @@ class OpeningResolver
}

public function isOpenSale(
SectionInterface $section,
SectionInterface $section = null,
UserInterface $user = null,
\DateTime $date = null,
string $context = null
): bool {
// Initialisation
$this->messages = [];

if (is_null($date)) {
$date = new \DateTime();
if(is_null($section)) {
$section = $this->sectionResolver->getCurrent();
}

$date = new \DateTime();

// État des prise de commande (voir configuration de section)
$orderState = $this->settingSolver->getSettingValue($section, SectionSettingDefinition::SETTING_ORDER_STATE);

@@ -93,9 +95,30 @@ class OpeningResolver
return false;
}

public function isOpenFullTime(SectionInterface $section = null)
{
if(is_null($section)) {
$section = $this->sectionResolver->getCurrent();
}

$orderState = $this->settingSolver->getSettingValue($section, SectionSettingDefinition::SETTING_ORDER_STATE);

if($orderState == SectionSettingDefinition::VALUE_ORDER_STATE_OPEN) {
return true;
}

return false;
}

// isHolidays
public function isClosingPeriod(SectionInterface $section, \DateTime $date)
public function isClosingPeriod(SectionInterface $section = null)
{
if(is_null($section)) {
$section = $this->sectionResolver->getCurrent();
}

$date = new \DateTime();

$orderClosedStart = $this->settingSolver->getSettingValue($section, SectionSettingDefinition::SETTING_ORDER_CLOSED_START);
$orderClosedEnd = $this->settingSolver->getSettingValue($section, SectionSettingDefinition::SETTING_ORDER_CLOSED_END);

@@ -162,13 +185,21 @@ class OpeningResolver
return false;
}

public function getDateEndCurrentSale(SectionInterface $section, $formatDate = '', $delimiterDayTime = 'à')
public function getDateEndCurrentSale(SectionInterface $section = null, $formatDate = '', $delimiterDayTime = 'à')
{
if(is_null($section)) {
$section = $this->sectionResolver->getCurrent();
}

// @TODO : à réécrire
}

public function getDateBeginNextSale(SectionInterface $section, $formatDate = '', $delimiterDayTime = 'à')
public function getDateBeginNextSale(SectionInterface $section = null, $formatDate = '', $delimiterDayTime = 'à')
{
if(is_null($section)) {
$section = $this->sectionResolver->getCurrent();
}

// @TODO : à réécrire
}


+ 27
- 21
Resolver/SectionResolver.php View File

@@ -18,41 +18,47 @@ class SectionResolver
protected EntityManagerInterface $entityManager;
protected MerchantResolver $merchantResolver;
protected SectionStore $sectionStore;
protected RequestStack $requestStack;

public function __construct(EntityManagerInterface $entityManager, MerchantResolver $merchantResolver, SectionStore $sectionStore)
public function __construct(EntityManagerInterface $entityManager, MerchantResolver $merchantResolver, SectionStore $sectionStore, RequestStack $requestStack)
{
$this->entityManager = $entityManager;
$this->merchantResolver = $merchantResolver;
$this->sectionStore = $sectionStore;
$this->requestStack = $requestStack;
}

public function getCurrentFrontend()
public function getCurrent()
{
return $this->sectionStore
->setMerchant($this->merchantResolver->getCurrent())
->getOneDefault();
}

public function getCurrent(): SectionInterface
{
$currentAdminSection = null;
$userMerchant = $this->merchantResolver->getUserMerchant();
$requestAttributesArray = $this->requestStack->getMainRequest()->attributes->all();

if ($userMerchant !== null) {
$currentAdminSection = $userMerchant->getCurrentAdminSection();
}
// admin
if(isset($requestAttributesArray['easyadmin_context'])) {
$currentAdminSection = null;
$userMerchant = $this->merchantResolver->getUserMerchant();

if ($currentAdminSection === null) {
$currentAdminSection = $this->sectionStore
->setMerchant($userMerchant->getMerchant())
->getOneDefault();
if ($userMerchant !== null) {
$currentAdminSection = $userMerchant->getCurrentAdminSection();
}

if ($currentAdminSection === null) {
throw new \ErrorException('Aucune section par défaut définie pour ce merchant');
$currentAdminSection = $this->sectionStore
->setMerchant($userMerchant->getMerchant())
->getOneDefault();

if ($currentAdminSection === null) {
throw new \ErrorException('Aucune section par défaut définie pour ce merchant');
}
}
}

return $currentAdminSection;
return $currentAdminSection;
}
// front
else {
return $this->sectionStore
->setMerchant($this->merchantResolver->getCurrent())
->getOneDefault();
}
}



+ 1
- 1
Statistic/Product/ProductsSalesStatistic.php View File

@@ -50,7 +50,7 @@ class ProductsSalesStatistic extends Statistic
public function init(SectionInterface $section, OrderShopSolver $orderShopSolver, OpeningResolver $openingResolver)
{
$currentCycleNumber = $orderShopSolver->getCycleNumberCurrentOrder();
if ($openingResolver->isOpenSale($section, null, null,OpeningResolver::OPENING_CONTEXT_BACKEND) == false && date('w') > 2) {
if ($openingResolver->isOpenSale($section, null,OpeningResolver::OPENING_CONTEXT_BACKEND) == false && date('w') > 2) {
$currentCycleNumber = $currentCycleNumber - 1;
}
$this->cycleNumbers = array();

+ 8
- 4
Twig/StoreTwigExtension.php View File

@@ -65,17 +65,21 @@ class StoreTwigExtension extends AbstractExtension

public function getProductCategories()
{
return $this->productCategoryStore->getParent(false);
return $this->productCategoryStore
->setSection($this->sectionResolver->getCurrent())
->getParent(false);
}

public function getSections()
{
return $this->sectionStore->setMerchant($this->merchantResolver->getCurrent())->getOnline();
return $this->sectionStore
->setMerchant($this->merchantResolver->getCurrent())
->getOnline();
}

public function getSectionCurrent()
{
return $this->sectionResolver->getCurrentFrontend();
return $this->sectionResolver->getCurrent();
}

public function getMerchants()
@@ -103,7 +107,7 @@ class StoreTwigExtension extends AbstractExtension

public function getReductionCartCodes()
{
//TODO mettre à jour une fois les repo fait
//TODO mettre à jour une fois les repo fait
return array();
}


Loading…
Cancel
Save