danjapro Posted September 13, 2018 Share Posted September 13, 2018 All I am Trying to do is Loop thru my Array fo results and out each one seperate if there is more than 1 data point: Trying to display each of tracking # as separate line: getIsOrderShipped($_order->getId()); // Is oorder shipped or not ``` $items = $_order->getAllVisibleItems(); $trackingNumbers = []; $trackNo = $adminHelper->getOrderTrackingNo($_order->getId()); $trackNos = explode(",", $trackNo); if (count($trackNos)) { for ($i=0; $i< count($trackNos); $i++) { $trackingURL = $adminHelper->getTrackingUrl(strtolower($_order->getShippingDescription()), $trackNo); $trackingNumbers[] = array("track_no" => $trackNo, "url" => $trackingURL); } } $trackingInfoInEmail = []; $i = 0; if (count($trackingNumbers) > 1) { foreach($trackingNumbers as $trackingNumber) { $i++; $trackingInfoInEmail[] = "<a href='" . $trackingNumber[$i]['url'] . "' target='_blank'>" . $trackingNumber[$i]['track_no'] . "</a>"; return false; } }else{ $trackingInfoInEmail[] = "<a href='" . $trackingNumbers[]['url'] . "' target='_blank'>" . $trackingNumbers[]['track_no'] . "</a>"; } $displayShippingMethod = $adminHelper->getTrackingTextInEmail($_order->getShippingDescription()); //Shipping Method Name if (!$isOrderShipped) { return false; } else { if (count($items) > 0) { echo "You may receive multiple shipments and emails. The tracking number for this shipment is " . $displayShippingMethod . " # " . implode(',', $trackingInfoInEmail); } else { echo "The tracking number for this shipment is " . $displayShippingMethod . " # " . implode(',', $trackingInfoInEmail); } } ``` Quote Link to comment Share on other sites More sharing options...
Barand Posted September 13, 2018 Share Posted September 13, 2018 As you "return false" a couple of times, I assume this code is within a function. Are you aware that all processing within the function will cease on encountering a "return" statement? Where is $isOrderShipped defined? Quote Link to comment Share on other sites More sharing options...
danjapro Posted September 13, 2018 Author Share Posted September 13, 2018 IT worked before. This is the Code base that is causing issues: $trackingInfoInEmail = [];$i = 0;if (count($trackingNumbers) > 1) { foreach($trackingNumbers as $trackingNumber) { $i++; $trackingInfoInEmail = "<a href='" . $trackingNumber[$i]['url'] . "' target='_blank'>" . $trackingNumber[$i]['track_no'] . "</a>"; } }else{ $trackingInfoInEmail = "<a href='" . $trackingNumber[$i]['url'] . "' target='_blank'>" . $trackingNumber[$i]['track_no'] . "</a>"; } Quote Link to comment Share on other sites More sharing options...
Barand Posted September 13, 2018 Share Posted September 13, 2018 It worked before what? What issues is it causing? What is or isn't happening? You need to give us some information to go on. We are not looking over your shoulder watching what is happening, you need to tell us. Quote Link to comment Share on other sites More sharing options...
danjapro Posted September 13, 2018 Author Share Posted September 13, 2018 I changed this, it works to a degree. Now it is returning duplicated tracking numbers and each tracking number. I need help, just get each one tracking number seperate. $isOrderShipped = $adminHelper->getIsOrderShipped($_order->getId()); // Is oorder shipped or not $items = $_order->getAllVisibleItems(); $trackingNumbers = []; $trackNo = $adminHelper->getOrderTrackingNo($_order->getId()); $trackNos = explode(",", $trackNo); if (count($trackNos)) { for ($i=0; $i< count($trackNos); $i++) { $trackingURL = $adminHelper->getTrackingUrl(strtolower($_order->getShippingDescription()), $trackNo); $trackingNumbers[] = array("track_no" => $trackNo, "url" => $trackingURL); } } $trackingInfoInEmail = []; if (count($trackingNumbers) > ) { for ($i=0; $i < count($trackingNumbers); $i++) { $trackingInfoInEmail[] = "<a href='" . $trackingNumbers[$i]['url'] . "' target='_blank'>" . $trackingNumbers[$i]['track_no'] . "</a>"; } } $displayShippingMethod = $adminHelper->getTrackingTextInEmail($_order->getShippingDescription()); //Shipping Method Name if (!$isOrderShipped) { return false; } else { if (count($items) > 1) { echo "You may receive multiple shipments and emails. The tracking number for this shipment is " . $displayShippingMethod . " # " . implode(',', $trackingInfoInEmail); } else { echo "The tracking number for this shipment is " . $displayShippingMethod . " # " . implode(',', $trackingInfoInEmail); } } Quote Link to comment Share on other sites More sharing options...
Barand Posted September 13, 2018 Share Posted September 13, 2018 8 minutes ago, danjapro said: if (count($trackingNumbers) > ) { That line won't work. Do you have error reporting turned on? 17 minutes ago, danjapro said: Now it is returning duplicated tracking numbers and each tracking number. As I have no idea what your input data looks like, that doesn't mean much to me. Quote Link to comment Share on other sites More sharing options...
danjapro Posted September 14, 2018 Author Share Posted September 14, 2018 I am having a hard time with this piece of code. Can you help me please. It still return, duplicate. Tracking No#s. $isOrderShipped = $adminHelper->getIsOrderShipped($_order->getId()); // Is oorder shipped or not$items = $_order->getAllVisibleItems();$trackingNumbers = [];$trackNo = $adminHelper->getOrderTrackingNo($_order->getId());$trackNos = explode(",", $trackNo);if (count($trackNos)) { for ($i=0; $i< count($trackNos); $i++) { $trackingURL = $adminHelper->getTrackingUrl(strtolower($_order->getShippingDescription()), $trackNo); $trackingNumbers[] = array("track_no" => $trackNo, "url" => $trackingURL); }}$trackingInfoInEmail = [];if (count($trackingNumbers) > 0) { for ($i=0; $i < count($trackingNumbers); $i++) { $trackingInfoInEmail[] = "<a href='" . $trackingNumbers[$i]['url'] . "' target='_blank'>" . $trackingNumbers[$i]['track_no'] . "</a>"; }}$displayShippingMethod = $adminHelper->getTrackingTextInEmail($_order->getShippingDescription()); //Shipping Method Nameif (!$isOrderShipped) { return false;} else { if (count($items) > 1) { echo "You may receive multiple shipments and emails. The tracking number for this shipment is " . $displayShippingMethod . " # " . implode(',', $trackingInfoInEmail); } else { echo "The tracking number for this shipment is " . $displayShippingMethod . " # " . implode(',', $trackingInfoInEmail); }} Quote Link to comment Share on other sites More sharing options...
ginerjm Posted September 14, 2018 Share Posted September 14, 2018 Most of this last line seems to be a comment.... Quote Link to comment Share on other sites More sharing options...
danjapro Posted September 14, 2018 Author Share Posted September 14, 2018 Struggling with this piece of code: Still getting duplicate Tracking #s: $isOrderShipped = $adminHelper->getIsOrderShipped($_order->getId()); // Is oorder shipped or not $items = $_order->getAllVisibleItems(); $trackingNumbers = []; $trackNo = $adminHelper->getOrderTrackingNo($_order->getId()); $trackNos = $adminHelper->getOrderTrackingNo($_order->getTrackingNumber()); //$trackNos = explode(",", $trackNo); if (count($trackNos)) { for ($i=0; $i< count($trackNos); $i++) { $trackingURL = $adminHelper->getTrackingUrl(strtolower($_order->getShippingDescription()), $trackNo); $trackingNumbers[] = array("track_no" => $trackNo, "url" => $trackingURL); } } $trackingInfoInEmail = []; if (count($trackingNumbers) > 0) { //for ($i=0; $i < count($trackingNumbers); $i++) { $trackingInfoInEmail[] = "<a href='" . $trackingNumbers[$i]['url'] . "' target='_blank'>" . $trackingNumbers[$i]['track_no'] . "</a>"; //} } $displayShippingMethod = $adminHelper->getTrackingTextInEmail($_order->getShippingDescription()); //Shipping Method Name if (!$isOrderShipped) { return false; } else { $i = 0; if (count($items) > 1) { echo "You may receive multiple shipments and emails."; foreach($items as $item) { $i++; echo "The tracking number for this shipment is " . $displayShippingMethod . " # " . implode(',', $trackingInfoInEmail); } } else { echo "The tracking number for this shipment is " . $displayShippingMethod . " # " . implode(',', $trackingInfoInEmail); } } Quote Link to comment Share on other sites More sharing options...
Barand Posted September 14, 2018 Share Posted September 14, 2018 What value are you expecting fot $i in this code (now the for loop is removed)? if (count($trackingNumbers) > 0) { //for ($i=0; $i < count($trackingNumbers); $i++) { $trackingInfoInEmail[] = "<a href='" . $trackingNumbers[$i]['url'] . "' target='_blank'>" . $trackingNumbers[$i]['track_no'] . "</a>"; //} } Quote Link to comment Share on other sites More sharing options...
danjapro Posted September 14, 2018 Author Share Posted September 14, 2018 $i was to loop thru ea trackin# to count each one. But I just need it to get each 1 tracking per ea email sent. not all tracking at same time in same email. thru an array,. dont need it that way Quote Link to comment Share on other sites More sharing options...
Barand Posted September 14, 2018 Share Posted September 14, 2018 I know what $i was doing before you removed the loop. The point is there is no loop now , therefore $i does not have a valid value - yet you are still using it. Quote Link to comment Share on other sites More sharing options...
danjapro Posted September 25, 2018 Author Share Posted September 25, 2018 I was able to Get back the Array, but when the Second email kicks-off, still returning the same tracking number from the array and not going to the next(). Can someone tell me if there is a way to if check current(), then go to next() if (!$isOrderShipped) { return false;} else { if (count($items) > 1 && count($trackingNumbers) >= 1) { echo "You may receive multiple shipments and emails. The tracking number for this shipment is " . $displayShippingMethod . " # " . next($trackingInfoInEmail); next($trackingInfoInEmail); } else if(count($items) == 1) { if (count($trackingNumbers) == 1) { echo "The tracking number for this shipment is " . $displayShippingMethod . " # " . next($trackingInfoInEmail); next($trackingInfoInEmail); } else if (count($trackingNumbers) > 1){ echo "You may receive multiple shipments and emails. The tracking number for this shipment is " . $displayShippingMethod . " # " . next($trackingInfoInEmail); next($trackingInfoInEmail); } else if(count($trackingNumbers)==0){ echo "Your Order has been Shipped with" . $displayShippingMethod; } } else { echo "Your Order has been Shipped with" . $displayShippingMethod; }} Quote Link to comment Share on other sites More sharing options...
Barand Posted September 25, 2018 Share Posted September 25, 2018 (edited) $trackNo = $adminHelper->getOrderTrackingNo($_order->getId()); ... if (count($trackNos)) { for ($i=0; $i< count($trackNos); $i++) { $trackingURL = $adminHelper->getTrackingUrl(strtolower($_order->getShippingDescription()), $trackNo); $trackingNumbers[] = array("track_no" => $trackNo, "url" => $trackingURL); } } In the code above you have got a value for $trackNo. In the loop you are putting that same value into each element of the array. EDIT: Try doing a bit of debugging, like echo '<pre>', print_r($trackingNumbers, 1), '</pre>'; to see what is in your arrays Edited September 25, 2018 by Barand Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.