Jump to content

Automated stock script - php - csv file


Naturel Deluxe

Recommended Posts

Already searching for hours, but unfortionally didn`t find the solution yet.

I`m using prestashop 1.7.2.4 & php version 7.0 

I would like to create a php script to import a csv file & update stock, price (tax in cluded), wholesale price, discount amount on a sheduled task. (using cron) 

 

This is where I get stock - always running out on a Error 500... 

 

<?php 


mysql_connect("localhost", "DBNAME", "DBPASWORD") or die(mysql_error()); 
mysql_select_db("DBNAME") or die(mysql_error()); 


$row = 0; 

$update_table = "psc5_product"; 


$handle = fopen("PATHOFCSV", "r"); 


while (($data = fgetcsv($handle, 100000, ";")) !== FALSE) { 
    $num = count($data); 
    echo "$num field update in this row $row:\n"; 
    $row++; 
    for ($c=0; $c < $num; $c++) { 
        if ($c = 1) { 
        $reference = $data[($c - 1)]; 
        echo $reference . " choosen reference\n"; 
        } 

        if ($c = 2) { 
        $wholesale_price = $data[($c - 1)]; 
        mysql_query("UPDATE $update_table SET wholesale_price='$wholesale_price' WHERE reference='$reference'")  
        or die(mysql_error());   
        echo $wholesale_price . " wholesale price updated to\n"; 

        } 
        if ($c = 4) { 
        $price = $data[($c - 1)]; 
        mysql_query("UPDATE $update_table SET price='$price' WHERE reference='$reference'")  
        or die(mysql_error());   
        echo $price . " retail price updated to\n"; 
        }
        if ($c = 6) { 
        $quantity = $data[($c - 1)]; 
        mysql_query("UPDATE $update_table SET quantity='$quantity' WHERE reference='$reference'")  
        or die(mysql_error());  
        echo $quantity . " quantity updated to\n";
        echo " --------------------\n"; 
        } 

    } 

fclose($handle);
echo " * * * * * * * * * * * * * * *\n"; 
echo strip_tags("<b><i>Update done!</i></b>","<b>");
echo " * * * * * * * * * * * * * * *\n"; 
?> 

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