src/Controller/EasyAdmin/Ozon/OzonProductCrudController.php line 79

Open in your IDE?
  1. <?php
  2. namespace App\Controller\EasyAdmin\Ozon;
  3. use App\Entity\OzonProduct;
  4. use App\Service\AdminUser\Type\AdminUserRoleType;
  5. use Doctrine\ORM\QueryBuilder;
  6. use EasyCorp\Bundle\EasyAdminBundle\Collection\FieldCollection;
  7. use EasyCorp\Bundle\EasyAdminBundle\Collection\FilterCollection;
  8. use EasyCorp\Bundle\EasyAdminBundle\Config\Action;
  9. use EasyCorp\Bundle\EasyAdminBundle\Config\Actions;
  10. use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
  11. use EasyCorp\Bundle\EasyAdminBundle\Config\Filters;
  12. use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
  13. use EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto;
  14. use EasyCorp\Bundle\EasyAdminBundle\Dto\SearchDto;
  15. use EasyCorp\Bundle\EasyAdminBundle\Field\ArrayField;
  16. use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
  17. use EasyCorp\Bundle\EasyAdminBundle\Field\BooleanField;
  18. use EasyCorp\Bundle\EasyAdminBundle\Field\DateTimeField;
  19. use EasyCorp\Bundle\EasyAdminBundle\Field\Field;
  20. use EasyCorp\Bundle\EasyAdminBundle\Field\IntegerField;
  21. use EasyCorp\Bundle\EasyAdminBundle\Field\NumberField;
  22. use EasyCorp\Bundle\EasyAdminBundle\Field\TextareaField;
  23. use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
  24. use EasyCorp\Bundle\EasyAdminBundle\Filter\EntityFilter;
  25. use EasyCorp\Bundle\EasyAdminBundle\Orm\EntityRepository;
  26. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  27. class OzonProductCrudController extends AbstractCrudController
  28. {
  29.     private UrlGeneratorInterface $urlGenerator;
  30.     public function __construct(UrlGeneratorInterface $urlGenerator)
  31.     {
  32.         $this->urlGenerator $urlGenerator;
  33.     }
  34.     public static function getEntityFqcn(): string
  35.     {
  36.         return OzonProduct::class;
  37.     }
  38.     /**
  39.      * @param SearchDto $searchDto
  40.      * @param EntityDto $entityDto
  41.      * @param FieldCollection $fields
  42.      * @param FilterCollection $filters
  43.      * @return QueryBuilder
  44.      */
  45.     public function createIndexQueryBuilder(SearchDto $searchDtoEntityDto $entityDtoFieldCollection $fieldsFilterCollection $filters): QueryBuilder
  46.     {
  47.         $response $this->get(EntityRepository::class)->createQueryBuilder($searchDto$entityDto$fields$filters);
  48.         if(!in_array(AdminUserRoleType::ROLE_ADMIN$this->getUser()->getRoles())) {
  49.             $response
  50.                 ->andWhere('entity.client IN (:clients)')
  51.                 ->setParameter('clients'$this->getUser()->getOzonClients());
  52.         }
  53.         return $response->orderBy('entity.id''DESC');
  54.     }
  55.     public function configureCrud(Crud $crud): Crud
  56.     {
  57.         return $crud
  58.             ->setEntityLabelInSingular('Продаваемые товары')
  59.             ->setEntityLabelInPlural('Продаваемые товары')
  60.             ->setDefaultSort(['id' => 'DESC'])
  61.             ->setPaginatorUseOutputWalkers(true)
  62.             ->setPaginatorFetchJoinCollection(true)
  63.             ->setSearchFields(['id''clientId''taskId''srcProductId''offerId''url''sku''srcCategoryId''categoryId''name''description''barcode''vendor''vendorCode''images''attributes''depth''width''height''dimensionUnit''weight''weightUnit''price''oldPrice''recommendedPrice''retailPrice''premiumPrice''buyboxPrice''minOzonPrice''marketingPrice''vat''stock''stockComing''stockPresent''stockReserved''state''validationErrors''note''stockWriteError''priceWriteError''infoPrice''infoStockFbo''infoStockFbs'])
  64.             ->setPaginatorPageSize(50);
  65.     }
  66.     public function configureActions(Actions $actions): Actions
  67.     {
  68.         $ozonProductReprice Action::new('ozonProductReprice''Обновить цену')
  69.             ->linkToUrl(function (OzonProduct $ozonProduct): string {
  70.                 return $this->urlGenerator->generate(
  71.                     'ozon_product_reprice',
  72.                     ['id' => $ozonProduct->getId()],
  73.                     UrlGeneratorInterface::ABSOLUTE_PATH
  74.                 );
  75.             });
  76.         $exportHidePriceProducts Action::new('exportHidePriceProducts''Выгрузить товары с откл. ценой')
  77.             ->linkToUrl(function (): string {
  78.                 return $this->urlGenerator->generate(
  79.                     'ozon_hide_price_products_export',
  80.                     [],
  81.                     UrlGeneratorInterface::ABSOLUTE_PATH
  82.                 );
  83.             })
  84.             ->createAsGlobalAction();
  85.         return $actions
  86.             ->add(Crud::PAGE_INDEX$ozonProductReprice)
  87.             ->add(Crud::PAGE_INDEX$exportHidePriceProducts)
  88.             ->add(Crud::PAGE_INDEXAction::DETAIL)
  89.             ->add(Crud::PAGE_EDITAction::INDEX)
  90.             ->disable('new''delete');
  91.     }
  92.     public function configureFilters(Filters $filters): Filters
  93.     {
  94.         return $filters
  95.             ->add(EntityFilter::new('client'))
  96.             ->add('offerId');
  97.     }
  98.     public function configureFields(string $pageName): iterable
  99.     {
  100.         $client AssociationField::new('client''Площадка');
  101.         $taskId IntegerField::new('taskId''ID заявки');
  102.         $srcProductId IntegerField::new('srcProductId''ID товара');
  103.         $offerId TextField::new('offerId''Артикул');
  104.         $sku IntegerField::new('sku''SKU товара на Озон');
  105.         $srcCategoryId IntegerField::new('srcCategoryId''ID категории на Озон');
  106.         $name TextField::new('name''Название');
  107.         $description TextareaField::new('description''Описание');
  108.         $barcode TextField::new('barcode''Штрихкод');
  109.         $vendor TextField::new('vendor''Производитель');
  110.         $vendorCode TextField::new('vendorCode''Код производителя');
  111.         $url TextField::new('url''Url/Адрес страницы товара');
  112.         $imagesText TextareaField::new('imagesText''Изображения');
  113.         $attributesText TextareaField::new('attributesText''Характеристики');
  114.         $depth IntegerField::new('depth''Глубина');
  115.         $width IntegerField::new('width''Ширина');
  116.         $height IntegerField::new('height''Высота');
  117.         $dimensionUnit TextField::new('dimensionUnit''Единицы размеров');
  118.         $weight IntegerField::new('weight''Масса');
  119.         $weightUnit TextField::new('weightUnit''Единицы массы');
  120.         $isPrepayment BooleanField::new('isPrepayment''Продажа по предоплате');
  121.         $price IntegerField::new('price''Цена товара с учетом скидок');
  122.         $oldPrice IntegerField::new('oldPrice''Цена до учета скидок');
  123.         $recommendedPrice IntegerField::new('recommendedPrice''Рекомендованная цена');
  124.         $retailPrice IntegerField::new('retailPrice''Цена товара для поставщиков');
  125.         $premiumPrice IntegerField::new('premiumPrice''Цена для клиентов Premium');
  126.         $buyboxPrice IntegerField::new('buyboxPrice''Цена главного предложения на Ozon');
  127.         $minOzonPrice IntegerField::new('minOzonPrice''Минимальная цена на аналогичный товар');
  128.         $marketingPrice IntegerField::new('marketingPrice''Цена на товар с учетом всех акций');
  129.         $vat NumberField::new('vat''Ставка НДС для товара');
  130.         $stock IntegerField::new('stock''Остатки');
  131.         $stockComing IntegerField::new('stockComing''Товары, которые ожидают поставки');
  132.         $stockPresent IntegerField::new('stockPresent''Товары в наличии');
  133.         $stockReserved IntegerField::new('stockReserved''Товары в резерве');
  134.         $hideStock Field::new('hideStock''Скрыть остатки');
  135.         $isVisible BooleanField::new('isVisible''Активно');
  136.         $visibilityHasPrice BooleanField::new('visibilityHasPrice''Товар активирован');
  137.         $visibilityHasStock BooleanField::new('visibilityHasStock''У товара есть цена');
  138.         $visibilityActiveProduct BooleanField::new('visibilityActiveProduct''Товар доступен на складе');
  139.         $state TextField::new('state''Статус добавления товара в систему');
  140.         $validationErrorsText TextareaField::new('validationErrorsText''Информация об ошибках валидации');
  141.         $note TextareaField::new('note''Заметка');
  142.         $createdAt DateTimeField::new('createdAt''Товар создан');
  143.         $hasBaseChanges BooleanField::new('hasBaseChanges''Изменена базовая информация');
  144.         $hasInfoChanges BooleanField::new('hasInfoChanges''Изменена редактируемая информация');
  145.         $hasActiveChanges BooleanField::new('hasActiveChanges''Изменена активность товара');
  146.         $hasPrepaymentChanges BooleanField::new('hasPrepaymentChanges''Изменена продажа по предоплате');
  147.         $hasStockChanges BooleanField::new('hasStockChanges''Есть неотправленные изменения остатков');
  148.         $hasPriceChanges BooleanField::new('hasPriceChanges''Есть неотправленные изменения цен');
  149.         $isDeleted BooleanField::new('isDeleted''Товар удален');
  150.         $productSources ArrayField::new('productSources''Информация о SKU Ozon');
  151.         $id IntegerField::new('id''ID');
  152.         $noMinStock Field::new('noMinStock''Остатки от 1')->setTemplatePath('admin/default/field_toggle_inverse.html.twig');
  153.         $stateText TextField::new('stateText''Статус добавления товара в систему');
  154.         $stockWriteTm DateTimeField::new('stockWriteTm''Время последней отправки остатков на Озон');
  155.         $stockWriteUpdated BooleanField::new('stockWriteUpdated''Остатки изменены');
  156.         $stockWriteError TextareaField::new('stockWriteError''Ошибки изменения остатков на Озон');
  157.         $priceWriteTm DateTimeField::new('priceWriteTm''Время последней отправки цен на Озон');
  158.         $priceWriteUpdated BooleanField::new('priceWriteUpdated''Цены изменены');
  159.         $priceWriteError TextareaField::new('priceWriteError''Ошибки изменения цен на Озон');
  160.         $isKgt BooleanField::new('isKgt''КГТ');
  161.         $priceRub Field::new('priceRub''Цена');
  162.         $stateStr TextareaField::new('stateStr''Статус');
  163.         $infoReadTm DateTimeField::new('infoReadTm''Обновлено');
  164.         $reserves ArrayField::new('reserves''Резервы');
  165.         $hidePrice BooleanField::new('hidePrice''Не передавать цену');
  166.         switch ($pageName) {
  167.             case Crud::PAGE_INDEX:
  168.                 $fields = [
  169.                     $client$srcProductId$offerId$name$isKgt$priceRub$hidePrice$stateStr,
  170.                     $stock$hideStock$noMinStock$infoReadTm$isVisible$stockWriteUpdated$priceWriteUpdated
  171.                 ];
  172.                 break;
  173.             case Crud::PAGE_DETAIL:
  174.                 $fields = [
  175.                     $id$client$taskId$srcProductId$offerId$sku$srcCategoryId$name$description$barcode,
  176.                     $vendor$vendorCode$url$imagesText$attributesText$depth$width$height$dimensionUnit,
  177.                     $weight$weightUnit$isPrepayment$price$oldPrice$recommendedPrice$retailPrice$premiumPrice,
  178.                     $buyboxPrice$minOzonPrice$marketingPrice$vat$stock$stockComing$stockPresent$stockReserved,
  179.                     $hideStock$noMinStock$isVisible$visibilityHasPrice$visibilityHasStock$visibilityActiveProduct,
  180.                     $stateText$validationErrorsText$note$createdAt$hasBaseChanges$hasInfoChanges$hasActiveChanges,
  181.                     $hasPrepaymentChanges$hasStockChanges$stockWriteTm$stockWriteUpdated$stockWriteError$hasPriceChanges,
  182.                     $priceWriteTm$priceWriteUpdated$priceWriteError$isDeleted$productSources$reserves
  183.                 ];
  184.                 break;
  185.             case Crud::PAGE_NEW:
  186.             case Crud::PAGE_EDIT:
  187.                 $fields = [
  188.                     $client$taskId$srcProductId$offerId$sku$srcCategoryId$name$description$barcode,
  189.                     $vendor$vendorCode$url$imagesText$attributesText$depth$width$height$dimensionUnit,
  190.                     $weight$weightUnit$isPrepayment$price$oldPrice$recommendedPrice$retailPrice$premiumPrice,
  191.                     $buyboxPrice$minOzonPrice$marketingPrice$vat$stock$stockComing$stockPresent$stockReserved,
  192.                     $hideStock$isVisible$visibilityHasPrice$visibilityHasStock$visibilityActiveProduct$state,
  193.                     $validationErrorsText$note$createdAt$hasBaseChanges$hasInfoChanges$hasActiveChanges,
  194.                     $hasPrepaymentChanges$hasStockChanges$hasPriceChanges$isDeleted$productSources
  195.                 ];
  196.                 break;
  197.             default:
  198.                 $fields = [];
  199.         }
  200.         return $fields;
  201.     }
  202. }