我已经创建了一个自定义模块,可以从我的CSV中导入静态块
以下代码:
$staticblock = Mage::getModel('cms/block');
$staticblock->load($identifier)->getData();
$staticblock->setData('title', $title);
$staticblock->setData('identifier', $identifier);
$staticblock->setData('content', $content);
$staticblock->setData('creation_time', $creation_time);
$staticblock->setData('update_time', $update_time);
$staticblock->setData('is_active', $is_active);
$staticblock->setData('stores',$store_id);
如果静态块已经包含我的商店ID,则错误会显示在我的报告文件中
"a:5:{i:0;s:84:"A block identifier with the same properties already exists in the selected store.bug";i:1;s:1117:"#0 "
如果带有标识符的块未就绪,我的代码可以正常工作,它将被创建一个新的静态块。
答案 0 :(得分:0)
$staticblock = Mage::getModel('cms/block')->load($identifier);
if ((!$staticblock) || (!$staticblock->getId())) { //not exists , or try using $staticblock->isObjectNew()
$staticblock->setData('identifier', $identifier);
}
$staticblock->setData('title', $title);
$staticblock->setData('content', $content);
$staticblock->setData('creation_time', $creation_time);
$staticblock->setData('update_time', $update_time);
$staticblock->setData('is_active', $is_active);
$staticblock->setData('stores',$store_id);
尝试查看它是否是新对象。