Jump to content

Create Product By Script


Recommended Posts

I can't believe in prestashop dont have ANY documentation about this.

In all another cms i found VERY VERY EASY way and docs for how to insert product by script.

I have search around the web and people say "read the source you have access all classes"

ARE YOU KIDDING ME?

he class Product, adminController has 10000 line of code and i'm trying to see what happen when i put the save button on the admin but its IMPOSSIBLE to track becouse have MANY internal mechanism that impossiblity to understand.

 

tell me if i'm wrong becouse i'm very angry with this.

Edited by xxMAGRAOxx (see edit history)
Link to comment
Share on other sites

It's not that complicated. Just include the main fies in your php script
 

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


Then 

$product = new Product();
 
// add a few things here, check the product class to see which fields are required, like name etc

Then

$product->add();


That's all
  • Like 1
Link to comment
Share on other sites

You are right, but my insertion is not simple as that.

 

Nemo1, i see you are a very experience in prestashop. Can you help me in another thing?

 

I cannot unserstand how the product insert the tags. I find another solution. I'm insert the tags of product by the Tag object, but i need to insert by Product object.

 

Can you tell in what function(s) this happen?

 

I'm not able to track the insert process.

Link to comment
Share on other sites

I believe it just manually adds tags
 

$result = Db::getInstance()->execute('
INSERT INTO `'._DB_PREFIX_.'product_tag` (`id_product`, `id_tag`, `id_lang`)
VALUES '.implode(',', $sql_values)
);

That's what it does with the webservice method
  • Like 1
Link to comment
Share on other sites

Yes, you touch in one important point that i pass in a moment.
 
I am avoid to insert anything manually, becouse its more chance of errors, more work and research in code of prestashop, but i think at this time haven't another way. Not in tag becouse tag i instanciate one or other, the problem is in the custom features. Listen, i'm import 50-200 ebooks by xml and the ebooks has custom fields like isbn, author, edition, etc etc. Imagine foreach ebook i create custom feature for each feature.

 

Ex:
 
$idFeatureValue = $product->addFeaturesToDB($idFeatureIDISBN, null, 1);
$product->addFeaturesCustomToDB($idFeatureValue, 1, 'isbn123');
 
$idFeatureValue = $product->addFeaturesToDB($idFeatureIDIdiom, null, 1);
$product->addFeaturesCustomToDB($idFeatureValue, 1, 'Brazil');
 
$idFeatureValue = $product->addFeaturesToDB($idFeatureIDCollectionTitle, null, 1);
$product->addFeaturesCustomToDB($idFeatureValue, 1, 'Star Wars');

 

...

many other custom features

...

 

Can you see? Its very very very poor performance.

 

Can you suggest something for me? 

 

ps: I need that field can be editable in adm.

Link to comment
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
×
×
  • Create New...