vendor/shopware/core/Content/Flow/Dispatching/Action/SetCustomerGroupCustomFieldAction.php line 69

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\Content\Flow\Dispatching\Action;
  3. use Doctrine\DBAL\Connection;
  4. use Shopware\Core\Checkout\Customer\Aggregate\CustomerGroup\CustomerGroupEntity;
  5. use Shopware\Core\Content\Flow\Dispatching\DelayableAction;
  6. use Shopware\Core\Content\Flow\Dispatching\StorableFlow;
  7. use Shopware\Core\Framework\Context;
  8. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
  9. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  10. use Shopware\Core\Framework\Event\CustomerGroupAware;
  11. use Shopware\Core\Framework\Event\FlowEvent;
  12. use Shopware\Core\Framework\Feature;
  13. /**
  14.  * @deprecated tag:v6.5.0 - reason:remove-subscriber - FlowActions won't be executed over the event system anymore,
  15.  * therefore the actions won't implement the EventSubscriberInterface anymore.
  16.  */
  17. class SetCustomerGroupCustomFieldAction extends FlowAction implements DelayableAction
  18. {
  19.     use CustomFieldActionTrait;
  20.     private Connection $connection;
  21.     private EntityRepositoryInterface $customerGroupRepository;
  22.     /**
  23.      * @internal
  24.      */
  25.     public function __construct(
  26.         Connection $connection,
  27.         EntityRepositoryInterface $customerGroupRepository
  28.     ) {
  29.         $this->connection $connection;
  30.         $this->customerGroupRepository $customerGroupRepository;
  31.     }
  32.     public static function getName(): string
  33.     {
  34.         return 'action.set.customer.group.custom.field';
  35.     }
  36.     /**
  37.      * @deprecated tag:v6.5.0 - reason:remove-subscriber - Will be removed
  38.      */
  39.     public static function getSubscribedEvents(): array
  40.     {
  41.         if (Feature::isActive('v6.5.0.0')) {
  42.             return [];
  43.         }
  44.         return [
  45.             self::getName() => 'handle',
  46.         ];
  47.     }
  48.     /**
  49.      * @return array<int, string>
  50.      */
  51.     public function requirements(): array
  52.     {
  53.         return [CustomerGroupAware::class];
  54.     }
  55.     /**
  56.      * @deprecated tag:v6.5.0 Will be removed, implement handleFlow instead
  57.      */
  58.     public function handle(FlowEvent $event): void
  59.     {
  60.         Feature::triggerDeprecationOrThrow(
  61.             'v6.5.0.0',
  62.             Feature::deprecatedMethodMessage(__CLASS____METHOD__'v6.5.0.0')
  63.         );
  64.         $baseEvent $event->getEvent();
  65.         if (!$baseEvent instanceof CustomerGroupAware) {
  66.             return;
  67.         }
  68.         $this->update($baseEvent->getContext(), $event->getConfig(), $baseEvent->getCustomerGroupId());
  69.     }
  70.     public function handleFlow(StorableFlow $flow): void
  71.     {
  72.         if (!$flow->hasStore(CustomerGroupAware::CUSTOMER_GROUP_ID)) {
  73.             return;
  74.         }
  75.         $this->update($flow->getContext(), $flow->getConfig(), $flow->getStore(CustomerGroupAware::CUSTOMER_GROUP_ID));
  76.     }
  77.     /**
  78.      * @param array<string, mixed> $config
  79.      */
  80.     private function update(Context $context, array $configstring $customerGroupId): void
  81.     {
  82.         /** @var CustomerGroupEntity $customerGroup */
  83.         $customerGroup $this->customerGroupRepository->search(new Criteria([$customerGroupId]), $context)->first();
  84.         $customFields $this->getCustomFieldForUpdating($customerGroup->getCustomfields(), $config);
  85.         if ($customFields === null) {
  86.             return;
  87.         }
  88.         $customFields = empty($customFields) ? null $customFields;
  89.         $this->customerGroupRepository->update([
  90.             [
  91.                 'id' => $customerGroupId,
  92.                 'customFields' => $customFields,
  93.             ],
  94.         ], $context);
  95.     }
  96. }