/** * @param string $barcode * @param TIG_MyParcel2014_Model_Shipment $myParcelShipment * * @return bool * @throws TIG_MyParcel2014_Exception */ public function sendBarcodeEmail($barcode = '', $myParcelShipment) { if (empty($barcode)) { return false; } if (!$myParcelShipment instanceof TIG_MyParcel2014_Model_Shipment) { return false; } $order = $myParcelShipment->getOrder(); $storeId = $order->getStoreId(); $templateId = $this->getConfig('tracktrace_template', 'general', $storeId); //if no template is set, return false: tracktrace should be send by MyParcel if ($templateId === null || $templateId == 'tig_myparcel_general_tracktrace_template') { return false; } try { // Retrieve specified view block from appropriate design package (depends on emulated store) $paymentBlock = Mage::helper('payment')->getInfoBlock($order->getPayment())->setIsSecureMode(true); $paymentBlock->getMethod()->setStore($storeId); $paymentBlockHtml = $paymentBlock->toHtml(); } catch (Exception $exception) { $paymentBlockHtml = ''; } $shippingAddress = $myParcelShipment->getShippingAddress(); $barcodeUrl = $this->getBarcodeUrl($barcode, $shippingAddress); // Set pakjegemak foreach ($order->getAddressesCollection() as $address) { if ($address->getAddressType() == 'pakje_gemak' && !$address->isDeleted()) { $myParcelShipment->setShippingAddress($address); $order->setShippingAddress($address); } } $templateVariables = array('tracktrace_url' => $barcodeUrl, 'order' => $order, 'shipment' => $myParcelShipment->getShipment(), 'billing' => $order->getBillingAddress(), 'payment_html' => $paymentBlockHtml); try { $mailer = Mage::getModel('core/email_template_mailer'); $emailInfo = Mage::getModel('core/email_info'); $emailInfo->addTo($order->getCustomerEmail(), $shippingAddress->getName()); $mailer->addEmailInfo($emailInfo); // Set all required params and send emails. $mailer->setSender(Mage::getStoreConfig(self::XML_PATH_EMAIL_IDENTITY, $storeId)); $mailer->setStoreId($storeId); $mailer->setTemplateId($templateId); $mailer->setTemplateParams($templateVariables); $mailer->send(); } catch (Exception $e) { $this->logException($e); return false; } return true; }