private function init() { if (Tools::isSubmit('printManifest')) { if ($shipment_ids = Tools::getValue('ShipmentsBox')) { $manifest = new DpdGroupManifest(); $manifest->shipments = $shipment_ids; if ($pdf_content = $manifest->printManifest()) { foreach ($shipment_ids as $id_shipment) { $shipment = new DpdGroupShipment(); $shipment->getAndSaveTrackingInfo((int) $id_shipment); } ob_end_clean(); header('Content-type: application/pdf'); header('Content-Disposition: attachment; filename="manifest_' . time() . '.pdf"'); echo $pdf_content; exit; } else { $this->module_instance->outputHTML($this->module_instance->displayError(reset(DpdGroupManifest::$errors))); } } else { $this->module_instance->outputHTML($this->module_instance->displayError($this->l('No selected shipments'))); } } if (Tools::isSubmit('printLabels')) { if ($shipment_ids = Tools::getValue('ShipmentsBox')) { $shipment = new DpdGroupShipment(); if ($pdf_content = $shipment->getLabelsPdf($shipment_ids)) { ob_end_clean(); header('Content-type: application/pdf'); header('Content-Disposition: attachment; filename="shipment_labels_' . time() . '.pdf"'); echo $pdf_content; } else { $this->module_instance->outputHTML($this->module_instance->displayError(reset(DpdGroupManifest::$errors))); } } else { $this->module_instance->outputHTML($this->module_instance->displayError($this->l('Select at least one shipment'))); } } if (Tools::isSubmit('changeOrderStatus')) { if ($shipment_ids = Tools::getValue('ShipmentsBox')) { foreach ($shipment_ids as $id_shipment) { $id_order = DpdGroupShipment::getOrderIdByShipmentId((int) $id_shipment); if (!self::changeOrderStatusToShipped($id_order)) { self::$errors[] = sprintf($this->l('Can not continue: shipment #%d order status could not be updated'), $id_shipment); break; } } if (self::$errors) { $this->module_instance->outputHTML($this->module_instance->displayError(reset(self::$errors))); } else { DpdGroup::addFlashMessage($this->l('Selected orders statuses were successfully updated')); Tools::redirectAdmin($this->module_instance->module_url . '&menu=shipment_list'); } } else { $this->module_instance->outputHTML($this->module_instance->displayError($this->l('Select at least one shipment'))); } } }
private function formatPieces() { if (!$this->id_shipment) { self::$errors[] = $this->l('Shipment ID is missing'); return false; } $pieces = array(); if (!is_array($this->id_shipment)) { $this->id_shipment = array($this->id_shipment); } foreach ($this->id_shipment as $id_shipment) { $id_order = (int) DpdGroupShipment::getOrderIdByShipmentId($id_shipment); $shipment = new DpdGroupShipment($id_order); if (!(int) $shipment->id_order) { self::$errors[] = sprintf($this->l('Order #%d does not exists'), (int) $shipment->id_order); return false; } if (!isset($pieces[$shipment->receiver_country_code])) { $pieces[$shipment->receiver_country_code] = array(); } $pieces[$shipment->receiver_country_code][] = array('serviceCode' => (int) $shipment->main_service_code, 'quantity' => count($shipment->parcels), 'weight' => (double) $shipment->getTotalParcelsWeight(), 'destinationCountryCode' => $shipment->receiver_country_code, 'id_shipment' => (int) $id_shipment); } return $pieces; }