Fab пре 3 година
родитељ
комит
30644a4c60
17 измењених фајлова са 164 додато и 70 уклоњено
  1. +33
    -4
      Builder/Order/OrderShopBuilder.php
  2. +2
    -1
      Controller/ControllerTrait.php
  3. +1
    -0
      Controller/Order/CartController.php
  4. +2
    -7
      Controller/Section/OpeningAdminController.php
  5. +6
    -2
      Form/Order/OrderProductsType.php
  6. +4
    -0
      Repository/Order/OrderShopStore.php
  7. +3
    -0
      Repository/Product/ProductCategoryRepositoryQuery.php
  8. +21
    -7
      Repository/Product/ProductFamilyRepositoryQuery.php
  9. +6
    -6
      Repository/Product/ProductFamilyStore.php
  10. +2
    -2
      Repository/Product/ProductRepositoryQuery.php
  11. +40
    -7
      Repository/Reduction/ReductionCatalogRepositoryQuery.php
  12. +2
    -1
      Resolver/OpeningResolver.php
  13. +14
    -10
      Resolver/SectionResolver.php
  14. +11
    -2
      Solver/Order/OrderProductReductionCatalogSolver.php
  15. +1
    -1
      Solver/Order/OrderShopSolver.php
  16. +8
    -19
      Solver/Section/OpeningSolver.php
  17. +8
    -1
      Twig/StoreTwigExtension.php

+ 33
- 4
Builder/Order/OrderShopBuilder.php Прегледај датотеку

@@ -50,6 +50,9 @@ use Lc\SovBundle\Model\User\UserInterface;
use Lc\SovBundle\Translation\FlashBagTranslator;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
use Symfony\Contracts\Cache\CacheInterface;
use Symfony\Contracts\Cache\ItemInterface;
use Symfony\Contracts\Cache\TagAwareCacheInterface;

class OrderShopBuilder
{
@@ -128,11 +131,24 @@ class OrderShopBuilder
return $orderShop;
}


protected array $cacheCartCurrentBySection = [];

public function createIfNotExist(
SectionInterface $section,
UserInterface $user = null,
VisitorInterface $visitor = null
VisitorInterface $visitor = null,
bool $cache = false
): OrderShopInterface {

$cart = null;

// cache
$cacheIdCartCurrent = 'cart_current_'.$section->getId();
if($cache && isset($this->cacheCartCurrentBySection[$cacheIdCartCurrent])) {
return $this->cacheCartCurrentBySection[$cacheIdCartCurrent];
}

$this->orderShopStore->setSection($section);

$cartUser = $this->orderShopStore->getOneCartCurrent($user);
@@ -141,7 +157,19 @@ class OrderShopBuilder
if ($cartUser && $cartVisitor && $cartUser->getId() != $cartVisitor->getId()) {
$cart = $this->merge($cartUser, $cartVisitor);
} else {
$cart = $cartUser ?: $cartVisitor;
if($cartUser) {
$cart = $cartUser;
}
elseif($cartVisitor) {

if($user && $cartVisitor && !$cartVisitor->getUser()) {
$cartVisitor->setUser($user);
$this->entityManager->update($cartVisitor);
$this->entityManager->flush();
}

$cart = $cartVisitor;
}
}

if (!$cart) {
@@ -151,6 +179,9 @@ class OrderShopBuilder
// @TODO : obligé de faire ça sinon le panier ne se met pas à jour quand on ajoute des produits. Pourquoi ?
$this->entityManager->refresh($cart);

// cache
$this->cacheCartCurrentBySection[$cacheIdCartCurrent] = $cart;

return $cart;
}

@@ -232,8 +263,6 @@ class OrderShopBuilder
&& $orderProduct->getRedelivery() == $orderProductAdd->getRedelivery()
&& (string)$this->priceSolver->getPrice($orderProduct)
== (string)$this->priceSolver->getPrice($orderProductAdd)
&& $orderProduct->getOrderProductReductionCatalog()
&& $orderProductAdd->getOrderProductReductionCatalog()
&& $this->orderProductReductionCatalogSolver->compare(
$orderProduct->getOrderProductReductionCatalog(),
$orderProductAdd->getOrderProductReductionCatalog()

+ 2
- 1
Controller/ControllerTrait.php Прегледај датотеку

@@ -157,7 +157,8 @@ trait ControllerTrait
return $this->getOrderShopContainer()->getBuilder()->createIfNotExist(
$this->getSectionCurrent(),
$this->getUserCurrent(),
$this->getVisitorCurrent()
$this->getVisitorCurrent(),
true
);
}


+ 1
- 0
Controller/Order/CartController.php Прегледај датотеку

@@ -50,6 +50,7 @@ class CartController extends AbstractController
$form->handleRequest($request);

if ($form->isSubmitted() && $form->isValid()) {

$orderShop = $this->getOrderShopContainer()->getBuilder()->createIfNotExist(
$this->getSectionCurrent(),
$this->getUserCurrent(),

+ 2
- 7
Controller/Section/OpeningAdminController.php Прегледај датотеку

@@ -24,10 +24,7 @@ abstract class OpeningAdminController extends AbstractAdminController

public function configureFields(string $pageName): iterable
{
$fields = parent::configureFields($pageName);

return array_merge(
[
return [
ChoiceField::new('day')
->setRequired(true)
->setChoices(
@@ -48,9 +45,7 @@ abstract class OpeningAdminController extends AbstractAdminController
->setRequired(false)
->setFormat('H:mm'),
AssociationField::new('groupUser'),
],
$fields
);
];
}

public function configureCrud(Crud $crud): Crud

+ 6
- 2
Form/Order/OrderProductsType.php Прегледај датотеку

@@ -36,6 +36,9 @@ class OrderProductsType extends AbstractType
$idProductFamily = $options['data']['id_product_family'];
$productFamily = $this->productFamilyStore->getOneById($idProductFamily);

// @TODO : obligé sinon ne fonctionne pas. Problème avec le chargement des relations ?
$this->entityManager->refresh($productFamily);

$builder->add('id_product_family', HiddenType::class, [
'data' => $productFamily->getId()
]);
@@ -43,9 +46,9 @@ class OrderProductsType extends AbstractType
if ($productFamily) {
if ($productFamily->getActiveProducts()
&& $productFamily->getBehaviorAddToCart() == 'multiple') {
$cpt = 0;

foreach ($this->productFamilySolver->getProductsGroupByTitle($productFamily) as $key => $product) {
$cpt = 0;
foreach ($this->productFamilySolver->getProductsGroupByTitle($productFamily) as $product) {
$orderProduct = $this->orderProductFactory->create($product[0], 0);
$builder->add('order_product_' . $cpt, OrderProductType::class, [
'data' => $orderProduct
@@ -56,6 +59,7 @@ class OrderProductsType extends AbstractType
$product = null;
if ($productFamily->getActiveProducts()) {
$products = $this->productFamilySolver->getProductsOnline($productFamily);

if ($products && count($products) > 0) {
$product = $products[0];
}

+ 4
- 0
Repository/Order/OrderShopStore.php Прегледај датотеку

@@ -288,6 +288,10 @@ class OrderShopStore extends AbstractStore
// findCartCurrent
public function getOneCartCurrent(UserInterface $user = null, VisitorInterface $visitor = null, $query = null): ?OrderShopInterface
{
if(is_null($user) && is_null($visitor)) {
return null;
}

$query = $this->createDefaultQuery($query);

if (!is_null($user)) {

+ 3
- 0
Repository/Product/ProductCategoryRepositoryQuery.php Прегледај датотеку

@@ -29,6 +29,9 @@ class ProductCategoryRepositoryQuery extends AbstractRepositoryQuery

return $this;
}



public function hasProductFamilyOnline(): self
{
$this->joinProductFamilies();

+ 21
- 7
Repository/Product/ProductFamilyRepositoryQuery.php Прегледај датотеку

@@ -11,11 +11,10 @@ use Lc\SovBundle\Repository\AbstractRepositoryQuery;

class ProductFamilyRepositoryQuery extends AbstractRepositoryQuery
{
//use SectionRepositoryQueryTrait;

protected bool $isJoinProductCategories = false;
protected bool $isJoinProductFamilySectionProperties = false;
protected bool $isJoinProducts = false;
protected bool $isJoinQualityLabels = false;

public function __construct(ProductFamilyRepository $repository, PaginatorInterface $paginator)
{
@@ -35,6 +34,19 @@ class ProductFamilyRepositoryQuery extends AbstractRepositoryQuery
return $this;
}

public function joinQualityLabels(bool $addSelect = true): self
{
if (!$this->isJoinQualityLabels) {
$this->isJoinQualityLabels = true;

$this->leftJoin('.qualityLabels', 'pfql');
if ($addSelect) {
$this->addSelect('pfql');
}
}
return $this;
}

public function filterBySection(SectionInterface $section,bool $addSelectProductFamilySectionProperties = true)
{
$this->joinProductFamilySectionProperties($addSelectProductFamilySectionProperties);
@@ -104,14 +116,15 @@ class ProductFamilyRepositoryQuery extends AbstractRepositoryQuery
return $this->andWhereEqual('supplier', $supplier);
}

public function joinProductCategories(): self
public function joinProductCategories(bool $addSelect = false): self
{
if (!$this->isJoinProductCategories) {
$this->isJoinProductCategories = true;

return $this
->leftJoin('.productCategories', 'cat');
//$query->addSelect('cat') ; ???
->leftJoin('.productCategories', 'cat')
->addSelect('cat')
;
}
return $this;
}
@@ -129,8 +142,9 @@ class ProductFamilyRepositoryQuery extends AbstractRepositoryQuery
$this->isJoinProducts = true;

return $this
->innerJoin('.products', 'pfp');
// $query->addSelect('pfp') ; ?????
->innerJoin('.products', 'pfp')
->addSelect('pfp')
;
}
return $this;
}

+ 6
- 6
Repository/Product/ProductFamilyStore.php Прегледај датотеку

@@ -34,13 +34,9 @@ class ProductFamilyStore extends AbstractStore

public function filtersDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
{
if($this->section) {
$query->filterBySection($this->section);
}

if(isset($this->merchant) && $this->merchant) {
$query->filterByMerchantViaSection($this->merchant);
}
$this->addFilterBySectionOptionnal($query);
$this->addFilterByMerchantViaSectionOptionnal($query);

return $query;
}
@@ -49,6 +45,8 @@ class ProductFamilyStore extends AbstractStore
{
$query->joinProductCategories();
$query->joinProducts();
$query->joinQualityLabels();

return $query;
}

@@ -252,7 +250,9 @@ class ProductFamilyStore extends AbstractStore

if (($onlyOnDiscount && $productFamily->getReductionCatalog()) || !$onlyOnDiscount) {
if ($organizeByParentCategory) {

$productCategories = $productFamily->getProductCategories();

if ($productCategories && count($productCategories) > 0) {
$parentCategory = $productCategories[0]->getParentCategory();
if ($this->productCategorySolver->isDisplay($parentCategory, $user)) {

+ 2
- 2
Repository/Product/ProductRepositoryQuery.php Прегледај датотеку

@@ -29,8 +29,8 @@ class ProductRepositoryQuery extends AbstractRepositoryQuery
$this->isJoinProductFamily = true;

return $this
->innerJoin('.productFamily', 'pf');
//$qb->addSelect('pf'); ???
->innerJoin('.productFamily', 'pf')
->addSelect('pf');
}
return $this;
}

+ 40
- 7
Repository/Reduction/ReductionCatalogRepositoryQuery.php Прегледај датотеку

@@ -14,6 +14,9 @@ class ReductionCatalogRepositoryQuery extends AbstractRepositoryQuery
protected bool $isJoinProductFamilies = false;
protected bool $isJoinProductFamily = false;
protected bool $isJoinProductCategories = false;
protected bool $isJoinUsers = false;
protected bool $isJoinGroupUsers = false;

use SectionRepositoryQueryTrait;

public function __construct(ReductionCatalogRepository $repository, PaginatorInterface $paginator)
@@ -21,14 +24,38 @@ class ReductionCatalogRepositoryQuery extends AbstractRepositoryQuery
parent::__construct($repository, 'r', $paginator);
}

public function joinUsers()
{
if (!$this->isJoinUsers) {
$this->isJoinUsers = true;

return $this
->leftJoin('.users', 'pf_users')
->addSelect('pf_users') ;
}
return $this;
}

public function joinGroupUsers()
{
if (!$this->isJoinGroupUsers) {
$this->isJoinGroupUsers = true;

return $this
->leftJoin('.groupUsers', 'pf_groupusers')
->addSelect('pf_groupusers') ;
}
return $this;
}

public function joinProductFamilies()
{
if (!$this->isJoinProductFamilies) {
$this->isJoinProductFamilies = true;

return $this
->leftJoin('.productFamilies', 'pfs');
//->addSelect('pfs') ;
->leftJoin('.productFamilies', 'pfs')
->addSelect('pfs') ;
}
return $this;
}
@@ -39,8 +66,8 @@ class ReductionCatalogRepositoryQuery extends AbstractRepositoryQuery
$this->isJoinProductFamily = true;

return $this
->leftJoin('.productFamily', 'pf');
//->addSelect('pf') ;
->leftJoin('.productFamily', 'pf')
->addSelect('pf') ;
}
return $this;
}
@@ -51,13 +78,12 @@ class ReductionCatalogRepositoryQuery extends AbstractRepositoryQuery
$this->isJoinProductCategories = true;

return $this
->leftJoin('.productCategories', 'pcs');
//->addSelect('pcs') ;
->leftJoin('.productCategories', 'pcs')
->addSelect('pcs') ;
}
return $this;
}


public function filterProductFamily(ProductFamilyInterface $productFamily)
{
return $this
@@ -74,6 +100,8 @@ class ReductionCatalogRepositoryQuery extends AbstractRepositoryQuery

public function filterConditionUser(UserInterface $user = null)
{
$this->joinUsers();

if ($user) {
return $this
->andWhere(':user MEMBER OF .users OR .users is empty')
@@ -86,6 +114,8 @@ class ReductionCatalogRepositoryQuery extends AbstractRepositoryQuery

public function filterConditionGroupUser(UserInterface $user = null)
{
$this->joinGroupUsers();

if ($user) {
return $this
->andWhere(':groupUser MEMBER OF .groupUsers OR .groupUsers is empty')
@@ -100,6 +130,7 @@ class ReductionCatalogRepositoryQuery extends AbstractRepositoryQuery
{
$this->joinProductFamilies();
$this->joinProductFamily();

return $this
->andWhere(':productFamilies MEMBER OF .productFamilies OR .productFamilies is empty')
->setParameter('productFamilies', $productFamilies);
@@ -109,6 +140,7 @@ class ReductionCatalogRepositoryQuery extends AbstractRepositoryQuery
{
$this->joinProductFamilies();
$this->joinProductFamily();

return $this
->andWhere(':productFamily MEMBER OF .productFamilies OR .productFamilies is empty')
->setParameter('productFamily', $productFamily);
@@ -117,6 +149,7 @@ class ReductionCatalogRepositoryQuery extends AbstractRepositoryQuery
public function filterConditionProductCategories(array $productCategories)
{
$this->joinProductCategories();

return $this
->andWhere(':productCategory MEMBER OF .productCategories OR .productCategories is empty')
->setParameter('productCategory', $productCategories);

+ 2
- 1
Resolver/OpeningResolver.php Прегледај датотеку

@@ -254,10 +254,11 @@ class OpeningResolver

if (!$this->isOpenSale($section)) {
$opening = $this->openingSolver->getNextOpeningOfOpening($date, $openingArray);

if ($opening) {
return $this->openingSolver->getFormatedDateByFormatAndDelimiterDayTime(
$date,
$opening->getTimeStart(),
$opening->getTimeStart() ?: (new \DateTime())->setTime(0, 0),
$formatDate,
$delimiterDayTime
);

+ 14
- 10
Resolver/SectionResolver.php Прегледај датотеку

@@ -68,18 +68,22 @@ class SectionResolver
}
} // front
else {
$merchantCurrent = $this->merchantResolver->getCurrent();
$sectionStore = $this->sectionStore->setMerchant($merchantCurrent);
$sectionCurrent = null;
$sectionDefault = $sectionStore->getOneDefault();

if (isset($requestAttributesArray['section'])) {
$sectionCurrent = $sectionStore
->setMerchant($merchantCurrent)
->getOneBySlug($requestAttributesArray['section']);
if($this->section === null) {
$merchantCurrent = $this->merchantResolver->getCurrent();
$sectionStore = $this->sectionStore->setMerchant($merchantCurrent);
$sectionCurrent = null;
$sectionDefault = $sectionStore->getOneDefault();

if (isset($requestAttributesArray['section'])) {
$sectionCurrent = $sectionStore
->setMerchant($merchantCurrent)
->getOneBySlug($requestAttributesArray['section']);
}

$this->section = $sectionCurrent ?: $sectionDefault;
}

return $sectionCurrent ?: $sectionDefault;
return $this->section;
}
}


+ 11
- 2
Solver/Order/OrderProductReductionCatalogSolver.php Прегледај датотеку

@@ -24,9 +24,18 @@ class OrderProductReductionCatalogSolver

// compareOrderProductReductionCatalog
public function compare(
OrderProductReductionCatalogInterface $orderProductReductionCatalog,
OrderProductReductionCatalogInterface $orderProductReductionCatalogCompare
OrderProductReductionCatalogInterface $orderProductReductionCatalog = null,
OrderProductReductionCatalogInterface $orderProductReductionCatalogCompare = null
): bool {

if(is_null($orderProductReductionCatalog) && is_null($orderProductReductionCatalogCompare)) {
return true;
}

if(is_null($orderProductReductionCatalog) || is_null($orderProductReductionCatalogCompare)) {
return false;
}

return $orderProductReductionCatalog->getUnit() == $orderProductReductionCatalogCompare->getUnit()
&& (string)$orderProductReductionCatalog->getValue(
) == (string)$orderProductReductionCatalogCompare->getValue()

+ 1
- 1
Solver/Order/OrderShopSolver.php Прегледај датотеку

@@ -99,7 +99,7 @@ class OrderShopSolver
|| (($behaviorCountStock == ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY || $behaviorCountStock == ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_MEASURE)
&& $orderProduct->getProduct()->getProductFamily()->getId() == $productFamily->getId())) {
if ($byWeight) {
$quantity += $orderProduct->getQuantityOrder() * ($orderProduct->getQuantityProduct() / $orderProduct->getProduct()->getUnitInherited()->getCoefficient());
$quantity += $orderProduct->getQuantityOrder() * ($orderProduct->getQuantityProduct() / $this->productSolver->getUnitInherited($orderProduct->getProduct())->getCoefficient());
} else {
$quantity += $orderProduct->getQuantityOrder();
}

+ 8
- 19
Solver/Section/OpeningSolver.php Прегледај датотеку

@@ -25,44 +25,33 @@ class OpeningSolver
}

$count = 0;
$isClosingDay = false;

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

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

return null;
}

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

public function isClosingDay(int $weekDay, array $openings): bool
protected 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()) {

if ($openingDay && $openingDay->getTimeEnd()) {
return true;
}


+ 8
- 1
Twig/StoreTwigExtension.php Прегледај датотеку

@@ -90,6 +90,7 @@ class StoreTwigExtension extends AbstractExtension
new TwigFunction('merchant_setting_current', [$this, 'getMerchantSettingCurrent']),
new TwigFunction('section_setting', [$this, 'getSectionSetting']),
new TwigFunction('section_setting_current', [$this, 'getSectionSettingCurrent']),
new TwigFunction('visitor_current', [$this, 'getVisitorCurrent']),
);
}

@@ -120,7 +121,8 @@ class StoreTwigExtension extends AbstractExtension
return $this->orderShopBuilder->createIfNotExist(
$this->sectionResolver->getCurrent(),
$this->security->getUser(),
$this->visitorResolver->getCurrent()
$this->visitorResolver->getCurrent(),
true
);
}

@@ -184,4 +186,9 @@ class StoreTwigExtension extends AbstractExtension
//TODO mettre à jour une fois les repo fait
return array();
}

public function getVisitorCurrent()
{
return $this->visitorResolver->getCurrent();
}
}

Loading…
Откажи
Сачувај