prestashop add images to products

时光总嘲笑我的痴心妄想 提交于 2019-11-30 17:10:08

问题


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.

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.

thanks!


回答1:


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();
    }
}


来源:https://stackoverflow.com/questions/20153131/prestashop-add-images-to-products

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!