@Patrick Stahl schrieb:
Moin @Ralf2011,
wie sieht denn die betroffene Stelle aus? Gerne den gesamten Methoden-Rumpf dazu.
Dann kann man dir da einfacher helfen!
So ist das ein bisschen ins Blaue raten.
Gruß,
Patrick
Hallo hier der ganze Code:
$this->getVersion(),
'autor' => 'Ralf',
'copyright' => '© 2017 ',
'label' => $this->getLabel(),
'source' => '',
'description' => 'Erweitert beim Downlaod von Rechnung den Namen',
'license' => '',
'support' => '',
'link' => ''
);
}
public function install()
{
$this->subscribeEvent('Shopware_Controllers_Backend_Order::openPdfAction::replace', 'openPdfActionWithFilenamePrefix');
return true;
}
public function openPdfActionWithFilenamePrefix(Enlight_Event_EventArgs $args) {
$controller = $args->getSubject();
$request = $controller->Request();
$name = basename($request->getParam('id', null)) . '.pdf';
$file = Shopware()->DocPath('files/documents') . $name;
if (!file_exists($file)) {
$this->View()->assign(array(
'success' => false,
'data' => $request->getParams(),
'message' => 'File not exist'
));
return;
}
// Disable Smarty rendering
$controller->Front()->Plugins()->ViewRenderer()->setNoRender();
$controller->Front()->Plugins()->Json()->setRenderer(false);
$orderModel = Shopware()->Models()->getRepository('Shopware\Models\Order\Document\Document')->findBy(array("hash" => $request->getParam('id')));
$orderModel = Shopware()->Models()->toArray($orderModel);
$orderId = $orderModel[0]["documentId"];
$typeId = $orderModel[0]["typeId"];
//DB
$order = Shopware()->Db()->fetchAll('SELECT ordernumber FROM s_order WHERE id = ?', [$orderModel[0]["orderId"]]);
$id = Shopware()->Db()->fetchAll('SELECT id,firstname,lastname FROM s_order_billingaddress WHERE OrderID = ?', [$orderModel[0]["orderId"]]);
$search = array("ä", "Ä", "ü", "Ü", "ö", "Ö", "ß");
$replace = array("ae", "Ae", "ue", "Ue", "oe", "Oe", "ss");
$name = str_replace($search, $replace, strtolower($id[0]['lastname']));
$type = array(1 => '', 2 => 'ls_', 3 => 'gs_', 4 => 'sr_');
$response = $controller->Response();
$response->setHeader('Cache-Control', 'public');
$response->setHeader('Content-Description', 'File Transfer');
$response->setHeader('Content-disposition', 'attachment; filename=' .$type[$typeId].$order[0]['ordernumber'].'_'.$name.".pdf");
$response->setHeader('Content-Type', 'application/pdf');
$response->setHeader('Content-Transfer-Encoding', 'binary');
$response->setHeader('Content-Length', filesize($file));
$response->sendHeaders();
echo readfile($file);
exit;
}
}