In the json data below, i will like to check the “stockAvailability[0].diffgr:diffgram.DocumentElement.StockAvailability” that have an item stock level in branches, now there is quantity object in the root level, i want to generate new object in the “stockAvailability[0].diffgr:diffgram.DocumentElement.StockAvailability.*” having the number of quantity i can get out of each branch to complete the total quantity required
{
“id”: 67,
“name”: “4127 - 16, Red”,
“product_id”: 1721,
“variation_id”: 1757,
“quantity”: 4,
“tax_class”: “”,
“subtotal”: “303.80”,
“subtotal_tax”: “0.00”,
“total”: “303.80”,
“total_tax”: “0.00”,
“taxes”: ,
“meta_data”: [
{
“id”: 707,
“key”: “pa_size”,
“value”: “16”,
“display_key”: “Size”,
“display_value”: “16”
},
{
“id”: 708,
“key”: “pa_colour”,
“value”: “red”,
“display_key”: “Colour”,
“display_value”: “Red”
},
{
“id”: 709,
“key”: “_reduced_stock”,
“value”: “4”,
“display_key”: “_reduced_stock”,
“display_value”: “4”
}
],
“sku”: “4127”,
“price”: 75.95,
“image”: {
“id”: 0,
“src”: “”
},
“parent_name”: “4127”,
“barCode_retrival”: {
“id”: 1757,
“date_created”: “2023-05-30T15:46:01”,
“date_created_gmt”: “2023-05-30T14:46:01”,
“date_modified”: “2023-05-30T18:07:18”,
“date_modified_gmt”: “2023-05-30T17:07:18”,
“description”: “”,
“permalink”: “https://shiffonz.sculpt.digital/p/4127/?attribute_pa_size=16&attribute_pa_colour=red”,
“sku”: “4127”,
“price”: “75.95”,
“regular_price”: “139.9”,
“sale_price”: “75.95”,
“date_on_sale_from”: null,
“date_on_sale_from_gmt”: null,
“date_on_sale_to”: null,
“date_on_sale_to_gmt”: null,
“on_sale”: true,
“status”: “publish”,
“purchasable”: true,
“virtual”: false,
“downloadable”: false,
“downloads”: ,
“download_limit”: -1,
“download_expiry”: -1,
“tax_status”: “taxable”,
“tax_class”: “”,
“manage_stock”: true,
“stock_quantity”: 10,
“stock_status”: “instock”,
“backorders”: “no”,
“backorders_allowed”: false,
“backordered”: false,
“low_stock_amount”: null,
“weight”: “”,
“dimensions”: {
“length”: “”,
“width”: “”,
“height”: “”
},
“shipping_class”: “”,
“shipping_class_id”: 0,
“image”: null,
“attributes”: [
{
“id”: 1,
“name”: “Size”,
“option”: “16”
},
{
“id”: 2,
“name”: “Colour”,
“option”: “Red”
}
],
“menu_order”: 36,
“meta_data”: [
{
“id”: 56921,
“key”: “_barcode”,
“value”: “0000000685672”
},
{
“id”: 56995,
“key”: “wcmlim_stock_at_223”,
“value”: “1”
},
{
“id”: 56996,
“key”: “wcmlim_regular_price_at_223”,
“value”: “”
},
{
“id”: 56997,
“key”: “wcmlim_sale_price_at_223”,
“value”: “”
},
{
“id”: 56998,
“key”: “wcmlim_cogs_at_223”,
“value”: “”
},
{
“id”: 56999,
“key”: “wcmlim_regular_price_at_222”,
“value”: “”
},
{
“id”: 57000,
“key”: “wcmlim_sale_price_at_222”,
“value”: “”
},
{
“id”: 57001,
“key”: “wcmlim_cogs_at_222”,
“value”: “”
},
{
“id”: 57002,
“key”: “wcmlim_regular_price_at_220”,
“value”: “”
},
{
“id”: 57003,
“key”: “wcmlim_sale_price_at_220”,
“value”: “”
},
{
“id”: 57004,
“key”: “wcmlim_cogs_at_220”,
“value”: “”
},
{
“id”: 57005,
“key”: “wcmlim_regular_price_at_219”,
“value”: “”
},
{
“id”: 57006,
“key”: “wcmlim_sale_price_at_219”,
“value”: “”
},
{
“id”: 57007,
“key”: “wcmlim_cogs_at_219”,
“value”: “”
},
{
“id”: 57008,
“key”: “wcmlim_regular_price_at_221”,
“value”: “”
},
{
“id”: 57009,
“key”: “wcmlim_sale_price_at_221”,
“value”: “”
},
{
“id”: 57010,
“key”: “wcmlim_cogs_at_221”,
“value”: “”
},
{
“id”: 57011,
“key”: “purchase_price”,
“value”: “”
},
{
“id”: 57012,
“key”: “_wc_additional_variation_images”,
“value”: “”
},
{
“id”: 57015,
“key”: “wcmlim_stock_at_222”,
“value”: “13”
}
],
“_links”: {
“self”: [
{
“href”: “https://shiffonz.sculpt.digital/wp-json/wc/v3/products/1721/variations/1757”
}
],
“collection”: [
{
“href”: “https://shiffonz.sculpt.digital/wp-json/wc/v3/products/1721/variations”
}
],
“up”: [
{
“href”: “https://shiffonz.sculpt.digital/wp-json/wc/v3/products/1721”
}
]
}
},
“_barCode”: [
“0000000685672”
],
“note”: “”,
“currency”: “GBP”,
“order_id”: 1761,
“payment_method”: “”,
“customer_id_inner”: 14,
“order_date_created”: [
[
“2023”,
“05”,
“30”
],
“17:57:56”
],
“customer_info”: “abubakar@micro1.ai”,
“fm_retail_customer_info”: [
{
“@xmlns”: “https://www.fashionmaster.co.uk/”,
“xs:schema”: {
“@id”: “NewDataSet”,
“xs:element”: {
“@name”: “NewDataSet”,
“@msdata:IsDataSet”: “true”,
“@msdata:MainDataTable”: “CustomerDetails”,
“@msdata:UseCurrentLocale”: “true”,
“xs:complexType”: {
“xs:choice”: {
“@minOccurs”: 0,
“@maxOccurs”: “unbounded”,
“xs:element”: {
“@name”: “CustomerDetails”,
“xs:complexType”: {
“xs:sequence”: {
“xs:element”: [
{
“@name”: “FMCustomerCode”,
“@type”: “xs:string”,
“@minOccurs”: 0,
“#”: “”
},
{
“@name”: “FMCustNo”,
“@type”: “xs:string”,
“@minOccurs”: 0,
“#”: “”
},
{
“@name”: “WebCustomerCode”,
“@type”: “xs:long”,
“@minOccurs”: 0,
“#”: “”
},
{
“@name”: “AltCustCode”,
“@type”: “xs:string”,
“@minOccurs”: 0,
“#”: “”
},
{
“@name”: “Email”,
“@type”: “xs:string”,
“@minOccurs”: 0,
“#”: “”
},
{
“@name”: “CompanyName”,
“@type”: “xs:string”,
“@minOccurs”: 0,
“#”: “”
},
{
“@name”: “Surname”,
“@type”: “xs:string”,
“@minOccurs”: 0,
“#”: “”
},
{
“@name”: “Forename”,
“@type”: “xs:string”,
“@minOccurs”: 0,
“#”: “”
},
{
“@name”: “Title”,
“@type”: “xs:string”,
“@minOccurs”: 0,
“#”: “”
},
{
“@name”: “Address1”,
“@type”: “xs:string”,
“@minOccurs”: 0,
“#”: “”
},
{
“@name”: “Address2”,
“@type”: “xs:string”,
“@minOccurs”: 0,
“#”: “”
},
{
“@name”: “Town”,
“@type”: “xs:string”,
“@minOccurs”: 0,
“#”: “”
},
{
“@name”: “County”,
“@type”: “xs:string”,
“@minOccurs”: 0,
“#”: “”
},
{
“@name”: “PostCode”,
“@type”: “xs:string”,
“@minOccurs”: 0,
“#”: “”
},
{
“@name”: “Country”,
“@type”: “xs:string”,
“@minOccurs”: 0,
“#”: “”
},
{
“@name”: “Telephone1”,
“@type”: “xs:string”,
“@minOccurs”: 0,
“#”: “”
},
{
“@name”: “Telephone2”,
“@type”: “xs:string”,
“@minOccurs”: 0,
“#”: “”
},
{
“@name”: “WholesaleCustomer”,
“@type”: “xs:int”,
“@minOccurs”: 0,
“#”: “”
},
{
“@name”: “LoyaltyCardNumber”,
“@type”: “xs:string”,
“@minOccurs”: 0,
“#”: “”
},
{
“@name”: “WhereHeardAboutUs”,
“@type”: “xs:int”,
“@minOccurs”: 0,
“#”: “”
},
{
“@name”: “WhereHeardAboutUsSpecific”,
“@type”: “xs:string”,
“@minOccurs”: 0,
“#”: “”
},
{
“@name”: “PostageCode”,
“@type”: “xs:string”,
“@minOccurs”: 0,
“#”: “”
},
{
“@name”: “RecordCreated”,
“@type”: “xs:dateTime”,
“@minOccurs”: 0,
“#”: “”
},
{
“@name”: “RecordAmended”,
“@type”: “xs:dateTime”,
“@minOccurs”: 0,
“#”: “”
}
]
}
}
}
}
}
}
},
“diffgr:diffgram”: {
“DocumentElement”: {
“CustomerDetails”: {
“@diffgr:id”: “CustomerDetails1”,
“@msdata:rowOrder”: 0,
“FMCustomerCode”: “MIC00001”,
“FMCustNo”: “MIC00001”,
“WebCustomerCode”: “0”,
“AltCustCode”: “123M”,
“Email”: “abubakar@micro1.ai”,
“CompanyName”: “Micro1”,
“Surname”: “Abubakar”,
“Forename”: “Bello”,
“Title”: “Mr”,
“Address1”: “test addres address”,
“Address2”: “test addres address”,
“Town”: “chelsea”,
“County”: “UK”,
“PostCode”: “1290”,
“Country”: “UK”,
“Telephone1”: “123456789”,
“Telephone2”: “”,
“WholesaleCustomer”: “0”,
“LoyaltyCardNumber”: “”,
“WhereHeardAboutUs”: “0”,
“WhereHeardAboutUsSpecific”: “”,
“PostageCode”: {
“@xml:space”: “preserve”,
“#”: " "
},
“RecordCreated”: “2023-03-02T08:15:40.327+00:00”,
“RecordAmended”: “2023-05-30T12:06:37.56+01:00”
}
}
}
}
],
“fmCustomerCode”: “MIC00001”,
“stockAvailability”: [
{
“@xmlns”: “https://www.fashionmaster.co.uk/”,
“xs:schema”: {
“@id”: “NewDataSet”,
“xs:element”: {
“@name”: “NewDataSet”,
“@msdata:IsDataSet”: “true”,
“@msdata:MainDataTable”: “StockAvailability”,
“@msdata:UseCurrentLocale”: “true”,
“xs:complexType”: {
“xs:choice”: {
“@minOccurs”: 0,
“@maxOccurs”: “unbounded”,
“xs:element”: {
“@name”: “StockAvailability”,
“xs:complexType”: {
“xs:sequence”: {
“xs:element”: [
{
“@name”: “BranchNumber”,
“@type”: “xs:string”,
“@minOccurs”: 0,
“#”: “”
},
{
“@name”: “BranchName”,
“@type”: “xs:string”,
“@minOccurs”: 0,
“#”: “”
},
{
“@name”: “Address1”,
“@type”: “xs:string”,
“@minOccurs”: 0,
“#”: “”
},
{
“@name”: “Address3”,
“@type”: “xs:string”,
“@minOccurs”: 0,
“#”: “”
},
{
“@name”: “Address4”,
“@type”: “xs:string”,
“@minOccurs”: 0,
“#”: “”
},
{
“@name”: “Postcode”,
“@type”: “xs:string”,
“@minOccurs”: 0,
“#”: “”
},
{
“@name”: “Stock”,
“@type”: “xs:int”,
“@minOccurs”: 0,
“#”: “”
}
]
}
}
}
}
}
}
},
“diffgr:diffgram”: {
“DocumentElement”: {
“StockAvailability”: [
{
“@diffgr:id”: “StockAvailability1”,
“@msdata:rowOrder”: 0,
“BranchNumber”: “004”,
“BranchName”: “BIRMINGHAM SHOP”,
“Address1”: “369 Stratford Rd,”,
“Address3”: “”,
“Address4”: “”,
“Postcode”: "B11 4JY ",
“Stock”: “1”
},
{
“@diffgr:id”: “StockAvailability2”,
“@msdata:rowOrder”: 1,
“BranchNumber”: “007”,
“BranchName”: “BRADFORD LEEDS ROAD”,
“Address1”: “77 LEEDS ROAD”,
“Address3”: “”,
“Address4”: “”,
“Postcode”: “BD3 8BZ”,
“Stock”: “2”
}
]
}
}
}
]
}
expected result since the quantity is 4, i should expect the stockAvailability to be
[{
“@diffgr:id”: “StockAvailability1”,
“@msdata:rowOrder”: 0,
“BranchNumber”: “004”,
“BranchName”: “BIRMINGHAM SHOP”,
“Address1”: “369 Stratford Rd,”,
“Address3”: “”,
“Address4”: “”,
“Postcode”: "B11 4JY ",
“Stock”: “1”,
"quantity: “1”
},
{
“@diffgr:id”: “StockAvailability2”,
“@msdata:rowOrder”: 1,
“BranchNumber”: “007”,
“BranchName”: “BRADFORD LEEDS ROAD”,
“Address1”: “77 LEEDS ROAD”,
“Address3”: “”,
“Address4”: “”,
“Postcode”: “BD3 8BZ”,
“Stock”: “2”,
"quantity: “2”
}
]
which means the new quantity object created carries the number of item i can get out of each branches to make up the total
if the quantity is 2 then it means i will get the below result
[{
“@diffgr:id”: “StockAvailability1”,
“@msdata:rowOrder”: 0,
“BranchNumber”: “004”,
“BranchName”: “BIRMINGHAM SHOP”,
“Address1”: “369 Stratford Rd,”,
“Address3”: “”,
“Address4”: “”,
“Postcode”: "B11 4JY ",
“Stock”: “1”,
"quantity: “0”
},
{
“@diffgr:id”: “StockAvailability2”,
“@msdata:rowOrder”: 1,
“BranchNumber”: “007”,
“BranchName”: “BRADFORD LEEDS ROAD”,
“Address1”: “77 LEEDS ROAD”,
“Address3”: “”,
“Address4”: “”,
“Postcode”: “BD3 8BZ”,
“Stock”: “2”,
"quantity: “2”
}
]
because branch two already have the total or they can share and pick 1 from each branches