Shopware 6: Using rules programmatically to filter orders

72 Views Asked by At

I am currently trying to create a plugin which uses the Rule Builder functionality to select which orders will be processed by my plugin. The rule can be selected in the plugin settings and will be loaded in a Symfony console command and / or a Message and Scheduled Task.

The plugin should filter all orders in the system by the given rule (only one selectable) and then pass them to a service which processes the orders further.

I loaded the rule and tried adding it to the context, but when i use the repository to search for the orders they will not be filtered.

My Code currently looks like:

$orderRule = $this->helperService->getOrderRule($this->context);

if ($orderRule) {
    $this->context->setRuleIds([$orderRule->getId()]);
}

$criteria = new Criteria();
$result = $this->orderRepository->search($criteria, $this->context)->getEntities();

When looking in the Shopware core i didn’t figure out where the rules for the usual SW standard things are applied. It seems like the filter logic is applied after the DAL result has been loaded? I thought about creating a SalesChannelContext myself using the SalesChannelContextFactory, as the Symfony Command doesn't have a SW Context. For testing purposes i used Context::createDefaultContext();

0

There are 0 best solutions below