I created a class to pass data from a shopping cart into a form emulation using cURL my problem is the way to retrieve the data to sent.
So far I created a class:
<?php
class ic {
var $code, $title, $description, $enabled;
function https_send($params)
{
$test_mode=0;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://www.internationalcheckout.com/cart.php");
// Seed cURL connection options
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POST, 1);
// Create iData packet from individual fields...
$idata=implode(",",$params["iData"]);
// Compose and send POST message
curl_setopt($ch, CURLOPT_POSTFIELDS, 'Company=' . $params["iccompany"] . '&iData=' . $idata);
$result=curl_exec ($ch);
curl_close ($ch);
return $result;
}
Then to get the product info from the shopping cart ...
//Prepare the data from the cart to be transmited using curl
function process_button() {
global $_SERVER, $product;
$products = $cart->get_products();
for ($i=0, $n=sizeof($products); $i<$n; $i++) {
if (($i/2) == floor($i/2)) {
$productsImage = (IMAGE_SHOPPING_CART_STATUS == 1 ? zen_image(DIR_WS_IMAGES . $products[$i]['image'], $products[$i]['name'], IMAGE_SHOPPING_CART_WIDTH, IMAGE_SHOPPING_CART_HEIGHT) : '');
$quantityField = zen_draw_input_field('cart_quantity[]', $products[$i]['quantity'], 'size="4"');
$productsPrice = $currencies->display_price($products[$i]['final_price'], zen_get_tax_rate($products[$i]['tax_class_id']), $products[$i]['quantity']) . ($products[$i]['onetime_charges'] != 0 ? '<br />' . $currencies->display_price($products[$i]['onetime_charges'], zen_get_tax_rate($products[$i]['tax_class_id']), 1) : '');
$productsPriceEach = $currencies->display_price($products[$i]['final_price'], zen_get_tax_rate($products[$i]['tax_class_id']), 1) . ($products[$i]['onetime_charges'] != 0 ? '<br />' . $currencies->display_price($products[$i]['onetime_charges'], zen_get_tax_rate($products[$i]['tax_class_id']), 1) : '');
// Create a smaller Array to hold just the data above
$productArray[$i] = array( 'productsImage'=>$productsImage,
'productsName'=>$productsName,
'quantityField'=>$quantityField,
'productsPrice'=>$productsPrice,
'productsPriceEach'=>$productsPriceEach,
'rowClass'=>$rowClass,
'id'=>$products[$i]['id']);
} // end FOR loop
foreach ($productArray as $product) {
$process_button_string = zen_draw_hidden_field('ItemQuantity',$product['quantityField'] .
zen_draw_hidden_field('ItemImage', $product['productsImage']) .
zen_draw_hidden_field('ItemDescription', $product['productsName']) .
zen_draw_hidden_field('ItemPrice', $product['productsPrice']);
$process_button_string .= zen_draw_hidden_field(zen_session_name(), zen_session_id());
return $process_button_string;
}
}
// !Functions to execute before processing the order
function before_process() {
global $_POST;
$params['iccompany']= MODULE_PAYMENT_IC_COMPANY;
$params['ItemQuantity'] = $_POST['ItemQuantity'];
$params['ItemImage'] = $_POST['ItemImage'];
$params['ItemDescription'] = $_POST['ItemDescription'];
$params['ItemPrice'] = $_POST['ItemPrice'];
$params['iccompany'] = urlencode($params['iccompany']);
$params['iData'][0] = urlencode($params['ItemQuantity']);
$params['iData'][1] = urlencode($params['ItemImage']);
$params['iData'][2] = urlencode($params['ItemDescription']);
$params['iData'][3] = urlencode($params['ItemPrice']);
So now what's left is how to loop through the products to concatenate the final string that will be added to CURLOPT_POSTFIELDS.
My problem is I am not sure if $productArray will be empty, because this info is retrieved from the cart.