Jump to content

programmatically adding product


webddr.net
 Share

Recommended Posts

Hi, I am new in prestashop, I plan to create special page to insert fix type of product for intern use.

 

Is there a function or way to save the product data/object programmatically?

 

I am imagine it will look like drupal add node programmatically.

 

If this not possible for now, anyone can tell me what tables are affected each time we adding product with combination?

 

Sorry for my bad English

 

Thanks

Share this post


Link to post
Share on other sites

  • 1 year later...

it is possible to create new product by php code (program)

 

$product = new Product();
$product->ean13 = 9999999999999;
$product->name = array((int)Configuration::get('PS_LANG_DEFAULT') =>  'Test importu');;
$product->link_rewrite = array((int)Configuration::get('PS_LANG_DEFAULT') =>  'test-importu');
$product->id_category = 2;
$product->id_category_default = 2;
$product->redirect_type = '404';
$product->price = 22;
$product->quantity = 1;
$product->minimal_quantity = 1;
$product->show_price = 1;
$product->on_sale = 0;
$product->online_only = 1;
$product->meta_keywords = 'test';
$product->is_virtual=1;
$product->add();
$product->addToCategories(array(2));

$shops = Shop::getShops(true, null, true);    
$image = new Image();
$image->id_product = $id_product;
$image->position = Image::getHighestPosition($id_product) + 1;
$image->cover = true; // or false;
if (($image->validateFields(false, true)) === true &&
($image->validateFieldsLang(false, true)) === true && $image->add())
{
    $image->associateTo($shops);
    if (!AdminImportController::copyImg($id_product, $image->id, $url, 'products', false))
    {
        $image->delete();
    }
}

  • Like 2

Share this post


Link to post
Share on other sites

  • 1 month later...

it is possible to create new product by php code (program)

 

$product = new Product();

$product->ean13 = 9999999999999;

$product->name = array((int)Configuration::get('PS_LANG_DEFAULT') =>  'Test importu');;

$product->link_rewrite = array((int)Configuration::get('PS_LANG_DEFAULT') =>  'test-importu');

$product->id_category = 2;

$product->id_category_default = 2;

$product->redirect_type = '404';

$product->price = 22;

$product->quantity = 1;

$product->minimal_quantity = 1;

$product->show_price = 1;

$product->on_sale = 0;

$product->online_only = 1;

$product->meta_keywords = 'test';

$product->is_virtual=1;

$product->add();

$product->addToCategories(array(2));

 

$shops = Shop::getShops(true, null, true);    

$image = new Image();

$image->id_product = $id_product;

$image->position = Image::getHighestPosition($id_product) + 1;

$image->cover = true; // or false;

if (($image->validateFields(false, true)) === true &&

($image->validateFieldsLang(false, true)) === true && $image->add())

{

    $image->associateTo($shops);

    if (!AdminImportController::copyImg($id_product, $image->id, $url, 'products', false))

    {

        $image->delete();

    }

}

 

Hi and its possible create this way a product with specific product_id?

When i run this script I obtain error : Call to protected method AdminImportControllerCore::copyImg() from context

Edited by mardon (see edit history)

Share this post


Link to post
Share on other sites

  • 4 weeks later...
  • 4 years later...
  • 9 months later...

Hey,
Depends on how you will do this and how you can access the prestashop database. For myself, I have access from outside to my database (well, the database is running local and the website is running external from my provider) and so I can do anything I want. So I made a windows program (c#) that controls almost everything, including adding products automatically.
To do so, you have to add data to a lot of rows in your database suchs as ps_product, ps_product_lang, ps_product_shop, ps_product_supplier, ps_stock, ps_stock_available, ps_image, ps_image, ps_image_lang, ps_image_shop, ps_category_product etc..
You can find the tables for your current version prestashop if you search for prestashop 1.x.x database product or someting like that.

Good luck!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More