Basically I'm creating a script to load a tracking pixel for Commission Junction orders on the confirmation page of an order. It is very straightforward for 1 order, but our shopping cart allows multiple orders to be placed at once and it only gives 1 confirmation page. This means I have to combine all the order numbers and items into 1 string before loading the pixel. The catch is that I have to combine similar data because item SKUs can't be repeated.
The four values I have to send are Order #, SKU(s), Amount(s), and Quantity.
A simple single order confirmation page example:
Order #: 100 SKU: RR-555 / AMT: 5.00 / QTY:1 SKU: SS-444 / AMT: 10.00 / QTY:2
The script would output this as:
&ITEM1=RR-555&AMT1=5.00&QTY1=1&ITEM2=SS-444&AMT2=10.00&QTY2=2&OID=100
A multiple order confirmation page example:
Order #: 101 SKU: RR-555 / AMT: 5.00 / QTY: 1 SKU: SS-444 / AMT: 10.00 / QTY:2
Order #: 102 SKU:TT-333 / AMT: 5.00 / QTY: 1 SKU: RR-555 / AMT: 5.00 / QTY: 1
The output of the script would currently read as:
&ITEM1=RR-555&AMT1=5.00&QTY1=1&ITEM2=SS-444&AMT2=10.00&QTY2=2&&ITEM3=TT-3333&AMT3=5.00&QTY3=1&ITEM4=RR-555&AMT4=5.00&QTY4=1&OID=101102
In cases with multiple orders the OID's will just get concatenated onto the ends of each other. The problem is the SKU 'RR-555' appears twice in this string and can only appear one time. So Im looking for the best way to combine like SKU numbers and add their quantities together. So it would read:
&ITEM1=RR-555&AMT1=5.00&QTY1=3&ITEM2=SS-444&AMT2=10.00&QTY2=2&
&ITEM3=TT-3333&AMT3=5.00&QTY3=1&OID=101102
I'm really puzzled at how to approach this. Would it be best to put all the item data from all the orders into an array, try to combine at that level, then create the string? Or should I have that string created and try to combine there? Any help is appreciated!