prestashop将图像添加到产品 [英] prestashop add images to products

查看:76
本文介绍了prestashop将图像添加到产品的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个产品对象,该对象是用PHP脚本创建的.我需要添加一个缩略图和一个大图像,这些文件已包含在zip文件中.文件名包含产品ID.

I have a product object, which I am creating in a PHP script. I need to add a thumbnail and a large image, which I have in a zip file. The file name contains the product ID.

用代码实现此目标的最佳方法是什么?我假设我需要将图像提取到文件系统中的某个位置,但是我不知道prestashop如何处理图像.

Whats the best way to achieve this in code? I'm assuming I need to extract the images to somewhere in file system, but I have no idea how prestashop handles images.

谢谢!

推荐答案

如果具有产品ID($ id_product)和图像URL($ url),则可以执行以下操作:

If you have the Product ID ($id_product) and the image URL ($url), you can do the following:

$image = new Image();
$image->id_product = $id_product;
$image->position = Image::getHighestPosition($id_product) + 1;
$image->cover = true; // or false;
if (($image->validateFields(false, true)) === true &&
($image->validateFieldsLang(false, true)) === true && $image->add())
{
    $image->associateTo($shops);
    if (!self::copyImg($id_product, $image->id, $url, 'products', false))
    {
        $image->delete();
    }
}

这篇关于prestashop将图像添加到产品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆