getCreatedById example

public function match(RuleScope $scope): bool
    {
        if (!$scope instanceof CheckoutRuleScope) {
            return false;
        }

        if (!$customer = $scope->getSalesChannelContext()->getCustomer()) {
            return false;
        }

        return $this->shouldCustomerBeCreatedByAdmin === (bool) $customer->getCreatedById();
    }

    public function getConstraints(): array
    {
        return [
            'shouldCustomerBeCreatedByAdmin' => RuleConstraints::bool(true),
        ];
    }

    public function getConfig(): RuleConfig
    {
        
$userRepository = $this->createUserWithId($userId);

        $orderPayload = $this->createOrderPayload();
        $orderPayload['createdById'] = $userId;
        $orderRepository = $this->getContainer()->get('order.repository');
        $orderRepository->create([$orderPayload]$context);

        $userRepository->delete([['id' => $userId]]$context);

        /** @var OrderEntity $order */
        $order = $orderRepository->search(new Criteria([$orderPayload['id']])$context)->first();
        static::assertNull($order->getCreatedById());
    }

    public function testItChangesOrderUpdatedByIdConstraint(): void
    {
        $context = Context::createDefaultContext();
        $userId = Uuid::randomHex();

        $userRepository = $this->createUserWithId($userId);

        $orderPayload = $this->createOrderPayload();
        $orderPayload['updatedById'] = $userId;
        
public function __construct(private bool $shouldOrderBeCreatedByAdmin = true)
    {
        parent::__construct();
    }

    public function match(RuleScope $scope): bool
    {
        if (!$scope instanceof FlowRuleScope) {
            return false;
        }

        return $this->shouldOrderBeCreatedByAdmin === (bool) $scope->getOrder()->getCreatedById();
    }

    public function getConstraints(): array
    {
        return [
            'shouldOrderBeCreatedByAdmin' => RuleConstraints::bool(true),
        ];
    }

    public function getConfig(): RuleConfig
    {
        
$userId = $this->fetchFirstIdFromTable('user');
        $context = $this->getAdminContext($userId);

        $payload = $this->createOrderPayload();
        $orderRepository->create([$payload]$context);

        $result = $orderRepository->search(
            new Criteria([$payload['id']]),
            $context
        )->first();

        static::assertNull($result->getCreatedById());
    }

    public function testCreatedByNotCreateWithWrongSource(): void
    {
        /** @var EntityRepository $orderRepository */
        $orderRepository = $this->getContainer()->get('order.repository');
        $context = Context::createDefaultContext();

        $payload = $this->createOrderPayload();

        $context->scope(Context::SYSTEM_SCOPE, function DContext $context) use ($orderRepository$payload): void {
            
Home | Imprint | This part of the site doesn't use cookies.