Browse Source

Tri produits par catégories

master
Fab 4 years ago
parent
commit
20fd88fe18
7 changed files with 111 additions and 4 deletions
  1. +1
    -1
      ShopBundle/Controller/Backend/AdminController.php
  2. +98
    -0
      ShopBundle/Controller/Backend/ProductFamilyController.php
  3. +0
    -1
      ShopBundle/EventSubscriber/InitializeEventSubscriber.php
  4. +0
    -1
      ShopBundle/Listener/MailLoggerListener.php
  5. +3
    -0
      ShopBundle/Repository/ProductFamilyRepository.php
  6. +1
    -1
      ShopBundle/Resources/translations/lcshop.fr.yaml
  7. +8
    -0
      ShopBundle/Resources/views/backend/productcategory/action_sort_productfamily.html.twig

+ 1
- 1
ShopBundle/Controller/Backend/AdminController.php View File

$latsPos = $elm['position']; $latsPos = $elm['position'];


} }
dump($latsPos);
//die(); //die();
//to do récupérer les élements hors ligne et incrémenter position //to do récupérer les élements hors ligne et incrémenter position
/*foreach ($repo->findBy(array('status'=> false)) as $offlineEntity) { /*foreach ($repo->findBy(array('status'=> false)) as $offlineEntity) {

+ 98
- 0
ShopBundle/Controller/Backend/ProductFamilyController.php View File

use Lc\ShopBundle\Context\ProductFamilyInterface; use Lc\ShopBundle\Context\ProductFamilyInterface;
use Lc\ShopBundle\Context\ReductionCatalogInterface; use Lc\ShopBundle\Context\ReductionCatalogInterface;
use Lc\ShopBundle\Context\TaxRateInterface; use Lc\ShopBundle\Context\TaxRateInterface;
use Lc\ShopBundle\Form\Backend\Common\AbstractEditPositionType;
use Lc\ShopBundle\Form\Backend\Common\ReductionCatalogType; use Lc\ShopBundle\Form\Backend\Common\ReductionCatalogType;
use Lc\ShopBundle\Form\Backend\ProductFamily\ProductType; use Lc\ShopBundle\Form\Backend\ProductFamily\ProductType;
use Lc\ShopBundle\Model\ProductFamily; use Lc\ShopBundle\Model\ProductFamily;






//hack utilisé pour filter sur les catégories lors du tri des produits par sous cat
//A améliorer à l'occas
protected function createListQueryBuilder($entityClass, $sortDirection, $sortField = null, $dqlFilter = null)
{
$productCategoryId = false;

if (isset($dqlFilter['productCategoryId'])) $productCategoryId = $dqlFilter['productCategoryId'];
if(isset($dqlFilter['filter']))$dqlFilter = $dqlFilter['filter'];

$queryBuilder = parent::createListQueryBuilder($entityClass, $sortDirection, $sortField, $dqlFilter);

$queryBuilder->leftJoin('entity.productCategories', 'product_categories');

if ($productCategoryId) {
$queryBuilder->andWhere('product_categories.id = :cat');
$queryBuilder->setParameter('cat', $productCategoryId);
}

return $queryBuilder;
}

public function sortByProductCategoryAction(){
$this->dispatch(EasyAdminEvents::PRE_LIST);
$entity = null;

//Replace this with query builder function, do not use finAll of easyAdmin
if ($this->request->query->get('productCategoryId')) {
if(!is_array($this->entity['list']['dql_filter'])) {
$this->entity['list']['dql_filter'] = array('filter' => $this->entity['list']['dql_filter']);
}
$this->entity['list']['dql_filter']['productCategoryId'] = $this->request->query->get('productCategoryId');
$easyadmin = $this->request->attributes->get('easyadmin');
$entity = $easyadmin['item'];
}else{
throw new \ErrorException('Action impossible') ;
}

if ($this->entity['list']['dql_filter']['filter']) $this->entity['list']['dql_filter']['filter'] .= sprintf(' AND entity.status = 1');
else $this->entity['list']['dql_filter']['filter'] .= sprintf(' entity.status = 1');

$fields = $this->entity['list']['fields'];

$paginator = $this->findAll($this->entity['class'], $this->request->query->get('page', 1), 500, 'position', 'asc', $this->entity['list']['dql_filter']);

$this->dispatch(EasyAdminEvents::POST_LIST, ['paginator' => $paginator]);

$positionForm = $this->createFormBuilder(array('entities', $paginator->getCurrentPageResults()))
->add('entities', CollectionType::class, array(
'required' => true,
'allow_add' => true,
'entry_type' => AbstractEditPositionType::class,
))
->getForm();

$positionForm->handleRequest($this->request);

if ($positionForm->isSubmitted() && $positionForm->isValid()) {
$class = $this->entity['class'];
$repo = $this->em->getRepository($class);

$latsPos = 0;
foreach ($positionForm->get('entities')->getData() as $elm) {
$this->dispatch(EasyAdminEvents::PRE_UPDATE, ['entity' => $entity]);
$entity = $repo->find($elm['id']);
$entity->setPosition($elm['position']);
$this->em->persist($entity);
$this->dispatch(EasyAdminEvents::POST_UPDATE, ['entity' => $entity]);
$latsPos = $elm['position'];

}

//die();
//to do récupérer les élements hors ligne et incrémenter position
/*foreach ($repo->findBy(array('status'=> false)) as $offlineEntity) {
$latsPos++;
$offlineEntity->setPosition($latsPos);
$this->em->persist($offlineEntity);
}*/
$this->em->flush();

$this->addFlash('success', 'Position modifié', array(), 'mweb');

return $this->redirectToReferrer();

}

$parameters = [
'paginator' => $paginator,
'fields' => $fields,
'batch_form' => $this->createBatchForm($this->entity['name'])->createView(),
'delete_form_template' => $this->createDeleteForm($this->entity['name'], '__id__')->createView(),
'postion_form' => $positionForm->createView(),
'entity' => $entity,
'sortable' => true
];
return $this->executeDynamicMethod('render<EntityName>Template', ['sortable', "@LcShop/backend/default/sortable.html.twig", $parameters]);
}
} }



+ 0
- 1
ShopBundle/EventSubscriber/InitializeEventSubscriber.php View File



public function postInitialize(GenericEvent $event) public function postInitialize(GenericEvent $event)
{ {
dump($event);
$request = $event->getArgument('request'); $request = $event->getArgument('request');


if($request->query->get('hubredirection')){ if($request->query->get('hubredirection')){

+ 0
- 1
ShopBundle/Listener/MailLoggerListener.php View File

: void : void
{ {


dump('ncnnc');
$level = $this->getLogLevel($evt); $level = $this->getLogLevel($evt);
$message = $evt->getMessage(); $message = $evt->getMessage();



+ 3
- 0
ShopBundle/Repository/ProductFamilyRepository.php View File

$query->innerJoin('e.products', 'pfp'); $query->innerJoin('e.products', 'pfp');
$query->addSelect('pfp') ; $query->addSelect('pfp') ;


$query->orderBy('e.position', 'ASC');

return $query ; return $query ;
} }


$query->setParameter('category', $category->getId()); $query->setParameter('category', $category->getId());


$query->andWhere('e.status = 1'); $query->andWhere('e.status = 1');
$query->orderBy('e.position', 'ASC');


return $query->getQuery()->getResult() ; return $query->getQuery()->getResult() ;
} }

+ 1
- 1
ShopBundle/Resources/translations/lcshop.fr.yaml View File

send: Envoyer send: Envoyer
duplicate: Dupliquer duplicate: Dupliquer
duplicateOtherHub: Dupliquer sur un autre hub duplicateOtherHub: Dupliquer sur un autre hub
sortProductFamily: Trier les produits de cette catégorie
group: group:
main: Général main: Général
address: Adresse address: Adresse

+ 8
- 0
ShopBundle/Resources/views/backend/productcategory/action_sort_productfamily.html.twig View File


{% if item.getChildrens()|length == 0 %}
<a class="btn {{ is_dropdown|default(false) ? 'dropdown-item' }} {{ action.css_class|default('btn-default') }}" data-toggle="tooltip"
title="{{ action.label|trans(arguments = trans_parameters|merge({ '%entity_id%': item_id }), domain = translation_domain) }}"
href="{{ path('easyadmin', {action: 'sortByProductCategory', entity: 'ProductFamily', productCategoryId: item.id, referer: app.request.requestUri|url_encode }) }}" target="{{ action.target }}">
{%- if action.icon %}<i class="fa fa-fw fa-{{ action.icon }}"></i> {% endif -%}
</a>
{% endif %}

Loading…
Cancel
Save