vendor/shopware/core/Content/Flow/Dispatching/Action/SetOrderCustomFieldAction.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\Order\OrderEntity;
  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\FlowEvent;
  11. use Shopware\Core\Framework\Event\OrderAware;
  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 SetOrderCustomFieldAction extends FlowAction implements DelayableAction
  18. {
  19.     use CustomFieldActionTrait;
  20.     private Connection $connection;
  21.     private EntityRepositoryInterface $orderRepository;
  22.     /**
  23.      * @internal
  24.      */
  25.     public function __construct(
  26.         Connection $connection,
  27.         EntityRepositoryInterface $orderRepository
  28.     ) {
  29.         $this->connection $connection;
  30.         $this->orderRepository $orderRepository;
  31.     }
  32.     public static function getName(): string
  33.     {
  34.         return 'action.set.order.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 [OrderAware::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 OrderAware) {
  66.             return;
  67.         }
  68.         $this->update($baseEvent->getContext(), $event->getConfig(), $baseEvent->getOrderId());
  69.     }
  70.     public function handleFlow(StorableFlow $flow): void
  71.     {
  72.         if (!$flow->hasStore(OrderAware::ORDER_ID)) {
  73.             return;
  74.         }
  75.         $this->update($flow->getContext(), $flow->getConfig(), $flow->getStore(OrderAware::ORDER_ID));
  76.     }
  77.     /**
  78.      * @param array<string, mixed> $config
  79.      */
  80.     private function update(Context $context, array $configstring $orderId): void
  81.     {
  82.         /** @var OrderEntity $order */
  83.         $order $this->orderRepository->search(new Criteria([$orderId]), $context)->first();
  84.         $customFields $this->getCustomFieldForUpdating($order->getCustomfields(), $config);
  85.         if ($customFields === null) {
  86.             return;
  87.         }
  88.         $customFields = empty($customFields) ? null $customFields;
  89.         $this->orderRepository->update([
  90.             [
  91.                 'id' => $orderId,
  92.                 'customFields' => $customFields,
  93.             ],
  94.         ], $context);
  95.     }
  96. }