改进CSV产品导入->按名称查询数组类别

问题描述

最近,我们进行了重大更改,例如为我们的网站构建新的类别树,并在正确的类别中转移了2M产品。

我们没有性能问题,一切运行顺利。

我唯一的问题是,类别树现在变得更加复杂和深入,并且在通过CSV导入添加新文章时会受到影响(超时脚本,非常慢,脚本崩溃) 基本上,通过CSV添加新产品时,类别字段始终为文本(用“#”分隔)示例:Engine#Crankshaft#Audi#Audi A5

因此,如果数据库中已存在或不存在该属性,则获取类别ID的问题出在哪里?我该如何改善?我认为主要问题在于创建的大型数组

protected function _getCategoriesID($field_value)
        {
            global $Database;
            $products_categories = array();
            $separator           = $this->_getSeparator($field_value);
            $category_array      = array();
            if ($separator != '') {
                $category_array = explode($separator,$field_value);
                $category_array = array_reverse($category_array);
            } else {
                $category_array[0] = $field_value;
            }
            unset($separator);
            $Qcategory = $Database->query('select c0.categories_id from :table_categories as c0 inner join :table_categories_description as cd on c0.categories_id=cd.categories_id where cd.categories_name = :categories_name and cd.language_id=:language_id');
            $Qcategory->bindTable(':table_categories',TABLE_CATEGORIES);
            $Qcategory->bindTable(':table_categories_description',TABLE_CATEGORIES_DESCRIPTION);
            $Qcategory->bindValue(':categories_name',$category_array[0]);
            $Qcategory->bindInt(':language_id',$this->language);
            $count = 1;
            if (count($category_array) > 1) {
                while ($count < count($category_array)) {
                    $Qcategory->appendQuery(' and c' . ($count - 1) . '.parent_id in (select c' . $count . '.categories_id from :table_categories' . $count . ' as c' . $count . ' inner join :table_categories_description' . $count . ' as cd' . $count . ' on c' . $count . '.categories_id=cd' . $count . '.categories_id where cd' . $count . '.categories_name = :categories_name' . $count . ' and cd' . $count . '.language_id=:language_id' . $count . ' ');
                    $Qcategory->bindTable(':table_categories' . $count,TABLE_CATEGORIES);
                    $Qcategory->bindTable(':table_categories_description' . $count,TABLE_CATEGORIES_DESCRIPTION);
                    $Qcategory->bindValue(':categories_name' . $count,$category_array[$count]);
                    $Qcategory->bindInt(':language_id' . $count,$this->language);
                    $count++;
                }
                for ($i = 0; $i < $count - 1; $i++) {
                    $Qcategory->appendQuery(')');
                }
            }
            $Qcategory->execute();
            while ($Qcategory->next()) {
                $products_categories[] = $Qcategory->value('categories_id');
            }
            unset($Qcategories);
            return $products_categories;
        }

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)