我从其他数据库 Web 服务获取类别,并在刷新文件以添加类别时将它们放在 PrestaShop 上,我想确保类别 ID 是否存在,如果存在,我想更新类别。$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(); } }
2 回答
阿晨1998
TA贡献2037条经验 获得超6个赞
这会起作用:
$default_lang = (int)Configuration::get('PS_LANG_DEFAULT');
$home = (int)Configuration::get('PS_HOME_CATEGORY');
$category = new Category((int)$family->Code);
$category->is_root_category = false;
$category->name = array($default_lang => $family->Designation);
$category->link_rewrite = array($default_lang => $family->Code);
$category->id_parent = $home;
$category->save();
此外,您始终可以使用Validate::isLoadedObject()静态方法检查对象是否有效。
- 2 回答
- 0 关注
- 186 浏览
添加回答
举报
0/150
提交
取消