JoelWebsites Posted January 19, 2015 Share Posted January 19, 2015 Below is the code to create your own api using prestashop database. webservice.php <?php error_reporting(-1); ini_set('display_errors', 'On'); //if(isset($_GET['format']) && intval($_GET['num'])) { //Set our variables $format = strtolower($_GET['format']); //$num = intval($_GET['num']); $db_host = "127.0.0.1"; // Place the username for the MySQL database here $db_username = "username"; // Place the password for the MySQL database here $db_pass = "password"; // Place the name for the MySQL database here $db_name = "prestashop"; // Run the actual connection here mysql_connect("$db_host","$db_username","$db_pass") or die ("could not connect to mysql"); mysql_select_db("$db_name") or die ("no database"); //Run our query $result = mysql_query('SELECT * FROM ps_employee ') or die('MySQL Error.'); //Preapre our output if($format == 'json') { $recipes = array(); while($recipe = mysql_fetch_array($result, MYSQL_ASSOC)) { $recipes[] = array('post'=>$recipe); } $output = json_encode(array('posts' => $recipes)); } elseif($format == 'xml') { header('Content-type: text/xml'); $output = "<?xml version=\"1.0\"?>\n"; $output .= "<recipes>\n"; for($i = 0 ; $i < mysql_num_rows($result) ; $i++){ $row = mysql_fetch_assoc($result); //$output .= "<recipes> \n"; $output .= "<recipe_id>" . $row['id_employee'] . "</recipe_id> \n"; $output .= "<recipe_name>" . $row['email'] . "</recipe_name> \n"; } $output .= "</recipes>"; } else { die('Improper response format.'); } //Output the output. echo $output; //} ?> Below is how to retrive retrive.php <?php error_reporting(-1); ini_set('display_errors', 'On'); $url = 'http://example/webservice.php?format=json'; $content = file_get_contents($url); $json = json_decode($content, true); print_r($json); echo "Name: ".$json[posts][1][firstname]."<br>"; //getting the username echo "Email: ".$json[posts][1]." "; ?> 2 Link to comment Share on other sites More sharing options...
polaije Posted November 19, 2015 Share Posted November 19, 2015 Hi, I am relatively new in php and module creation, I am c# developper. I wonder if I can andapt you code to retrieve data from a web service describe in https://platform.medipim.be/docs/api/v1.html. The module must do three things: - update products, like price, picture - create new products based on filter like brand or reference. - Map some fields like category Is this very difficult to do ? Jean-Marie 1 Link to comment Share on other sites More sharing options...
JoelWebsites Posted November 19, 2015 Author Share Posted November 19, 2015 Do you want to retrive data from a webservice..and use that data to create new products? is that correct? Link to comment Share on other sites More sharing options...
techjp Posted November 23, 2015 Share Posted November 23, 2015 If you wish to use the web service from C# you should definitely check out PrestaSharp, you can find it on Github. 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