Please add packingslip processing to the API
seansan opened this issue · 1 comments
seansan commented
- I've verified and I assure that I'm running the latest version of the TIG PostNL Magento extension.
- [ x] Feature request (request for a new functionality)
- [ x] Bug report (encountered problems with the TIG PostNL Magento extension)
Please add packingslip processing to the API (now it only supports the labels)
/**
* Get the shipping labels for the requested shipments.
*
* @param TIG_PostNL_Model_Core_Service_Shipment $serviceModel
* @param int $shipmentId
* @param bool $confirm
*
* @return array
*/
protected function _getPackingSlips(TIG_PostNL_Model_Core_Service_Shipment $serviceModel, $shipmentId, $confirm = false)
{
/** @var TIG_PostNL_Helper_Data $helper */
$helper = Mage::helper('postnl');
/**
* Get the PostNL shipment for this shipment ID.
*/
$postnlShipment = $serviceModel->getPostnlShipment($shipmentId);
/**
* If the PostNL shipment does not exist, return an error.
*/
if (!$postnlShipment || !is_object($postnlShipment) || !$postnlShipment->getId()) {
$response = array(
'order_id' => null,
'shipment_id' => $shipmentId,
'label' => null,
'warning' => null,
'error' => array(
array(
'entity_id' => $shipmentId,
'code' => 'POSTNL-0225',
'description' => $helper->__('No PostNL Shipment found for shipment ID #%s.', $shipmentId)
),
),
);
return $response;
}
/**
* Form the base response array.
*/
$response = array(
'order_id' => $postnlShipment->getOrderId(),
'shipment_id' => $postnlShipment->getShipmentId(),
'label' => null,
);
$errors = array();
try {
/**
* Check whether we should also get the return labels based on the shop's configuration.
*/
$printReturnLabels = $helper->canPrintReturnLabelsWithShippingLabels($postnlShipment);
/**
* Get the actual labels.
*/
$labels = $serviceModel->getLabels($postnlShipment, $confirm, $printReturnLabels, $postnlShipment->isBelgiumShipment());
/**
* Get the label model which will convert the base64_encoded pdf strings to a single, merged pdf.
*/
/** @var TIG_PostNL_Model_Core_Label $labelModel */
$packingSlipModel = Mage::getModel('postnl_core/packingSlip');
/**
* Create the merged pdf.
*/
$packingSlips = $packingSlipModel->createPdf($labels);
/**
* Base64_encode the merged pdf and add it to the response array.
*/
$response['packingslips'] = base64_encode($packingSlips);
} catch (TIG_PostNL_Exception $e) {
$helper->logException($e);
$code = $e->getCode();
if (empty($code)) {
$code = null;
}
$errors[] = array(
'entity_id' => $shipmentId,
'code' => $code,
'description' => $e->getMessage(),
);
} catch (Exception $e) {
$helper->logException($e);
$errors[] = array(
'entity_id' => $shipmentId,
'code' => null,
'description' => $e->getMessage(),
);
}
/**
* Add any warnings that may have occurred.
*/
if ($serviceModel->hasWarnings()) {
$response['warning'] = $serviceModel->getWarnings();
}
/**
* Add any errors that may have occurred.
*/
if (!empty($errors)) {
$response['error'] = $errors;
}
return $response;
}
tig-jaspersmits commented
This has been open for a while, but we won't be adding this to the extension since the conflicts haven't been solved yet in the pull request. Please take another look at: #42