You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
2.4KB

  1. <?php
  2. namespace Lc\CaracoleBundle\Controller\Product;
  3. use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
  4. use EasyCorp\Bundle\EasyAdminBundle\Config\KeyValueStore;
  5. use EasyCorp\Bundle\EasyAdminBundle\Context\AdminContext;
  6. use Lc\CaracoleBundle\Container\Order\OrderShopContainer;
  7. use Lc\CaracoleBundle\Container\Product\ProductFamilyContainer;
  8. use Lc\CaracoleBundle\Controller\AbstractAdminController;
  9. use Lc\CaracoleBundle\Definition\ActionDefinition;
  10. use Lc\CaracoleBundle\Resolver\SectionResolver;
  11. use Lc\SovBundle\Repository\RepositoryQueryInterface;
  12. use Symfony\Component\HttpFoundation\Response;
  13. abstract class ProductFamilyAdminController extends AbstractAdminController
  14. {
  15. public function configureCrud(Crud $crud): Crud
  16. {
  17. $crud = parent::configureCrud($crud);
  18. $crud->setPaginatorPageSize(100);
  19. if ($this->getRequestCrudAction() === ActionDefinition::SORT) {
  20. $crud->setDefaultSort(['position' => 'ASC']);
  21. } else {
  22. $crud->setDefaultSort(['id' => 'DESC']);
  23. }
  24. return $crud;
  25. }
  26. public function getRepositoryQuery(): RepositoryQueryInterface
  27. {
  28. return $this->get(ProductFamilyContainer::class)->getRepositoryQuery();
  29. }
  30. public function createEntity(string $entityFqcn)
  31. {
  32. return $this->getProductFamilyContainer()
  33. ->getFactory()
  34. ->create($this->getMerchantCurrent());
  35. }
  36. public function configureResponseParameters(KeyValueStore $responseParameters): KeyValueStore
  37. {
  38. $responseParameters = parent::configureResponseParameters($responseParameters);
  39. $productFamiliesDto = [];
  40. $productFamilies = [];
  41. if ($responseParameters->get('entities')) {
  42. $productFamiliesDto = $responseParameters->get('entities');
  43. } elseif ($responseParameters->get('entity')) {
  44. $productFamiliesDto = [$responseParameters->get('entity')];
  45. }
  46. foreach ($productFamiliesDto as $productFamilyDto) {
  47. $productFamilies[] = $productFamilyDto->getInstance();
  48. }
  49. if($responseParameters->get('pageName') != 'new') {
  50. $this->getProductFamilyContainer()->getStore()
  51. ->setSection($this->getSectionCurrentDefault())
  52. ->getWithReductions($productFamilies);
  53. }
  54. // affichage du filtre sur section
  55. $responseParameters->set('display_switch_section', true);
  56. return $responseParameters;
  57. }
  58. }