prestashop add images to products

后端 未结 1 1626
甜味超标
甜味超标 2021-01-06 02:27

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.

1条回答
  •  感情败类
    2021-01-06 03:21

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

    0 讨论(0)
提交回复
热议问题