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

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