Bläddra i källkod

Tri produits par catégories

master
Fab 4 år sedan
förälder
incheckning
20fd88fe18
7 ändrade filer med 111 tillägg och 4 borttagningar
  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 Visa fil

@@ -350,7 +350,7 @@ class AdminController extends EasyAdminController
$latsPos = $elm['position'];

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

+ 98
- 0
ShopBundle/Controller/Backend/ProductFamilyController.php Visa fil

@@ -12,6 +12,7 @@ use Lc\ShopBundle\Context\ProductCategoryInterface;
use Lc\ShopBundle\Context\ProductFamilyInterface;
use Lc\ShopBundle\Context\ReductionCatalogInterface;
use Lc\ShopBundle\Context\TaxRateInterface;
use Lc\ShopBundle\Form\Backend\Common\AbstractEditPositionType;
use Lc\ShopBundle\Form\Backend\Common\ReductionCatalogType;
use Lc\ShopBundle\Form\Backend\ProductFamily\ProductType;
use Lc\ShopBundle\Model\ProductFamily;
@@ -439,5 +440,102 @@ class ProductFamilyController extends AdminController



//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 Visa fil

@@ -35,7 +35,6 @@ class InitializeEventSubscriber implements EventSubscriberInterface

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

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

+ 0
- 1
ShopBundle/Listener/MailLoggerListener.php Visa fil

@@ -36,7 +36,6 @@ class MailLoggerUtil implements Swift_Events_SendListener
: void
{

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


+ 3
- 0
ShopBundle/Repository/ProductFamilyRepository.php Visa fil

@@ -27,6 +27,8 @@ class ProductFamilyRepository extends BaseRepository implements DefaultRepositor
$query->innerJoin('e.products', 'pfp');
$query->addSelect('pfp') ;

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

return $query ;
}

@@ -61,6 +63,7 @@ class ProductFamilyRepository extends BaseRepository implements DefaultRepositor
$query->setParameter('category', $category->getId());

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

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

+ 1
- 1
ShopBundle/Resources/translations/lcshop.fr.yaml Visa fil

@@ -13,7 +13,7 @@ list:
send: Envoyer
duplicate: Dupliquer
duplicateOtherHub: Dupliquer sur un autre hub
sortProductFamily: Trier les produits de cette catégorie
group:
main: Général
address: Adresse

+ 8
- 0
ShopBundle/Resources/views/backend/productcategory/action_sort_productfamily.html.twig Visa fil

@@ -0,0 +1,8 @@

{% 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 %}

Laddar…
Avbryt
Spara