我从其他数据库 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();
}
}
阿晨1998