英文:
Get values defined in Shopware 6 backend into MultiFilter
问题
我将在Shopware 6后端中获取一些定义的值,并将它们传递给MultiFilter。有人可以提供一些实现的提示吗?
我是否可以在MultiFilter内部以某种方式循环遍历前缀?
当然,这不起作用,但只是为了展示我试图在Subscriber.php中设置的想法:
// 这里我将接收到文本字符串
$prefixes = ['Aaa', 'Bbb', 'Ccc', 'Ddd'];
$ii = 0;
// 用于在PrefixFilter中使用
if (in_array('3f777000a2734deead391133cee3a6a9', $currentPropertyOptions)) {
$criteria->addFilter(
new MultiFilter(
Multifilter::CONNECTION_OR,
[
// 这是想法
while($ii < count($prefixes))
{
echo "new PrefixFilter('product.properties.name', '$prefixes[$i]'),";
$ii++;
}
// 它应该像这样工作
new PrefixFilter('product.properties.name', 'Aaa'),
new PrefixFilter('product.properties.name', 'Bbb'),
new PrefixFilter('product.properties.name', 'Ccc'),
new PrefixFilter('product.properties.name', 'Ddd'),
// 其他过滤器
new EqualsFilter('product.properties.group.name', 'G1'),
new EqualsFilter('product.properties.group.name', 'G2'),
..
]
)
);
}
英文:
I'm going to get some values defined in Shopware 6 backend into MultiFilter. Can someone give a tip on implementation?
Can I loop through prefixes inside the MultiFilter somehow?
Surely it doesn't work, but just to give the idea of what I'm trying to setup at Subscriber.php:
// Here I will receive text strings
$prefixes = ['Aaa', 'Bbb', 'Ccc', 'Ddd'];
$ii = 0;
// To use in PrefixFilter
if (in_array('3f777000a2734deead391133cee3a6a9', $currentPropertyOptions)) {
$criteria->addFilter(
new MultiFilter(
Multifilter::CONNECTION_OR,
[
// This is the idea
while($ii < count($prefixes))
{
echo "new PrefixFilter('product.properties.name', '$prefixes[$i]'),";
$ii++;
}
// It should work like this
new PrefixFilter('product.properties.name', 'Aaa'),
new PrefixFilter('product.properties.name', 'Bbb'),
new PrefixFilter('product.properties.name', 'Ccc'),
new PrefixFilter('product.properties.name', 'Ddd'),
// Other filters
new EqualsFilter('product.properties.group.name', 'G1'),
new EqualsFilter('product.properties.group.name', 'G2'),
..
]
)
);
}
答案1
得分: 1
$multiFilter = new MultiFilter(MultiFilter::CONNECTION_OR);
foreach ($prefixes as $prefix) {
$multiFilter->addQuery(new PrefixFilter('product.properties.name', $prefix));
}
$multiFilter->addQuery(new EqualsFilter('product.properties.group.name', 'G1'));
$multiFilter->addQuery(new EqualsFilter('product.properties.group.name', 'G2'));
$criteria->addFilter($multiFilter);
英文:
$multiFilter = new MultiFilter(MultiFilter::CONNECTION_OR);
foreach ($prefixes as $prefix) {
$multiFilter->addQuery(new PrefixFilter('product.properties.name', $prefix));
}
$multiFilter->addQuery(new EqualsFilter('product.properties.group.name', 'G1'));
$multiFilter->addQuery(new EqualsFilter('product.properties.group.name', 'G2'));
$criteria->addFilter($multiFilter);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论