Import 以编程方式在类别prestashop上添加图像

Import 以编程方式在类别prestashop上添加图像,import,prestashop,Import,Prestashop,我试图通过编程在prestashop中创建带有图像的类别。我知道了如何创建类别,但我找不到任何关于向类别添加图像的内容。创建类别后,获取类别的ID并创建/上传或是一张名为“ID\u of_category.”jpg的图片,然后将其放入根文件夹/img/c/ 另外,制作一份此图片的副本,并将其命名为'id\u of_category'-category\u default.jpg,并制作另一个名为'id\u of_category'-medium\u default.jpg的较小版本 因此,如果您

我试图通过编程在prestashop中创建带有图像的类别。我知道了如何创建类别,但我找不到任何关于向类别添加图像的内容。

创建类别后,获取类别的ID并创建/上传或是一张名为“ID\u of_category.”jpg的图片,然后将其放入根文件夹
/img/c/

另外,制作一份此图片的副本,并将其命名为
'id\u of_category'-category\u default.jpg
,并制作另一个名为
'id\u of_category'-medium\u default.jpg
的较小版本

因此,如果您创建了一个ID为10的类别,请制作3张图片

两张高分辨率图片(默认prestashop使用870x217分辨率)

一个中等分辨率(默认prestashop使用125x125分辨率)

并将它们全部放入文件夹
/img/c/

这将适用于默认的prestashop主题/安装,但要与图像的后台设置完全兼容(自定义主题可以为图像名称以及高度和宽度使用不同的后缀),请查看
AdminCategoriesController.php
及其方法
positmage()
查看通过backoffice中的类别设置上载图像时图像的处理方式


要查找的主要内容是
ImageType::getImageTypes('categories')
检索有关类别图像设置和
图像类型::GetFormattedName('medium')的所有信息用于缩略图信息。

创建类别后,获取类别的ID并创建/上传一张名为“类别的ID”的图片。jpg
并将其放入根文件夹
/img/c/

另外,制作一份此图片的副本,并将其命名为
'id\u of_category'-category\u default.jpg
,并制作另一个名为
'id\u of_category'-medium\u default.jpg
的较小版本

因此,如果您创建了一个ID为10的类别,请制作3张图片

两张高分辨率图片(默认prestashop使用870x217分辨率)

一个中等分辨率(默认prestashop使用125x125分辨率)

并将它们全部放入文件夹
/img/c/

这将适用于默认的prestashop主题/安装,但要与图像的后台设置完全兼容(自定义主题可以为图像名称以及高度和宽度使用不同的后缀),请查看
AdminCategoriesController.php
及其方法
positmage()
查看通过backoffice中的类别设置上载图像时图像的处理方式


要查找的主要内容是
ImageType::getImageTypes('categories')
检索有关类别图像设置和
图像类型::GetFormattedName('medium')的所有信息用于缩略图信息。

类别图像存储在PrestaShop的img/目录中,路径如下:

/prestashop/img/c/
此文件夹中的图像文件如下(让我们以ID为3的类别为例):


您只需使用添加的类别ID为您的类别添加图像,如上所示。

类别图像存储在PrestaShop的img/目录中,路径如下:

/prestashop/img/c/
此文件夹中的图像文件如下(让我们以ID为3的类别为例):


您只需使用添加的类别ID为您的类别添加图像,如上所示。

我们准备了与其他软件同步的代码。这里给你举个例子

$object->name = array((int)Configuration::get('PS_LANG_DEFAULT') => $nombre);
$object->link_rewrite = array((int)Configuration::get('PS_LANG_DEFAULT') => str2url($nombre));
$object->description =  array((int)Configuration::get('PS_LANG_DEFAULT') => $nombre);;
$object->meta_title = array((int)Configuration::get('PS_LANG_DEFAULT') => $nombre);
$object->meta_description = array((int)Configuration::get('PS_LANG_DEFAULT') => $nombre);
$object->meta_keywords = array ( (int)Configuration::get('PS_LANG_DEFAULT') => getMetaKeywords($nombre,2));

$object->id_parent = $parent;
$object->save();

$image = new Image();
if (!copyImg2($object->id, $image->id, $imagen, 'categories', true))
{
   $image->delete();
}



function copyImg2($id_entity, $id_image, $url, $entity = 'products', $regenerate = true) {
    $tmpfile = tempnam(_PS_TMP_IMG_DIR_, 'ps_import');
    $watermark_types = explode(',', Configuration::get('WATERMARK_TYPES'));
    switch ($entity) {
        default:
        case 'products':
            $image_obj = new Image($id_image);
            $path = $image_obj->getPathForCreation();
            break;
        case 'categories':
            $path = _PS_CAT_IMG_DIR_ . (int) $id_entity;
            break;
        case 'manufacturers':
            $path = _PS_MANU_IMG_DIR_ . (int) $id_entity;
            break;
        case 'suppliers':
            $path = _PS_SUPP_IMG_DIR_ . (int) $id_entity;
            break;
    }
    $url = str_replace(' ', '%20', trim($url));
    if (!ImageManager::checkImageMemoryLimit($url))
        return false;
        if (Tools::copy($url, $tmpfile)) {
            ImageManager::resize($tmpfile, $path . '.jpg');
            $images_types = ImageType::getImagesTypes($entity);
            if ($regenerate)
                foreach ($images_types as $image_type) {
                    ImageManager::resize($tmpfile, $path . '-' . stripslashes($image_type['name']) . '.jpg', $image_type['width'], $image_type['height']);
                    if (in_array($image_type['id_image_type'], $watermark_types))
                        Hook::exec('actionWatermark', array('id_image' => $id_image, 'id_product' => $id_entity));
                }
        }
        else {
            unlink($tmpfile);
            return false;
        }
        unlink($tmpfile);
        return true;
}

我们准备与其他软件同步的代码。这里给你举个例子

$object->name = array((int)Configuration::get('PS_LANG_DEFAULT') => $nombre);
$object->link_rewrite = array((int)Configuration::get('PS_LANG_DEFAULT') => str2url($nombre));
$object->description =  array((int)Configuration::get('PS_LANG_DEFAULT') => $nombre);;
$object->meta_title = array((int)Configuration::get('PS_LANG_DEFAULT') => $nombre);
$object->meta_description = array((int)Configuration::get('PS_LANG_DEFAULT') => $nombre);
$object->meta_keywords = array ( (int)Configuration::get('PS_LANG_DEFAULT') => getMetaKeywords($nombre,2));

$object->id_parent = $parent;
$object->save();

$image = new Image();
if (!copyImg2($object->id, $image->id, $imagen, 'categories', true))
{
   $image->delete();
}



function copyImg2($id_entity, $id_image, $url, $entity = 'products', $regenerate = true) {
    $tmpfile = tempnam(_PS_TMP_IMG_DIR_, 'ps_import');
    $watermark_types = explode(',', Configuration::get('WATERMARK_TYPES'));
    switch ($entity) {
        default:
        case 'products':
            $image_obj = new Image($id_image);
            $path = $image_obj->getPathForCreation();
            break;
        case 'categories':
            $path = _PS_CAT_IMG_DIR_ . (int) $id_entity;
            break;
        case 'manufacturers':
            $path = _PS_MANU_IMG_DIR_ . (int) $id_entity;
            break;
        case 'suppliers':
            $path = _PS_SUPP_IMG_DIR_ . (int) $id_entity;
            break;
    }
    $url = str_replace(' ', '%20', trim($url));
    if (!ImageManager::checkImageMemoryLimit($url))
        return false;
        if (Tools::copy($url, $tmpfile)) {
            ImageManager::resize($tmpfile, $path . '.jpg');
            $images_types = ImageType::getImagesTypes($entity);
            if ($regenerate)
                foreach ($images_types as $image_type) {
                    ImageManager::resize($tmpfile, $path . '-' . stripslashes($image_type['name']) . '.jpg', $image_type['width'], $image_type['height']);
                    if (in_array($image_type['id_image_type'], $watermark_types))
                        Hook::exec('actionWatermark', array('id_image' => $id_image, 'id_product' => $id_entity));
                }
        }
        else {
            unlink($tmpfile);
            return false;
        }
        unlink($tmpfile);
        return true;
}
$object->name = array((int)Configuration::get('PS_LANG_DEFAULT') => $nombre);
$object->link_rewrite = array((int)Configuration::get('PS_LANG_DEFAULT') => str2url($nombre));
$object->description =  array((int)Configuration::get('PS_LANG_DEFAULT') => $nombre);;
$object->meta_title = array((int)Configuration::get('PS_LANG_DEFAULT') => $nombre);
$object->meta_description = array((int)Configuration::get('PS_LANG_DEFAULT') => $nombre);
$object->meta_keywords = array ( (int)Configuration::get('PS_LANG_DEFAULT') => getMetaKeywords($nombre,2));

$object->id_parent = $parent;
$object->save();

$image = new Image();
if (!copyImg2($object->id, $image->id, $imagen, 'categories', true))
{
   $image->delete();
}



function copyImg2($id_entity, $id_image, $url, $entity = 'products', $regenerate = true) {
    $tmpfile = tempnam(_PS_TMP_IMG_DIR_, 'ps_import');
    $watermark_types = explode(',', Configuration::get('WATERMARK_TYPES'));
    switch ($entity) {
        default:
        case 'products':
            $image_obj = new Image($id_image);
            $path = $image_obj->getPathForCreation();
            break;
        case 'categories':
            $path = _PS_CAT_IMG_DIR_ . (int) $id_entity;
            break;
        case 'manufacturers':
            $path = _PS_MANU_IMG_DIR_ . (int) $id_entity;
            break;
        case 'suppliers':
            $path = _PS_SUPP_IMG_DIR_ . (int) $id_entity;
            break;
    }
    $url = str_replace(' ', '%20', trim($url));
    if (!ImageManager::checkImageMemoryLimit($url))
        return false;
        if (Tools::copy($url, $tmpfile)) {
            ImageManager::resize($tmpfile, $path . '.jpg');
            $images_types = ImageType::getImagesTypes($entity);
            if ($regenerate)
                foreach ($images_types as $image_type) {
                    ImageManager::resize($tmpfile, $path . '-' . stripslashes($image_type['name']) . '.jpg', $image_type['width'], $image_type['height']);
                    if (in_array($image_type['id_image_type'], $watermark_types))
                        Hook::exec('actionWatermark', array('id_image' => $id_image, 'id_product' => $id_entity));
                }
        }
        else {
            unlink($tmpfile);
            return false;
        }
        unlink($tmpfile);
        return true;
}