UPDATE: THIS IS SOLVED AND THE WORKING CODE IS PASTED IN THE BOTTOM OF THIS POST. I KEEP THE ORIGINAL POST SO OTHERS CAN READ AND FOLLOW.
I have had a big problem going Live with PayPal but think I have found the issue.
Look at this screenshot, it is from the pdt.php where customers are redirected to after purchase and it is a real one, did with a real visa: http://snag.gy/5XCvA.jpg
I have printed the whole TX-id at the top for debugging and here I can see that item_number1=54, quantity1=1 and item_name1=Introduktionsföreläsning.
The problem is that these do not show under Produkt, ID and Antal(Product, Id and Quantity) which is used to be presented to the customer. This is because I have the variables set like this:
$item_number = $response[item_number];
$item_name = $response[item_name];
$qty = $response[quantity];
and they never get anymore than just item_number, when they need to get "++:ed" to item_number1, item_number2 etc for every product.
I have tried to do a lot of changes, for example:
for($idx = 1; $idx < $count; $idx ++)
{
//$item_name .=$idx ++;
//$item_name = $item_name++;
echo ("<div class='abouttext'>Produkt: ".$item_name."</div>\n");
echo ("<div class='abouttext'>ID: ".$item_number."</div>\n");
echo ("<div class='abouttext'>Antal: ".$qty."</div>\n");
echo ("<br />");
}
Where the outcommented lines is where I try to append a number to item_name but I just get "1" or nothing at all as an answer when I need it to be item_name1 and so on.
Here is my PDT script: But im pretty sure it can be fixed in this area of code: http://pastebin.com/L2nyT9q7
$array_keys = array_keys($response);
$count = 1;
foreach($array_keys as $element)
{
if (!strncmp('item_number', $element, strlen('item_number')))
$count++;
}
for($idx = 1; $idx < $count; $idx ++)
{
if (isset($string1) && 'item_name' != null)
{
//$item_name .=$idx ++;
//$item_name = $item_name++;
echo ("<div class='abouttext'>Produkt: ".$item_name."</div>\n");
echo ("<div class='abouttext'>ID: ".$item_number."</div>\n");
echo ("<div class='abouttext'>Antal: ".$qty."</div>\n");
echo ("<br />");
}
}
Also: I have read on some forums with people with similar problems and they have gotten replies to use item_nameX as the variable name and I have tried that too, without any other result. If I hardcode $item_number = $response[item_number1];
<- where I specify the 1 I will get the correct details. I have tested that.
WORKING CODE:
$array_keys = array_keys($response);
$count = 1;
$i = 1;
foreach($array_keys as $element)
{
if (!strncmp('item_number', $element, strlen('item_number')))
$count++;
}
for($idx = 1; $idx < $count; $idx ++ & $i++)
{
$item_number = $response[item_number . $i];
$item_name = $response[item_name . $i];
$qty = $response[quantity . $i];
echo ("<div class='abouttext'>Produkt: ".$item_name."</div>\n");
echo ("<div class='abouttext'>ID: ".$item_number."</div>\n");
echo ("<div class='abouttext'>Antal: ".$qty."</div>\n");
echo ("<br />");
}
I have rewritten and cleaned up some of your code. This is untested, but hopefully it will get you going in the right direction.
$product_ids = array(1,3,5,7,9,11,13,15,17,18,19,20,21,22,24,26,27,28,29,30,31,33,41,43,45,47,49,51,54,55,57,58);
$msg = '';
$num_items = 0;
if ( array_key_exists('num_cart_items', $response) )
$num_items = intval($response['num_cart_items']);
if ( !empty($num_items) )
{
$string1 = 'item_name';
$string2 = 'item_number';
$firstname = $response['first_name'];
$lastname = $response['last_name'];
$total = $response['mc_gross'];
for ($i = 1; $i <= $num_items; $i++)
{
$item_number = $response['item_number'.$i];
$item_name = $response['item_name'.$i];
$qty = $response['quantity'.$i];
$id = $response['item_number'.$i];
// do something with these vars since they change every iteration through the loop and only exist within the scope of the loop.
if ( in_array($item_number, $product_ids) ) {
$msg = '<p><div id="bold">Produkter tillgängliga för nerladdning/lyssning</div></p><br>';
}
}
}
echo '
<div id="wrapper">
<div id="welcomeText">Tack för ditt köp!</div>
<div class="abouttext3">Har du köpt produkter som ska laddas ned, laddar du ned dem NU till din dator. <br> Du har endast möjlighet att ladda ned från just den här sidan.<br>
Stanna kvar på sidan tills du laddat ned ALLT du köpt. <br>OBS! Om du stänger ned sidan har du inte möjlighet att komma tillbaka till den.<br>
Har du köpt en lyssning av ”Guidning till förlåtelse” lyssnar du på den HÄR och NU. <br> Var kvar på sidan tills du lyssnat klart. <br> OBS!
Om du stänger ned sidan har du inte möjlighet att komma tillbaka till den. <br />
Har du köpt varor som levereras med Posten, skickas de så snart som möjligt från oss. <br> Allra senast inom en vecka.
</div>
<div class="abouttext2">Vi önskar Dig en bra dag. <br>
Välkommen tillbaka till energyshop.se när du vill!
</div>'
. $msg; // If item_number matches any product that is for download/listetning, then print this headline