Advertisement
Guest User

Untitled

a guest
Jan 2nd, 2018
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 18.96 KB | None | 0 0
  1. <?php
  2. class ControllerProductFastorder extends Controller {
  3.     // Set the developer version
  4.     private static $dev = false;
  5.  
  6.     public function index($data) {
  7.         // Debugging
  8.         if(self::$dev){
  9.             // Write message if developer version is enable.
  10.             echo '<div style="margin:0px; width:100%; text-align: right; padding:0 10px; font-weight:bold; color:#c53d36">This is developer version (FastOrder)!</div>';
  11.         }
  12.  
  13.         // If page not found - do not show button
  14.         if(empty($data['name'])){
  15.             return false;
  16.         }
  17.  
  18.         // If Display stock is enable and out of stock is disbale - do not show fastorder button
  19.         if ( $this->config->get('config_stock_display')
  20.                 and !$this->config->get('config_stock_checkout')
  21.                 and $this->model_catalog_product->getProduct($data['product_id'])['quantity'] < 1
  22.             ) {
  23.             return false;
  24.         }
  25.  
  26.         // Load lanuage
  27.         $this->load->language('product/fastorder');
  28.  
  29.         // Language data
  30.         $data['text_fastorder_button']                      = $this->language->get('text_fastorder_button');
  31.         $data['text_fastorder_form_header']                 = $this->language->get('text_fastorder_form_header');
  32.         $data['text_fastorder_form_info']                   = $this->language->get('text_fastorder_form_info');
  33.         $data['text_fastorder_name']                        = $this->language->get('text_fastorder_name');
  34.         $data['text_fastorder_phone']                       = $this->language->get('text_fastorder_phone');
  35.         $data['text_fastorder_mail']                        = $this->language->get('text_fastorder_mail');
  36.         $data['text_fastorder_comment']                     = $this->language->get('text_fastorder_comment');
  37.         $data['text_fastorder_button_submit']               = $this->language->get('text_fastorder_button_submit');
  38.         $data['text_fastorder_button_close']                = $this->language->get('text_fastorder_button_close');
  39.         $data['text_fastorder_success_message']             = $this->language->get('text_fastorder_success_message');
  40.         $data['text_fastorder_button_cancel']               = $this->language->get('text_fastorder_button_cancel');
  41.         $data['text_fastorder_input_name_placeholder']      = $this->language->get('text_fastorder_input_name_placeholder');
  42.         $data['text_fastorder_input_phone_placeholder']     = $this->language->get('text_fastorder_input_phone_placeholder');
  43.         $data['text_fastorder_input_mail_placeholder']      = $this->language->get('text_fastorder_input_mail_placeholder');
  44.         $data['text_fastorder_input_comment_placeholder']   = $this->language->get('text_fastorder_input_comment_placeholder');
  45.         $data['text_fastorder_success_title']               = $this->language->get('text_fastorder_success_title');
  46.         $data['text_fastorder_mail_msg_order']              = $this->language->get('text_fastorder_mail_msg_order');
  47.         $data['text_fastorder_mail_msg_price']              = $this->language->get('text_fastorder_mail_msg_price');
  48.         $data['txt_text_fastorder_form_info_message']       = $this->language->get('txt_text_fastorder_form_info_message');
  49.         $data['txt_none_price']                             = $this->language->get('txt_none_price');
  50.  
  51.         // If special price is set - display it
  52.         if(isset($data['special'])){
  53.           $data['price'] = $data['special'];
  54.         }else{
  55.  
  56.         }
  57.  
  58.         if(!isset($data['price'])){
  59.           $data['price'] = $data['txt_none_price'];
  60.         }
  61.  
  62.         if($this->config->get('config_template')) {
  63.             $template = $this->config->get('config_template');
  64.         }else{
  65.             $template = 'default';
  66.         }
  67.  
  68.         // Need before rewrite module (hack)
  69.         $data['product_name'] = $data['name'];
  70.  
  71.         // Get the product link
  72.         // if (isset($this->request->server['REQUEST_SCHEME'])) {
  73.         //     $data['product_link'] = $this->request->server['REQUEST_SCHEME'].'://' . $this->request->server['HTTP_HOST'] . $this->request->server['REQUEST_URI'];
  74.         // }else{
  75.         //     $data['product_link'] = 'http://' . $this->request->server['HTTP_HOST'] . $this->request->server['REQUEST_URI'];
  76.         // }
  77.  
  78.         // Get the product link
  79.         if (isset($this->request->get['path'])) {
  80.            $path = 'path=' . $this->request->get['path'];
  81.         }else{
  82.             $path = 'route=' . $this->request->get['route'];
  83.         }
  84.  
  85.         $data['product_link'] = $this->url->link('product/product', $path . '&product_id=' . $data['product_id']);
  86.  
  87.         // FastOrder price var
  88.         $data['price'] = $this->currency->format($this->tax->calculate($data['price'], $data['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency'],'',false);
  89.  
  90.         // FastOrder special price var
  91.         if($data['special']){
  92.             $fo_special = $this->currency->format($this->tax->calculate($data['special'], $data['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency'],'',false);
  93.         }else{
  94.             $fo_special = null;
  95.         }
  96.  
  97.  
  98.         $this->document->addStyle('catalog/view/theme/'. $template.'/stylesheet/fastorder.css');
  99.  
  100.         if(VERSION >= '2.2.0.0') {
  101.           return $this->load->view('product/fastorder', $data);
  102.         }else{
  103.           return $this->load->view($this->config->get('config_template') . '/template/product/fastorder.tpl', $data);
  104.         }
  105.     }
  106.  
  107.     public function getForm(){
  108.         // Get the currency symbol
  109.         $data['symbolLeft'] = $this->currency->getSymbolLeft($this->session->data['currency']) ? $this->currency->getSymbolLeft($this->session->data['currency']) : '';
  110.         $data['symbolRight'] = $this->currency->getSymbolRight($this->session->data['currency']);
  111.  
  112.         // Load lanuage
  113.         $this->load->language('product/fastorder');
  114.  
  115. // =================================================================================================
  116. //Getting the customer data
  117.  
  118.         // Get Customer info (if user login in system)
  119.         $this->load->model('account/customer');
  120.         $customer_info = $this->model_account_customer->getCustomer($this->customer->getId());
  121.  
  122.         if($customer_info){
  123.             $data['customer_id'] = $this->customer->getId();
  124.             $data['customer_group_id'] = $customer_info['customer_group_id'];
  125.             $data['username'] = $customer_info['firstname'] . ' ' . $customer_info['lastname'];
  126.             $data['email'] = $customer_info['email'];
  127.             $data['telephone'] = $customer_info['telephone'];
  128.         }
  129. // =================================================================================================
  130.  
  131.         // Language data
  132.         $data['text_fastorder_button']                      = $this->language->get('text_fastorder_button');
  133.         $data['text_fastorder_form_header']                 = $this->language->get('text_fastorder_form_header');
  134.         $data['text_fastorder_form_info']                   = $this->language->get('text_fastorder_form_info');
  135.         $data['text_fastorder_name']                        = $this->language->get('text_fastorder_name');
  136.         $data['text_fastorder_phone']                       = $this->language->get('text_fastorder_phone');
  137.         $data['text_fastorder_comment']                     = $this->language->get('text_fastorder_comment');
  138.         $data['text_fastorder_button_submit']               = $this->language->get('text_fastorder_button_submit');
  139.         $data['text_fastorder_button_close']                = $this->language->get('text_fastorder_button_close');
  140.         $data['text_fastorder_success_message']             = $this->language->get('text_fastorder_success_message');
  141.         $data['text_fastorder_button_cancel']               = $this->language->get('text_fastorder_button_cancel');
  142.         $data['text_fastorder_input_name_placeholder']      = $this->language->get('text_fastorder_input_name_placeholder');
  143.         $data['text_fastorder_input_phone_placeholder']     = $this->language->get('text_fastorder_input_phone_placeholder');
  144.         $data['text_fastorder_input_mail_placeholder']      = $this->language->get('text_fastorder_input_mail_placeholder');
  145.         $data['text_fastorder_input_comment_placeholder']   = $this->language->get('text_fastorder_input_comment_placeholder');
  146.         $data['text_fastorder_success_title']               = $this->language->get('text_fastorder_success_title');
  147.         $data['text_fastorder_mail_msg_order']              = $this->language->get('text_fastorder_mail_msg_order');
  148.         $data['text_fastorder_mail_msg_price']              = $this->language->get('text_fastorder_mail_msg_price');
  149.         $data['txt_text_fastorder_form_info_message']       = $this->language->get('txt_text_fastorder_form_info_message');
  150.         $data['text_fastorder_count']                       = $this->language->get('text_fastorder_count');
  151.         $data['text_fastorder_input_count_placeholder']     = $this->language->get('text_fastorder_input_count_placeholder');
  152.  
  153.         $data['product_name'] = $this->request->post['product_name'];
  154.         $data['price'] = $this->request->post['price'];
  155.         $data['product_id'] = $this->request->post['product_id'];
  156.  
  157.         $data['product_link'] = $this->request->post['product_link'];
  158.  
  159.         if (VERSION >= '2.2.0.0') {
  160.           $tpl =  $this->load->view('product/fastorder_form', $data);
  161.         }else{
  162.           $tpl =  $this->load->view($this->config->get('config_template') . '/template/product/fastorder_form.tpl', $data);
  163.         }
  164.  
  165.         $this->response->setOutput($tpl);
  166.     }
  167.  
  168.     public function sender(){
  169.         // Load language
  170.         $this->load->language('product/fastorder');
  171.  
  172.         // Language data
  173.         $data['text_fastorder_mail_subject']    = $this->language->get('text_fastorder_mail_subject');
  174.         $data['text_fastorder_mail_msg_data']   = $this->language->get('text_fastorder_mail_msg_data');
  175.         $data['text_fastorder_name']            = $this->language->get('text_fastorder_name');
  176.         $data['text_fastorder_phone']           = $this->language->get('text_fastorder_phone');
  177.         $data['text_fastorder_mail']            = $this->language->get('text_fastorder_mail');
  178.         $data['text_fastorder_comment']         = $this->language->get('text_fastorder_comment');
  179.         $data['text_fastorder_mail_msg_order']  = $this->language->get('text_fastorder_mail_msg_order');
  180.         $data['text_fastorder_mail_msg_price']  = $this->language->get('text_fastorder_mail_msg_price');
  181.         $data['text_fastorder_mail_msg_count']  = $this->language->get('text_fastorder_mail_msg_count');
  182.         $data['text_fastorder_mail_msg_total']  = $this->language->get('text_fastorder_mail_msg_total');
  183.  
  184.         // Get the currency symbol
  185.         $data['symbolLeft'] = $this->currency->getSymbolLeft($this->session->data['currency']) ? $this->currency->getSymbolLeft($this->session->data['currency']) : '';
  186.         $data['symbolRight'] = $this->currency->getSymbolRight($this->session->data['currency']);
  187.  
  188.         $json = array();
  189.  
  190.         if (isset($this->request->post['product_id'])){
  191.           $json['product_id'] = $this->request->post['product_id'];
  192.         }
  193.         if (isset($this->request->post['name'])){
  194.           $json['name'] = $this->request->post['name'];
  195.         }
  196.         if (isset($this->request->post['phone'])){
  197.           $json['phone'] = $this->request->post['phone'];
  198.         }
  199.         if (isset($this->request->post['mail']) and !empty($this->request->post['mail'])){
  200.           $json['mail'] = $this->request->post['mail'];
  201.         }else{
  202.              $json['mail'] = ' ';
  203.         }
  204.         if (isset($this->request->post['comment'])){
  205.           $json['comment'] = $this->request->post['comment'];
  206.         }
  207.         if (isset($this->request->post['product_name'])){
  208.           $json['product_name'] = $this->request->post['product_name'];
  209.         }
  210.         if (isset($this->request->post['price'])){
  211.           $json['price'] = $this->request->post['price'];
  212.         }
  213.         if (isset($this->request->post['count']) and !empty($this->request->post['count']) and
  214.             $this->request->post['count'] != 0){
  215.           $json['count'] = $this->request->post['count'];
  216.         }else{
  217.             $json['count'] = 1;
  218.         }
  219.         if (isset($this->request->post['total'])){
  220.             $json['total'] = $this->request->post['total'];
  221.         }
  222.  
  223.         // Need to test new features
  224.         if (self::$dev) {
  225.             require_once 'developer_test_file.php';
  226.         }
  227.  
  228.  
  229.         // Mail subject
  230.         $subject    = $data['text_fastorder_mail_subject'] .' ('.$_SERVER['HTTP_HOST'] . ')';
  231.         $products   = $json['product_name'];
  232.  
  233.         // Data to mail template
  234.         $mail_tmpl_data = array (
  235.             'product_link'                  => $this->request->post['product_link'],
  236.             'subject'                       => $subject,
  237.             'text_fastorder_name'           => $data['text_fastorder_name'],
  238.             'text_fastorder_mail_msg_data'  => $data['text_fastorder_mail_msg_data'],
  239.             'name'                          => $json['name'],
  240.             'text_fastorder_phone'          => $data['text_fastorder_phone'],
  241.             'phone'                         => $json['phone'],
  242.             'text_fastorder_mail'           => $data['text_fastorder_mail'],
  243.             'mail'                          => $json['mail'],
  244.             'text_fastorder_comment'        => $data['text_fastorder_comment'],
  245.             'comment'                       => $json['comment'],
  246.             'text_fastorder_mail_msg_order' => $data['text_fastorder_mail_msg_order'],
  247.             'text_fastorder_mail_msg_price' => $data['text_fastorder_mail_msg_price'],
  248.             'price'                         => $json['price'],
  249.             'count'                         => $json['count'],
  250.             'text_fastorder_mail_msg_count' => $data['text_fastorder_mail_msg_count'],
  251.             'total'                         => $json['total'],
  252.             'text_fastorder_mail_msg_total' => $data['text_fastorder_mail_msg_total'],
  253.             'config_name'                   => $this->config->get('config_name'),
  254.             'config_telephone'              => $this->config->get('config_telephone'),
  255.             'config_email'                  => $this->config->get('config_email'),
  256.             'products'                      => $products,
  257.             'symbolLeft'                    => $data['symbolLeft'],
  258.             'symbolRight'                   => $data['symbolRight']
  259.             );
  260.  
  261.         // Get the main message template
  262.         if (VERSION >= '2.2.0.0') {
  263.           $mail_message =  $this->load->view('mail/fastorder_mail_msg', $mail_tmpl_data);
  264.         }else{
  265.           $mail_message =  $this->load->view($this->config->get('config_template') . '/template/mail/fastorder_mail_msg.tpl', $mail_tmpl_data);
  266.         }
  267.  
  268.         // Debugging
  269.         if(self::$dev){
  270.             // Write mail messege to the file.
  271.             file_put_contents('./mail_message.html', $mail_message);
  272.         }
  273.  
  274.         $email_to = $this->config->get('config_email');
  275.  
  276.         // Create OpenCart mail object
  277.         $mail = new Mail();
  278.  
  279.         // Гребанные мудаки, разработчики Opencart, никак не могу определиться с названием параметров конфига. Ебланы хуевы, как можно быть такими... ну блин... это же будут читать тысячи пользователей... Я адски зол, где стандарты, мать его....
  280.         // Пока что тестировано на OC_2.2, и каком-то более низком через mail, без использования SMTP
  281.         // Потребуется доработка под разные версии.
  282.         // Последнее изменение с версии 1.2.1
  283.  
  284.         // SMTP mail in tested mode.
  285.         // Now working with mail is normal.
  286.         if (VERSION >= '2.2.0.0') {
  287.             // Setup the mail parameters
  288.             $mail->protocol = $this->config->get('config_mail_protocol');
  289.             $mail->parameter = $this->config->get('config_mail_parameter');
  290.             $mail->smtp_hostname = $this->config->get('config_mail_smtp_hostname');
  291.             $mail->smtp_username = $this->config->get('config_mail_smtp_username');
  292.             $mail->smtp_password = $this->config->get('config_mail_smtp_password');
  293.             $mail->smtp_port = $this->config->get('config_mail_smtp_port');
  294.             $mail->smtp_timeout = $this->config->get('config_mail_smtp_timeout');
  295.             $mail->setTo($email_to);
  296.             $mail->setFrom(explode(',', $this->config->get('config_email'))[0]);
  297.             $mail->setSender($this->config->get('config_name'));
  298.             $mail->setSubject(html_entity_decode($data['text_fastorder_mail_subject'] .' ('.$_SERVER['HTTP_HOST'] . ')'), ENT_QUOTES, 'UTF-8');
  299.             $mail->setHtml($mail_message);
  300.             $mail->setText(html_entity_decode($mail_message, ENT_QUOTES, 'UTF-8'));
  301.         }else{
  302.             // Older
  303.             // Setup the mail parameters
  304.             $mail->protocol = $this->config->get('config_mail_protocol');
  305.             $mail->parameter = $this->config->get('config_mail_parameter');
  306.             $mail->hostname = $this->config->get('config_smtp_host');
  307.             $mail->username = $this->config->get('config_smtp_username');
  308.             $mail->password = $this->config->get('config_smtp_password');
  309.             $mail->port = $this->config->get('config_smtp_port');
  310.             $mail->timeout = $this->config->get('config_smtp_timeout');
  311.             $mail->setTo($email_to);
  312.             $mail->setFrom(explode(',', $this->config->get('config_email'))[0]);
  313.             $mail->setSender($this->config->get('config_name'));
  314.             $mail->setSubject(html_entity_decode($data['text_fastorder_mail_subject'] .' ('.$_SERVER['HTTP_HOST'] . ')'), ENT_QUOTES, 'UTF-8');
  315.             $mail->setHtml($mail_message);
  316.             $mail->setText(html_entity_decode($mail_message, ENT_QUOTES, 'UTF-8'));
  317.         }
  318.  
  319.         // Send mail to the shop owner
  320.         $mail->send();
  321.  
  322.         //Send to other mail from Config Mail. OC =>2.2.0.0
  323.         if ($this->config->get('config_mail_alert_email')) {
  324.             $mail->setTo($this->config->get('config_mail_alert_email'));
  325.             $mail->send();
  326.         }
  327.  
  328.         //Send to other mail from Config Mail.OC <2.2.0.0
  329.         if ($this->config->get('config_mail_alert')) {
  330.             $mail->setTo($this->config->get('config_mail_alert'));
  331.             $mail->send();
  332.         }
  333.  
  334.  
  335.         // Send mail to the customer
  336.         if(!empty($this->request->post['mail'])){
  337.  
  338.             $mail->setTo($json['mail']);
  339.             $mail->send();
  340.         }
  341.  
  342.         $this->response->addHeader('Content-Type: application/json');
  343.         $this->response->setOutput(json_encode($json));
  344.     }
  345. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement