My task is to categorize products from the products array based on the corresponding season provided in the orders array. Each entry in the orders array contains a key-value pair for season (e.g., "season": "2015"). The products are associated with individual order objects using the "id" of the order array and the "orderlineId" of the products array.
Once I have grouped the products by season, they also need to be further grouped based on the values of "uniqueId" and "colorCode" found within product.uniqueId and product.colorCode.
Orders array
{
"id": 99945333,
"key": "1",
"orderNumber": "01",
"season": "2007"
},
{
"id": 99945335,
"key": "1",
"orderNumber": "02",
"season": "2016"
},
{
"id": 99945333,
"key": "2",
"orderNumber": "03",
"season": "2019"
},
{
"id": 99945333,
"key": "3",
"orderNumber": "04",
"season": "2017"
}
]
Products array
"orderlineId": 99945333,
"product": {
"season": null,
"size": "XXL",
"category: "pants"
"sizeSortCode": "60",
"subSize": null,
"subSizeSortCode": "0",
"uniqueId": "80457",
"year": null
},
"quantity": 1,
"quantityDelivered": 0,
"remark": null
},
{
"orderlineId": 99945333,
"product": {
"season": null,
"size": "XXL",
"category: "pants"
"sizeSortCode": "60",
"subSize": null,
"subSizeSortCode": "0",
"uniqueId": "80457",
"year": null
},
"quantity": 1,
"quantityDelivered": 0,
"remark": null
},
{
"orderlineId": 99945335,
"product": {
"season": null,
"size": "XXL",
"category: "shirt"
"sizeSortCode": "60",
"subSize": null,
"subSizeSortCode": "0",
"uniqueId": "80457",
"year": null
},
"quantity": 1,
"quantityDelivered": 0,
"remark": null
},
{
"orderlineId": 99945335,
"product": {
"season": null,
"size": "XXL",
"category: "trouser"
"sizeSortCode": "60",
"subSize": null,
"subSizeSortCode": "0",
"uniqueId": "80453",
"year": null
},
"quantity": 1,
"quantityDelivered": 0,
"remark": null
},
{
"orderlineId": 99945473,
"product": {
"season": null,
"category: "blouse"
"size": "XXL",
"sizeSortCode": "60",
"subSize": null,
"subSizeSortCode": "0",
"uniqueId": "80453",
"year": null
},
"quantity": 1,
"quantityDelivered": 0,
"remark": null
},
I believe creating a new array would simplify the process for easier iteration.
Desired outcome: new array
{
"season": 2007,
"products": [
{
"season": null,
"size": "XXL",
"category: "pants"
"sizeSortCode": "60",
"subSize": null,
"subSizeSortCode": "0",
"uniqueId": "80453",
"year": null
}
{
"season": null,
"size": "XXL",
"sizeSortCode": "60",
"subSize": null,
"subSizeSortCode": "0",
"uniqueId": "80453",
"year": null
}
},
{
"season": 2016,
"products": [
{
"season": null,
"size": "XXL",
"sizeSortCode": "60",
"subSize": null,
"subSizeSortCode": "0",
"uniqueId": "80457",
"year": null
},
},
{
"season": null,
"size": "XXL",
"sizeSortCode": "60",
"subSize": null,
"subSizeSortCode": "0",
"uniqueId": "80453",
"year": null
}
}
]
This task has proven challenging. My initial plan is to iterate over the seasons first, but I am uncertain how to group the products and construct a new array. Any assistance would be greatly appreciated!