本文介绍了如何在 prestashop 中的程序化产品导入期间添加图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找不到有关在产品插入过程中添加图像的正确文档.这是我的 xml 产品导入脚本的工作代码.我不知道如何在添加产品的同时添加产品图片.

I can't find a proper documentation on adding images during product inserting. Here is the working code of my xml product import script. I have no idea how to add product images also while adding a product.

foreach ($xml->Products as $product_xml)
{
    if ($product_xml->Valid_internet_product == 1)
    {
        /* Update an existing product or Create a new one */
        $id_product = (int)Db::getInstance()->getValue('SELECT id_product FROM '._DB_PREFIX_.'product WHERE reference = \''.pSQL($product_xml->Reference).'\'');
        $product = $id_product ? new Product((int)$id_product, true) : new Product();
        $product->reference = $product_xml->Reference;
        $product->price = (float)$product_xml->Price;
        $product->active = (int)$product_xml->Active_product;
        $product->weight = (float)$product_xml->Weight;
        $product->minimal_quantity = (int)$product_xml->MinOrderQty;
        $product->id_category_default = 2;
        $product->name = utf8_encode($product_xml->Products_name);
        $product->description = utf8_encode($product_xml->Description);
        $product->description_short = utf8_encode($product_xml->Short_Description);
        $product->link_rewrite = Tools::link_rewrite($product_xml->Products_name);
        $product->image_url = 'http://i.imgur.com/jLThaBj.jpg';
        if (!isset($product->date_add) || empty($product->date_add))
            $product->date_add = date('Y-m-d H:i:s');
        $product->date_upd = date('Y-m-d H:i:s');
        $id_product ? $product->updateCategories(array(2)) : $product->addToCategories(array(2));


        $product->save();

        echo 'Product <b>'.$product->name.'</b> '.($id_product ? 'updated' : 'created').'<br />';
    }
} 

推荐答案

这是通过以下方法实现的:

This is implemented with the following method:

AdminImportControllerCore::copyImg()

您可以复制/粘贴它,或者根据需要进行更改.

You can just copy/paste it, or change it if you need.

这篇关于如何在 prestashop 中的程序化产品导入期间添加图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 17:46