PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
danjapro
Forum Commoner
Posts: 72 Joined: Mon Sep 27, 2004 10:56 am
Post
by danjapro » Thu Sep 13, 2018 10:20 am
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:
Code: Select all
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);
}
}
```
danjapro
Forum Commoner
Posts: 72 Joined: Mon Sep 27, 2004 10:56 am
Post
by danjapro » Thu Sep 13, 2018 3:48 pm
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.
Code: Select all
$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);
}
}
danjapro
Forum Commoner
Posts: 72 Joined: Mon Sep 27, 2004 10:56 am
Post
by danjapro » Fri Sep 14, 2018 9:25 am
Still Struggling, still getting duplicate tracking #s n my email:
I need help:
Code: Select all
$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);
}
}
Christopher
Site Administrator
Posts: 13596 Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US
Post
by Christopher » Sun Sep 16, 2018 9:36 pm
In your first loop, you use $trackNo in every loop? Is this first case when there is only one trackNo? Or do you want to get the trackNo from each element in $trackNos?
Code: Select all
$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);
}
}
(#10850)
danjapro
Forum Commoner
Posts: 72 Joined: Mon Sep 27, 2004 10:56 am
Post
by danjapro » Tue Sep 25, 2018 4:06 pm
I re-wrote this to just append to the next record, when the emails keep coming thru. I need someone to look at this and tell me if this makes.
Code: Select all
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);
echo "You may receive multiple shipments and E-mails. The tracking N-umber for this shipment is " . $displayShippingMethod . " # " . current($trackingInfoInEmail);
(($trackingInfoInEmail+1));
} 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;
}
}
Christopher
Site Administrator
Posts: 13596 Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US
Post
by Christopher » Fri Sep 28, 2018 5:27 pm
I don't know the exact logic, but that looks confusing. You only have three unique responses.
And how do you deal with more than two tracking numbers?
And what is this line supposed to do?
(#10850)