如何在我的 Drupal 模块中添加 Ubercart 产品图像?
我正在编写一个从我们的供应商之一导入产品的脚本,除了产品图像之外,几乎所有内容都正确导入。
据我所知,产品图像在 files
和 content_field_image_cache
表中进行了描述。 files
表似乎没有任何问题,因此这是我插入 content_field_image_cache
的代码。
$fileData->vid = $vid;
$fileData->nid = $nid;
$fileData->delta = 0;
$fileData->field_image_cache_fid = $fid;
$fileData->field_image_cache_list = 1;
drupal_write_record('content_field_image_cache', $fileData);
当我导入产品时,图像文件会显示在正确的目录中,并且会在 files
中插入一行,其中包含正确的路径和自动递增的 fid
。一行也会插入到 content_field_image_cache
中,其中包含正确的 vid
、nid
和 delta
,但所有其他字段都是设置为NULL。即使当我设置 $fileData->field_image_cache_fid = 1
或其他一些随机整数时,它仍然出现NULL。
我如何插入这些数据?或者,如果您知道 API 中有更简单的方法可以完成此任务,请发布它。
编辑: db_query("INSERT INTO {content_field_image_cache} VALUES (%d, %d, 0, %d, 1, NULL)", $vid, $nid, $fid);< /code> 甚至不起作用!什么球?
I'm writing a script that imports products from one of our suppliers, and I have almost everything importing correctly except product images.
From what I can tell, the product images are described in the files
and content_field_image_cache
tables. There don't seem to be any problems with the files
table, so here is my code for inserting into content_field_image_cache
.
$fileData->vid = $vid;
$fileData->nid = $nid;
$fileData->delta = 0;
$fileData->field_image_cache_fid = $fid;
$fileData->field_image_cache_list = 1;
drupal_write_record('content_field_image_cache', $fileData);
When I import products, the image file shows up in the correct directory, and a row is inserted into files
with the correct path and an auto incremented fid
. A row is also inserted into content_field_image_cache
with the correct vid
, nid
, and delta
, but every other field is set as NULL. Even when I set $fileData->field_image_cache_fid = 1
or some other random integer, it still comes up NULL.
How do I insert this data? Or, if you know of an easier method in the API for this task, please post it.
Edit: db_query("INSERT INTO {content_field_image_cache} VALUES (%d, %d, 0, %d, 1, NULL)", $vid, $nid, $fid);
doesn't even work! What the balls?!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
经过多次想法和失败的尝试后,我发现在我有机会接触该条目之前,该条目已被添加到
content_field_image_cache
表中。我不知道插入的是什么;我的代码中什么都没有。不管怎样,我发现使用UPDATE
解决了我的问题。After many ideas and failed attempts, I discovered that the entry is being added to the
content_field_image_cache
table before I have the chance to touch it. I have no idea what is inserting it; it's nothing in my code. Anyway, I found that using anUPDATE
solved my problem.