I had a previous problem which I have somewhat overcome. However this has resulted in a new problem which when fixed it should be working as intended.
I have created an array
of Orders from a csv file and have managed to extract the data from the Orders (Products, Address etc.) and be printed together (Which was originally first problem). For example the csv file contains 2 Orders which prints them all together such as:
Order: Order1
Recipient: Timmy
Address: 123 Street
Products:
Table (Quantity: 1)
Cup (Quantity 4)
Order: Order2
Recipient: Billy
Address: 456 Street
Products:
Chair (Quantity 5)
The new problem is now this data needs to go back into multiple arrays
because of the API which is being used. I have this nearly working apart from the products, which is currently adding products from the previous order. Using the above example, the array
would be the following:
//Order1
array(2)
{
[0]=> array(7)
{
["Product"]=> string(13) "Table"
["Quantity"]=> float(1)
}
[1]=> array(7)
{
["Product"]=> string(13) "Cup"
["Quantity"]=> float(4)
}
}
//Order2
array(3)
{
[0]=> array(7)
{
["Product"]=> string(13) "Table"
["Quantity"]=> float(1)
}
[1]=> array(7)
{
["Product"]=> string(13) "Cup"
["Quantity"]=> float(4)
}
[2]=> array(7)
{
["Product"]=> string(13) "Chair"
["Quantity"]=> float(5)
}
}
As shown above, the products from the previous order is duplicated onto the second order. The other order details are working as intended and being inserted as separate records into the database (Order Number, Address etc.). I'm unsure where I am going wrong, but this is the part of the code for the products array
:
foreach ($Order[$OrderNumber][$RecipientName][$Address1] as $key => $value)
{
$APIOrderItem[] = array('Product' => $key,
'Quantity' => $value);
}
$Items = array('APIOrderItem' => $APIOrderItem);
If previous code is required, I'll happily edit this post.