vendor/shopware/core/Framework/Api/EventListener/Acl/CreditOrderLineItemListener.php line 23

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\Framework\Api\EventListener\Acl;
  3. use Shopware\Core\Checkout\Cart\LineItem\LineItem;
  4. use Shopware\Core\Checkout\Order\Aggregate\OrderLineItem\OrderLineItemDefinition;
  5. use Shopware\Core\Framework\Api\Acl\Event\CommandAclValidationEvent;
  6. use Shopware\Core\Framework\Api\Acl\Role\AclRoleDefinition;
  7. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  8. class CreditOrderLineItemListener implements EventSubscriberInterface
  9. {
  10.     public const ACL_ORDER_CREATE_DISCOUNT_PRIVILEGE 'order:create:discount';
  11.     /**
  12.      * @return array<string, string|array{0: string, 1: int}|list<array{0: string, 1?: int}>>
  13.      */
  14.     public static function getSubscribedEvents()
  15.     {
  16.         return [CommandAclValidationEvent::class => 'validate'];
  17.     }
  18.     public function validate(CommandAclValidationEvent $event): void
  19.     {
  20.         $command $event->getCommand();
  21.         $resource $command->getDefinition()->getEntityName();
  22.         $privilege $command->getPrivilege();
  23.         if ($privilege !== AclRoleDefinition::PRIVILEGE_CREATE || $resource !== OrderLineItemDefinition::ENTITY_NAME) {
  24.             return;
  25.         }
  26.         $payload $command->getPayload();
  27.         $type $payload['type'] ?? null;
  28.         if ($type !== LineItem::CREDIT_LINE_ITEM_TYPE) {
  29.             return;
  30.         }
  31.         if (!$event->getSource()->isAllowed(self::ACL_ORDER_CREATE_DISCOUNT_PRIVILEGE)) {
  32.             $event->addMissingPrivilege(self::ACL_ORDER_CREATE_DISCOUNT_PRIVILEGE);
  33.         }
  34.     }
  35. }