DivideBV / Postnl

Library to connect to PostNL's SOAP service called CIF
GNU General Public License v2.0
31 stars 40 forks source link

how get labels multi collo shipment #44

Closed matthijs-neijenhuijs closed 7 years ago

matthijs-neijenhuijs commented 7 years ago

How can i get the labels. This is working:

https://github.com/DivideBV/Postnl/wiki/Multi-collo-shipment

But what do need to do to get the labels? You cannot get it from GenerateLabelResponse.

I can get the labels deeper: $result->getResponseShipments()->getResponseShipment() but i want to have a MergedLabel.

slokhorst commented 7 years ago

Get a mergedLabel like so (note that you need to specify 'GraphicFile|PDF|Merge' in the generateLabels call):

$result = $client->generateLabels(new ComplexTypes\ArrayOfShipment([$shipment1,$shipment2]), 'GraphicFile|PDF|Merge');

$i = 0;
foreach($result->getMergedLabels() as $mergedLabel){
    foreach($mergedLabel->getLabels() as $label) {
        $filename = "label_$i.pdf";
        $file = new \SplFileObject($filename, 'w');
        $file->fwrite($label->getContent());
        $file = null; //close file
        $i++;
    }
}

It should only return one label file, but I've put it in a loop to be sure.

matthijs-neijenhuijs commented 7 years ago

Thnx! didn't now there was a second parameter :-) Stupid