我要将Shopware 6 Backend中定义的一些值放入MultiFilter.有没有人能给出一个实施方面的建议?

我可以以某种方式循环访问多重过滤器中的前缀吗?

它肯定不起作用,但我只是想给出我试图在Subcriber.php上设置的内容的 idea :

    // 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'),
                ..
            ]
        )
    );
}

推荐答案

$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);

Php相关问答推荐

Symfony Monolog:使用多个格式化程序

composer如何解析包名?

make dd()如何正确工作?¨

从产品中获取WooCommerce产品属性单选按钮的列表WP_Query

从WooCommerce Checkout Country Select2下拉列表中重新排序国家/地区

照明\Support\Collection::Filter():参数#1($Callback)的类型必须为?可调用、已给定数组、已调用

致命错误:无法使用简单的php博客重新声明spl_autoload_Register()

这是在可召回的背景下吗?

使用DOMPDF获取PDF格式的本 map 像

将自定义字段添加到管理产品中 WooCommerce 3.2+ 中的快速编辑

通过添加计数器修改文本区域表单中的重复值

如果 Select 的县不是store 所在的县,如何隐藏本地自提?

AWS S3:当对象名称包含 % 时复制对象失败并出现错误 - 无效的复制源编码

Firefox 115 会话行为:为什么页面无法找到要加载的现有会话 ID?

使用其ID查询和捕获与订单相关的其他详细信息的shopware 6方法

PHP 中的正则表达式,具有字符范围,但不包括特定字符

php-http/discovery 插件 1.15.1 是否仍在使用自己的模块 destruct Contao 4.13 中的composer 安装?

hasOne/belongsToMany 或多对多

如何在 php/laravel 中获取元素在数组中的位置

fopen 功能不断向我发送我重新加载网页时已发布的重复版本的表单