Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/233.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Shopware6-由于我的foreach循环,无法获取值_Php_Symfony_Data Access Layer_Shopware - Fatal编程技术网

Php Shopware6-由于我的foreach循环,无法获取值

Php Shopware6-由于我的foreach循环,无法获取值,php,symfony,data-access-layer,shopware,Php,Symfony,Data Access Layer,Shopware,我们目前有以下代码来获取一些属性组选项: //Nederlands & English $languages = ['94a1a2d118464bdaab37d6e05d404508', '2fbb5fe2e29a4d70aa5854ce7ce3e20b']; $context = new Context(new SystemSource(), [], Defaults::CURRENCY, $languages); $criteria = new Criteria(); Foreac

我们目前有以下代码来获取一些属性组选项:

//Nederlands & English
$languages = ['94a1a2d118464bdaab37d6e05d404508', '2fbb5fe2e29a4d70aa5854ce7ce3e20b'];
$context = new Context(new SystemSource(), [], Defaults::CURRENCY, $languages);
$criteria = new Criteria();

Foreach ($propertiesArray as $property)
{
    $criteria->addFilter(new EqualsFilter('name', $property['name']);
    $lineInfo = $this->propertyGroupOptionRepository->search($criteria, $context)->first();
    var_dump($lineInfo);
}
由于某些原因,它无法获取值'Zilver',$lineInfo返回空对象。但值“Zilver”存在于db中,语言id为“Nederlands”=94a1a2d118464bdaab37d6e05d404508(在上下文中给出)

奇怪的事实:它对我的$propertiesArray数组的第一项非常有效。如果我尝试手动将$property['value']替换为'Zilver',并将其与foreach循环隔离,则可以得到所需的结果

我是做错了什么还是误解了它的工作方式

这是$PROPERTIES阵列的转储=

      [0]=>
      array(1) {
        ["value"]=>
        string(10) "Eenkleurig"
      }
      [1]=>
      array(1) {
        ["value"]=>
        string(6) "Zilver"
      }
      [2]=>
      array(1) {
        ["value"]=>
        string(5) "Praag"
      }

信息:我们实例的主要语言是英语,但我们目前正在与一个在荷兰向我们发送值的系统合作。

我不完全确定shopware,但是,您的逻辑似乎有缺陷,因为您在每次迭代中向相同的
标准添加了额外的
equalFilter
。这就是为什么只有第一次搜索成功。
尝试在循环内创建一个新的
标准

//Nederlands & English
$languages = ['94a1a2d118464bdaab37d6e05d404508', '2fbb5fe2e29a4d70aa5854ce7ce3e20b'];
$context = new Context(new SystemSource(), [], Defaults::CURRENCY, $languages);

Foreach ($propertiesArray as $property)
{
    $criteria = new Criteria();
    $criteria->addFilter(new EqualsFilter('name', $property['name']);
    $lineInfo = $this->propertyGroupOptionRepository->search($criteria, $context)->first();
    var_dump($lineInfo);
}
在浏览完这些文档之后,我认为您实际上可能想要使用,然后您应该只需要对数据库进行一次查询。这应该更有效率

//Nederlands & English
$languages = ['94a1a2d118464bdaab37d6e05d404508', '2fbb5fe2e29a4d70aa5854ce7ce3e20b'];
$context = new Context(new SystemSource(), [], Defaults::CURRENCY, $languages);
$criteria = new Criteria();

$criteria->addFilter(new EqualsAnyFilter('name', array_column($propertiesArray, 'name')));
$results= $this->propertyGroupOptionRepository->search($criteria, $context);
var_dump($results);

我不完全确定shopware,但是,您的逻辑似乎有缺陷,因为您在每次迭代中向相同的
标准添加了额外的
EqualsFilter
。这就是为什么只有第一次搜索成功。
尝试在循环内创建一个新的
标准

//Nederlands & English
$languages = ['94a1a2d118464bdaab37d6e05d404508', '2fbb5fe2e29a4d70aa5854ce7ce3e20b'];
$context = new Context(new SystemSource(), [], Defaults::CURRENCY, $languages);

Foreach ($propertiesArray as $property)
{
    $criteria = new Criteria();
    $criteria->addFilter(new EqualsFilter('name', $property['name']);
    $lineInfo = $this->propertyGroupOptionRepository->search($criteria, $context)->first();
    var_dump($lineInfo);
}
在浏览完这些文档之后,我认为您实际上可能想要使用,然后您应该只需要对数据库进行一次查询。这应该更有效率

//Nederlands & English
$languages = ['94a1a2d118464bdaab37d6e05d404508', '2fbb5fe2e29a4d70aa5854ce7ce3e20b'];
$context = new Context(new SystemSource(), [], Defaults::CURRENCY, $languages);
$criteria = new Criteria();

$criteria->addFilter(new EqualsAnyFilter('name', array_column($propertiesArray, 'name')));
$results= $this->propertyGroupOptionRepository->search($criteria, $context);
var_dump($results);