PNR generating issue using amadeus flight create orders API - php

I want to create booking and generate PNR using amadeus flight booking API.
I have follow 3 step to create booking and generate PNR
Flight Offers Search API using bellow API
https://developers.amadeus.com/self-service/category/air/api-doc/flight-offers-search/api-reference
Flight Offers Price API using bellow API
https://developers.amadeus.com/self-service/category/air/api-doc/flight-offers-price/api-reference
Flight Create Orders API using bellow API
https://developers.amadeus.com/self-service/category/air/api-doc/flight-create-orders/api-reference
When i serach with city with one way thip and choose specific offer and puting passenger details
to create booking and generat PNR. then PNR will generate successfully
i am using bellow API to generate PNR
https://developers.amadeus.com/self-service/category/air/api-doc/flight-create-orders/api-reference
this is my request json
"data": {
"type": "flight-order",
"flightOffers": [
{
"type": "flight-offer",
"id": "5",
"source": "GDS",
"instantTicketingRequired": false,
"nonHomogeneous": false,
"paymentCardRequired": false,
"lastTicketingDate": "2021-07-23",
"itineraries": [
{
"segments": [
{
"departure": {
"iataCode": "JFK",
"terminal": "5",
"at": "2021-07-30T09:20:00"
},
"arrival": {
"iataCode": "FLL",
"terminal": "3",
"at": "2021-07-30T12:30:00"
},
"carrierCode": "B6",
"number": "201",
"aircraft": {
"code": "320"
},
"operating": {
"carrierCode": "B6"
},
"duration": "PT3H10M",
"id": "91",
"numberOfStops": 0,
"co2Emissions": [
{
"weight": 155,
"weightUnit": "KG",
"cabin": "ECONOMY"
}
]
},
{
"departure": {
"iataCode": "FLL",
"terminal": "3",
"at": "2021-07-30T16:25:00"
},
"arrival": {
"iataCode": "LAX",
"terminal": "5",
"at": "2021-07-30T18:49:00"
},
"carrierCode": "B6",
"number": "1301",
"aircraft": {
"code": "32S"
},
"operating": {
"carrierCode": "B6"
},
"duration": "PT5H24M",
"id": "92",
"numberOfStops": 0,
"co2Emissions": [
{
"weight": 253,
"weightUnit": "KG",
"cabin": "ECONOMY"
}
]
}
],
"duration": "PT12H29M"
}
],
"price": {
"currency": "USD",
"total": "276.20",
"base": "235.35",
"fees": [
{
"amount": "0.00",
"type": "SUPPLIER"
},
{
"amount": "0.00",
"type": "TICKETING"
},
{
"amount": "0.00",
"type": "FORM_OF_PAYMENT"
}
],
"grandTotal": "276.20",
"billingCurrency": "USD"
},
"pricingOptions": {
"fareType": [
"PUBLISHED"
],
"includedCheckedBagsOnly": false
},
"validatingAirlineCodes": [
"B6"
],
"travelerPricings": [
{
"travelerId": "1",
"fareOption": "STANDARD",
"travelerType": "ADULT",
"price": {
"currency": "USD",
"total": "276.20",
"base": "235.35",
"taxes": [
{
"amount": "8.60",
"code": "ZP"
},
{
"amount": "5.60",
"code": "AY"
},
{
"amount": "17.65",
"code": "US"
},
{
"amount": "9.00",
"code": "XF"
}
],
"refundableTaxes": "40.85"
},
"fareDetailsBySegment": [
{
"segmentId": "91",
"cabin": "ECONOMY",
"fareBasis": "OL7AUEL1",
"brandedFare": "DN",
"class": "L",
"includedCheckedBags": {
"quantity": 0
}
},
{
"segmentId": "92",
"cabin": "ECONOMY",
"fareBasis": "ZI3PUEL1",
"brandedFare": "DN",
"class": "L",
"includedCheckedBags": {
"quantity": 0
}
}
]
}
]
}
],
"travelers": [
{
"id": 1,
"dateOfBirth": "**********",
"name": {
"firstName": "**********",
"lastName": "**********"
},
"gender": "**********"
}
],
"contacts": [
{
"addresseeName": {
"firstName": "**********",
"lastName": "**********"
},
"purpose": "STANDARD",
"emailAddress": "**********",
"phones": [
{
"deviceType": "MOBILE",
"countryCallingCode": "**",
"number": "**********"
}
],
"address": {
"lines": [
"**********"
],
"postalCode": "**********",
"cityName": "**********",
"countryCode": "**********"
}
}
],
"remarks": {
"general": [
{
"subType": "GENERAL_MISCELLANEOUS",
"text": "ONLINE BOOKING FROM INCREIBLE VIAJES"
}
]
},
"ticketingAgreement": {
"option": "DELAY_TO_CANCEL",
"delay": "6D"
}
}
}
and this is my API response.
PNR generated successfully/
stdClass Object
(
[warnings] => Array
(
[0] => stdClass Object
(
[status] => 200
[code] => 0
[title] => ContactInfoSsrNotAddedToBookingWarning
[detail] => Unable to create some contact information SSR. Email and mobile phone number required.
)
)
[data] => stdClass Object
(
[type] => flight-order
[id] => eJzTd9f3cg228PcBAAskAls%3D
[associatedRecords] => Array
(
[0] => stdClass Object
(
[reference] => JES8OL
[creationDate] => 2021-07-23T10:28:00.000
[originSystemCode] => GDS
[flightOfferId] => 5
)
)
[flightOffers] => Array
(
[0] => stdClass Object
(
[type] => flight-offer
[id] => 5
[source] => GDS
[nonHomogeneous] =>
[lastTicketingDate] => 2021-07-23
[itineraries] => Array
But when i search with differnt city and follow the same step.
this is my request json
data": {
"type": "flight-order",
"flightOffers": [
{
"type": "flight-offer",
"id": "3",
"source": "GDS",
"instantTicketingRequired": false,
"nonHomogeneous": false,
"paymentCardRequired": false,
"lastTicketingDate": "2021-07-28",
"itineraries": [
{
"segments": [
{
"departure": {
"iataCode": "DEL",
"terminal": "3",
"at": "2021-08-05T05:35:00"
},
"arrival": {
"iataCode": "BLR",
"at": "2021-08-05T08:20:00"
},
"carrierCode": "AI",
"number": "803",
"aircraft": {
"code": "32B"
},
"operating": {
"carrierCode": "AI"
},
"duration": "PT2H45M",
"id": "17",
"numberOfStops": 0,
"co2Emissions": [
{
"weight": 145,
"weightUnit": "KG",
"cabin": "ECONOMY"
}
]
}
],
"duration": "PT2H45M"
},
{
"segments": [
{
"departure": {
"iataCode": "BLR",
"at": "2021-08-10T17:10:00"
},
"arrival": {
"iataCode": "DEL",
"terminal": "3",
"at": "2021-08-10T19:55:00"
},
"carrierCode": "AI",
"number": "501",
"aircraft": {
"code": "32B"
},
"operating": {
"carrierCode": "AI"
},
"duration": "PT2H45M",
"id": "42",
"numberOfStops": 0,
"co2Emissions": [
{
"weight": 145,
"weightUnit": "KG",
"cabin": "ECONOMY"
}
]
}
],
"duration": "PT2H45M"
}
],
"price": {
"currency": "USD",
"total": "88.59",
"base": "68.00",
"fees": [
{
"amount": "0.00",
"type": "SUPPLIER"
},
{
"amount": "0.00",
"type": "TICKETING"
},
{
"amount": "0.00",
"type": "FORM_OF_PAYMENT"
}
],
"grandTotal": "88.59",
"billingCurrency": "USD"
},
"pricingOptions": {
"fareType": [
"PUBLISHED"
],
"includedCheckedBagsOnly": true
},
"validatingAirlineCodes": [
"AI"
],
"travelerPricings": [
{
"travelerId": "1",
"fareOption": "STANDARD",
"travelerType": "ADULT",
"price": {
"currency": "USD",
"total": "88.59",
"base": "68.00",
"taxes": [
{
"amount": "6.34",
"code": "P2"
},
{
"amount": "3.78",
"code": "IN"
},
{
"amount": "3.63",
"code": "K3"
},
{
"amount": "2.28",
"code": "WO"
},
{
"amount": "4.56",
"code": "YR"
}
],
"refundableTaxes": "17.19"
},
"fareDetailsBySegment": [
{
"segmentId": "17",
"cabin": "ECONOMY",
"fareBasis": "SAP8",
"class": "S",
"includedCheckedBags": {
"weight": 25,
"weightUnit": "KG"
}
},
{
"segmentId": "42",
"cabin": "ECONOMY",
"fareBasis": "SAP8",
"class": "S",
"includedCheckedBags": {
"weight": 25,
"weightUnit": "KG"
}
}
]
}
]
}
],
"travelers": [
{
"id": 1,
"dateOfBirth": "**********",
"name": {
"firstName": "**********",
"lastName": "**********"
},
"gender": "**********"
}
],
"contacts": [
{
"addresseeName": {
"firstName": "**********",
"lastName": "**********"
},
"purpose": "STANDARD",
"emailAddress": "**********",
"phones": [
{
"deviceType": "**********",
"countryCallingCode": "**",
"number": "**********"
}
],
"address": {
"lines": [
"**********"
],
"postalCode": "**********",
"cityName": "**********",
"countryCode": "**********"
}
}
],
"remarks": {
"general": [
{
"subType": "GENERAL_MISCELLANEOUS",
"text": "ONLINE BOOKING FROM INCREIBLE VIAJES"
}
]
},
"ticketingAgreement": {
"option": "DELAY_TO_CANCEL",
"delay": "6D"
}
}
and this is my API response.
stdClass Object
(
[errors] => Array
(
[0] => stdClass Object
(
[status] => 400
[code] => 34651
[title] => SEGMENT SELL FAILURE
[detail] => Could not sell segment 2
[source] => stdClass Object
(
[pointer] => /data/flightOffers[0]/itineraries[1]/segments[0]
)
)
)
)
Can you please guide me what is the issue.I am using amadeus test API credential.Also guide me how to solve the issue
Thank You

You usually get this error when trying to book a seat that is not available anymore. You are using the test environment, it means everybody else using Amadeus for Developers in test can be trying to book the same seat.
Try with another flight and don't forget to perform the Flight Offers Price before booking.
PS: I see some personal data in the example above, you should edit your post to remove it.

Related

MongoDB Aggregation in nested collection data

In a collection I'm saving all the Store wise transactions and there is a key named "items" inside all the documents which contains all the items of a particular sale.
Now I've to perform aggregation onto it and send the data somewhere else.
Below I've given the collection data
[{
"_id": {
"$oid": "63ee26bcb64550cbb20de158"
},
"employee": "1",
"custId": "6357cb852c61064d53040ff2",
"store_code": "BAN-01",
"store_no": "7",
"shift": "Second",
"employee_role": "POS Store Manager",
"store_name": "175",
"customer_name": "Vivek Kumar",
"customer_email": "vivek.kumar98705#gmail.com",
"customer_phone": "9958137221",
"counter_code": "175-Counter-01",
"deposit_amount": "100",
"emp_code": "TCP004",
"items": "[{\"internalid\":2969,\"type\":\"InvtPart\",\"islotitem\":true,\"isserialitem\":false,\"isspecialorderitem\":false,\"itemName\":\"201450\",\"price\":\"252.50\",\"qty\":\"1\",\"itemamount\":\"265.13\",\"mrp\":\"252.50\",\"discount\":\"0.00\",\"tax\":\"12.63\",\"promotion\":\"NA\",\"item_display_name\":\"UOM: BETADINE GARGLE 100ML\",\"item_upc_code\":\"5285239186\",\"item_hsn_code\":\"30041090\",\"uom\":\"EA\",\"batchDetails\":{\"#PJ0672\":{\"batch_expiry\":\"4/4/2025\",\"qty\":1}}},{\"internalid\":2963,\"type\":\"InvtPart\",\"islotitem\":true,\"isserialitem\":false,\"isspecialorderitem\":false,\"itemName\":\"225124\",\"price\":\"7.00\",\"qty\":\"15\",\"itemamount\":\"110.25\",\"mrp\":\"7.00\",\"discount\":\"0.00\",\"tax\":\"5.25\",\"promotion\":\"NA\",\"item_display_name\":\"UOM: ZINCOVIT 15TAB\",\"item_upc_code\":\"8035476959\",\"item_hsn_code\":\"21069099\",\"uom\":\"SH(15)\",\"batchDetails\":{\"#ZVT21203\":{\"batch_expiry\":\"4/4/2025\",\"qty\":15}}},{\"internalid\":3067,\"type\":\"InvtPart\",\"islotitem\":true,\"isserialitem\":false,\"isspecialorderitem\":false,\"itemName\":\"315043\",\"price\":\"1.70\",\"qty\":\"45\",\"itemamount\":\"80.33\",\"mrp\":\"1.70\",\"discount\":\"0.00\",\"tax\":\"3.83\",\"promotion\":\"NA\",\"item_display_name\":\"UOM: FOLVITE 45TAB\",\"item_upc_code\":\"9312066071\",\"item_hsn_code\":\"30045039\",\"uom\":\"SH(45)\",\"batchDetails\":{\"#GH3735\":{\"batch_expiry\":\"4/4/2025\",\"qty\":45}}},{\"internalid\":3069,\"type\":\"InvtPart\",\"islotitem\":true,\"isserialitem\":false,\"isspecialorderitem\":false,\"itemName\":\"204009\",\"price\":\"75.44\",\"qty\":\"10\",\"itemamount\":\"792.12\",\"mrp\":\"75.44\",\"discount\":\"0.00\",\"tax\":\"37.72\",\"promotion\":\"NA\",\"item_display_name\":\"UOM: DUPHASTON 10TAB\",\"item_upc_code\":\"3444014334\",\"item_hsn_code\":\"30043919\",\"uom\":\"SH(10)\",\"batchDetails\":{\"#KAVA2050\":{\"batch_expiry\":\"4/4/2025\",\"qty\":10}}}]",
"total_amount": 1247.83,
"total_tax": 59.43,
"total_discount": 0,
"subTotal": 1188.4,
"payment_details": [
[
{
"paymentMethod": "cash",
"amount_paid": 1247.83,
"transaction_date": "2/16/2023 4:58:19 pm",
"payment_status": "Success",
"transaction_id": "test123"
}
]
],
"auth_id": "master_ad14cca679b44ef1d78a3e_master",
"created_by": "master_ad14cca679b44ef1d78a3e_master",
"updated_by": "master_ad14cca679b44ef1d78a3e_master",
"invoice_no": "WFINV#1",
"updated_at": {
"$date": {
"$numberLong": "1676551868017"
}
},
"created_at": {
"$date": {
"$numberLong": "1676551868017"
}
}
},
{
"_id": {
"$oid": "63ee2778b64550cbb20de17c"
},
"employee": "1",
"custId": "6357cb852c61064d53040ff2",
"store_code": "BAN-01",
"store_no": "7",
"shift": "Second",
"employee_role": "POS Store Manager",
"store_name": "175",
"customer_name": "Vivek Kumar",
"customer_email": "vivek.kumar98705#gmail.com",
"customer_phone": "9958137221",
"counter_code": "175-Counter-01",
"deposit_amount": "100",
"emp_code": "TCP004",
"items": "[{\"internalid\":\"undefined\",\"type\":\"undefined\",\"islotitem\":true,\"isserialitem\":false,\"isspecialorderitem\":false,\"itemName\":\"\",\"price\":\"2.30\",\"qty\":\"20\",\"itemamount\":\"48.30\",\"mrp\":\"2.30\",\"discount\":\"0.00\",\"tax\":\"2.3\",\"promotion\":\"NA\",\"item_display_name\":\"UOM: COMBIFLAM 20TAB\",\"item_upc_code\":\"UPC000004\",\"item_hsn_code\":\"30049063\",\"uom\":\"SH(20)\",\"batchDetails\":{\"#1022563\":{\"batch_expiry\":\"4/4/2025\",\"qty\":20}}},{\"internalid\":\"undefined\",\"type\":\"undefined\",\"islotitem\":true,\"isserialitem\":false,\"isspecialorderitem\":false,\"itemName\":\"\",\"price\":\"93.00\",\"qty\":\"1\",\"itemamount\":\"97.65\",\"mrp\":\"93.00\",\"discount\":\"0.00\",\"tax\":\"4.65\",\"promotion\":\"NA\",\"item_display_name\":\"UOM: FEBREX-PLUS DS SYP 60ML\",\"item_upc_code\":\"1036121752\",\"item_hsn_code\":\"30049093\",\"uom\":\"EA\",\"batchDetails\":{\"#22430041\":{\"batch_expiry\":\"4/4/2025\",\"qty\":1}}}]",
"total_amount": 145.95,
"total_tax": 6.95,
"total_discount": 0,
"subTotal": 139,
"payment_details": [
[
{
"paymentMethod": "cash",
"amount_paid": 145.95,
"transaction_date": "2/16/2023 4:54:25 pm",
"payment_status": "Success",
"transaction_id": "test123"
}
]
],
"auth_id": "master_ad14cca679b44ef1d78a3e_master",
"created_by": "master_ad14cca679b44ef1d78a3e_master",
"updated_by": "master_ad14cca679b44ef1d78a3e_master",
"invoice_no": "WFINV#4",
"updated_at": {
"$date": {
"$numberLong": "1676552056047"
}
},
"created_at": {
"$date": {
"$numberLong": "1676552056047"
}
}
}
]
I Tried the below aggregation but it didn't work.
$data = \DB::collection("online_orders")->raw(function($collection) use ($requestData) {
return $collection->aggregate([
[
'$match' => [
'created_at' => [
'$gte' => $requestData['from'],
'$lte' => $requestData['to']
]
],
'$group' => [
'_id' => [
'store_code' => '$store_code',
'sku' => '$items.itemName'
],
'items' => '$items',
'sold_qty' => [ '$sum' => '$items.qty' ]
]
]
]);
});
After Pipeline
Expected Result :
Result Keys relation to the collection keys just for reference**
sku -> itemName
sold_qty -> how many time that particular item has been sold store code wise
return_qty -> curerntly leave it as 0
total_amount -> total amount of particular item sold
uom -> uom
batchNo -> batchDetails key is batchNo
Quantity -> batchDetails -- qty
{
"order_type": "CS",
"data": [
{
"store_code": "175",
"cash_sale_details": [
{
"sku": "321405",
"sold_qty": "5",
"return_qty": "0",
"total_amount": "69.83",
"uom": "EA",
"batchDetails": [
{
"batchNo": "LOT121",
"Quantity": 5
}
]
},
{
"sku": "223327",
"sold_qty": "5",
"return_qty": "0",
"total_amount": "488.25",
"uom": "EA",
"batchDetails": [
{
"batchNo": "22430041",
"Quantity": 5
}
]
},
{
"sku": "222045",
"sold_qty": "5",
"return_qty": "0",
"total_amount": "842.89",
"uom": "EA",
"batchDetails": [
{
"batchNo": "B2329D164",
"Quantity": 5
}
]
},
{
"sku": "341106",
"sold_qty": "5",
"return_qty": "0",
"total_amount": "623.44",
"uom": "EA",
"batchDetails": [
{
"batchNo": "AS2211",
"Quantity": 5
}
]
}
]
}
]
}
Thanks

Compare 2 Multidimensional Arrays in PHP and show all the difference in an array

I have 2 Multiple-Arrays and I want to compare them. In the second Array I want then show with colors which value has changed, which key is new and which key is removed.
I have found a lot of different solutions, but no one function for me.
Here are my arrays:
{
"originFormation": {
"stationName": "Bern",
"sections": [{
"name": "B",
"cars": [{
"type": "LOK",
"occupancy": "UNKNOWN",
"attributes": [],
"closed": false,
"previousPassage": false,
"nextPassage": false
}]
}, {
"name": "C",
"cars": [{
"type": "CAR",
"number": "1",
"class": "1",
"occupancy": "UNKNOWN",
"attributes": ["AbteilRollstuhl", "AbteilBusiness"],
"closed": false,
"previousPassage": false,
"nextPassage": true
}, {
"type": "CAR",
"number": "1",
"class": "2",
"occupancy": "UNKNOWN",
"attributes": [],
"closed": false,
"previousPassage": true,
"nextPassage": true
}]
}],
"legendItems": [{
"id": "1",
"text": "1st class coach",
"refersTo": "type"
}, {
"id": "2",
"text": "2st class coach",
"refersTo": "type"
}, {
"id": "Fahrtrichtung",
"text": "Direction of travel",
"refersTo": "code"
}, {
"id": "FA",
"text": "Family Coach with play area",
"refersTo": "type"
}, {
"id": "AbteilRollstuhl",
"text": "Wheelchair space",
"refersTo": "code"
}, {
"id": "AbteilVeloPl",
"text": "Bicycle loading: Without reservation",
"refersTo": "code"
}, {
"id": "LK",
"text": "Locomotive",
"refersTo": "type"
}, {
"id": "WR",
"text": "Restaurant 1st and 2nd class",
"refersTo": "type"
}, {
"id": "AbteilBusiness",
"text": "Business zone in 1st class: Reservation possible",
"refersTo": "code"
},
{
"id": "HFS_WG_NUM",
"text": "Coach",
"refersTo": "code"
}, {
"id": "KD",
"text": "No passage",
"refersTo": "type"
}
],
"info": {
"title": "Changes to the composition of the train",
"formationChanges": []
}
}
}
Array2:
{
"originFormation": {
"stationName": "Bern",
"sections": [
{
"name": "B",
"cars": [
{
"type": "LOK",
"occupancy": "UNKNOWN",
"attributes": [],
"closed": false,
"previousPassage": false,
"nextPassage": false
}
]
},
{
"name": "C",
"cars": [
{
"type": "CAR",
"number": "12",
"class": "1",
"occupancy": "UNKNOWN",
"attributes": [
"AbteilRollstuhl",
"AbteilBusiness"
],
"closed": false,
"previousPassage": false,
"nextPassage": true
},
{
"type": "CAR",
"number": "1",
"class": "2",
"occupancy": "UNKNOWN",
"attributes": [
"AbteilStefan"
],
"closed": false,
"previousPassage": true,
"nextPassage": true
},
{
"type": "CAR",
"number": "2",
"class": "1",
"occupancy": "UNKNOWN",
"attributes": [],
"closed": false,
"previousPassage": true,
"nextPassage": true
}
]
}
],
"legendItems": [
{
"id": "1",
"text": "1st class coach",
"refersTo": "type"
},
{
"id": "2",
"text": "2st class coach",
"refersTo": "type"
},
{
"id": "Fahrtrichtung",
"text": "Direction of travel",
"refersTo": "code"
},
{
"id": "FA",
"text": "Family Coach with play area",
"refersTo": "type"
},
{
"id": "AbteilRollstuhl",
"text": "Wheelchair space",
"refersTo": "code"
},
{
"id": "AbteilVeloPl",
"text": "Bicycle loading: Without reservation",
"refersTo": "code"
},
{
"id": "LK",
"text": "Locomotive",
"refersTo": "type"
},
{
"id": "WR",
"text": "Restaurant 1st and 2nd class",
"refersTo": "type"
},
{
"id": "AbteilBusiness",
"text": "Business zone in 1st class: Reservation possible",
"refersTo": "code"
},
{
"id": "AbteilStefan",
"text": "Ich bin ein neues Abteil",
"refersTo": "code"
},
{
"id": "HFS_WG_NUM",
"text": "Coach",
"refersTo": "code"
},
{
"id": "KD",
"text": "No passage",
"refersTo": "type"
}
],
"info": {
"title": "Changes to the composition of the train",
"formationChanges": [
"All Changed"
]
}
}
}
My fonction to compare:
function array_diff_assoc_recursive($array1, $array2)
{
foreach($array1 as $key => $value)
{
if(is_array($value))
{
if(!isset($array2[$key]))
{
$difference[$key] = $value;
}
elseif(!is_array($array2[$key]))
{
$difference[$key] = "<b>".$value."</b>";
}
else
{
$new_diff = array_diff_assoc_recursive($value, $array2[$key]);
if($new_diff != FALSE)
{
$difference[$key] = $new_diff;
}
}
}
elseif(!isset($array2[$key]) || $array2[$key] != $value)
{
$difference[$key] = "<b>".$value."</b>";
}
}
return !isset($difference) ? 0 : $difference;
}
var_dump(array_diff_assoc_recursive($array2, $array1));
This difference i get:
[originformation][sections][1][cars][0][number] -> newValue 12
[originformation][sections][1][cars][1][attributes] -> newValue AbteilStefan
[originformation][sections][1][cars][2] -> all Attributes are new
[originformation][legendItems][9][id] -> newValue AbteilStefan
[originformation][legendItems][9][text] -> newValue Ich bin ein neues Abteil
[originformation][legendItems][10] -> all Attributes are new
[originformation][legendItems][11] -> all Attributes are new
[originformation][info][formationChanges][0] => newValue All Changed
The difference i expected
[originformation][sections][1][cars][0][number] -> newValue 12
[originformation][sections][1][cars][1] -> all Attributes are new
[originformation][legendItems][9] -> all Attributes are new
[originformation][info][formationChanges][0] => newValue All Changed
Problem
My function doesn't see, that car in Array2 I put in a complete new car and also a complete new legendItem and the rest is still the same.
Does someone know how I can compare the arrays, that he doesn't check the order of the attributes on the same level?

creating json file from database

I need to create this json in the following format
{
"status": true,
"message": "",
"orders": [
{
"orderId": "1",
"orderDate": "1/06/2021",
"products": [
{
"productName": "Product 1",
"quantity": "1",
"price": "5.00"
},
{
"productName": "Product 2",
"quantity": "2",
"price": "24.00"
},
{
"productName": "Product 3",
"quantity": "1",
"price": "6.50"
}
]
},
{
"orderId": "2",
"orderDate": "2/06/2021",
"products": [
{
"productName": "Product 1",
"quantity": "1",
"price": "3.00"
},
{
"productName": "Product 2",
"quantity": "1",
"price": "11.50"
}
]
},
{
"orderId": "3",
"orderDate": "03/05/2021",
"products": [
{
"productName": "Product 1",
"quantity": "1",
"price": "3.00"
},
{
"productName": "Product 2",
"quantity": "1",
"price": "11.50"
}
]
}
]
}
This is my code that I use to retrive the information from the database
$stmt = $con->prepare("SELECT OrderID, OrderDate, ProductName, ProductQty, ProductPrice FROM Orders where CustomerID = ?");
$stmt->bind_param("s", $CustomerID);
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($OrderID, $OrderDate, $ProductName, $ProductQty, $ProductPrice);
while($stmt->fetch()) {
$message[] = array(
"status" => true,
"message" => "",
"orders" => array(
array(
"orderId" => "$OrderID",
"orderDate" => "$OrderDate",
"products" => array(
array(
"productName" => "$ProductName",
"quantity" => "$ProductQty",
"price" => "$ProductPrice"
),
)
)
)
);
}
$json = $message;
header('content-type: application/json');
echo json_encode($json);
This is how the information from the database displays. I do not know how to show the information about the products correctly. Can anyone show me how to do it in the format that I require in php? Thanks in advance for any help.
[
{
"status": true,
"message": "",
"orders": [
{
"orderId": "1",
"orderDate": "1/06/2021",
"products": [
{
"productName": "620",
"quantity": "1",
"price": "5.00"
}
]
}
]
},
{
"status": true,
"message": "",
"orders": [
{
"orderId": "1",
"orderDate": "1/06/2021",
"products": [
{
"productName": "240",
"quantity": "1",
"price": "5.00"
},
{
"productName": "270",
"quantity": "1",
"price": "10.00"
}
]
}
]
},
{
"status": true,
"message": "",
"orders": [
{
"orderId": "1",
"orderDate": "1/06/2021",
"products": [
{
"productName": "30",
"quantity": "1",
"price": "5.00"
}
]
}
]
},
{
"status": true,
"message": "",
"orders": [
{
"orderId": "1",
"orderDate": "1/06/2021",
"products": [
{
"productName": "280",
"quantity": "1",
"price": "5.00"
}
]
}
]
},
{
"status": true,
"message": "",
"orders": [
{
"orderId": "1",
"orderDate": "1/06/2021",
"products": [
{
"productName": "610",
"quantity": "1",
"price": "5.00"
}
]
}
]
}
]
You are repeating the orders structure which you shouldn't. That's why you get the wrong structure. This is what you should do instead (your code, modified):
// specify your return response array only once
$message = array(
"status" => true,
"message" => "",
"orders" => array();
);
$stmt = $con->prepare("SELECT OrderID, OrderDate, ProductName, ProductQty, ProductPrice FROM Orders where CustomerID = ?");
$stmt->bind_param("s", $CustomerID);
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($OrderID, $OrderDate, $ProductName, $ProductQty, $ProductPrice);
while($stmt->fetch()) {
// and fill its "orders" member with your orders list
$message["orders"][] = array(
"orderId" => "$OrderID",
"orderDate" => "$OrderDate",
"products" => array(
array(
"productName" => "$ProductName",
"quantity" => "$ProductQty",
"price" => "$ProductPrice"
),
)
);
}
$json = $message;
header('content-type: application/json');
echo json_encode($json);
You can try like below
const data = [
{
"status": true,
"message": "",
"orders": [
{
"orderId": "1",
"orderDate": "1/06/2021",
"products": [
{
"productName": "620",
"quantity": "1",
"price": "5.00"
}
]
}
]
},
{
"status": true,
"message": "",
"orders": [
{
"orderId": "1",
"orderDate": "1/06/2021",
"products": [
{
"productName": "240",
"quantity": "1",
"price": "5.00"
},
{
"productName": "270",
"quantity": "1",
"price": "10.00"
}
]
}
]
},
{
"status": true,
"message": "",
"orders": [
{
"orderId": "1",
"orderDate": "1/06/2021",
"products": [
{
"productName": "30",
"quantity": "1",
"price": "5.00"
}
]
}
]
},
{
"status": true,
"message": "",
"orders": [
{
"orderId": "1",
"orderDate": "1/06/2021",
"products": [
{
"productName": "280",
"quantity": "1",
"price": "5.00"
}
]
}
]
},
{
"status": true,
"message": "",
"orders": [
{
"orderId": "1",
"orderDate": "1/06/2021",
"products": [
{
"productName": "610",
"quantity": "1",
"price": "5.00"
}
]
}
]
},
{
"status": false,
"message": "",
"orders": [
{
"orderId": "1",
"orderDate": "1/06/2021",
"products": [
{
"productName": "800",
"quantity": "50",
"price": "5.00"
}
]
}
]
},
{
"status": false,
"message": "",
"orders": [
{
"orderId": "1",
"orderDate": "1/06/2021",
"products": [
{
"productName": "1800",
"quantity": "50",
"price": "5.00"
}
]
}
]
}
];
const resutl = data.reduce((acc, cur) => {
const key = cur.status ? "successItems" : "failureItems";
if (acc[key]) {
return {
...acc,
[key]: {
status: cur.status,
messgae: '',
orders: [
...acc[key].orders,
...cur.orders
]
}
}
} else {
return {
...acc,
[key]: {
status: cur.status,
messgae: '',
orders: [
...cur.orders
]
}
}
}
}, {});
console.log('resutl', resutl);
console.log('resutl', Object.values(resutl));

Get all options for configurable product Magento 2.0 REST Api

When i call this API,
{{base_url}}index.php/rest/V1/configurable-products/:sku/options/all
I am getting a response like this,
[
{
"id": 9,
"attribute_id": "93",
"label": "Color",
"position": 0,
"values": [
{
"value_index": 15
},
{
"value_index": 16
},
{
"value_index": 17
}
],
"product_id": 19
},
{
"id": 10,
"attribute_id": "176",
"label": "side",
"position": 1,
"values": [
{
"value_index": 18
},
{
"value_index": 19
}
],
"product_id": 19
}
]
But i want label for all these value_indexes.Could i get all these values in a single request
There is an pi for getting all the labels,
{{base_url}}/index.php/rest/V1/products/attributes/:attribute_id/options
Ex:
{{base_url}}/index.php/rest/V1/products/attributes/93/options
will return
[
{
"label": " ",
"value": ""
},
{
"label": "green",
"value": "12"
},
{
"label": "yellow",
"value": "13"
},
{
"label": "red",
"value": "14"
}
]
You can use this endpoint to fetch multiple attribute sets in a single request
/rest/V1/products/attributes
example:
{domain}/rest/V1/products/attributes?search_criteria[filter_groups][0][filters][0][field]=attribute_id&search_criteria[filter_groups][0][filters][0][value]=93,138&search_criteria[filter_groups][0][filters][0][condition_type]=in
response:
"items": [
{
"is_wysiwyg_enabled": false,
"is_html_allowed_on_front": false,
"used_for_sort_by": false,
"is_filterable": true,
"is_filterable_in_search": false,
"is_used_in_grid": true,
"is_visible_in_grid": false,
"is_filterable_in_grid": true,
"position": 0,
"apply_to": [
"simple",
"virtual",
"configurable"
],
"is_searchable": "1",
"is_visible_in_advanced_search": "1",
"is_comparable": "1",
"is_used_for_promo_rules": "0",
"is_visible_on_front": "0",
"used_in_product_listing": "0",
"is_visible": true,
"scope": "global",
"attribute_id": 93,
"attribute_code": "color",
"frontend_input": "select",
"entity_type_id": "4",
"is_required": false,
"options": [
{
"label": " ",
"value": ""
},
{
"label": "blue",
"value": "8"
},
{
"label": "red",
"value": "9"
},
{
"label": "black",
"value": "10"
},
{
"label": "white",
"value": "11"
}
],
"is_user_defined": true,
"default_frontend_label": "Color",
"frontend_labels": [],
"backend_type": "int",
"source_model": "Magento\\Eav\\Model\\Entity\\Attribute\\Source\\Table",
"default_value": "",
"is_unique": "0",
"validation_rules": []
},
{
"is_wysiwyg_enabled": false,
"is_html_allowed_on_front": true,
"used_for_sort_by": false,
"is_filterable": false,
"is_filterable_in_search": false,
"is_used_in_grid": true,
"is_visible_in_grid": true,
"is_filterable_in_grid": true,
"position": 0,
"apply_to": [],
"is_searchable": "0",
"is_visible_in_advanced_search": "0",
"is_comparable": "0",
"is_used_for_promo_rules": "0",
"is_visible_on_front": "0",
"used_in_product_listing": "0",
"is_visible": true,
"scope": "global",
"attribute_id": 138,
"attribute_code": "simple_size",
"frontend_input": "select",
"entity_type_id": "4",
"is_required": true,
"options": [
{
"label": " ",
"value": ""
},
{
"label": "small",
"value": "12"
},
{
"label": "medium",
"value": "13"
},
{
"label": "large",
"value": "14"
}
],
"is_user_defined": true,
"default_frontend_label": "simple_size",
"frontend_labels": [
{
"store_id": 1,
"label": "Size"
}
],
"backend_type": "int",
"source_model": "Magento\\Eav\\Model\\Entity\\Attribute\\Source\\Table",
"default_value": "",
"is_unique": "0",
"validation_rules": []
}
],
"search_criteria": {
"filter_groups": [
{
"filters": [
{
"field": "attribute_id",
"value": "93,138",
"condition_type": "in"
}
]
}
]
},
"total_count": 2
}

extract data value from nested JSON

I am trying to get some specific fields out of this Json.
fn({
"processingDurationMillis": 454,
"authorisedAPI": true,
"success": true,
"airline": "MH",
"validCreditCards": [
"AX",
"CA",
"VI"
],
"paypal": true,
"outboundOptions": [
{
"optionId": 0,
"flights": [
{
"flightNumber": "0066",
"departureAirport": {
"code": "KUL",
"name": "Kuala Lumpur Intl",
"city": "Kuala Lumpur",
"country": "Malaysia",
"timezone": "Asia/Kuala_Lumpur",
"lat": 2.745578,
"lng": 101.709917,
"terminal": null,
"gate": null
},
"arrivalAirport": {
"code": "ICN",
"name": "Incheon Intl",
"city": "Seoul",
"country": "South Korea",
"timezone": "Asia/Seoul",
"lat": 37.469075,
"lng": 126.450517,
"terminal": null,
"gate": null
},
"marketingAirline": "MH",
"mealIndicator": "M",
"allowedSsrs": {
},
"operatingAirline": null,
"equipment": "333",
"equipmentName": "Airbus A330-300",
"flightRPH": 10101,
"comments": [
"MH CODESHARE WITH KE"
],
"depScheduled": "2015-04-28T23:30:00.000+08:00",
"arrScheduled": "2015-04-29T07:10:00.000+09:00",
"depEstimated": null,
"depActual": null,
"arrEstimated": null,
"arrActual": null,
"eligibleForEticketing": true,
"cabin": "ECONOMY",
"fareMarketingType": "BASIC",
"rbd": "N",
"seatsAvailable": 9,
"durationMinutes": 400,
"minutesToScheduledFlightDeparture": 6486
}
],
"stopOvers": [
],
"fareDetails": {
"perPassengerJourneyFares": [
{
"passengerType": "ADT",
"fare": "1214.95",
"currencyCode": "MYR"
}
],
"perPassengerTripTaxes": [
{
"passengerType": "ADT",
"totalTax": "68.90",
"taxes": [
{
"code": "MY",
"amount": "65.00",
"currency": "MYR"
},
{
"code": "D8",
"amount": "3.90",
"currency": "MYR"
}
]
}
],
"journeyFare": "1214.95",
"totalTripFare": "1283.90",
"fareCurrency": "MYR"
},
"magicString": "2t2qi8oNXWkrDR75zYDrk9+3wNaJBzHyK1ftoR/VZPVgHO+EFTkh8DMg5WUl1ap7VjwBsnhD2gFxAwBbHhY0+k0lp7BUvSoYSKg6S6u4ZkvbIWMktl+lHgcKl46vht9//2dZVJvH4D7WJvnJTtK5O4TWNrkiTmEdHp55yRmjwWfsgNswOIMXoWrZj3OUJ4DH4POJ8rmfilimvtpBCdxNsqoZDVC9d6/6LiICZ3wHZJ7w/88QuExFV7OsHbc+jI3trRzDCCb6Ns62MGyfsXX6Pz8mJe6gs02UjapVSPa3M9CqLGMCN0xCF28WNbavhSI9jG3cWsQbxGU8rnhmjx00Iw5v2qqjdE/Dx432Qzs4s36SqUjLF7KN9hAJoQuMX3emE4gZ+7ANJ5bDTDEYZlnUZ4iXKykzUptYDyGay0evu1kdCjxPJlgiEtOl3hFMaKC+eoTsjps4RoYy0Z7oD3aP52qCYPdCH+8XTic522UKU1mW9HMjmGxH5zrvYK2rOgzSR2+xH5K3IpXHBAQqWOTEvmirP4qvg5VOPjyO9mIM83I6aY1JAkqo9jYqtEwrGqANdhA9z78EdoyQYKZBXcLsQMKz06fAczwk/WxxIi1ctL8EW+aZYddkbPo7xD6NWc8bJ+ARw5AlS1tirVNcO3mN5jVr/a6qftVuaz/0q83VsX4ztQpgMjDkptbw9Zz6DNLgiLJEzdf7fraoVUyzeth5wucOMzpLBP+ERbD7XFnDSKN8QzG6lLpDK8qy95K5FMmcF4uDq8Y1waTyIN9sS+v50OTbjr7Ebs3uKIxMZFfGUfp7YpDiVyo+2x4La4K7rhHPtoR6iEfVCjnTAUvamQu3qgL3vuSCPPPJiHFbdOrKVlp3kfAxaIcJpX3Z+Twx2cNAhsGHSk2ZazzvP5Pw1EF066VcoDkld9Oe/Qu5cC+DtG2LHhMA7NU8hMD66q9UCsXC6P/mjbKr7hatjHyyklDIKuxxirMpYkukEa73RJlhKmC0fjj4EYcgRy5MtybexuN59KaTeSEFxMGFIkv0zHp5jO/wHUvyypqbxTKFR3VAx6WpmSNg/Iui2uXDhNu/F4zJnYQUW9EyluZEPebFk2Uj455O2+y0UmFe4WnUY+0d92obZNv855/ctA4UC/LQn2s9azqdhDIeUUHuHEn2a4Grb+7l8wuai6ybBmmE62ck+CqMou+A+CUwk71KMkh3ZXf8BdeelW8Ia7r9ja7wKNBklgYo4Q8xOR63QhyCt2BiiR9aOxiDIKiW7bxSFCBga7yIPWx/NZdGjUYTuiJ9KZ7W2dKLhF6XDU5mWOV7XwMRzkyschEnjSzQWGjTTftEIiNI1V1M2bhFwc92JkfVFxwXCg==",
"seatsAvailable": [
9
],
"corporateAccount": false,
"flightCanBeHeld": true,
"durationMinutes": 400,
"gaFareDetails": {
"perPassengerJourneyFares": [
{
"passengerType": "ADT",
"fare": "1214.95",
"currencyCode": "MYR"
}
],
"perPassengerTripTaxes": [
{
"passengerType": "ADT",
"totalTax": "68.90",
"taxes": [
{
"code": "MY",
"amount": "65.00",
"currency": "MYR"
},
{
"code": "D8",
"amount": "3.90",
"currency": "MYR"
}
]
}
],
"journeyFare": "1214.95",
"totalTripFare": "1283.90",
"fareCurrency": "MYR"
},
"adobeFareDetails": {
"perPassengerJourneyFares": [
{
"passengerType": "ADT",
"fare": "336.66",
"currencyCode": "USD"
}
],
"perPassengerTripTaxes": [
{
"passengerType": "ADT",
"totalTax": "19.09",
"taxes": [
{
"code": "MY",
"amount": "18.01",
"currency": "USD"
},
{
"code": "D8",
"amount": "1.08",
"currency": "USD"
}
]
}
],
"journeyFare": "336.66",
"totalTripFare": "355.77",
"fareCurrency": "USD"
},
"userAgentFareDetails": {
"perPassengerJourneyFares": [
{
"passengerType": "ADT",
"fare": "336.66",
"currencyCode": "USD"
}
],
"perPassengerTripTaxes": [
{
"passengerType": "ADT",
"totalTax": "19.09",
"taxes": [
{
"code": "MY",
"amount": "18.01",
"currency": "USD"
},
{
"code": "D8",
"amount": "1.08",
"currency": "USD"
}
]
}
],
"journeyFare": "336.66",
"totalTripFare": "355.77",
"fareCurrency": "USD"
},
"eligibleForeTicketing": true,
"lowestSeatCount": 9,
"directFlight": true
}
],
"departureAirport": {
"code": "KUL",
"name": "Kuala Lumpur Intl",
"city": "Kuala Lumpur",
"country": "Malaysia",
"timezone": "Asia/Kuala_Lumpur",
"lat": 2.745578,
"lng": 101.709917,
"terminal": null,
"gate": null
},
"arrivalAirport": {
"code": "ICN",
"name": "Incheon Intl",
"city": "Seoul",
"country": "South Korea",
"timezone": "Asia/Seoul",
"lat": 37.469075,
"lng": 126.450517,
"terminal": null,
"gate": null
},
"apiRequired": true,
"fareRules": [
{
"id": 50,
"order": 1,
"priority": 0,
"code": "Basic",
"name": "MHbasic",
"value": "Economy Class Fares",
"listFareRules": [
{
"id": 130,
"order": 0,
"code": "",
"name": "Discount level",
"value": "Up to 65%"
},
{
"id": 140,
"order": 1,
"code": "",
"name": "Where to buy",
"value": "All channels"
},
{
"id": 150,
"order": 2,
"code": "",
"name": "Advance purchase",
"value": "Applies"
},
{
"id": 160,
"order": 3,
"code": "",
"name": "Payment",
"value": "Ticket dateline applies"
},
{
"id": 170,
"order": 4,
"code": "",
"name": "Baggage allowance",
"value": "2pc/30kg"
},
{
"id": 180,
"order": 5,
"code": "",
"name": "Advance seat selection",
"value": "Not allowed"
},
{
"id": 190,
"order": 6,
"code": "",
"name": "Enrich miles",
"value": "Nil"
},
{
"id": 200,
"order": 7,
"code": "",
"name": "Change of booking",
"value": "Not allowed"
},
{
"id": 210,
"order": 8,
"code": "",
"name": "Upgrade",
"value": "Not allowed"
},
{
"id": 220,
"order": 9,
"code": "",
"name": "Stand by at the airport",
"value": "For a fee"
},
{
"id": 220,
"order": 10,
"code": "",
"name": "No show",
"value": "Penalty applies"
},
{
"id": 230,
"order": 11,
"code": "",
"name": "Refund",
"value": "For a fee"
}
],
"listFareNotes": [
{
"id": 10,
"order": 0,
"code": "",
"name": "Important Notice",
"value": ""
},
{
"id": 15,
"order": 1,
"code": "",
"name": "",
"value": ""
},
{
"id": 20,
"order": 2,
"code": "",
"name": "1.",
"value": "Generic attributes shown only applies to MH operated flights. MH3000-3999, MH5200-5999 and MH9000-9999 Series flights are subject to their own rules. Please contact MH Call Center or ticket offices for actual fare rules."
},
{
"id": 30,
"order": 3,
"code": "",
"name": "2.",
"value": "For transpacific and transatlantic flights, the following baggage allowances apply: Economy - 2 pieces (23kg each piece), First and Business - 2 pieces (32kg each piece)."
},
{
"id": 50,
"order": 5,
"code": "",
"name": "3.",
"value": "Upgrade, standby at the airport and refund fees for specific routes can be obtained from subsequent booking pages."
},
{
"id": 60,
"order": 6,
"code": "",
"name": "4.",
"value": "Standby at the airport denotes the same day for an earlier flight."
},
{
"id": 70,
"order": 7,
"code": "",
"name": "5.",
"value": "Fare rules shown are indicative only. Please call our Contact Center to check the detailed fare rules."
},
{
"id": 80,
"order": 8,
"code": "",
"name": "",
"value": "Should there be any discrepancy between the above information and the terms and conditions (T&C) published in the fare rules, then the T&C in the fare rules shall prevail."
}
]
}
],
"Errors": [
],
"Warnings": [
]
})
i want extract flight number, depScheduled, arrScheduled and journey fare from the above json.
here are my code:
$json2 = json_decode($json,true);
$result= array();
foreach ($json2['outboundOptions']['flights']as $theentity) {
$result[] = $theentity['flightNumber'];
}
print_r($result);
The code above return me a error, "Invalid argument supplied for foreach()".I searched around, but still have not found the solution yet..
It is giving you that error because outboundOptions is an array of objects. What you want is to access the first object:
foreach ($json2['outboundOptions'][0]['flights']as $theentity) {
$result[] = $theentity['flightNumber'];
}
Also, remove the trailing comma (,) from your ] at the end as that causes invalid json.
You can check if your json is valid by going to jsonlint.com
Working Example
Update as per your comment
To get all the flights, change your foreach loop to this:
foreach ($json3['outboundOptions'] as $flight) {
foreach($flight['flights'] as $theentity) {
$result[] = $theentity['flightNumber'];
}
}
Example
remove the trailing ',' near the very end of your json.
change your code, add a [0] before ['flights']
$json2 = json_decode($json,TRUE);
$result= array();
foreach ($json2['outboundOptions'][0]['flights']as $theentity) {
$result[] = $theentity['flightNumber'];
}
print_r($result);

Categories