Skip to content

Commit

Permalink
fix order email invoice attachment
Browse files Browse the repository at this point in the history
  • Loading branch information
dpfaffenbauer committed Dec 2, 2016
1 parent f510260 commit 7025a61
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
14 changes: 10 additions & 4 deletions lib/CoreShop/Mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,18 @@ public static function sendOrderMail($emailDocument, Order $order, Order\State $
$invoices = $order->getInvoices();

foreach($invoices as $invoice) {
if ($invoice instanceof Asset\Document) {
$attachment = new \Zend_Mime_Part($invoice->getData());
$attachment->type = $invoice->getMimetype();
if ($invoice instanceof Order\Invoice) {
$asset = $invoice->getAsset();

if(!$asset instanceof Asset) {
$asset = $invoice->generate();
}

$attachment = new \Zend_Mime_Part($asset->getData());
$attachment->type = $asset->getMimetype();
$attachment->disposition = \Zend_Mime::DISPOSITION_ATTACHMENT;
$attachment->encoding = \Zend_Mime::ENCODING_BASE64;
$attachment->filename = $invoice->getFilename();
$attachment->filename = $asset->getFilename();

$mail->addAttachment($attachment);
}
Expand Down
11 changes: 11 additions & 0 deletions lib/CoreShop/Model/Order/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use CoreShop\Model\User;
use CoreShop\Tool\Wkhtmltopdf;
use Pimcore\Logger;
use Pimcore\Model\Asset;
use Pimcore\Model\Asset\Document;
use Pimcore\Model\Asset\Service;
use Pimcore\Model\Object;
Expand Down Expand Up @@ -318,6 +319,16 @@ public function calculatePrices() {
$this->save();
}

/**
* @return Asset
*/
public function getAsset() {
$path = $this->getOrder()->getPathForInvoices();
$fileName = 'invoice-'.$this->getInvoiceNumber().'.pdf';

return Asset::getByPath($path . "/" . $fileName);
}

/**
* Renders the Invoice to a PDF
*
Expand Down
2 changes: 1 addition & 1 deletion lib/CoreShop/Model/Order/State.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public function processStep(Order $order)
$emailDocument = $this->getEmailDocument();
$emailDocument = Document::getByPath($emailDocument);

Mail::sendOrderMail($emailDocument, $order, $order->getOrderState());
Mail::sendOrderMail($emailDocument, $order, $this);
}

$order->setOrderState($this);
Expand Down

0 comments on commit 7025a61

Please sign in to comment.