Jump to content

CSV Import and Text Fields


hanny137

Recommended Posts

When I prepare CSV to import products I have there field

 

Text Fields (0 = No, 1 = Yes)

 

I put 1 and receive text field in front office

 

But, after import I need to go to every imported item go to Customization tab click on Save&stay give a name to the fields and click save again

 

If I don't do this and only import CSV in front office there will be field to input text, but it doesn't work until I do the steps above.

 

Is there any way to put some information to CSV and skip the steps at Back office

Link to comment
Share on other sites

  • 2 weeks later...

Since no one has replied on these forums (which is not surprising - it's pretty rare that I've seen replies to any of the more difficult questions); I created a short script to handle this after the user imports a CSV.

 

It looks like this (adjust to your taste):

// Create connection
$conn = new mysqli($servername, $username, $password, $database);

/* check connection */
if ($conn->connect_errno) {
    printf("Connect failed: %s\n", $mysqli->connect_error);
    exit();
}
echo "Connected successfully<br /><br />";

$conn->query("update ps_category_lang set name=SUBSTRING_INDEX(name, '(', 1)  WHERE  name REGEXP '([[:digit:]]+)';"); 

$conn->query("truncate table ps_customization_field;");
$conn->query("INSERT INTO ps_customization_field (id_product,type,required) SELECT id_product,0,0 FROM ps_product WHERE id_shop_default = 1 AND customizable = 1;");
$conn->query("INSERT INTO ps_customization_field (id_product,type,required) SELECT id_product,1,1 FROM ps_product WHERE id_shop_default = 1 AND customizable = 1;"); 

echo "Added uploadable files & customized field to each item!<br /><br />";

$conn->query("truncate table ps_customization_field_lang;");
$conn->query("INSERT INTO ps_customization_field_lang (id_customization_field, id_lang,id_shop,name) select id_customization_field,1,1,'Upload 1' from ps_customization_field WHERE type = 0;");
$conn->query("INSERT INTO ps_customization_field_lang (id_customization_field, id_lang,id_shop,name) select id_customization_field,1,1,'Field 1' from ps_customization_field WHERE type = 1;");

echo "Added appropriate labeling for each field, for each product!<br /><br />";

echo "<h2>Yay, We're done!</h2>";


$conn->close();
Edited by hanny137 (see edit history)
Link to comment
Share on other sites

  • 2 weeks later...

Hi thank you for the script

it looks promising but somehow it doesnt work for me.

so what i did i put the script int a php file changed the "$conn = new mysqli($servername, $username, $password, $database);"

and after i run it i get the successful update message page but none of my products have the text field fixed.

 

in my CSV i have CUSTOMIZABLE PRODUCT set to 1

and TEXT FIELD I have set to 1

 

after i have them imported i run your script and it shows me its done btu nothing happened. Am I forgetting something? Can someone advice? Thanks

<?php





// Create connection
$conn = new mysqli('xxxxx', 'xxxxx', 'xxxxx', 'xxxxx');

/* check connection */
if ($conn->connect_errno) {
    printf("Connect failed: %s\n", $mysqli->connect_error);
    exit();
}
echo "Connected successfully<br /><br />";

$conn->query("update ps_category_lang set name=SUBSTRING_INDEX(name, '(', 1)  WHERE  name REGEXP '([[:digit:]]+)';"); 

$conn->query("truncate table ps_customization_field;");
$conn->query("INSERT INTO ps_customization_field (id_product,type,required) SELECT id_product,0,0 FROM ps_product WHERE id_shop_default = 1 AND customizable = 1;");
$conn->query("INSERT INTO ps_customization_field (id_product,type,required) SELECT id_product,1,1 FROM ps_product WHERE id_shop_default = 1 AND customizable = 1;"); 

echo "Added uploadable files & customized field to each item!<br /><br />";

$conn->query("truncate table ps_customization_field_lang;");
$conn->query("INSERT INTO ps_customization_field_lang (id_customization_field, id_lang,id_shop,name) select id_customization_field,1,1,'Upload 1' from ps_customization_field WHERE type = 0;");
$conn->query("INSERT INTO ps_customization_field_lang (id_customization_field, id_lang,id_shop,name) select id_customization_field,1,1,'Field 1' from ps_customization_field WHERE type = 1;");

echo "Added appropriate labeling for each field, for each product!<br /><br />";

echo "<h2>Yay, We're done!</h2>";


$conn->close();

?>
Link to comment
Share on other sites

  • 1 year later...

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...