PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Mon Oct 22, 2018 8:30 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Thu Sep 13, 2018 10:20 am 
Offline
Forum Commoner

Joined: Mon Sep 27, 2004 10:56 am
Posts: 72
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:
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 . " #&nbsp;" . implode(',', $trackingInfoInEmail);
    } else  {
        echo  "The tracking number for this shipment is " . $displayShippingMethod . " #&nbsp;" . implode(',', $trackingInfoInEmail);
    }
}
```



Top
 Profile  
 
PostPosted: Thu Sep 13, 2018 3:48 pm 
Offline
Forum Commoner

Joined: Mon Sep 27, 2004 10:56 am
Posts: 72
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:
    $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 . " #&nbsp;" . implode(',', $trackingInfoInEmail);
        } else  {
            echo  "The tracking number for this shipment is " . $displayShippingMethod . " #&nbsp;" . implode(',', $trackingInfoInEmail);
        }
    }


Top
 Profile  
 
PostPosted: Fri Sep 14, 2018 9:25 am 
Offline
Forum Commoner

Joined: Mon Sep 27, 2004 10:56 am
Posts: 72
Still Struggling, still getting duplicate tracking #s n my email:

I need help:

Code:
    $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 . " #&nbsp;" . implode(',', $trackingInfoInEmail);
             }
        } else {
              echo  "The tracking number for this shipment is " . $displayShippingMethod . " #&nbsp;" . implode(',', $trackingInfoInEmail);
        }
       
    }



Top
 Profile  
 
PostPosted: Sun Sep 16, 2018 9:36 pm 
Offline
Site Administrator
User avatar

Joined: Wed Aug 25, 2004 7:54 pm
Posts: 13581
Location: New York, NY, US
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:
    $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)


Top
 Profile  
 
PostPosted: Tue Sep 25, 2018 4:06 pm 
Offline
Forum Commoner

Joined: Mon Sep 27, 2004 10:56 am
Posts: 72
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:

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 . " #&nbsp;" . next($trackingInfoInEmail);
        next($trackingInfoInEmail);
        echo  "You may receive multiple shipments and E-mails. The tracking N-umber for this shipment is " . $displayShippingMethod . " #&nbsp;" . current($trackingInfoInEmail);
        (($trackingInfoInEmail+1));
    } else if(count($items) == 1) {
        if (count($trackingNumbers) == 1) {
            echo "The tracking number for this shipment is " . $displayShippingMethod . " #&nbsp;" . 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 . " #&nbsp;" . 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;
    }
}



Top
 Profile  
 
PostPosted: Fri Sep 28, 2018 5:27 pm 
Offline
Site Administrator
User avatar

Joined: Wed Aug 25, 2004 7:54 pm
Posts: 13581
Location: New York, NY, US
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?
Syntax: [ Download ] [ Hide ]
(($trackingInfoInEmail+1));

_________________
(#10850)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: Majestic-12 [Bot] and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group