Create product from a module in prestashop

孤人 提交于 2019-11-30 07:33:23
Paul Campbell

The name and meta keyword field are both multi-language arrays. If you look at AdminImport.php in admin/tabs you'll find the definition for a function:

private static function createMultiLangField($field) 

Copy this function into your module and you can use it to create a suitable array for these multi-language fields if you call it by passing your text as the $field parameter (it will set the value for all languages to the string you pass in). You should also set a default value for the description_short and link_rewrite fields:

$object->description_short = array((int)(Configuration::get('PS_LANG_DEFAULT')) => '');

and

$object->link_rewrite = array((int)(Configuration::get('PS_LANG_DEFAULT')) => '');

The second point is that although you've set the default category, you will also have to explicitly set id_category as an array e.g.

$object->category=array(18);

I also think you should then set the categories explicitly with:

$object->updateCategories($object->category, true);

It should then appear in the catalog.

You can refer to this example where the author created an import procedure to import products.

Custom Product Import

As you can see after download the ProductImporter.php is that the id_lang is added to each property.

to make the product available, You need to change this:

$object->active = 1; // sets the product as active for shop

-rk-

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