Ver código fonte

Refactoring frontend

packProduct
Guillaume 3 anos atrás
pai
commit
d877203af7
7 arquivos alterados com 204 adições e 33 exclusões
  1. +0
    -1
      Repository/Product/ProductCategoryStore.php
  2. +6
    -2
      Repository/Product/ProductFamilyStore.php
  3. +3
    -0
      Repository/Section/OpeningRepositoryQuery.php
  4. +2
    -0
      Repository/Section/OpeningStore.php
  5. +92
    -27
      Resolver/OpeningResolver.php
  6. +99
    -0
      Solver/Section/OpeningSolver.php
  7. +2
    -3
      Twig/StoreTwigExtension.php

+ 0
- 1
Repository/Product/ProductCategoryStore.php Ver arquivo

@@ -32,7 +32,6 @@ class ProductCategoryStore extends AbstractStore

public function relationsDefault($query): RepositoryQueryInterface
{
$query->joinProductFamilies();
return $query;
}
}

+ 6
- 2
Repository/Product/ProductFamilyStore.php Ver arquivo

@@ -101,18 +101,22 @@ class ProductFamilyStore extends AbstractStore
}

// findByTerms
public function getByTerms($terms, $maxResults = false, $query = null)
public function getByTerms($terms, $maxResults = false, $organizeByParentCategory = false, $user = null, $query = null)
{
$query = $this->createDefaultQuery($query);

$query->filterIsOnline();
$query->filterByTerms($terms);

$query->groupBy('id');

if($maxResults) {
$query->limit($maxResults);
}

return $query->find();
$results = $query->find();

return $this->getWithReductions($results, $user, false, $organizeByParentCategory);
}

public function getBestReductionCatalog(

+ 3
- 0
Repository/Section/OpeningRepositoryQuery.php Ver arquivo

@@ -3,10 +3,13 @@
namespace Lc\CaracoleBundle\Repository\Section;

use Knp\Component\Pager\PaginatorInterface;
use Lc\CaracoleBundle\Repository\SectionRepositoryQueryTrait;
use Lc\SovBundle\Repository\AbstractRepositoryQuery;

class OpeningRepositoryQuery extends AbstractRepositoryQuery
{
use SectionRepositoryQueryTrait;

public function __construct(OpeningRepository $repository, PaginatorInterface $paginator)
{
parent::__construct($repository, 'r', $paginator);

+ 2
- 0
Repository/Section/OpeningStore.php Ver arquivo

@@ -3,6 +3,7 @@
namespace Lc\CaracoleBundle\Repository\Section;

use Lc\CaracoleBundle\Repository\SectionStoreTrait;
use Lc\CaracoleBundle\Solver\Section\OpeningSolver;
use Lc\SovBundle\Repository\AbstractStore;
use Lc\SovBundle\Repository\RepositoryQueryInterface;

@@ -33,4 +34,5 @@ class OpeningStore extends AbstractStore
{
return $query;
}

}

+ 92
- 27
Resolver/OpeningResolver.php Ver arquivo

@@ -8,6 +8,8 @@ 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\CaracoleBundle\Repository\Section\OpeningStore;
use Lc\CaracoleBundle\Solver\Section\OpeningSolver;
use Lc\SovBundle\Model\User\UserInterface;
use Lc\SovBundle\Solver\Setting\SettingSolver;
use Symfony\Component\Security\Core\Security;
@@ -22,17 +24,23 @@ class OpeningResolver
protected Security $security;
protected OrderShopStore $orderShopStore;
protected SettingSolver $settingSolver;
protected OpeningStore $openingStore;
protected OpeningSolver $openingSolver;

public function __construct(
SectionResolver $sectionResolver,
Security $security,
OrderShopStore $orderShopStore,
SettingSolver $settingSolver
SettingSolver $settingSolver,
OpeningStore $openingStore,
OpeningSolver $openingSolver
) {
$this->sectionResolver = $sectionResolver;
$this->security = $security;
$this->orderShopStore = $orderShopStore;
$this->settingSolver = $settingSolver;
$this->openingStore = $openingStore;
$this->openingSolver = $openingSolver;
}

public function isOpenSale(
@@ -43,10 +51,14 @@ class OpeningResolver
// Initialisation
$this->messages = [];

if(is_null($section)) {
if (is_null($section)) {
$section = $this->sectionResolver->getCurrent();
}

if (is_null($user)) {
$user = $this->security->getUser();
}

$date = new \DateTime();

// État des prise de commande (voir configuration de section)
@@ -97,13 +109,13 @@ class OpeningResolver

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

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

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

@@ -113,14 +125,20 @@ class OpeningResolver
// isHolidays
public function isClosingPeriod(SectionInterface $section = null)
{
if(is_null($section)) {
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);
$orderClosedStart = $this->settingSolver->getSettingValue(
$section,
SectionSettingDefinition::SETTING_ORDER_CLOSED_START
);
$orderClosedEnd = $this->settingSolver->getSettingValue(
$section,
SectionSettingDefinition::SETTING_ORDER_CLOSED_END
);

if ($orderClosedStart && $orderClosedEnd && $date >= $orderClosedStart && $date <= $orderClosedEnd) {
return true;
@@ -136,7 +154,10 @@ class OpeningResolver
->setSection($section)
->countValidByCurrentCycle();

$orderMaximumPerCycle = $this->settingSolver->getSettingValue($section, SectionSettingDefinition::SETTING_ORDER_MAXIMUM_PER_CYCLE);
$orderMaximumPerCycle = $this->settingSolver->getSettingValue(
$section,
SectionSettingDefinition::SETTING_ORDER_MAXIMUM_PER_CYCLE
);
if ($orderMaximumPerCycle && $countOrderShopCycle >= $orderMaximumPerCycle) {
return true;
}
@@ -185,41 +206,73 @@ class OpeningResolver
return false;
}

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

// @TODO : à réécrire
$date = new \DateTime();
$openingArray = $this->openingStore
->setSection($section)
->get();

if ($this->isOpenSale($section)) {
$openingClosing = $this->openingSolver->getNextOpeningOfClosing($date, $openingArray);
if ($openingClosing) {
return $this->openingSolver->getFormatedDateByFormatAndDelimiterDayTime(
$date,
$openingClosing->getTimeEnd(),
$formatDate,
$delimiterDayTime
);
}
}

return '';
}

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

// @TODO : à réécrire
}

public function getMessages(): array
{
return $this->messages;
}
$date = new \DateTime();
$openingArray = $this->openingStore
->setSection($section)
->get();

if (!$this->isOpenSale($section)) {
$opening = $this->openingSolver->getNextOpeningOfOpening($date, $openingArray);
if ($opening) {
return $this->openingSolver->getFormatedDateByFormatAndDelimiterDayTime(
$date,
$opening->getTimeStart(),
$formatDate,
$delimiterDayTime
);
}
}

public function addMessage(string $message): void
{
$this->messages[] = $message;
return '';
}

public function isOpenSaleOnlyComplementaryOrders(Section $section = null, UserInterface $user = null)
{
if(is_null($section)) {
if (is_null($section)) {
$section = $this->sectionResolver->getCurrent();
}

if(is_null($user)) {
if (is_null($user)) {
$user = $this->security->getUser();
}

@@ -230,4 +283,16 @@ class OpeningResolver
&& $this->isMaximumOrderCycleAchieved($section)
&& count($orderShopsUser) > 0;
}

public function getMessages(): array
{
return $this->messages;
}

public function addMessage(string $message): void
{
$this->messages[] = $message;
}


}

+ 99
- 0
Solver/Section/OpeningSolver.php Ver arquivo

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

namespace Lc\CaracoleBundle\Solver\Section;

use Lc\CaracoleBundle\Model\Section\OpeningInterface;

class OpeningSolver
{
public function getNextOpeningOfOpening(\DateTime $date, array $openings): ?OpeningInterface
{
return $this->getNextOpening($date, $openings, 'opening');
}

public function getNextOpeningOfClosing(\DateTime $date, array $openings): ?OpeningInterface
{
return $this->getNextOpening($date, $openings, 'closing');
}

protected function getNextOpening(\DateTime $date, array $openings, $typeOpening = 'opening')
{
if ($typeOpening == 'opening') {
$methodTestDay = 'isOpeningDay';
} else {
$methodTestDay = 'isClosingDay';
}

$count = 0;
$isClosingDay = false;

do {
if ($count) {
$date->modify('+1 day');
}
$weekDay = $date->format('N');
$isClosingDay = $this->$methodTestDay($weekDay, $openings);
$count++;
} while (!$isClosingDay && $count <= 7);

if ($isClosingDay) {
return $this->getOpeningByWeekday($weekDay, $openings);
}

return null;
}

public function isOpeningDay(int $weekDay, array $openings): bool
{
return $this->isOpeningOrClosingDay($weekDay, $openings, 'opening');
}

public function isClosingDay(int $weekDay, array $openings): bool
{
return $this->isOpeningOrClosingDay($weekDay, $openings, 'closing');
}

protected function isOpeningOrClosingDay(int $weekDay, array $openings, string $testOpeningOrClosing = 'opening')
{
if ($testOpeningOrClosing == 'opening') {
$methodGetTime = 'getTimeStart';
} else {
$methodGetTime = 'getTimeEnd';
}

$openingDay = $this->getOpeningByWeekday($weekDay, $openings);
if ($openingDay && $openingDay->$methodGetTime()) {
return true;
}

return false;
}

public function getOpeningByWeekday(int $weekDay, array $openings): ?OpeningInterface
{
foreach ($openings as $opening) {
if ($opening->getDay() == $weekDay) {
return $opening;
}
}

return null;
}

public function getFormatedDateByFormatAndDelimiterDayTime(
\DateTime $date,
\DateTimeInterface $time,
string $formatDate = '',
string $delimiterDayTime = ''
): string {
setlocale(LC_TIME, 'fr_FR.UTF8', 'fr.UTF8', 'fr_FR.UTF-8', 'fr.UTF-8');
if (!strlen($formatDate)) {
$formatDate = '%A %e %B';
}
return strftime(
$formatDate . ' ' . $delimiterDayTime . ' ' . $time->format('H\hi'),
$date->getTimestamp()
);
}

}

+ 2
- 3
Twig/StoreTwigExtension.php Ver arquivo

@@ -72,9 +72,8 @@ class StoreTwigExtension extends AbstractExtension
new TwigFunction('carac_units', [$this, 'getUnits']),
new TwigFunction('carac_tax_rates', [$this, 'getTaxRates']),
new TwigFunction('carac_reduction_cart_codes', [$this, 'getTaxRates']),
new TwigFunction('carac_product_categories', [$this, 'getProductCategories']),


new TwigFunction('product_categories', [$this, 'getProductCategories']),
new TwigFunction('cart_current', [$this, 'getCartCurrent']),
new TwigFunction('merchant_current', [$this, 'getMerchantCurrent']),
new TwigFunction('user_merchant_current', [$this, 'getUserMerchantCurrent']),
@@ -144,7 +143,7 @@ class StoreTwigExtension extends AbstractExtension
{
return $this->productCategoryStore
->setSection($this->sectionResolver->getCurrent())
->getParent(false);
->getParent();
}

public function getReminders($params = [])

Carregando…
Cancelar
Salvar