Link gekopieerd
Hoi Ward,
Daar heb ik tweemaal een topic geopend, hier kwamen echter geen reacties op.
Het gaat om een oplossing van 3BM. De volgende code hebben zij aangeleverd.
<?php
// start xml string soap
// opbouwen van de XML string op basis van de order die naar warehouse moet
$xmlstring = '';
$xmlstring .= '<?xml version="1.0" encoding="UTF-8"?>';
$xmlstring .= '<orders>';
$i= "0";
try
{
// get list of orders
// ophalen order(s)
$completed_orders = salesOrderList();
}
catch (Exception $e)
{
$l_error_mess = $e -> getMessage ();
exit;
}
$l_i = 0;
foreach ( $completed_orders as $order_header )
{
$l_i = $l_i + 1;
// get order data and place in variables
$order_increment_id = ($order_header->increment_id);
$i=(1);
$order_id = ($order->increment_id);
$order_store = ($order->store_name);
$order_order_number = ($order->order_id);
$order_created_at = ($order->created_at);
$order_updated_at = ($order->updated_at);
// enzovoorts
//
//opbouwen xml string op basis van variabelen
$xmlstring .= '<order>';
$xmlstring .= '<orderid>' . $order_id . '</orderid>';
$xmlstring .= '<shop>' . $order_store . '</shop>';
$xmlstring .= '<customerid>' . '</customerid>';
$xmlstring .= '<email>' . $order_customer_email . '</email>';
$xmlstring .= '<phone>' . $order_billing_address_phone . '</phone>';
$xmlstring .= '<language>' . 'NL' . '</language>';
$xmlstring .= '<billing>';
$xmlstring .= '<billing_company>' . '</billing_company>';
$xmlstring .= '<billing_first_name>' . $order_billing_address_first_name .
'</billing_first_name>';
$xmlstring .= '<billing_last_name>' . $order_billing_address_last_name .
'</billing_last_name>';
$xmlstring .= '<billing_address>' . $order_billing_address_address_1 .
'</billing_address>';
$xmlstring .= '<billing_postal>' . $order_billing_address_postcode .
'</billing_postal>';
$xmlstring .= '<billing_city>' . $order_billing_address_city . '</billing_city>';
$xmlstring .= '<billing_country>' . $order_billing_address_country .
'</billing_country>';
$xmlstring .= '</billing>';
$xmlstring .= '<shipping>';
$xmlstring .= '<shipping_method>' . $order_shipping_methods . '</shipping_method>';
$xmlstring .= '<shipping_company>' . '</shipping_company>';
$xmlstring .= '<shipping_first_name>' . $order_shipping_address_first_name .
'</shipping_first_name>';
$xmlstring .= '<shipping_last_name>' . $order_shipping_address_last_name .
'</shipping_last_name>';
$xmlstring .= '<shipping_address>' . $order_shipping_address_address_1 .
'</shipping_address>';
$xmlstring .= '<shipping_postal>' . $order_shipping_address_postcode .
'</shipping_postal>';
$xmlstring .= '<shipping_city>' . $order_shipping_address_city . '</shipping_city>';
$xmlstring .= '<shipping_country>' . $order_shipping_address_country .
'</shipping_country>';
$xmlstring .= '</shipping>';
$xmlstring .= '<invoice>';
$xmlstring .= '<incoterm>20</incoterm>';
$xmlstring .= '<shipping_currency>' . $order_currency . '</shipping_currency>';
$xmlstring .= '<shipping_cost>' . '</shipping_cost>';
$xmlstring .= '<total_order_currency>' . $order_currency . '</total_order_currency>';
$xmlstring .= '<total_order_value>' . $order_total . '</total_order_value>';
$xmlstring .= '<show_price>' . 'N' . '</show_price>';
$xmlstring .= '<order_description>' . '' . '</order_description>';
$xmlstring .= '</invoice>';
$xmlstring .= '<items>';
// get order lines
$orderItems = $order->items;
foreach($orderItems as $orderItem)
{
$order_line_items_id = ($orderItem->item_id);
$order_line_items_total = ($orderItem->row_total);
$order_line_items_total_tax = ($orderItem->tax_amount);
$order_line_items_price = ($orderItem->price);
$order_line_items_quantity = ($orderItem->qty_ordered);
$order_line_items_name = ($orderItem->name);
$order_line_items_product_id = ($orderItem->product_id);
$order_line_items_sku = ($orderItem->sku);
// build item xml
$xmlstring .= '<item>';
$xmlstring .= '<ProductName>' . $order_line_items_name . '</ProductName>';
$xmlstring .= '<ProductCode>' . $order_line_items_product_id . '</ProductCode>';
$xmlstring .= '<quantity>' . $order_line_items_quantity . '</quantity>';
$xmlstring .= '<item_units>' . '1' . '</item_units>';
$xmlstring .= '<item_price>' . $order_line_items_total . '</item_price>';
$xmlstring .= '<item_weight>' . '</item_weight>';
$xmlstring .= '</item>';
}
// close item xml
$xmlstring .= '</items>';
$xmlstring .= '</order>';
$xmlstring = str_replace("\r", "", $xmlstring);
$xmlstring = str_replace("\n", "", $xmlstring);
}
if ($i == "0")
{
$v_error_mess = "Message: " . "Er staan geen orders klaar om te exporteren" ;
exit;
}
$xmlstring .= '</orders>';
// prepare soap connection
$options = array
( 'trace' => 1, // enable trace to view what is happening
'exceptions' => 1, // disable exceptions
'cache_wsdl' => 0, // disable any caching on the wsdl, encase you alter the
wsdl server
// login naam om soap te benaderen (via 3BM)
'loginname'=>SHOP_LOGINNAME,
'password'=>SHOP_PASSWORD,
);
try
{
$client_s = new SoapClient(SOAP_URL, $options);
$xmlstring_soap = array
( 'loginname' => SHOP_LOGINNAME,
'password' => SHOP_PASSWORD,
'version' => SHOP_VERSION,
'xml' => $xmlstring,
);
// call soap function
$response = $client_s->order_creation($xmlstring_soap);
}
catch (Exception $e)
{
$l_error_mess = $e -> getMessage ();
$v_error_mess = "Error " . $l_error_mess . " Last response: " . $client_s-
>__getLastResponse();
driebm_log($v_error_mess);
exit;
}
// process return file soap call
//xml strippen van omliggende tags
$simple = ($client_s->__getLastResponse());
$simple_s = ( explode( '?>', $simple ) );
$simple_e = ( explode( '</order_creationResult>', $simple_s[1] ) );
$xmlObject_str = htmlspecialchars_decode($simple_e[0]);
// omzetten XML naar Array om elementen te benaderen
$xmlObject = new SimpleXMLElement($xmlObject_str);
foreach ($xmlObject->order as $result)
{
$result_orderid = $result->orderid;
$result_status = $result->status;
$result_error = $result->error;
$result_error_line = $result->error->line;
$result_date_time = $result->date_time;
if ($result_status == "error")
{
echo "<br>naar error " . $result_orderid . " | " . $result_error_line;
}
if ($result_status == "pending")
{
$c_order_status = 'processing';
// update your order with new status
// $result = update_order();
//
echo "<br>naar completed " . $result_orderid;
}
}
}
?>
Link gekopieerd