简体   繁体   English

Magento无法使用商店ID保存静态块

[英]Magento could not save static block with store id

I have been created a custom module to make importing static block from my CSV 我已经创建了一个自定义模块,可以从CSV导入静态块

The code below: 下面的代码:

$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);

if the static block is already with my store id, the error showing in my report file 如果静态块已经具有我的商店标识,那么错误将显示在我的报告文件中

"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 "

My code work well if the block with identifier is not ready, it will be created a new static block. 如果带有标识符的块未准备好,我的代码将运行良好,它将创建一个新的静态块。

$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);

Try to see whether it is new object. 尝试查看它是否是新对象。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM