<?php
namespace App\EventListener;
use Sylius\Bundle\UiBundle\Menu\Event\MenuBuilderEvent;
use Sylius\Bundle\AdminBundle\Event\CustomerShowMenuBuilderEvent;
use Knp\Menu\ItemInterface;
use Sylius\Bundle\ResourceBundle\Event\ResourceControllerEvent;
use Doctrine\ORM\Event\PostLoadEventArgs;
use Symfony\Component\DependencyInjection\ContainerInterface;
final class MinItem
{
protected $container;
protected const itemMin = 5;
protected const itemMinAdmin = 1;
public function __construct(ContainerInterface $container)
{
$this->container = $container;
}
public function postLoad(PostLoadEventArgs $event) {
$entity = $event->getObject();
if (method_exists($entity, 'setItemMin')) {
$customer = $this->container->get('sylius.context.customer')->getCustomer();
// if($_SERVER['HTTP_X_FORWARDED_FOR'] == '91.168.137.186') {
// $customer = $this->container->get('sylius.context.customer')->getCustomer();
// dump($customer);
// exit();
// }
$isAdmin = $this->container->get('session')->get('admin_impersonate_shop_user_id');
if($isAdmin && !empty($customer)) {
$entity->setItemMin(self::itemMinAdmin);
}
else {
$entity->setItemMin(self::itemMin);
}
}
}
}