Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

ProductFamilyAdminController.php 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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\Resolver\SectionResolver;
  10. use Lc\SovBundle\Repository\RepositoryQueryInterface;
  11. use Symfony\Component\HttpFoundation\Response;
  12. abstract class ProductFamilyAdminController extends AbstractAdminController
  13. {
  14. public function configureCrud(Crud $crud): Crud
  15. {
  16. $crud = parent::configureCrud($crud);
  17. $crud->setDefaultSort(['id' => 'DESC']);
  18. return $crud;
  19. }
  20. public function getRepositoryQuery() :RepositoryQueryInterface
  21. {
  22. return $this->get(ProductFamilyContainer::class)->getRepositoryQuery();
  23. }
  24. public function createEntity(string $entityFqcn)
  25. {
  26. return $this->getProductFamilyContainer()
  27. ->getFactory()
  28. ->create($this->getMerchantCurrent());
  29. }
  30. public function configureResponseParameters(KeyValueStore $responseParameters): KeyValueStore
  31. {
  32. $responseParameters = parent::configureResponseParameters($responseParameters);
  33. // affichage du filtre sur section
  34. $responseParameters->set('display_switch_section', true);
  35. return $responseParameters;
  36. }
  37. public function showSalesStatistic(AdminContext $context)
  38. {
  39. $productFamily = $context->getEntity()->getInstance();
  40. $currentSection = $this->get(SectionResolver::class)->getCurrent();
  41. $productsSalesStatistic = $this->get(OrderShopContainer::class)->getBuilder()->getProductsSalesStatistic($currentSection, $productFamily, 16);
  42. $parameters = array(
  43. 'productFamily' => $productFamily,
  44. 'productsSalesStatistic' => $productsSalesStatistic
  45. );
  46. //TODO flashMessages ???
  47. $response['flashMessages'] = [];//$this->utils->getFlashMessages();
  48. $response['data'] = $this->render('@LcCaracole/admin/product/modal/show_products_sales_statistic.html.twig', $parameters)->getContent();
  49. $response['statistics'] = $productsSalesStatistic;
  50. return new Response(json_encode($response));
  51. }
  52. }