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

@@ -6,22 +6,25 @@ use Lc\CaracoleBundle\Factory\Section\SectionFactory;
use Lc\CaracoleBundle\Repository\Section\SectionRepositoryQuery;
use Lc\CaracoleBundle\Repository\Section\SectionStore;
use Lc\CaracoleBundle\Resolver\SectionResolver;
use Lc\SovBundle\Solver\Setting\SettingSolver;
use Lc\CaracoleBundle\Solver\Section\SectionSolver;

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

public function __construct(
SectionFactory $factory,
SectionSolver $solver,
SectionResolver $resolver,
SectionRepositoryQuery $repositoryQuery,
SectionStore $store
) {
$this->factory = $factory;
$this->solver = $solver;
$this->resolver = $resolver;
$this->repositoryQuery = $repositoryQuery;
$this->store = $store;
@@ -32,6 +35,11 @@ class SectionContainer
return $this->factory;
}

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

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

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

@@ -0,0 +1,92 @@
<?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

@@ -48,27 +48,13 @@ use Lc\CaracoleBundle\Container\User\VisitorContainer;
use Lc\CaracoleBundle\Doctrine\Extension\FilterMerchantInterface;
use Lc\CaracoleBundle\Doctrine\Extension\FilterMultipleMerchantsInterface;
use Lc\CaracoleBundle\Doctrine\Extension\FilterSectionInterface;
use Lc\CaracoleBundle\Factory\User\UserMerchantFactory;
use Lc\CaracoleBundle\Form\Merchant\DuplicateToOtherMerchantFormType;
use Lc\CaracoleBundle\Form\Section\DuplicateToOtherSectionFormType;
use Lc\CaracoleBundle\Repository\Reduction\ReductionCatalogStore;
use Lc\CaracoleBundle\Resolver\MerchantResolver;
use Lc\CaracoleBundle\Resolver\SectionResolver;
use EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto;
use EasyCorp\Bundle\EasyAdminBundle\Dto\SearchDto;
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 Symfony\Component\HttpFoundation\Response;


+ 2
- 2
Controller/ControllerTrait.php View File

@@ -88,12 +88,12 @@ trait ControllerTrait
);
}

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

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

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

@@ -4,6 +4,7 @@ namespace Lc\CaracoleBundle\Controller\Setting;

use Lc\CaracoleBundle\Container\Setting\MerchantSettingContainer;
use Lc\CaracoleBundle\Container\Setting\SectionSettingContainer;
use Lc\CaracoleBundle\Controller\ControllerTrait;
use Lc\CaracoleBundle\Resolver\MerchantResolver;
use Lc\CaracoleBundle\Resolver\SectionResolver;
use Lc\SovBundle\Container\Setting\SiteSettingContainer;
@@ -19,33 +20,7 @@ use Symfony\Component\Routing\Annotation\Route;

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")
@@ -70,16 +45,16 @@ class SettingAdminController extends SovSettingController
$type
) {
$entity = null;
$entityManager = $this->entityManager;
$entityManager = $this->getEntityManager();

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

$entity = $resolver->getCurrent();
@@ -93,7 +68,7 @@ class SettingAdminController extends SovSettingController
$entityManager->update($entity);
$entityManager->flush();

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

return $this->render(
@@ -111,9 +86,10 @@ class SettingAdminController extends SovSettingController
/**
* @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->handleRequest($request);
@@ -122,13 +98,13 @@ class SettingAdminController extends SovSettingController
$entityManager->update($site);
$entityManager->flush();

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

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

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

@@ -24,7 +24,6 @@ use Lc\SovBundle\Model\User\UserInterface;
abstract class OrderShopModel extends AbstractLightEntity implements FilterSectionInterface, OrderShopInterface
{


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


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

@@ -145,6 +145,17 @@ class OrderShopRepositoryQuery extends AbstractRepositoryQuery
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
{
if (!$this->isJoinOrderReductionCredits) {

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

@@ -81,12 +81,16 @@ class OrderShopStore extends AbstractStore

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

return $query;
}

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

@@ -311,7 +315,7 @@ class OrderShopStore extends AbstractStore
{
$query = $this->createDefaultQuery($query);
$query->selectCount();
$this->applyGetByFilters($query);
$this->applyGetByFilters($params, $query);
return $query->count();
}

@@ -320,7 +324,7 @@ class OrderShopStore extends AbstractStore
{
$query = $this->createDefaultQuery($query);

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

$orderShops = $query->find();

@@ -329,10 +333,11 @@ class OrderShopStore extends AbstractStore
$this->orderShopSolver->mergeComplentaryOrderShops($orderShop);
}
}

return $orderShops;
}

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

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

@@ -31,7 +31,6 @@ class ProductFamilyStore extends AbstractStore
}

public function filtersDefault(RepositoryQueryInterface $query): RepositoryQueryInterface

{
$query->filterBySection($this->section);
return $query;
@@ -44,9 +43,28 @@ class ProductFamilyStore extends AbstractStore
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
public function getByCategory(ProductCategoryInterface $productCategory, $query = null)
{
public function getByCategory(
ProductCategoryInterface $productCategory,
$query = null
) {
$query = $this->createDefaultQuery($query);

$query
@@ -87,22 +105,32 @@ class ProductFamilyStore extends AbstractStore
// getProductFamiliesOnDiscount
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
public function getFavorite($user = null, $organizeByParentCategory = true, $query = null)
{
if ($user) {
return $this->getWithReductions($user->getFavoriteProductFamilies(), $user, false, $organizeByParentCategory);
return $this->getWithReductions(
$user->getFavoriteProductFamilies(),
$user,
false,
$organizeByParentCategory
);
}

return [];
}

// 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->filterIsOnline();
@@ -110,7 +138,7 @@ class ProductFamilyStore extends AbstractStore

$query->groupBy('id');

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


+ 1
- 1
Repository/SectionStoreTrait.php View File

@@ -6,7 +6,7 @@ use Lc\CaracoleBundle\Model\Section\SectionInterface;

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

public function setSection(SectionInterface $section):self
{

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

@@ -2,12 +2,14 @@

namespace Lc\CaracoleBundle\Solver\Section;

use Lc\CaracoleBundle\Model\Section\SectionInterface;

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

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

Loading…
Cancel
Save