Create products from PHP in PrestaShop

In this video we will see how to create a simple script to generate products with PHP in PrestaShop

Watch the screencast

Final Code

<?php

include(dirname(__FILE__).'/config/config.inc.php');
include(dirname(__FILE__).'/init.php');


// we have a csv file open
$default_lang = Configuration::get('PS_LANG_DEFAULT');
// looping through products
// this is a single line in the loop


$product = new Product(20);
$product->name = [$default_lang => 'Test'];
$product->link_rewrite = [$default_lang => 'test'];
$product->price = 13.90;
$product->quantity = 70;
$product->id_category = [3,4];
$product->id_category_default = 3;
StockAvailable::setQuantity((int)$product->id, 0, $product->quantity, Context::getContext()->shop->id);

$product->update();

You like the tuts and want to say "thank you"? Well, you can always feel free to donate:

  • wortis mohand

    hello,
    can you show me the conians of the files config.inc.php and init.php please !
    thank you

  • Pepe Jimenez Arcos

    Very good articles.

    I would like the article put both the high, as the product modifications, I can not make it work.

    Thank you.

Store Top Sales

You like the tuts and want to say "thank you"? Well, you can always feel free to donate: