DivideBV / Postnl

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

Getting all labels from an multi colli #59

Closed qualityplatforms closed 6 years ago

qualityplatforms commented 7 years ago

Hello there,

I'm using multi-colli labeling from the wiki, but the labels won't been displayed. Only the last label will. I don't know what i'm doing wrong. Here's my code:

`$receiverAddress = ComplexTypes\Address::create() ->setAddressType('01') ->setFirstName($item['first_name']) ->setName($item['name']) ->setCompanyName($item['company']) ->setStreet($item['street']) ->setHouseNr($item['housenr']) ->setHouseNrExt($item['housenr_extra']) ->setZipcode($item['zip']) ->setCity($item['city']) ->setCountrycode($item['country']);

//Set our address $senderAddress = ComplexTypes\Address::create() ->setAddressType('02') ->setFirstName(' ') ->setName(' ') ->setCompanyName('B.V.') ->setStreet('weg') ->setHouseNr('2') ->setHouseNrExt('') ->setZipcode('1111AB') ->setCity('Plaats') ->setCountrycode('NL');

// Create a shipment. $shipment = ComplexTypes\Shipment::create() ->setAddresses(new ComplexTypes\ArrayOfAddress([ $receiverAddress, $senderAddress, ])) ->setBarcode($item['code']) ->setDimension(ComplexTypes\Dimension::create() ->setWeight($item['package_weight'].'00') // Weight in g ->setWidth($item['package_width'].'00') // Width in mm ->setLength($item['package_length'].'00') // Length in mm ->setHeight($item['package_height'].'00') // Height in mm ) ->setProductCodeDelivery('3085');

$results = $client->generateLabelsWithoutConfirm(new ComplexTypes\ArrayOfShipment([$shipment1,$shipment2,$shipment3]));

if(isset($results)) { foreach($results->getResponseShipments() as $result) { // Save the label PDF locally $label = $result->getLabels()[0]; $file = new \SplFileObject("$barcode.pdf", 'w'); file_put_contents("files/label.$barcode.pdf", $label->getContent()); }
}`

There is an foreach from the MySQL database and the code is a bit stripped.

Can any of you have a look on this?

Thanks in advance. Best regards.

danslo commented 7 years ago

You're missing a Group at the very least. See the wiki page for Multi collo shipments.

slokhorst commented 7 years ago

Also you should loop over $result->getLabels(), and save them with different names (now you're just overwriting them)

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