将图像插入到 prestashop 数据库 [英] Insert image to prestashop database

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

问题描述

我正在制作一个简单的脚本,可以将产品直接插入到 prestashop 数据库中,但我找不到如何将图像插入到数据库中.

I am making a simple script that will insert product to prestashop database directly and I can't find how to insert an image to the database.

到目前为止我的脚本是:

So far my script is:

  mysqli_query($conn, 'INSERT INTO ps_product (id_supplier, id_manufacturer, id_category_default, id_shop_default, id_tax_rules_group, on_sale, online_only, quantity, minimal_quantity, price, wholesale_price, out_of_stock, active, redirect_type, available_for_order,  show_price, indexed, visibility, cache_default_attribute, date_add, date_upd, pack_stock_type,ean13,upc,unity,reference,supplier_reference,location) 
VALUES ("2", "2" , "5", "1", "1","1","1", "0", "1", "30", "30", "2", "1", "302","1","1","1","both","19",now(),now(),"3","0","0","","demo_1","","" )');


mysqli_query($conn, 'INSERT INTO ps_product_lang (id_product, id_lang, description, description_short, link_rewrite, name, available_now,meta_description,meta_keywords,meta_title,available_later) 
VALUES (LAST_INSERT_ID(),"1","long des","test","insert title","title inserted","In stock","","","","")');


mysqli_query($conn, 'INSERT INTO ps_product_shop (id_product,id_shop,id_category_default,id_tax_rules_group,price,wholesale_price,unity,active,redirect_type,indexed,cache_default_attribute,date_add,date_upd ) 
VALUES (LAST_INSERT_ID(),"1","5","1","30","30","","1","301","1","1",now(),now())');

现在我必须在其中插入照片,以便我可以完成产品并发布它.

And now I have to inset the photo in it so that the I can complete the product and publish it.

推荐答案

首先,您需要为数据库中的图像(表格图像)创建一个新条目.如果您查看 Prestashop Image Class,它将图像存储在根据您的图像 ID 创建的目录下.您需要拆分图像 ID 的每个数字以获取路径.这是 Prestashop Image Class 方法:

First you need to create a new entry for your image in database (table image). If you look at Prestashop Image Class it stores images under directories created from your image id. You need to split each number of your image id to get the path. Here is Prestashop Image Class method :

/**
 * Returns the path to the folder containing the image in the new filesystem
 *
 * @param mixed $id_image
 * @return string path to folder
 */
public static function getImgFolderStatic($id_image)
{
    if (!is_numeric($id_image)) {
        return false;
    }
    $folders = str_split((string)$id_image);
    return implode('/', $folders).'/';
}

在defines.inc.php _PS_IMG_DIR_ 定义您的图片文件夹(默认:/img/),_PS_PROD_IMG_DIR_ 定义您的产品图片文件夹(默认值:p/).默认情况下,产品图片的文件夹是 /img/p/.

In defines.inc.php _PS_IMG_DIR_ defines your image folder (default: /img/) and _PS_PROD_IMG_DIR_ defines your product image folder (default: p/). by default the folder for product image is then /img/p/.

如果图像的 id 为 927 且名称为test.jpg",它将存储在 /img/p/9/2/7/927.jpg

If an image has for id 927 and for name "test.jpg" it will be stored under /img/p/9/2/7/927.jpg

首先尝试一些产品,然后在 Prestashop BackOffice 中转到 Preferences >图像 >重新生成缩略图(在页面底部).Prestashop 应为您生成每种产品的图片尺寸.

First try this for a few products and then in Prestashop BackOffice go to Preferences > Images > regenerate thumbnails (at the bottom of the page). Prestashop should generate each products image sizes for you.

如果它不起作用或者您需要更多说明,请告诉我.

Please let me know if it doesn't work or if you need more instructions.

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

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