Jump to content

[SOLVED]how to properly add a custom Field on CSV product import


jahyax

Recommended Posts

Good day everyone

 

I have searched the forum regarding how to add a custom field on product CSV import, found some useful thread, but it doesn't solve my problem

 

I am trying to add a custom field on Product CSV import, somehow I manage to add an option/selection to add my custom field, but when I try to hit 'CSV Import' I still get an empty value on my database.

 

currently the files that I am messing with are AdminImportController.php and Products.php

 

Hopefully someone could give a better direction.. on what to..

 

i am using prestashop 1.5.4

Link to comment
Share on other sites

Sorry for not being so detailed..

 

I did add a field on my database first.. which is on PREFIX_products --- I added customfield

 

 

Here is how did it..

On AdminImportController I added on the

 

'customfield' => array('label' => $this->l('My Custom Field')), //somewhere on line 238

 

and also on

 

public function productImport() I added

 

if (isset($product->customfield){

$product->customfield = $product->customfield;

}

  • Sad 1
Link to comment
Share on other sites

  • 2 months later...

In 1.5.6, I found a direct database entry was "easiest"...crazy you can't do this through the standard CSV import...Anways, here's a sample code that should work...

INSERT into ps_customization_field (id_customization_field, id_product, type) VALUES ('7','5','1');
INSERT into ps_customization_field_lang (id_customization_field, id_lang, name) VALUES ('7','1','Comments');
UPDATE ps_product Set customizable = '1', text_fields = '1' where id_product = '5';
UPDATE ps_product_shop Set customizable = '1', text_field = '1'  where id_product = '5';
 
NOTE: the "7" need to auto-increment as this is the PK/FK, and "5" matches each product.  I created an Excel sheet that automatically creates these four lines of SQL for every product, then copied that into a text file, then copied that into phpMyAdmin...worked like a charm...ugh
  • Like 1
Link to comment
Share on other sites

  • 5 months later...

I followed @Jahayx's code, but its not working on prestashop on v 1.6.0 ... Should I add anything to product class? (classes/Product.php) 

Ty for advice

 

Its working, but it dont store it to database, if i'll try to list it in mysql using

SELECT real_name FROM ps_product;

i get NULL, using this code

if (isset($product->real_name))
            {
                $product->real_name = $product->real_name;
            }
Edited by kolega (see edit history)
  • Like 1
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...