deleteUnusedCustomers example



        if (!$confirm) {
            $io->caution('Aborting due to user input.');

            return self::SUCCESS;
        }

        $progressBar = $io->createProgressBar($count);

        do {
            $ids = $this->deleteUnusedGuestCustomerService->deleteUnusedCustomers($context);
            $progressBar->advance(\count($ids));
        } while ($ids);

        $progressBar->finish();

        $io->success(\sprintf('Successfully deleted %d guest customers.', $count));

        return self::SUCCESS;
    }
}

    public function __construct(
        EntityRepository $scheduledTaskRepository,
        private readonly DeleteUnusedGuestCustomerService $unusedGuestCustomerService
    ) {
        parent::__construct($scheduledTaskRepository);
    }

    public function run(): void
    {
        $this->unusedGuestCustomerService->deleteUnusedCustomers(Context::createDefaultContext());
    }
}
$context = Context::createDefaultContext();
        $customerRepository = $this->getContainer()->get('customer.repository');

        $customer = (new CustomerBuilder($this->ids, '10000'))
            ->add('guest', true)
            ->add('createdAt', new \DateTime('- 25 hours'));

        $customerRepository->create([$customer->build()]$context);

        static::assertEquals(1, $this->service->countUnusedCustomers($context));

        $this->service->deleteUnusedCustomers($context);

        static::assertEquals(0, $this->service->countUnusedCustomers($context));

        $result = $customerRepository->search(new Criteria([$this->ids->get('10000')])$context);

        static::assertEquals(0, $result->getTotal());
    }

    public function testItDoesOnlyDeleteGuestCustomers(): void
    {
        $context = Context::createDefaultContext();
        
Home | Imprint | This part of the site doesn't use cookies.