gpt4 book ai didi

categories - 以编程方式添加类别 prestashop

转载 作者:行者123 更新时间:2023-12-04 22:32:10 32 4
gpt4 key购买 nike

我想以编程方式向 prestashop 添加类别,我试过这段代码

$object = new Category();

$object->name = "xcvxvvx";
if (!$parent_id){
$parent_id = Configuration::get('PS_HOME_CATEGORY');
}
$object->id_parent = $parent_id;
$object->link_rewrite = array((int)(Configuration::get('PS_LANG_DEFAULT')) => $category);
$object->add();
$object->id_category = $object->id;

$object->id_category_default = $object->id;

$object->update();

我收到此错误消息:
Fatal error: Uncaught exception 'PrestaShopException' with message 'Property
Category->name is empty' in /var/www/autospareparts.se.com/classes/ObjectModel.php:874
Stack trace:
#0 /var/www/autospareparts.se.com/classes/ObjectModel.php(306):
ObjectModelCore->validateFieldsLang()
#1 /var/www/autospareparts.se.com/classes/ObjectModel.php(490):
ObjectModelCore->getFieldsLang()
#2 /var/www/autospareparts.se.com/classes/Category.php(157):
ObjectModelCore->add(true, false)
#3 /var/www/autospareparts.se.com/get_product.php(51): CategoryCore->add()
#4 {main}
thrown in /var/www/autospareparts.se.com/classes/ObjectModel.php on line 874

与我分配的名称字段相关的错误
$object->name = "xcvxvvx";

提前致谢

最佳答案

这是因为国际化。 ObjectModel class 需要一个数组作为名称,就像 link_rewrite .

工作代码(在 1.5.4.1 上测试,但应该在 >=1.5 上工作)

$object = new Category();
$object->name = array((int)Configuration::get('PS_LANG_DEFAULT') => 'Cool name');
$object->id_parent = Configuration::get('PS_HOME_CATEGORY');
$object->link_rewrite = array((int)Configuration::get('PS_LANG_DEFAULT') => 'cool-url');
$object->add();

关于categories - 以编程方式添加类别 prestashop,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18720880/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com