Jump to content

tonton

Members
  • Posts

    14
  • Joined

  • Last visited

tonton's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hi Jacques, thanks for this. This is just speculation. Because I think that the cUrl doesn't retry automatically but the TCP protocol does : if TCP not getting its ACK so it re-sends the packet a couple of times, does not it? And this situation is very rare/exceptionnel 1%! When the "total_time" (by [curl_getinfo]) is more than 7 second.
  2. can you some idea for me ?
  3. Hi Jacques1, many thanks When you say "your service", is it web service which I use, isn't it ? So this web service provided us by our supplier. So I can not any control this web service : I must ask to change to our provider ? Or I must add something in my script ? What is a nonce ? It means a token ? Where can I put this token ? I can create a unique/single token with "microtime" + order number, is it right ? Before "curl_close" line 84? Here is my code : include 'includes/info.php'; include 'includes/functions.php'; $micro_date = microtime(); $date_array = explode(" ",$micro_date); $nowDate = date("Y_m_d__H_i_s__",$date_array[1]); define('KEY_SECRET', $key_shared_secret); function verify_webHk($dataIn, $hmac_header) { $calculated_hmac = base64_encode(hash_hmac('sha256', $dataIn, KEY_SECRET, true)); return ($hmac_header == $calculated_hmac); } $hmac_header = $_SERVER['HTTP_X_HMAC_SHA256']; $dataIn; $dataIn = file_get_contents('php://input'); $verified = verify_webHk($dataIn, $hmac_header); $dataInDecode = json_decode($dataIn); $dataInDecodeArray = json_decode($dataIn, true); $nowDateFile = date("Ymd"); $orderNumber = $dataInDecodeArray['orderNumberJsn']; $logFileName = '\sent_response_' . $orderNumber . '_' . $nowDateFile. '.txt'; $logFileNameConnexion = '\error_connexion_' . $orderNumber . '_' . $nowDateFile. '.txt'; $orderNumber = $dataInDecode->orderNumberJsn; foreach ($dataInDecode->lineItems as $objProd) { switch($objProd->trader) { case 'TraderPeekABoo' : $errorNumberCurl = NULL; $errorTitleCurl = NULL; $searchID = funcFind(array("*-","--","=="),$objProd->nsm); $productID = $searchID[0]; $priceItems = $objProd->priceItems; $pricesTaxs = (array)$objProd->taxLines; $tax1st = !empty($pricesTaxs[0]) ? $pricesTaxs[0]->priceItems : 0.00; $tax2nd = !empty($pricesTaxs[1]) ? $pricesTaxs[1]->priceItems : 0.00; $total = $priceItems + $tax1st + $tax2nd ; $commandXML = '<?xml version="1.0" encoding="utf-8"?> <command> <traderId>' . $orderNumber . '</traderId>'; $commandXML .= '<commandItem> <faceValue>' . number_format($total, 2, '.', '')*100 . '</faceValue> '; $commandXML .= '</commandItem></command>'; $urlWS = $url . $productID. '?account=' . $account . '&key=' . $key ; $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $urlWS); curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query(array('xml' => $commandXML))); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); $dataOut = curl_exec($curl); $infoOut = curl_getinfo($curl); $logData = "\r\n" .'Information transfer :'. "\r\n" . serialize($infoOut) . "\r\n" .'result :'."\n". $dataOut. "\r\n"; if(curl_errno($curl)) { $errorNumberCurl = curl_errno($curl); $errorTitleCurl = curl_error($curl); } curl_close($curl); if($errorNumberCurl) { $dataLogError = "\r\n" .'CURL\'S Error number: "' . $errorNumberCurl . '" and Error info: "'. $errorTitleCurl. '"'."\r\n"; file_put_contents($logDirectory.$logFileNameConnexion, $dataLogError, FILE_APPEND | LOCK_EX); } file_put_contents($logDirectory.$logFileName, $logData, FILE_APPEND | LOCK_EX); break; default: // echo '<p>NOTHING</p>'; break; } } exit();
  4. Hi, I have a PHP script using the cURL function. This script send the data by a web service. It works often without problem. Sometimes, he sent a double data : same data by two times. I checked the log file this script (by curl_getinfo) on "total_time" When this script works correctly (it send the data only one time) : the total_time is less than 6 second. but when the total_time is more than 7 second, (this is a casual/occasional situation), my script send same data by two times so it is double data! So the web service send the ACK(Acknowledgment) which takes a long time (more than 7 second) and then, the TCP send again same data to a web service. How can I avoid this doubling ? By increasing this time waiting / time limit ? How can I define this time limit for 12 second? Could you help me : Thanks
  5. Hi QuickOldCar, Thanks, but I check always and I checked it : My json data is valid... Here is my json : { "currency": "CAD", "email": "toto@gmail.com", "items": [ { "name_title": "pen", "quantity": 1, "price": "20.00", "taxs": [ { "price": "3.00", "rates": 0.15, "name_title": "TaxOne" }, { "price": "1.38", "rates": 0.05, "name_title": "TaxSecond" } ] } ], "shipping_cost": [ { "code": "FDX", "price": "6.23", "name_title": "Fidex", "taxs": [ { "price": "1.55", "rates": 0.25, "name_title": "TaxOne" }, { "price": "2.37", "rates": 0.38, "name_title": "TaxSecond" } ] } ], "billing": { "names": "John Toto" }, "billing": { "names": "John Toto" }, "customers": { "invoce": null, "default_address": { "names": "John Toto" } } } But I think, you did not copy all of my json data in my code : in part of my exemple, you are right last accolade " }" was lost But in my code, There are 3 accolade " }" at end of my data. Here is my code : $json = ' { "currency": "CAD", "email": "toto@gmail.com", "items": [ { "name_title": "pen", "quantity": 2, "price": "20.00", "taxs": [ { "price": "1.00", "rates": 0.15, "name_title": "TaxOne" } ] }, { "name_title": "pensil", "quantity": 3, "price": "10.00", "taxs": [ { "price": "1.00", "rates": 0.15, "name_title": "TaxOne" } ] }, { "name_title": "notebook", "quantity": 2, "price": "5.00", "taxs": [ { "price": "1.00", "rates": 0.15, "name_title": "TaxOne" }, { "price": "1.38", "rates": 0.05, "name_title": "TaxSecond" } ] } ], "shipping_cost": [ { "code": "FDX", "price": "6.23", "name_title": "Fidex", "taxs": [ { "price": "1.55", "rates": 0.25, "name_title": "TaxOne" }, { "price": "2.37", "rates": 0.38, "name_title": "TaxSecond" } ] } ], "billing": { "names": "John Toto" }, "billing": { "names": "John Toto" }, "customers": { "invoce": null, "default_address": { "names": "John Toto" } } }'; // transforming my data in json table**** ****** ******** ***** $new_array = json_decode($json, true);; /* //print_r($new_array); var_dump($new_array); exit(); */ // delete those information "billing" ; "billing" and "customers" **** ****** ******** ***** unset($new_array['billing']); unset($new_array['billing']); unset($new_array['customers']); /* var_dump($new_array); exit(); */ //Consolidate taxs --> items of tax + billing tax **** ****** ******** ***** //find the taxs item $taxs_items = array(); $taxs_items = $new_array['items']['0']['taxs']; //Is not this good way, with ['0']? If zero exchange ? /* var_dump($taxs_items); exit(); */ //find the taxs of shipping $taxs_billing = array(); $taxs_billing = $new_array['shipping_cost']['0']['taxs']; //Is not this good way, with ['0']? If zero exchange ? /* var_dump($taxs_billing); exit(); */ // merge taxs array $taxs_items_billing = array_merge($taxs_items, $taxs_billing); /* var_dump($taxs_items_billing); exit(); */ //consolidate taxs sorting by name in a new array $taxs_items_billing_grouped = array(); foreach ($taxs_items_billing as &$allOfTax_value) { $tax_name = $allOfTax_value['name_title']; if (isset($taxs_items_billing_grouped[$tax_name])) { $taxs_items_billing_grouped[$tax_name]['price'] += $allOfTax_value['price']; } else { $taxs_items_billing_grouped[$tax_name] = $allOfTax_value; } } // Sort an array by key ksort($taxs_items_billing_grouped); /* var_dump($taxs_items_billing_grouped); exit(); */ //array of billing without taxs **** ****** ******** ***** $billing_without_tax = array(); $billing_without_tax = $new_array['shipping_cost']; // remove taxs unset($billing_without_tax['0']['taxs']); ////Is not this good way, with ['0']? If zero exchange ?!!!!!!!!!!!!!!! /* var_dump($billing_without_tax); exit(); */ // un nouveau table avec les items **** ****** ******** ***** $items_shipping_all_tx = array(); $items_shipping_all_tx = $new_array['items']; // remove taxs unset($items_shipping_all_tx['0']['taxs']); ////Is not this good way, with ['0']? If zero exchange ?!!!!!!!!!!!!!!! /* var_dump($items_shipping_all_tx); exit(); */ // add array of billing $items_shipping_all_tx = array_merge($items_shipping_all_tx, $billing_without_tax); /* var_dump($items_shipping_all_tx); exit(); */ // add array of taxs $items_shipping_all_tx = array_merge($items_shipping_all_tx, $taxs_items_billing_grouped); /* var_dump($items_shipping_all_tx); exit(); */ // find the total price with taxs **** ****** ******** ***** // here are my variable for calculations $price_without_tax_for_each_itmes = 0; $price_ht_all_items = 0; //I will use it later $total_taxs = 0; //I will use it later $total_sums = 0; foreach ($items_shipping_all_tx as &$all_value) { $total = $all_value['price']; //price without tax par item if (!isset($all_value['quantity'])) { $quantity = 1; // such as taxes (by cons I need this information later for my xml file } else { $quantity = $all_value['quantity']; // quantity per item } $price_without_tax_for_each_itmes = $total * $quantity; // price total hors tax par unite $total_sums += $price_without_tax_for_each_itmes; // amount : price without tax } $total_sums = number_format($total_sums, 2); echo $total_sums; exit(); How can I change my codes to not use zeros like this : ['0'] ? why my codes forget items tax when there are several items ? How do I correct? Thanks
  6. Hi, goodnight, I have a json data which contains some items (it may have one or more items (with one or two taxes) and one shipping costs (with one or two taxes) : { "currency": "CAD", "email": "toto@gmail.com", "items": [ { "name_title": "pen", "quantity": 1, "price": "20.00", "taxs": [ { "price": "3.00", "rates": 0.15, "name_title": "TaxOne" }, { "price": "1.38", "rates": 0.05, "name_title": "TaxSecond" } ] } ], "shipping_cost": [ { "code": "FDX", "price": "6.23", "name_title": "Fidex", "taxs": [ { "price": "1.55", "rates": 0.25, "name_title": "TaxOne" }, { "price": "2.37", "rates": 0.38, "name_title": "TaxSecond" } ] } ], "billing": { "names": "John Toto" }, "billing": { "names": "John Toto" }, "customers": { "invoce": null, "default_address": { "names": "John Toto" } } } With these data, I need the following information: Find the total price (Item price x quantity + its taxes + shipping costs + shipping taxes) = 20.00 x 1 + 3.0 + 1.00 + 6.23 + 1.55 + 2.37 = 34.15 find information articles and shipping information and its taxs like this : name --> pen, quantity --> 1 price --> 20.00 name --> Fidex quantity --> 1 (for this, it is always : 1!) price --> 6.23 name --> TaxOne quantity --> 1 (for this, it is always : 1!) price --> 4.55 name --> TaxSecond quantity --> 1 (for this, it is always : 1!) price --> 3.37 How can I change my array as seen above? In fact, I must build a new array with all this information above. like this : I transform my json data in array I delete the information on "Billing"; "delivery" and "client" Join taxes --> Items taxes + shipping tax I find tax items like this: $taxs_items = $new_array['items']['0']['taxs']; I wonder if this is good way, because of this ['0'] ? If zero change by another number ? Same for the shipping charges: $taxs_billing = $new_array['shipping_cost']['0']['taxs']; Then I merged the two array here this is my tax array: array(2) { ["TaxOne"]=> array(3) { ["price"]=> float(4.55) ["rates"]=> float(0.15) ["name_title"]=> string(6) "TaxOne" } ["TaxSecond"]=> array(3) { ["price"]=> float(3.75) ["rates"]=> float(0.05) ["name_title"]=> string(9) "TaxSecond" } } I also make another array for delivery without taxes In this array, I have to remove the tax, but how? I do like that, but it is not good as the others since there is a['0'].... unset($billing_without_tax['0']['taxs']); So now I will add items in this array Here's what I get: array(4) { [0]=> array(3) { ["name_title"]=> string(3) "pen" ["quantity"]=> int(1) ["price"]=> string(5) "20.00" } [1]=> array(3) { ["code"]=> string(3) "FDX" ["price"]=> string(4) "6.23" ["name_title"]=> string(5) "Fidex" } ["TaxOne"]=> array(3) { ["price"]=> float(4.55) ["rates"]=> float(0.15) ["name_title"]=> string(6) "TaxOne" } ["TaxSecond"]=> array(3) { ["price"]=> float(3.75) ["rates"]=> float(0.05) ["name_title"]=> string(9) "TaxSecond" } } So now, I'll do my calculation to find the total amount with taxes: and I find the right value: 34.53 When there is only one tax for an item, the code works too: For exemple, I romeve the following tax : "price": "1.38", rates:0.05, "name": "TaxSecond" I find the right value: 33.15 (34.53 - 1.38) The code is capable of calculating the amount according whit quantity: if there are two examples of an article, it find the right value. By cons, if there are two or three different items it does not add its tax. for exemple : { "currency": "CAD", "email": "toto@gmail.com", "items": [ { "name_title": "pen", "quantity": 2, "price": "20.00", "taxs": [ { "price": "1.00", "rates": 0.15, "name_title": "TaxOne" } ] }, { "name_title": "pensil", "quantity": 3, "price": "10.00", "taxs": [ { "price": "1.00", "rates": 0.15, "name_title": "TaxOne" } ] }, { "name_title": "notebook", "quantity": 2, "price": "5.00", "taxs": [ { "price": "1.00", "rates": 0.15, "name_title": "TaxOne" }, { "price": "1.38", "rates": 0.05, "name_title": "TaxSecond" } ] } ], "shipping_cost": [ { "code": "FDX", "price": "6.23", "name_title": "Fidex", "taxs": [ { "price": "1.55", "rates": 0.25, "name_title": "TaxOne" }, { "price": "2.37", "rates": 0.38, "name_title": "TaxSecond" } ] } ], "billing": { "names": "John Toto" }, "billing": { "names": "John Toto" }, "customers": { "invoce": null, "default_address": { "names": "John Toto" } } Here the calculated transaction : pen => 2 x 20.00 + 1.00 = 41.00 pensil => 3 x 10.00 + 1.00 = 31.00 "notebook" => 2 x 5.00 + 1.00 + 1.38 = 12.38 shipping => 6.23 + 1.55 + 2.37 = 10.15 sum => 41 + 31 + 12.38 + 10.15 = 94.53 by cons, my codes find this : 91.15 therefore missing : tax of items : 1 + 1 + 1 + 1,38 Here are my codes $json = ' { "currency": "CAD", "email": "toto@gmail.com", "items": [ { "name_title": "pen", "quantity": 2, "price": "20.00", "taxs": [ { "price": "1.00", "rates": 0.15, "name_title": "TaxOne" } ] }, { "name_title": "pensil", "quantity": 3, "price": "10.00", "taxs": [ { "price": "1.00", "rates": 0.15, "name_title": "TaxOne" } ] }, { "name_title": "notebook", "quantity": 2, "price": "5.00", "taxs": [ { "price": "1.00", "rates": 0.15, "name_title": "TaxOne" }, { "price": "1.38", "rates": 0.05, "name_title": "TaxSecond" } ] } ], "shipping_cost": [ { "code": "FDX", "price": "6.23", "name_title": "Fidex", "taxs": [ { "price": "1.55", "rates": 0.25, "name_title": "TaxOne" }, { "price": "2.37", "rates": 0.38, "name_title": "TaxSecond" } ] } ], "billing": { "names": "John Toto" }, "billing": { "names": "John Toto" }, "customers": { "invoce": null, "default_address": { "names": "John Toto" } } }'; // transforming my data in json table**** ****** ******** ***** $new_array = json_decode($json, true);; /* //print_r($new_array); var_dump($new_array); exit(); */ // delete those information "billing" ; "billing" and "customers" **** ****** ******** ***** unset($new_array['billing']); unset($new_array['billing']); unset($new_array['customers']); /* var_dump($new_array); exit(); */ //Consolidate taxs --> items of tax + billing tax **** ****** ******** ***** //find the taxs item $taxs_items = array(); $taxs_items = $new_array['items']['0']['taxs']; //Is not this good way, with ['0']? If zero exchange ? /* var_dump($taxs_items); exit(); */ //find the taxs of shipping $taxs_billing = array(); $taxs_billing = $new_array['shipping_cost']['0']['taxs']; //Is not this good way, with ['0']? If zero exchange ? /* var_dump($taxs_billing); exit(); */ // merge taxs array $taxs_items_billing = array_merge($taxs_items, $taxs_billing); /* var_dump($taxs_items_billing); exit(); */ //consolidate taxs sorting by name in a new array $taxs_items_billing_grouped = array(); foreach ($taxs_items_billing as &$allOfTax_value) { $tax_name = $allOfTax_value['name_title']; if (isset($taxs_items_billing_grouped[$tax_name])) { $taxs_items_billing_grouped[$tax_name]['price'] += $allOfTax_value['price']; } else { $taxs_items_billing_grouped[$tax_name] = $allOfTax_value; } } // Sort an array by key ksort($taxs_items_billing_grouped); /* var_dump($taxs_items_billing_grouped); exit(); */ //array of billing without taxs **** ****** ******** ***** $billing_without_tax = array(); $billing_without_tax = $new_array['shipping_cost']; // remove taxs unset($billing_without_tax['0']['taxs']); ////Is not this good way, with ['0']? If zero exchange ?!!!!!!!!!!!!!!! /* var_dump($billing_without_tax); exit(); */ // un nouveau table avec les items **** ****** ******** ***** $items_shipping_all_tx = array(); $items_shipping_all_tx = $new_array['items']; // remove taxs unset($items_shipping_all_tx['0']['taxs']); ////Is not this good way, with ['0']? If zero exchange ?!!!!!!!!!!!!!!! /* var_dump($items_shipping_all_tx); exit(); */ // add array of billing $items_shipping_all_tx = array_merge($items_shipping_all_tx, $billing_without_tax); /* var_dump($items_shipping_all_tx); exit(); */ // add array of taxs $items_shipping_all_tx = array_merge($items_shipping_all_tx, $taxs_items_billing_grouped); /* var_dump($items_shipping_all_tx); exit(); */ // find the total price with taxs **** ****** ******** ***** // here are my variable for calculations $price_without_tax_for_each_itmes = 0; $price_ht_all_items = 0; //I will use it later $total_taxs = 0; //I will use it later $total_sums = 0; foreach ($items_shipping_all_tx as &$all_value) { $total = $all_value['price']; //price without tax par item if (!isset($all_value['quantity'])) { $quantity = 1; // such as taxes (by cons I need this information later for my xml file } else { $quantity = $all_value['quantity']; // quantity per item } $price_without_tax_for_each_itmes = $total * $quantity; // price total hors tax par unite $total_sums += $price_without_tax_for_each_itmes; // amount : price without tax } $total_sums = number_format($total_sums, 2); echo $total_sums; exit(); So here are my questions: How can I change my codes to not use zeros like this : ['0'] ? why my codes forget items tax when there are several items ? How do I correct? have a nice night or day Thanks
  7. Hi Barand, Many thanks This great, it works. But I change little bit, I don't know if It is correct or not. What do you say ? ------------------------------------------------------------------- price of chocolat 2.00 and tax : 1.00 +2.00 = 5.00 Price of bonbon 3.00 with tax = 3.00 + 2.00 + 3.00 = 8.00 and gateaux = 2.00 2.00 + 1.00 +2.00 = 5.00 so 5.00+8.00+5.00 = 18.00 So $allOfPrice + $$amountAl = 18 ------------------------------------------------------------------- like this : $amountAll = 0; $price_product = 0; foreach ($data['products'] as $product) { $price_product+= $product['price'] * $product['quantity']; // price without tax New } foreach ($data['products'] as $product) { foreach ($product['tax'] as $item) { $amountAll += $item['quantity'] * $item['price']; //$amountAll += $item['quantity'] * $item['price']; // with this is it double } } $allOfPrice = $price_product; echo number_format( $allOfPrice, 2) . '<br>'; //it get 7.00 amount without tax echo number_format($amountAll, 2). '<br>'; // it get 11.00 all of tax echo number_format($allOfPrice + $amountAll, 2). '<br>'; // it get 18.00 price with tax IT S FUNY So what do you think : is it correct or I must change it ? Thanks
  8. Hi Brand, I try it but I have a Fatal error afther Print_r and here is line 22 : foreach ($decodageDatajs['products'] as $product) { What is wrong ? Thanks
  9. Hi, I have a json data, below which contains an item with tax: "date": "2015-05-05 12:41", "shop": "Toto", "products": [ { "price": "2.00", "quantity": "1", "description": "chocolat", "tax": [ { "price": "1.00", "quantity": "1", "description": "tax1" }, { "price": "2.00", "quantity": "1", "description": "tax2" } ] } ] } I am able to calculate the price ($amountAll) with the following code: $datajs = "myJsonSimple2.json"; $datajs = file_get_contents($datajs); $decodageDatajs = json_decode($datajs); $dateBiling = $decodageDatajs->date; $shopName = $decodageDatajs->shop; foreach ($decodageDatajs->products as $obj) { $ItemPrice = $obj->price; $ItemQuantity = $obj->quantity; $ItemDescription = $obj->description; $taxes = (array)$obj->tax; $taxesPrice1 = !empty($taxes[0]) ? $taxes[0]->price : 0.00; $taxesPrice2 = !empty($taxes[1]) ? $taxes[1]->price : 0.00; $taxesQuantity1 = !empty($taxes[0]) ? $taxes[0]->quantity : 0; $taxesQuantity2 = !empty($taxes[1]) ? $taxes[1]->quantity : 0; $taxesDescription1 = !empty($taxes[0]) ? $taxes[0]->description : '1er tax null'; $taxesDescription2 = !empty($taxes[1]) ? $taxes[1]->description : '2e tax null'; $amountAll = $ItemPrice * $ItemQuantity + $taxesPrice1 + $taxesPrice2; } But how I calculate if there are several items (2 or 3 or 5...) { "date": "2015-05-05 12:41", "shop": "Toto", "products": [ { "price": "2.00", "quantity": "1", "description": "chocolat", "tax": [ { "price": "1.00", "quantity": "1", "description": "tax1" }, { "price": "2.00", "quantity": "1", "description": "tax2" } ] }, { "price": "3.00", "quantity": "1", "description": "bonbon", "tax": [ { "price": "2.00", "quantity": "1", "description": "tax1" }, { "price": "3.00", "quantity": "1", "description": "tax2" } ] }, { "price": "2.00", "quantity": "1", "description": "gateaux", "tax": [ { "price": "1.00", "quantity": "1", "description": "tax1" }, { "price": "2.00", "quantity": "1", "description": "tax2" } ] } ] } I need like as : $amountAll = $ItemPrice1 * $ItemQuantity1 + $ItemPrice2 * $ItemQuantity2 + $ItemPrice3 * $ItemQuantity3 + $taxesPrice1a + $taxesPrice2a + $taxesPrice1b + $taxesPrice2b + $taxesPrice1c + $taxesPrice2c; but this is wrong : I must counter and use while statement but I don,t know how I can write ? $calculeItems = count($decodageDatajs->products); $i = 0; while ($i < $calculeItems) { foreach ($decodageDatajs->products as $obj) { $ItemPrice = $obj->price; $ItemQuantity = $obj->quantity; $ItemDescription = $obj->description; $taxes = (array)$obj->tax; $taxesPrice1 = !empty($taxes[0]) ? $taxes[0]->price : 0.00; $taxesPrice2 = !empty($taxes[1]) ? $taxes[1]->price : 0.00; $taxesQuantity1 = !empty($taxes[0]) ? $taxes[0]->quantity : 0; $taxesQuantity2 = !empty($taxes[1]) ? $taxes[1]->quantity : 0; $taxesDescription1 = !empty($taxes[0]) ? $taxes[0]->description : '1er tax null'; $taxesDescription2 = !empty($taxes[1]) ? $taxes[1]->description : '2e tax null'; $amountAll = $ItemPrice * $ItemQuantity + $taxesPrice1 + $taxesPrice2; /* this si wrong !!!!! $amountAll = $ItemPrice1 * $ItemQuantity1 + $ItemPrice2 * $ItemQuantity2 + $ItemPrice3 * $ItemQuantity3 + $taxesPrice1a + $taxesPrice2a + $taxesPrice1b + $taxesPrice2b + $taxesPrice1c + $taxesPrice2c; */ } $i++; } can you help me please Thanks
  10. Many Thanks Many Thanks Jcbones, it works
  11. Hi jcbones, I have also wrong valus with this code! Here is a result : 1st item :::: good value email:john@john.fr sku:123456789 price:0.67 price_with_tax:4.00 price_tax1:1.11 price_tax2:2.22 2nd item :::: email:john@john.fr sku:012345666 price:1.67 price_with_tax:5.00 wrong value :::: price_tax1:1.11 wrong! [this is a good value : 3.33] price_tax2:2.22 wrong! [this is a good value : 0.00 or NULL] With 2nd Items we have only one tax in json data : look like that : for 1st item : "tax_lines": [ { "title": "tax010", "rate": 0.01, "price": "1.11" }, { "title": "tax00200", "rate": 0.02, "price": "2.22" } ] and for second item (only one tax) "tax_lines": [ { "title": "tax0003000", "rate": 0.03, "price": "3.33" } ] How I must write my code so I get the following result : first item value: ... price_tax1:1.11 price_tax2:2.22 second item value (when there are only one tax) ... price_tax1:3.33 price_tax2:0.00 or second item value (when there are only one tax) ... price_tax1:3.33 price_tax2:NULL
  12. Hi Jcbones, Non, I have a wrong valus with this code! Here is a result : 1st item email:john@john.fr sku:123456789 price:0.67 price_with_tax:4.00 price_tax1:tax010 wrong! [this is a good value : 1.11) price_tax2:2.22 2nd item :::: email:john@john.fr sku:012345666 price:1.67 price_with_tax:5.00 wrong value :::: price_tax1:tax00200 wrong! [this is a good value : 3.33] price_tax: 2:2.22 wrong! [this is a good value : 0.00 or NULL]
  13. Hi I have a json data : { "email": "john@john.fr", "line_items": [ { "sku": "123456789", "price": "0.67", "price_with_tax": "4.00", "tax_lines": [ { "title": "tax010", "rate": 0.01, "price": "1.11" }, { "title": "tax00200", "rate": 0.02, "price": "2.22" } ] }, { "sku": "012345666", "price": "1.67", "price_with_tax": "5.00", "tax_lines": [ { "title": "tax0003000", "rate": 0.03, "price": "3.33" } ] } ] } and I try put this data in mySql. First data have a good value but second have a wrong data on 'price_tax1' and 'price_tax2' in mySql : Here is my MySql 1st item :::: good value email:john@john.fr sku:123456789 price:0.67 price_with_tax:4.00 price_tax1:1.11 price_tax2:2.22 2nd item :::: email:john@john.fr sku:012345666 price:1.67 price_with_tax:5.00 wrong value :::: price_tax1:1.11 price_tax2:2.22 here is my code : $jsondata = file_get_contents($jsondata); $dataDecode = json_decode($jsondata); $email = $dataDecode->email; try { $dtbs = new PDO($dsn_dev, $pdo_user, $pdo_password, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION)); } catch (Exception $e) { die('Error : ' . $e->getMessage()); } try { foreach ($dataDecode->line_items as $obj) { $var_sku = $obj->sku; $var_price = $obj->price; $var_price_with_tax = $obj->price_with_tax; $taxNewArray = array(); foreach ($dataDecode->line_items[0]->tax_lines as $obj2) { array_push($taxNewArray , $obj2); } $val1st = array_shift($taxNewArray); $val2nd = array_pop ($taxNewArray); $var_tax1 = $val1st->price; $var_tax2 = $val2nd->price; $stmt = $dtbs->prepare("INSERT INTO $tabledata ($mysql_email, $mysql_sku, $mysq_price, $mysql_price_with_tax, $mysql_price__tax1___line_items, $mysql_price__tax2___line_items ) VALUES (:email, :sku, :price, :price_with_tax, :price_tax1, :price_tax2)"); $stmt->execute(array(':email'=>$email, ':sku'=>$var_sku, ':price'=>$var_price, ':price_with_tax'=>$var_price_with_tax, ':price_tax1'=>$var_tax1, ':price_tax2'=>$var_tax2 )); } } catch(Exception $e) { throw $e; } How can I put goog value of 2nd data in mySql ? thanks
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.