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 satır
2.6KB

  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. // affichage du filtre sur section
  39. $responseParameters->set('display_switch_section', true);
  40. return $responseParameters;
  41. }
  42. public function showSalesStatistic(AdminContext $context)
  43. {
  44. $productFamily = $context->getEntity()->getInstance();
  45. $currentSection = $this->get(SectionResolver::class)->getCurrent();
  46. $productsSalesStatistic = $this->get(OrderShopContainer::class)->getBuilder()->getProductsSalesStatistic($currentSection, $productFamily, 16);
  47. $parameters = array(
  48. 'productFamily' => $productFamily,
  49. 'productsSalesStatistic' => $productsSalesStatistic
  50. );
  51. //TODO flashMessages ???
  52. $response['flashMessages'] = [];//$this->utils->getFlashMessages();
  53. $response['data'] = $this->render('@LcCaracole/admin/product/modal/show_products_sales_statistic.html.twig', $parameters)->getContent();
  54. $response['statistics'] = $productsSalesStatistic;
  55. return new Response(json_encode($response));
  56. }
  57. }