Browse Source

Refactoring frontend

packProduct
Guillaume 3 years ago
parent
commit
c022cddb73
11 changed files with 177 additions and 70 deletions
  1. +9
    -1
      Container/Section/SectionContainer.php
  2. +92
    -0
      Controller/Address/AddressApiController.php
  3. +0
    -14
      Controller/AdminControllerTrait.php
  4. +2
    -2
      Controller/ControllerTrait.php
  5. +13
    -37
      Controller/Setting/SettingAdminController.php
  6. +0
    -1
      Model/Order/OrderShopModel.php
  7. +11
    -0
      Repository/Order/OrderShopRepositoryQuery.php
  8. +9
    -4
      Repository/Order/OrderShopStore.php
  9. +36
    -8
      Repository/Product/ProductFamilyStore.php
  10. +1
    -1
      Repository/SectionStoreTrait.php
  11. +4
    -2
      Solver/Section/SectionSolver.php

+ 9
- 1
Container/Section/SectionContainer.php View File

use Lc\CaracoleBundle\Repository\Section\SectionRepositoryQuery; use Lc\CaracoleBundle\Repository\Section\SectionRepositoryQuery;
use Lc\CaracoleBundle\Repository\Section\SectionStore; use Lc\CaracoleBundle\Repository\Section\SectionStore;
use Lc\CaracoleBundle\Resolver\SectionResolver; use Lc\CaracoleBundle\Resolver\SectionResolver;
use Lc\SovBundle\Solver\Setting\SettingSolver;
use Lc\CaracoleBundle\Solver\Section\SectionSolver;


class SectionContainer class SectionContainer
{ {
protected SectionFactory $factory; protected SectionFactory $factory;
protected SectionSolver $solver;
protected SectionResolver $resolver; protected SectionResolver $resolver;
protected SectionRepositoryQuery $repositoryQuery; protected SectionRepositoryQuery $repositoryQuery;
protected SectionStore $store; protected SectionStore $store;


public function __construct( public function __construct(
SectionFactory $factory, SectionFactory $factory,
SectionSolver $solver,
SectionResolver $resolver, SectionResolver $resolver,
SectionRepositoryQuery $repositoryQuery, SectionRepositoryQuery $repositoryQuery,
SectionStore $store SectionStore $store
) { ) {
$this->factory = $factory; $this->factory = $factory;
$this->solver = $solver;
$this->resolver = $resolver; $this->resolver = $resolver;
$this->repositoryQuery = $repositoryQuery; $this->repositoryQuery = $repositoryQuery;
$this->store = $store; $this->store = $store;
return $this->factory; return $this->factory;
} }


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

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

+ 92
- 0
Controller/Address/AddressApiController.php View File

<?php

namespace Lc\CaracoleBundle\Controller\Address;

use Lc\CaracoleBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Routing\Annotation\Route;

class AddressApiController extends AbstractController
{
/**
* @Route("/api-cities", name="api_cities")
*/
public function cities(Request $request): JsonResponse
{
$citiesComponent = $this->getComponentContainer()->getCitiesComponent();
$term = $request->get('term');
$context = $request->get('context');
$data = [
'boost' => 'population',
];

if (strlen($term) == 5 && is_numeric($term)) {
$data['codePostal'] = $term;
} else {
$data['nom'] = $term;
}

$result = array_merge(
json_decode($citiesComponent->callCitiesApi('get', 'communes', array_merge($data, ['codeRegion' => 27]))),
json_decode($citiesComponent->callCitiesApi('get', 'communes', array_merge($data, ['codeRegion' => 44])))
);

$return = [];
foreach ($result as $city) {
$codesPostaux = $city->codesPostaux;

if ($context == 'frontend') {
$label = '<span class="city">' . $city->nom . '</span> <span class="zip">' . $codesPostaux[0] . '</span>';
} else {
$label = $city->nom . ' - ' . $codesPostaux[0];
}

$return[] = [
'label' => $label,
'city' => $city->nom,
'value' => $city->code
];
}

if ($context == 'frontend') {
$return = [
'items' => $return
];
}

return new JsonResponse($return);
}

/**
* @Route("/api-addresses", name="api_addresses")
*/
public function addresses(Request $request): JsonResponse
{
$citiesComponent = $this->getComponentContainer()->getCitiesComponent();
$return = [];
$address = $request->get('address');
$context = $request->get('context');
$results = $citiesComponent->callAddressApi($address);

foreach ($results as $result) {
if ($result->getStreetNumber() && strlen($result->getStreetNumber()) > 0) {
$streetNameNumber = $result->getStreetNumber() . ' ' . $result->getStreetName();
$return[] = [
'label' => $streetNameNumber,
'value' => $streetNameNumber,
'latitude' => $result->getCoordinates()->getLatitude(),
'longitude' => $result->getCoordinates()->getLongitude()
];
}
}

if ($context == 'frontend') {
$return = [
'items' => $return
];
}

return new JsonResponse($return);
}
}

+ 0
- 14
Controller/AdminControllerTrait.php View File

use Lc\CaracoleBundle\Doctrine\Extension\FilterMerchantInterface; use Lc\CaracoleBundle\Doctrine\Extension\FilterMerchantInterface;
use Lc\CaracoleBundle\Doctrine\Extension\FilterMultipleMerchantsInterface; use Lc\CaracoleBundle\Doctrine\Extension\FilterMultipleMerchantsInterface;
use Lc\CaracoleBundle\Doctrine\Extension\FilterSectionInterface; use Lc\CaracoleBundle\Doctrine\Extension\FilterSectionInterface;
use Lc\CaracoleBundle\Factory\User\UserMerchantFactory;
use Lc\CaracoleBundle\Form\Merchant\DuplicateToOtherMerchantFormType; use Lc\CaracoleBundle\Form\Merchant\DuplicateToOtherMerchantFormType;
use Lc\CaracoleBundle\Form\Section\DuplicateToOtherSectionFormType; use Lc\CaracoleBundle\Form\Section\DuplicateToOtherSectionFormType;
use Lc\CaracoleBundle\Repository\Reduction\ReductionCatalogStore;
use Lc\CaracoleBundle\Resolver\MerchantResolver; use Lc\CaracoleBundle\Resolver\MerchantResolver;
use Lc\CaracoleBundle\Resolver\SectionResolver; use Lc\CaracoleBundle\Resolver\SectionResolver;
use EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto; use EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto;
use EasyCorp\Bundle\EasyAdminBundle\Dto\SearchDto; use EasyCorp\Bundle\EasyAdminBundle\Dto\SearchDto;
use Lc\SovBundle\Component\EntityComponent; use Lc\SovBundle\Component\EntityComponent;
use Lc\SovBundle\Container\File\FileContainer;
use Lc\SovBundle\Container\Newsletter\NewsletterContainer;
use Lc\SovBundle\Container\Reminder\ReminderContainer;
use Lc\SovBundle\Container\Setting\SiteSettingContainer;
use Lc\SovBundle\Container\Site\NewsContainer;
use Lc\SovBundle\Container\Site\PageContainer;
use Lc\SovBundle\Container\Site\SiteContainer;
use Lc\SovBundle\Container\Ticket\TicketContainer;
use Lc\SovBundle\Container\Ticket\TicketMessageContainer;
use Lc\SovBundle\Container\User\GroupUserContainer;
use Lc\SovBundle\Container\User\UserContainer;
use Lc\SovBundle\Factory\User\UserFactory;
use Lc\SovBundle\Translation\TranslatorAdmin; use Lc\SovBundle\Translation\TranslatorAdmin;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;



+ 2
- 2
Controller/ControllerTrait.php View File

); );
} }


public function getMerchantSettingCurrent($settingName)
public function getMerchantSettingCurrent(string $settingName)
{ {
return $this->getSettingValue($this->getMerchantCurrent(), $settingName); return $this->getSettingValue($this->getMerchantCurrent(), $settingName);
} }


public function getSectionSettingCurrent($settingName)
public function getSectionSettingCurrent(string $settingName)
{ {
return $this->getSettingValue($this->getCurrentSection(), $settingName); return $this->getSettingValue($this->getCurrentSection(), $settingName);
} }

+ 13
- 37
Controller/Setting/SettingAdminController.php View File



use Lc\CaracoleBundle\Container\Setting\MerchantSettingContainer; use Lc\CaracoleBundle\Container\Setting\MerchantSettingContainer;
use Lc\CaracoleBundle\Container\Setting\SectionSettingContainer; use Lc\CaracoleBundle\Container\Setting\SectionSettingContainer;
use Lc\CaracoleBundle\Controller\ControllerTrait;
use Lc\CaracoleBundle\Resolver\MerchantResolver; use Lc\CaracoleBundle\Resolver\MerchantResolver;
use Lc\CaracoleBundle\Resolver\SectionResolver; use Lc\CaracoleBundle\Resolver\SectionResolver;
use Lc\SovBundle\Container\Setting\SiteSettingContainer; use Lc\SovBundle\Container\Setting\SiteSettingContainer;


class SettingAdminController extends SovSettingController class SettingAdminController extends SovSettingController
{ {
protected MerchantResolver $merchantResolver;
protected SectionResolver $sectionResolver;
protected MerchantSettingContainer $merchantSettingContainer;
protected SectionSettingContainer $sectionSettingContainer;
protected SiteContainer $siteContainer;
protected SiteSettingContainer $siteSettingContainer;
protected TranslatorAdmin $translatorAdmin;

public function __construct(
EntityManagerInterface $entityManager,
MerchantResolver $merchantResolver,
SectionResolver $sectionResolver,
MerchantSettingContainer $merchantSettingContainer,
SectionSettingContainer $sectionSettingContainer,
SiteContainer $siteContainer,
SiteSettingContainer $siteSettingContainer,
TranslatorAdmin $translatorAdmin
) {
parent::__construct($entityManager);
$this->merchantResolver = $merchantResolver;
$this->sectionResolver = $sectionResolver;
$this->merchantSettingContainer = $merchantSettingContainer;
$this->sectionSettingContainer = $sectionSettingContainer;
$this->siteContainer = $siteContainer;
$this->siteSettingContainer = $siteSettingContainer;
$this->translatorAdmin = $translatorAdmin;
}
use ControllerTrait;


/** /**
* @Route("/admin/setting/merchant", name="carac_admin_setting_merchant") * @Route("/admin/setting/merchant", name="carac_admin_setting_merchant")
$type $type
) { ) {
$entity = null; $entity = null;
$entityManager = $this->entityManager;
$entityManager = $this->getEntityManager();


if ($type == 'merchant') { if ($type == 'merchant') {
$resolver = $this->merchantResolver;
$resolver = $this->getMerchantContainer()->getResolver();
$formClass = MerchantSettingsFormType::class; $formClass = MerchantSettingsFormType::class;
$settingDefinition = $this->merchantSettingContainer->getDefinition();
$settingDefinition = $this->getMerchantSettingContainer()->getDefinition();
} elseif ($type == 'section') { } elseif ($type == 'section') {
$resolver = $this->sectionResolver;
$resolver = $this->getSectionContainer()->getResolver();
$formClass = SectionSettingsFormType::class; $formClass = SectionSettingsFormType::class;
$settingDefinition = $this->sectionSettingContainer->getDefinition();
$settingDefinition = $this->getSectionSettingContainer()->getDefinition();
} }


$entity = $resolver->getCurrent(); $entity = $resolver->getCurrent();
$entityManager->update($entity); $entityManager->update($entity);
$entityManager->flush(); $entityManager->flush();


$this->addFlash('success', $this->get(TranslatorAdmin::class)->transFlashMessage('settings_saved'));
$this->addFlash('success', $this->getTranslatorAdmin()->transFlashMessage('settings_saved'));
} }


return $this->render( return $this->render(
/** /**
* @Route("/admin/setting/site2", name="carac_admin_setting_site") * @Route("/admin/setting/site2", name="carac_admin_setting_site")
*/ */
public function manageGlobal(Request $request, EntityManagerInterface $entityManager)
public function manageGlobal(Request $request)
{ {
$site = $this->siteContainer->getStore()->getOneByDevAlias('default');
$entityManager = $this->getEntityManager();
$site = $this->getSiteContainer()->getStore()->getOneByDevAlias('default');
$form = $this->createForm(SiteSettingsFormType::class, $site); $form = $this->createForm(SiteSettingsFormType::class, $site);


$form->handleRequest($request); $form->handleRequest($request);
$entityManager->update($site); $entityManager->update($site);
$entityManager->flush(); $entityManager->flush();


$this->addFlash('success', $this->translatorAdmin->transFlashMessage('settings_saved'));
$this->addFlash('success', $this->getTranslatorAdmin()->transFlashMessage('settings_saved'));
} }


return $this->render( return $this->render(
'@LcCaracole/admin/setting/edit_site.html.twig', '@LcCaracole/admin/setting/edit_site.html.twig',
[ [
'setting_definition' => $this->siteSettingContainer->getDefinition(),
'setting_definition' => $this->getSiteSettingContainer()->getDefinition(),
'form' => $form->createView() 'form' => $form->createView()
] ]
); );

+ 0
- 1
Model/Order/OrderShopModel.php View File

abstract class OrderShopModel extends AbstractLightEntity implements FilterSectionInterface, OrderShopInterface abstract class OrderShopModel extends AbstractLightEntity implements FilterSectionInterface, OrderShopInterface
{ {



const DELIVERY_TYPE_HOME = 'home'; const DELIVERY_TYPE_HOME = 'home';
const DELIVERY_TYPE_POINTSALE = 'point-sale'; const DELIVERY_TYPE_POINTSALE = 'point-sale';



+ 11
- 0
Repository/Order/OrderShopRepositoryQuery.php View File

return $this->addSelect('orcart'); return $this->addSelect('orcart');
} }


public function joinOrderProduct(): self
{
if (!$this->isJoinOrderProduct) {
$this->isJoinOrderProduct = true;

return $this
->innerJoin('.orderProducts', 'op');
}
return $this;
}

public function joinOrderReductionCredits(): self public function joinOrderReductionCredits(): self
{ {
if (!$this->isJoinOrderReductionCredits) { if (!$this->isJoinOrderReductionCredits) {

+ 9
- 4
Repository/Order/OrderShopStore.php View File



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

return $query; return $query;
} }


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


{ {
$query = $this->createDefaultQuery($query); $query = $this->createDefaultQuery($query);
$query->selectCount(); $query->selectCount();
$this->applyGetByFilters($query);
$this->applyGetByFilters($params, $query);
return $query->count(); return $query->count();
} }


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


$this->applyGetByFilters($query);
$this->applyGetByFilters($params, $query);


$orderShops = $query->find(); $orderShops = $query->find();


$this->orderShopSolver->mergeComplentaryOrderShops($orderShop); $this->orderShopSolver->mergeComplentaryOrderShops($orderShop);
} }
} }

return $orderShops; return $orderShops;
} }


protected function applyGetByFilters($query)
protected function applyGetByFilters(array $params, $query)
{ {
if (isset($params['isMerchantOnline'])) { if (isset($params['isMerchantOnline'])) {
$query->filterIsMerchantOnline(); $query->filterIsMerchantOnline();

+ 36
- 8
Repository/Product/ProductFamilyStore.php View File

} }


public function filtersDefault(RepositoryQueryInterface $query): RepositoryQueryInterface public function filtersDefault(RepositoryQueryInterface $query): RepositoryQueryInterface

{ {
$query->filterBySection($this->section); $query->filterBySection($this->section);
return $query; return $query;
return $query; return $query;
} }


public function getByParentCategory(
ProductCategoryInterface $parentCategory,
$user = null,
$query = null
) {
$productFamiliesArray = [];

foreach ($parentCategory->getChildrens() as $i => $category) {
$productFamiliesCategory = $this->getByCategory($category, $query);
foreach ($productFamiliesCategory as $productFamily) {
$productFamiliesArray[$productFamily->getId()] = $productFamily;
}
}

return $this->getWithReductions($productFamiliesArray, $user, true);
}

// getProductFamiliesByCategory // getProductFamiliesByCategory
public function getByCategory(ProductCategoryInterface $productCategory, $query = null)
{
public function getByCategory(
ProductCategoryInterface $productCategory,
$query = null
) {
$query = $this->createDefaultQuery($query); $query = $this->createDefaultQuery($query);


$query $query
// getProductFamiliesOnDiscount // getProductFamiliesOnDiscount
public function getDiscount($user = null, $organizeByParentCategory = true, $query = null) public function getDiscount($user = null, $organizeByParentCategory = true, $query = null)
{ {
return $this->getWithReductions($this->getOnline($query), $user, false, $organizeByParentCategory);
return $this->getWithReductions($this->getOnline($query), $user, false, $organizeByParentCategory, true);
} }


// getProductFamiliesFavorites // getProductFamiliesFavorites
public function getFavorite($user = null, $organizeByParentCategory = true, $query = null) public function getFavorite($user = null, $organizeByParentCategory = true, $query = null)
{ {
if ($user) { if ($user) {
return $this->getWithReductions($user->getFavoriteProductFamilies(), $user, false, $organizeByParentCategory);
return $this->getWithReductions(
$user->getFavoriteProductFamilies(),
$user,
false,
$organizeByParentCategory
);
} }


return []; return [];
} }


// findByTerms // findByTerms
public function getByTerms($terms, $maxResults = false, $organizeByParentCategory = false, $user = null, $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->groupBy('id'); $query->groupBy('id');


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



+ 1
- 1
Repository/SectionStoreTrait.php View File



trait SectionStoreTrait trait SectionStoreTrait
{ {
protected SectionInterface $section;
protected ?SectionInterface $section = null;


public function setSection(SectionInterface $section):self public function setSection(SectionInterface $section):self
{ {

+ 4
- 2
Solver/Section/SectionSolver.php View File



namespace Lc\CaracoleBundle\Solver\Section; namespace Lc\CaracoleBundle\Solver\Section;


use Lc\CaracoleBundle\Model\Section\SectionInterface;

class SectionSolver class SectionSolver
{ {
// @TODO : à voir si pertinent // @TODO : à voir si pertinent
public function getNewsletter()
public function getNewsletter(SectionInterface $section)
{ {
$newsletters = $this->getNewsletters();
$newsletters = $section->getNewsletters();


foreach ($newsletters as $newsletter) { foreach ($newsletters as $newsletter) {
if ($newsletter->getIsMain()) { if ($newsletter->getIsMain()) {

Loading…
Cancel
Save