Esempio n. 1
0
 function getInvoicePDF($orderDetails = 0, $viewName = 'invoice', $layout = 'invoice', $format = 'html', $force = false)
 {
     // 		$force = true;
     $path = tsmConfig::get('forSale_path', 0);
     if (empty($path)) {
         vmError('No path set to store invoices');
         return false;
     } else {
         $path .= shopFunctionsF::getInvoiceFolderName() . DS;
         if (!file_exists($path)) {
             vmError('Path wrong to store invoices, folder invoices does not exist ' . $path);
             return false;
         } else {
             if (!is_writable($path)) {
                 vmError('Cannot store pdf, directory not writeable ' . $path);
                 return false;
             }
         }
     }
     $orderModel = tmsModel::getModel('orders');
     $invoiceNumberDate = array();
     if (!$orderModel->createInvoiceNumber($orderDetails['details']['BT'], $invoiceNumberDate)) {
         return false;
     }
     if (!empty($invoiceNumberDate[0])) {
         $invoiceNumber = $invoiceNumberDate[0];
     } else {
         $invoiceNumber = FALSE;
     }
     if (!$invoiceNumber or empty($invoiceNumber)) {
         vmError('Cant create pdf, createInvoiceNumber failed');
         return 0;
     }
     if (shopFunctionsF::InvoiceNumberReserved($invoiceNumber)) {
         return 0;
     }
     //$path .= preg_replace('/[^A-Za-z0-9_\-\.]/', '_', 'vm'.$layout.'_'.$invoiceNumber.'.pdf');
     $path .= shopFunctionsF::getInvoiceName($invoiceNumber, $layout) . '.pdf';
     if (file_exists($path) and !$force) {
         return $path;
     }
     //We come from the be, so we need to load the FE language
     tsmConfig::loadJLang('com_virtuemart', true);
     $this->addViewPath(VMPATH_SITE . DS . 'views');
     $view = $this->getView($viewName, $format);
     $this->writeJs = false;
     $view->addTemplatePath(VMPATH_SITE . DS . 'views' . DS . $viewName . DS . 'tmpl');
     if (!class_exists('VmTemplate')) {
         require VMPATH_SITE . DS . 'helpers' . DS . 'vmtemplate.php';
     }
     $template = VmTemplate::loadVmTemplateStyle();
     $templateName = VmTemplate::setTemplate($template);
     if (!empty($templateName)) {
         $TemplateOverrideFolder = JPATH_SITE . DS . "templates" . DS . $templateName . DS . "html" . DS . "com_virtuemart" . DS . "invoice";
         if (file_exists($TemplateOverrideFolder)) {
             $view->addTemplatePath($TemplateOverrideFolder);
         }
     }
     $view->invoiceNumber = $invoiceNumberDate[0];
     $view->invoiceDate = $invoiceNumberDate[1];
     $view->orderDetails = $orderDetails;
     $view->uselayout = $layout;
     $view->showHeaderFooter = false;
     $vendorModel = tmsModel::getModel('vendor');
     $virtuemart_vendor_id = 1;
     //We could set this automatically by the vendorId stored in the order.
     $vendor = $vendorModel->getVendor($virtuemart_vendor_id);
     $metadata = array('title' => tsmText::sprintf('COM_VIRTUEMART_INVOICE_TITLE', $vendor->vendor_store_name, $view->invoiceNumber, $orderDetails['details']['BT']->order_number), 'keywords' => tsmText::_('COM_VIRTUEMART_INVOICE_CREATOR'));
     return VmPdf::createVmPdf($view, $path, 'F', $metadata);
 }
Esempio n. 2
0
 public static function renderMail($viewName, $recipient, $vars = array(), $controllerName = NULL, $noVendorMail = FALSE, $useDefault = true)
 {
     if (!class_exists('VirtueMartControllerVirtuemart')) {
         require VMPATH_SITE . DS . 'controllers' . DS . 'virtuemart.php';
     }
     $controller = new VirtueMartControllerVirtuemart();
     // refering to http://forum.virtuemart.net/index.php?topic=96318.msg317277#msg317277
     $controller->addViewPath(VMPATH_SITE . DS . 'views');
     $view = $controller->getView($viewName, 'html');
     if (!$controllerName) {
         $controllerName = $viewName;
     }
     $controllerClassName = 'VirtueMartController' . ucfirst($controllerName);
     if (!class_exists($controllerClassName)) {
         require VMPATH_SITE . DS . 'controllers' . DS . $controllerName . '.php';
     }
     //refering to http://forum.virtuemart.net/index.php?topic=96318.msg317277#msg317277
     $view->addTemplatePath(VMPATH_SITE . '/views/' . $viewName . '/tmpl');
     if (!class_exists('VmTemplate')) {
         require VMPATH_SITE . DS . 'helpers' . DS . 'vmtemplate.php';
     }
     $template = VmTemplate::loadVmTemplateStyle();
     VmTemplate::setTemplate($template);
     if ($template) {
         if (is_array($template) and isset($template['template'])) {
             $view->addTemplatePath(VMPATH_ROOT . DS . 'templates' . DS . $template['template'] . DS . 'html' . DS . 'com_virtuemart' . DS . $viewName);
         } else {
             $view->addTemplatePath(VMPATH_ROOT . DS . 'templates' . DS . $template . DS . 'html' . DS . 'com_virtuemart' . DS . $viewName);
         }
     }
     foreach ($vars as $key => $val) {
         $view->{$key} = $val;
     }
     $user = FALSE;
     if (isset($vars['orderDetails'])) {
         //If the vRequest is there, the update is done by the order list view BE and so the checkbox does override the defaults.
         //$name = 'orders['.$order['details']['BT']->virtuemart_order_id.'][customer_notified]';
         //$customer_notified = vRequest::getVar($name,-1);
         if (!$useDefault and isset($vars['newOrderData']['customer_notified']) and $vars['newOrderData']['customer_notified'] == 1) {
             $user = self::sendVmMail($view, $recipient, $noVendorMail);
             vmdebug('renderMail by overwrite');
         } else {
             $orderstatusForShopperEmail = VmConfig::get('email_os_s', array('U', 'C', 'S', 'R', 'X'));
             if (!is_array($orderstatusForShopperEmail)) {
                 $orderstatusForShopperEmail = array($orderstatusForShopperEmail);
             }
             if (in_array((string) $vars['orderDetails']['details']['BT']->order_status, $orderstatusForShopperEmail)) {
                 $user = self::sendVmMail($view, $recipient, $noVendorMail);
                 vmdebug('renderMail by default');
             } else {
                 $user = -1;
             }
         }
     } else {
         $user = self::sendVmMail($view, $recipient, $noVendorMail);
     }
     if (isset($view->doVendor) && !$noVendorMail) {
         if (isset($vars['orderDetails'])) {
             $order = $vars['orderDetails'];
             $orderstatusForVendorEmail = VmConfig::get('email_os_v', array('U', 'C', 'R', 'X'));
             if (!is_array($orderstatusForVendorEmail)) {
                 $orderstatusForVendorEmail = array($orderstatusForVendorEmail);
             }
             if (in_array((string) $order['details']['BT']->order_status, $orderstatusForVendorEmail)) {
                 self::sendVmMail($view, $view->vendorEmail, TRUE);
             } else {
                 $user = -1;
             }
         } else {
             self::sendVmMail($view, $view->vendorEmail, TRUE);
         }
     }
     return $user;
 }