如何测试一个类别是否已经存在?PrestaShop [英] How to test if a category already exists? PrestaShop

查看:47
本文介绍了如何测试一个类别是否已经存在?PrestaShop的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从其他数据库 Web 服务获取类别,并在刷新文件以添加类别时将它们放在 PrestaShop 上 我想确定类别 ID 是否存在,如果存在我想更新类别.

I get the category from other database web service and I put them on PrestaShop when I refresh the file to add categories I wanna make sure if the category id exists, if exist I wanna update the category.

$XMLRQString = '<?xml version="1.0" encoding="utf-8"?>'.
    '<x:Winmax4GetFamiliesRQ xmlns:x="urn:Winmax4GetFamiliesRQ">'.
    '</x:Winmax4GetFamiliesRQ >';

$return = $client->GetFamilies($Params);
$XMLRSString = new SimpleXMLElement($return->GetFamiliesResult);
if ($XMLRSString->Code > 0)
    echo '</br>Error: '.$XMLRSString->Code." ".$XMLRSString->Message;
else{

        foreach ($XMLRSString->Families->Family as $family)
        {   

            $category = new Category();

            $category->id = $family->Code;

            $category->force_id = true;

            $category->is_root_category = false;

            $category->name = array((int)Configuration::get('PS_LANG_DEFAULT') => $family->Designation);

            $category->link_rewrite = array((int)Configuration::get('PS_LANG_DEFAULT') =>  $family->Code);

            $category->id_parent = Configuration::get('PS_HOME_CATEGORY');

            $category->add();

        }
    }

推荐答案

一般来说,如果您有大量数据(还有安全数据),最好将数据直接插入到数据库中.使用 Db 类而不是 Category 类.

In general, If you have large data (and also safe data), it's better to insert your data directly to your database. Use Db class instead of Category class.

否则,您必须使用 save() 方法而不是 add() 方法

Otherwise, you must use a save() method instead of add() method

这篇关于如何测试一个类别是否已经存在?PrestaShop的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆