Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function order_check_by_number($order_custom_number) {
- global $api;
- $docSearchValue = array (
- 'number' => (INTEGER) $order_custom_number,
- );
- $documentSearch = $api->sendRequest("getSalesDocuments", $docSearchValue);
- return json_decode($documentSearch);
- }
- $xml = file_get_contents("http://store.bredenkids.com/wp-content/uploads/wpallexport/exports/4084483bc00eb0b623869fe8394565b0/current-orders.xml");
- $order = new SimpleXMLElement($xml);
- $order = json_decode(json_encode($order),true);
- // Order basic infrmation
- $OrderID = $order->OrderID;
- $OrderDate = $order->OrderDate;
- $PaymentMethodTitle = $order->PaymentMethodTitle;
- $OrderTotal = $order->OrderTotal;
- $BillingFirstName = $order->BillingFirstName;
- $BillingLastName = $order->BillingLastName;
- $BillingAddress1 = $order->BillingAddress1;
- $BillingAddress2 = $order->BillingAddress2;
- $BillingCity = $order->BillingCity;
- $BillingPostcode = $order->BillingPostcode;
- $BillingCountry = $order->BillingCountry;
- $BillingPhone = $order->BillingPhone;
- $BillingState = $order->BillingState;
- $BillingEmailAddress = $order->BillingEmailAddress;
- $ShippingFirstName = $order->ShippingFirstName;
- $ShippingLastName = $order->ShippingLastName;
- $ShippingCompany = $order->ShippingCompany;
- $ShippingAddress1 = $order->ShippingAddress1;
- $ShippingAddress2 = $order->ShippingAddress2;
- $ShippingCity = $order->ShippingCity;
- $ShippingPostcode = $order->ShippingPostcode;
- $ShippingCountry = $order->ShippingCountry;
- $ShippingState = $order->ShippingState;
- // Ordered products
- $ProductID = $order->OrderItems->Item->ProductID;
- $SKU = $order->OrderItems->Item->SKU;
- $ProductName = $order->OrderItems->Item->ProductName;
- $Quantity = $order->OrderItems->Item->Quantity;
- $ItemCost = $order->OrderItems->Item->ItemCost;
- $ItemTotal = $order->OrderItems->Item->ItemTotal;
- $ItemTax = $order->OrderItems->Item->ItemTax;
- $ItemTaxTotal = $order->OrderItems->Item->ItemTaxTotal;
- $OrderLineID = $order->OrderItems->Item->OrderLineID;
- // Order TAX amounts, coupon usage, order note and total discount
- $TotalTaxAmount = $order->TotalTaxAmount;
- $CouponsUsed = $order->CouponsUsed;
- $TotalDiscountAmount = $order->TotalDiscountAmount;
- $CustomerNote = $order->CustomerNote;
- // alustame sessioni
- session_start([
- 'cookie_lifetime' => 15,
- 'read_and_close' => true,
- ]);
- // include ERPLY API class
- include("EAPI.class.php");
- // Initialise class
- $api = new EAPI();
- // Configuration settings
- $api->clientCode = "";
- $api->username = "kristo.meerits";
- $api->password = "Bredentugi";
- $api->url = "https://".$api->clientCode.".erply.com/api/";
- // Salvestame kliendi aadressi ERPLYsse
- //$inputParameters_aadress = array(
- //"addressID" => "",
- //"ownerID" => "",
- //"typeID" => "",
- //"street" => $tanav,
- //"city" => $linn,
- //"postalCode" => $indeks,
- //"state" => $maakond,
- //"country" => $riik,
- //);
- //$result = $api->sendRequest("saveAddress", $inputParameters_aadress);
- // Salvestame kliendi info ERPLYsse
- $inputParameters_kliendid = array(
- "customerID" => "",
- "groupID" => "17",
- "fullname" => $BillingFirstName,
- "name" => $BillingLastName,
- "email" => $BillingEmailAddress,
- "mobile" => $BillingPhone
- );
- $searchValues = array(
- 'searchName' => $BillingEmailAddress
- );
- // Teeme päringu ERPLYsse ja otsime emaili järgi kliendi
- $searchResult = $api->sendRequest("getCustomers", $searchValues);
- $searchResult = json_decode($searchResult, TRUE);
- $params = array (
- 'parameterName' => "search_invoice_by_regular_and_custom_number",
- 'parameterValue' => 1,
- );
- $api->sendRequest("saveConfParameter", $params);
- if(order_check_by_number($number)->status->recordsTotal > 0) {
- die("Sellise tellimuse numbriga on andmebaasis juba kirje olemas!");
- }
- // kui klient on olemas salvestame tema ID
- if($searchResult['status']['recordsInResponse'] > 0 && ($searchResult['status']['errorCode'] == 0))
- {
- $customerID = $searchResult['records'][0]['id'];
- }
- // kui klienti olemas ei ole siis salvestame kliendi ning jätame ID alles
- else
- {
- $result_klientidega = $api->sendRequest("saveCustomer", $inputParameters_kliendid);
- $output2 = json_decode($result_klientidega, true);
- $customerID = $output2['records'][0]['clientID'];
- }
- // Tellimuse info, mis tuli e-poest sisestus
- $inputParameters = array(
- // Tellimuse ID number e-poest
- "id" => "",
- "invoiceNo" => "",
- "customNumber" => $OrderID,
- "allowDuplicateNumbers" => "0",
- // Tellimuse tüüp (arve, pakkumine, tellimus, saateleht)
- "type" => "ORDER",
- // Valuuta kood
- "currencyCode" => "EUR",
- // ERPLY lao ID ( 1 on põhiladu)
- "warehouseID" => "1",
- // Kuupäev Y-m-d formaadis
- "date" => $OrderDate, // Ajutine manuaalne
- // Kellaaeg H:m:s formaadis
- "time" => date('H:m:s'), // Ajutine manuaalne
- // Kas kinnitame tellimuse/arve/saatelehe automaatselt?
- "confirmInvoice" => "1",
- // Kliendi ID ERPLY'S & Maksja ID ERPLY'S
- "customerID" => $customerID,
- "payerID" => "",
- // Saaja Addressi ID ERPLY'S & Maksja aadressi ID ERPLY'S
- "addressID" => "",
- "payerAddressID" => "",
- // Tellimuse lisainformatsioon väljatrükil
- "notes" => $CustomerNote,
- // Lisainformatsioon, mis on nähtav vaid adminnile.
- "internalNotes" => CustomerNote,
- // Tellimuse kogusumma?
- "externalNetTotal" => "",
- // Makseviis, kood ERPLY'st (CARD; TRANSFER, CASH...)
- "paymentType" => "TRANSFER",
- // Maksetingimus
- "paymentDays" => "1",
- // Makse staatus (PAID; UNPAID)
- "paymentStatus" => "PAID",
- );
- $i = 1;
- foreach ($post['OrderItems']['Item'] as $product) {
- $inputParameters["productID".$i] = $product["SKU"];
- $inputParameters["amount".$i] = $product["Quantity"];
- $inputParameters["vatrateID".$i] = "1";
- $inputParameters["price".$i] = $product["ItemCost"];
- $inputParameters["discount".$i] = "";
- $i++;
- }
- $result = $api->sendRequest("saveSalesDocument", $inputParameters);
- $output = json_decode($result, true);
- print "<pre>";
- print_r($output);
- echo "Kliendi ID: ".$customerID;
- print "</pre>";
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement