0

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!

1 Answer 1

0

Combine them into a PHP data structure like an array first. It makes no sense to try and combine them after they've been converted to a string because you'll simply be re-parsing data that was already parsed!

Sign up to request clarification or add additional context in comments.

4 Comments

Thats what I figured would be the best way. Im just not sure how to deal with it once its in the array.
Sorry about that last comment, wrong thread.., maybe you could update your question to show the structure of the arrays?
Even at that step I am unsure on how I should even structure them. I assume I would use array_push to put the items into an array as it loops through but I get stuck there.
How do you have the data before you build the strings? I'd expect the data would already be in some sort of structure within PHP before building the stings in the first place.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.