src/EventListener/MinItem.php line 32

Open in your IDE?
  1. <?php
  2. namespace App\EventListener;
  3. use Sylius\Bundle\UiBundle\Menu\Event\MenuBuilderEvent;
  4. use Sylius\Bundle\AdminBundle\Event\CustomerShowMenuBuilderEvent;
  5. use Knp\Menu\ItemInterface;
  6. use Sylius\Bundle\ResourceBundle\Event\ResourceControllerEvent;
  7. use Doctrine\ORM\Event\PostLoadEventArgs;
  8. use Symfony\Component\DependencyInjection\ContainerInterface;
  9. final class MinItem
  10. {
  11.     protected $container;
  12.     protected const itemMin 5;
  13.     protected const itemMinAdmin 1;
  14.     public function __construct(ContainerInterface $container)
  15.     {
  16.         $this->container $container;
  17.     }
  18.     public function postLoad(PostLoadEventArgs $event) {
  19.         $entity $event->getObject();
  20.         if (method_exists($entity'setItemMin')) {
  21.             $customer $this->container->get('sylius.context.customer')->getCustomer();
  22.             // if($_SERVER['HTTP_X_FORWARDED_FOR'] == '91.168.137.186') {
  23.             //     $customer = $this->container->get('sylius.context.customer')->getCustomer();
  24.             //     dump($customer);
  25.             //     exit();
  26.             // }
  27.             $isAdmin $this->container->get('session')->get('admin_impersonate_shop_user_id');
  28.             if($isAdmin && !empty($customer)) {
  29.                 $entity->setItemMin(self::itemMinAdmin);
  30.             }
  31.             else {
  32.                 $entity->setItemMin(self::itemMin);
  33.             }
  34.         }    
  35.     }
  36. }