imnotcraig Posted March 20, 2013 Share Posted March 20, 2013 Hi, How to use class product? I want to add a product from my own module and I code like this but it doesn't work $p = new Product(); $p->name = "bla bla"; $p->description = "bla bla" $p->price = 1000; ... $p->add(); Link to comment Share on other sites More sharing options...
Valérie Assetskaya Posted March 20, 2013 Share Posted March 20, 2013 Hi, Please, open class source and make sure that in your script all the fields marked as 'required' => true are filled. Best regards. Link to comment Share on other sites More sharing options...
imnotcraig Posted March 20, 2013 Author Share Posted March 20, 2013 Yes, I looked into the source code and I followed the comments. The problem is when I do: $ p-> name = "Product name"; This saves individually "P", "r", "o", .... then it is marked on the comments that the value of the $name is string. Link to comment Share on other sites More sharing options...
Alex Simonchik BelVG Posted March 20, 2013 Share Posted March 20, 2013 Hi, we don't understand your problem. Can you describe us your problem more clearly? Link to comment Share on other sites More sharing options...
imnotcraig Posted March 21, 2013 Author Share Posted March 21, 2013 I want to know how to use class Product. I use this class to add a product from my own module and It doesn't work. Ex: $name saves a charactere not a string on database Link to comment Share on other sites More sharing options...
vekia Posted March 21, 2013 Share Posted March 21, 2013 you are talking about object model probaly, you should create an object with fields that are necessary for product class, exactly as Valérie Assetskaya mentioned above 1 Link to comment Share on other sites More sharing options...
imnotcraig Posted March 21, 2013 Author Share Posted March 21, 2013 I don't understand. Link to comment Share on other sites More sharing options...
Paul C Posted March 21, 2013 Share Posted March 21, 2013 There's a reason that: $ p-> name = "Product name"; Doesn't work, and that's because it should be an array of language strings and not just a string. If you look in the AdminImportController.php file you'll see that these are actually populated using a function: static function createMultiLangField($field) { $languages = Language::getLanguages(false); $res = array(); foreach ($languages as $lang) $res[$lang['id_lang']] = $field; return $res; } Use a similar function in your own code and the problem with the name will be fixed. You can see which fields require this by looking at the above admin import file for clues (in later PS1.5 versions the admin "tabs" are in controllers/admin) Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now