Get values defined in Shopware 6 backend into MultiFilter

huangapple go评论59阅读模式
英文:

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 = [&#39;Aaa&#39;, &#39;Bbb&#39;, &#39;Ccc&#39;, &#39;Ddd&#39;];
$ii = 0;

// To use in PrefixFilter
if (in_array(&#39;3f777000a2734deead391133cee3a6a9&#39;, $currentPropertyOptions)) {
    $criteria-&gt;addFilter(
        new MultiFilter(
            Multifilter::CONNECTION_OR,
            [

            	// This is the idea
                while($ii &lt; count($prefixes))
                {
                    echo &quot;new PrefixFilter(&#39;product.properties.name&#39;, &#39;$prefixes[$i]&#39;),&quot;;
                    $ii++;
                }

                // It should work like this
                new PrefixFilter(&#39;product.properties.name&#39;, &#39;Aaa&#39;),
                new PrefixFilter(&#39;product.properties.name&#39;, &#39;Bbb&#39;),
                new PrefixFilter(&#39;product.properties.name&#39;, &#39;Ccc&#39;),
                new PrefixFilter(&#39;product.properties.name&#39;, &#39;Ddd&#39;),

                // Other filters
                new EqualsFilter(&#39;product.properties.group.name&#39;, &#39;G1&#39;),
                new EqualsFilter(&#39;product.properties.group.name&#39;, &#39;G2&#39;),
                ..
            ]
        )
    );
}

答案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-&gt;addQuery(new PrefixFilter(&#39;product.properties.name&#39;, $prefix));
}

$multiFilter-&gt;addQuery(new EqualsFilter(&#39;product.properties.group.name&#39;, &#39;G1&#39;));
$multiFilter-&gt;addQuery(new EqualsFilter(&#39;product.properties.group.name&#39;, &#39;G2&#39;));

$criteria-&gt;addFilter($multiFilter);

huangapple
  • 本文由 发表于 2023年6月22日 00:01:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/76525178.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定