Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

73 linhas
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. if ($this->getRequestCrudAction() === ActionDefinition::SORT) {
  19. $crud->setDefaultSort(['position' => 'ASC']);
  20. } else {
  21. $crud->setDefaultSort(['id' => 'DESC']);
  22. }
  23. return $crud;
  24. }
  25. public function getRepositoryQuery(): RepositoryQueryInterface
  26. {
  27. return $this->get(ProductFamilyContainer::class)->getRepositoryQuery();
  28. }
  29. public function createEntity(string $entityFqcn)
  30. {
  31. return $this->getProductFamilyContainer()
  32. ->getFactory()
  33. ->create($this->getMerchantCurrent());
  34. }
  35. public function configureResponseParameters(KeyValueStore $responseParameters): KeyValueStore
  36. {
  37. $responseParameters = parent::configureResponseParameters($responseParameters);
  38. $productFamiliesDto = [];
  39. $productFamilies = [];
  40. if ($responseParameters->get('entities')) {
  41. $productFamiliesDto = $responseParameters->get('entities');
  42. } elseif ($responseParameters->get('entity')) {
  43. $productFamiliesDto = [$responseParameters->get('entity')];
  44. }
  45. foreach ($productFamiliesDto as $productFamilyDto) {
  46. $productFamilies[] = $productFamilyDto->getInstance();
  47. }
  48. if($responseParameters->get('pageName') != 'new') {
  49. $this->getProductFamilyContainer()->getStore()
  50. ->setSection($this->getSectionCurrentDefault())
  51. ->getWithReductions($productFamilies);
  52. }
  53. // affichage du filtre sur section
  54. $responseParameters->set('display_switch_section', true);
  55. return $responseParameters;
  56. }
  57. }