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.

68 lines
2.6KB

  1. <?php
  2. namespace Lc\CaracoleBundle\Controller\Product;
  3. use EasyCorp\Bundle\EasyAdminBundle\Config\KeyValueStore;
  4. use EasyCorp\Bundle\EasyAdminBundle\Context\AdminContext;
  5. use Lc\CaracoleBundle\Container\Order\OrderShopContainer;
  6. use Lc\CaracoleBundle\Container\Product\ProductFamilyContainer;
  7. use Lc\CaracoleBundle\Controller\AbstractAdminController;
  8. use Lc\CaracoleBundle\Resolver\SectionResolver;
  9. use Lc\SovBundle\Repository\RepositoryQueryInterface;
  10. use Symfony\Component\HttpFoundation\Response;
  11. abstract class ProductFamilyAdminController extends AbstractAdminController
  12. {
  13. public function getRepositoryQuery() :RepositoryQueryInterface
  14. {
  15. return $this->get(ProductFamilyContainer::class)->getRepositoryQuery();
  16. }
  17. public function createEntity(string $entityFqcn)
  18. {
  19. return $this->getProductFamilyContainer()
  20. ->getFactory()
  21. ->create($this->getMerchantCurrent());
  22. }
  23. // public function createIndexQueryBuilder(SearchDto $searchDto, EntityDto $entityDto, FieldCollection $fields, FilterCollection $filters): QueryBuilder
  24. // {
  25. // $queryBuilder = parent::createIndexQueryBuilder($searchDto, $entityDto, $fields, $filters);
  26. //
  27. // $queryBuilder->leftJoin('entity.productFamilySectionProperties', 'pfsp');
  28. // $queryBuilder->andWhereSection('pfsp', $this->getSectionCurrent());
  29. // $queryBuilder->addOrderBy('entity.id');
  30. // return $queryBuilder;
  31. // }
  32. public function configureResponseParameters(KeyValueStore $responseParameters): KeyValueStore
  33. {
  34. $responseParameters = parent::configureResponseParameters($responseParameters);
  35. // affichage du filtre sur section
  36. $responseParameters->set('display_switch_section', true);
  37. return $responseParameters;
  38. }
  39. public function showSalesStatistic(AdminContext $context)
  40. {
  41. $productFamily = $context->getEntity()->getInstance();
  42. $currentSection = $this->get(SectionResolver::class)->getCurrent();
  43. $productsSalesStatistic = $this->get(OrderShopContainer::class)->getBuilder()->getProductsSalesStatistic($currentSection, $productFamily, 16);
  44. $parameters = array(
  45. 'productFamily' => $productFamily,
  46. 'productsSalesStatistic' => $productsSalesStatistic
  47. );
  48. //TODO flashMessages ???
  49. $response['flashMessages'] = [];//$this->utils->getFlashMessages();
  50. $response['data'] = $this->render('@LcCaracole/admin/product/modal/show_products_sales_statistic.html.twig', $parameters)->getContent();
  51. $response['statistics'] = $productsSalesStatistic;
  52. return new Response(json_encode($response));
  53. }
  54. }