I am writing a php script that makes a cURL POST request to a miva page.
I would like to convert the request parameters (args) to global variables.
Is there a Miva function that can do this?
Here is php script:
Here is the page template:
From different testing that I have done the global quantity and product_code variable work when I enter it into the address bar but not when it is requested through cURL.
I can echo the cURL html_parmas, json_params and json_reponse and I know they are being posted correctly from the php function.
is there an mvt:do miva function that can convert query_string to json data variables?
I would like to convert the request parameters (args) to global variables.
Is there a Miva function that can do this?
Here is php script:
Code:
<?php error_reporting(E_ERROR | E_PARSE | E_NOTICE | E_WARNING); require_once('lib/init.php'); // header("Access-Control-Allow-Origin: *"); $params = array( 'Product_Code' => 'some_code', 'Quantity' => '1' ); $str_params = json_encode($params); $html_params = http_build_query($params); $url = "https://www.mydomain.com/path/add-to-cart.html"; $curl = curl_init($url); curl_setopt($curl, CURLOPT_HEADER, false); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-type: application/json")); curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_POSTFIELDS, $html_params); // use for html params // curl_setopt($curl, CURLOPT_POSTFIELDS, $str_params); toggle to use json params $json_response = curl_exec($curl); $status = curl_getinfo($curl, CURLINFO_HTTP_CODE); if ( $status != 200 ) { die("Error: call to URL $url failed with status $status, response $json_response, curl_error " . curl_error($curl) . ", curl_errno " . curl_errno($curl)); } curl_close($curl); echo ('<!doctype html><html><head>'); echo ('</head><body>'); echo ('<h2>Details'.$html_params.'</h2>'); echo ('<h2>Details'.$str_params.'</h2>'); echo ('<h2>Details'.$json_response.'</h2>'); echo ('</body></html>'); ?>
Code:
<mvt:do file="g.module_merchant" name="g.adpr_callback" value="Action_AddProductToBasket()" /> {"type":"Success", "text":"JSON Received", "adpr_callback":"&mvt:global:adpr_callback;", "Quantity":"&mvt:global:quantity;", "Product_Code":"&mvt:global:product_code;" }
I can echo the cURL html_parmas, json_params and json_reponse and I know they are being posted correctly from the php function.
is there an mvt:do miva function that can convert query_string to json data variables?
Comment