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

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. /**
  9.  * @deprecated tag:v6.5.0 - reason:becomes-internal - EventSubscribers will become internal in v6.5.0
  10.  */
  11. class CreditOrderLineItemListener implements EventSubscriberInterface
  12. {
  13.     public const ACL_ORDER_CREATE_DISCOUNT_PRIVILEGE 'order:create:discount';
  14.     /**
  15.      * @return array<string, string|array{0: string, 1: int}|list<array{0: string, 1?: int}>>
  16.      */
  17.     public static function getSubscribedEvents()
  18.     {
  19.         return [CommandAclValidationEvent::class => 'validate'];
  20.     }
  21.     public function validate(CommandAclValidationEvent $event): void
  22.     {
  23.         $command $event->getCommand();
  24.         $resource $command->getDefinition()->getEntityName();
  25.         $privilege $command->getPrivilege();
  26.         if ($privilege !== AclRoleDefinition::PRIVILEGE_CREATE || $resource !== OrderLineItemDefinition::ENTITY_NAME) {
  27.             return;
  28.         }
  29.         $payload $command->getPayload();
  30.         $type $payload['type'] ?? null;
  31.         if ($type !== LineItem::CREDIT_LINE_ITEM_TYPE) {
  32.             return;
  33.         }
  34.         if (!$event->getSource()->isAllowed(self::ACL_ORDER_CREATE_DISCOUNT_PRIVILEGE)) {
  35.             $event->addMissingPrivilege(self::ACL_ORDER_CREATE_DISCOUNT_PRIVILEGE);
  36.         }
  37.     }
  38. }