Browse Source

Refactoring frontend

packProduct
Guillaume 3 years ago
parent
commit
d877203af7
7 changed files with 204 additions and 33 deletions
  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 View File



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

+ 6
- 2
Repository/Product/ProductFamilyStore.php View File

} }


// findByTerms // 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 = $this->createDefaultQuery($query);


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

$query->groupBy('id'); $query->groupBy('id');


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


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

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


public function getBestReductionCatalog( public function getBestReductionCatalog(

+ 3
- 0
Repository/Section/OpeningRepositoryQuery.php View File

namespace Lc\CaracoleBundle\Repository\Section; namespace Lc\CaracoleBundle\Repository\Section;


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


class OpeningRepositoryQuery extends AbstractRepositoryQuery class OpeningRepositoryQuery extends AbstractRepositoryQuery
{ {
use SectionRepositoryQueryTrait;

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

+ 2
- 0
Repository/Section/OpeningStore.php View File

namespace Lc\CaracoleBundle\Repository\Section; namespace Lc\CaracoleBundle\Repository\Section;


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


{ {
return $query; return $query;
} }

} }

+ 92
- 27
Resolver/OpeningResolver.php View File

use Lc\CaracoleBundle\Model\Section\SectionInterface; use Lc\CaracoleBundle\Model\Section\SectionInterface;
use Lc\CaracoleBundle\Model\Section\SectionModel; use Lc\CaracoleBundle\Model\Section\SectionModel;
use Lc\CaracoleBundle\Repository\Order\OrderShopStore; 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\Model\User\UserInterface;
use Lc\SovBundle\Solver\Setting\SettingSolver; use Lc\SovBundle\Solver\Setting\SettingSolver;
use Symfony\Component\Security\Core\Security; use Symfony\Component\Security\Core\Security;
protected Security $security; protected Security $security;
protected OrderShopStore $orderShopStore; protected OrderShopStore $orderShopStore;
protected SettingSolver $settingSolver; protected SettingSolver $settingSolver;
protected OpeningStore $openingStore;
protected OpeningSolver $openingSolver;


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


public function isOpenSale( public function isOpenSale(
// Initialisation // Initialisation
$this->messages = []; $this->messages = [];


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


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

$date = new \DateTime(); $date = new \DateTime();


// État des prise de commande (voir configuration de section) // État des prise de commande (voir configuration de section)


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


$orderState = $this->settingSolver->getSettingValue($section, SectionSettingDefinition::SETTING_ORDER_STATE); $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; return true;
} }


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


$date = new \DateTime(); $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) { if ($orderClosedStart && $orderClosedEnd && $date >= $orderClosedStart && $date <= $orderClosedEnd) {
return true; return true;
->setSection($section) ->setSection($section)
->countValidByCurrentCycle(); ->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) { if ($orderMaximumPerCycle && $countOrderShopCycle >= $orderMaximumPerCycle) {
return true; return true;
} }
return false; 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(); $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(); $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) public function isOpenSaleOnlyComplementaryOrders(Section $section = null, UserInterface $user = null)
{ {
if(is_null($section)) {
if (is_null($section)) {
$section = $this->sectionResolver->getCurrent(); $section = $this->sectionResolver->getCurrent();
} }


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


&& $this->isMaximumOrderCycleAchieved($section) && $this->isMaximumOrderCycleAchieved($section)
&& count($orderShopsUser) > 0; && 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 View File

<?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 View File

new TwigFunction('carac_units', [$this, 'getUnits']), new TwigFunction('carac_units', [$this, 'getUnits']),
new TwigFunction('carac_tax_rates', [$this, 'getTaxRates']), new TwigFunction('carac_tax_rates', [$this, 'getTaxRates']),
new TwigFunction('carac_reduction_cart_codes', [$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('cart_current', [$this, 'getCartCurrent']),
new TwigFunction('merchant_current', [$this, 'getMerchantCurrent']), new TwigFunction('merchant_current', [$this, 'getMerchantCurrent']),
new TwigFunction('user_merchant_current', [$this, 'getUserMerchantCurrent']), new TwigFunction('user_merchant_current', [$this, 'getUserMerchantCurrent']),
{ {
return $this->productCategoryStore return $this->productCategoryStore
->setSection($this->sectionResolver->getCurrent()) ->setSection($this->sectionResolver->getCurrent())
->getParent(false);
->getParent();
} }


public function getReminders($params = []) public function getReminders($params = [])

Loading…
Cancel
Save