/** * @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; }
/** * Gets the product code parameters for this shipment. * * @param TIG_MyParcel2014_Model_Shipment $myParcelShipment * * @return array */ protected function _getOptionsData(TIG_MyParcel2014_Model_Shipment $myParcelShipment) { /** * Add the shipment type parameter. */ switch ($myParcelShipment->getShipmentType()) { case $myParcelShipment::TYPE_LETTER_BOX: $packageType = 2; break; case $myParcelShipment::TYPE_UNPAID: $packageType = 3; break; case $myParcelShipment::TYPE_NORMAL: default: $packageType = 1; } $data = array('package_type' => $packageType, 'large_format' => (int) $myParcelShipment->isXL(), 'only_recipient' => (int) $myParcelShipment->isHomeAddressOnly(), 'signature' => (int) $myParcelShipment->isSignatureOnReceipt(), 'return' => (int) $myParcelShipment->getReturnIfNoAnswer(), 'label_description' => $myParcelShipment->getOrder()->getIncrementId()); $checkoutData = json_decode($myParcelShipment->getOrder()->getMyparcelData(), true); if ($checkoutData !== null) { if ($checkoutData['time'][0]['price_comment'] !== null) { switch ($checkoutData['time'][0]['price_comment']) { case 'morning': $data['delivery_type'] = self::TYPE_MORNING; break; case 'standard': $data['delivery_type'] = self::TYPE_STANDARD; break; case 'night': $data['delivery_type'] = self::TYPE_NIGHT; break; } if ($checkoutData['date'] !== null) { $checkoutDateTime = $checkoutData['date'] . ' 00:00:00'; if (date_parse($checkoutDateTime) >= new dateTime()) { $data['delivery_date'] = $checkoutDateTime; } $dateTime = date_parse($checkoutData['date']); $data['label_description'] = $data['label_description'] . ' (' . $dateTime['day'] . '-' . $dateTime['month'] . ')'; } } elseif ($checkoutData['price_comment'] !== null) { switch ($checkoutData['price_comment']) { case 'retail': $data['delivery_type'] = self::TYPE_RETAIL; break; case 'retailexpress': $data['delivery_type'] = self::TYPE_RETAIL_EXPRESS; break; } } } if ((int) $myParcelShipment->getInsured() === 1) { $data['insurance']['amount'] = $this->_getInsuredAmount($myParcelShipment) * 100; $data['insurance']['currency'] = 'EUR'; } if ($myParcelShipment->getShippingAddress()->getCountry() != 'NL') { // strip all Dutch domestic options if shipment is not NL unset($data['only_recipient']); unset($data['signature']); unset($data['return']); unset($data['delivery_type']); unset($data['delivery_date']); } return $data; }