You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using code sample from docs to create consignment and return consignments.
When there are more than 1 consigmnet in $yourShipments this code creates extra return consignments because generateReturnConsignments() method is called in loop and on second iteration it will handle regular consignments and 1 return consignment created on 1st iteration and so on.
Most probably generateReturnConsignments() should be called once after the loop.
// Create the collection before the loop$consignments = newMyParcelCollection();
// Loop through your shipments, adding each to the same MyParcelCollectionforeach ($yourShipmentsas$yourShipment) {
$consignment = ((ConsignmentFactory::createByCarrierId(PostNLConsignment::CARRIER_ID))
->setApiKey('api_key_from_backoffice')
->setCountry($yourShipment['cc'])
->setPerson($yourShipment['person'])
->setCompany($yourShipment['company'])
->setFullStreet($yourShipment['full_street_input'])
->setPostalCode($yourShipment['postal_code'])
->setCity($yourShipment['city'])
->setLabelDescription($yourShipment['label_description'])
);
// Add the consignment to the collection$consignments
->addConsignment($consignment);
}
// Generate the return consignment// When there are no options set, the options from the parent consignment are used$consignments
->generateReturnConsignments(
false,
function (
AbstractConsignment$returnConsignment,
AbstractConsignment$parent
): AbstractConsignment {
$returnConsignment->setLabelDescription(
'Return: ' . $parent->getLabelDescription() .
' This label is valid until: ' . date("d-m-Y", strtotime("+ 28 days"))
);
$returnConsignment->setSignature(true);
return$returnConsignment;
}
);
The text was updated successfully, but these errors were encountered:
I'm using code sample from docs to create consignment and return consignments.
When there are more than 1 consigmnet in
$yourShipments
this code creates extra return consignments becausegenerateReturnConsignments()
method is called in loop and on second iteration it will handle regular consignments and 1 return consignment created on 1st iteration and so on.Most probably
generateReturnConsignments()
should be called once after the loop.The text was updated successfully, but these errors were encountered: