Ejemplo n.º 1
0
 public static function renderItem($message, $form_id, $type = 'error')
 {
     if (!$message) {
         return '';
     }
     if (is_array($message)) {
         foreach ($message as $key => &$item) {
             $item = self::renderItem($item, $form_id, $type);
         }
         return $message;
     } else {
         $html = FALSE;
         if ($message && ($options = id::decode($form_id))) {
             $template = new tpl(tpl::find($type . '-message', $options), array('message' => $message));
             $html = $template->render();
         }
         return $html;
     }
 }
Ejemplo n.º 2
0
 public static function renderFields($fields)
 {
     spl_autoload_register(array('field', 'autoloader_field'), FALSE, TRUE);
     $data = $options = $data['fields'] = $sort_order = array();
     foreach ($fields as $key => $value) {
         $sort_order[$key] = $value['weight'];
     }
     array_multisort($sort_order, SORT_ASC, $fields);
     foreach ($fields as $field_id => $field_info) {
         if (!$field_info['status']) {
             continue;
         }
         $action = self::getAction($field_info['type']['type']);
         if (!empty($action['class'])) {
             $data['fields'][] = $action['class']::getInstance($field_info)->render();
         }
     }
     $last_form_id = oc::registry()->config->get('quick_order_pro_last_form_id');
     if (!empty($last_form_id)) {
         $options = id::decode($last_form_id);
         $data += $options;
     }
     return tpl::getInstance(tpl::find('fields', $options), $data)->render();
 }
Ejemplo n.º 3
0
 public function index($module = array())
 {
     self::$item_id++;
     if ($this->customer->isLogged()) {
         $customer_group_id = $this->customer->getCustomerGroupId();
     } else {
         $customer_group_id = $this->config->get('config_customer_group_id');
     }
     if (!empty($this->setting['customer_group']) && !in_array($customer_group_id, $this->setting['customer_group'])) {
         return;
     } elseif (!$this->setting['guest_checkout'] && !$this->customer->isLogged()) {
         return;
     } elseif (!is_null($this->setting['autch_checkout']) && !$this->setting['autch_checkout'] && $this->customer->isLogged()) {
         return;
     }
     $template_info = $this->getTemplate($module['template_id']);
     if (!$template_info) {
         return;
     }
     if (!array_key_exists('store', $template_info) || !in_array($this->config->get('config_store_id'), $template_info['store'])) {
         return;
     }
     if (isset($this->request->get['route']) && $this->request->get['route'] == 'product/product') {
         if (isset($this->request->get['product_id'])) {
             $product_id = $this->request->get['product_id'];
         } else {
             $product_id = 0;
         }
         $this->load->model('catalog/product');
         $product_info = $this->model_catalog_product->getProduct($product_id);
         if ($product_info) {
             $this->data['type'] = '1';
         } else {
             return;
             // product not found
         }
     } elseif (!$this->cart->hasProducts() || !empty($this->session->data['vouchers'])) {
         return;
         // cart empty
     } else {
         $this->data['type'] = '0';
     }
     $position = in_array($module['position'], array('column_left', 'column_right')) ? 'sidebar' : 'content';
     $key = implode(id::$separator, array($module['template_id'], $this->data['type'], (int) ($position == 'content'), self::$item_id, $module['layout_id']));
     oc::registry()->message->data['form_id'] = $this->data['form_id'] = $this->form_id = id::encode($key);
     $this->language->load('module/quick_order_pro');
     if ($this->request->server['REQUEST_METHOD'] == 'POST' && $this->validate()) {
         $this->doCreateOrder($this->request->post);
         if ($template_info['redirect']) {
             $redirect = $this->url->link('checkout/success');
         } else {
             $redirect = $this->request->server['HTTP_REFERER'];
             message::setState('success', $template_info['success_message'], $this->form_id, 'success');
             $this->session->data['quick_order_pro_success'][$this->form_id] = $template_info['success_message'];
         }
         $this->redirect($redirect);
     }
     $this->data['total'] = false;
     $this->data['fields'] = field::renderFields($template_info['fields']);
     if ($this->data['type'] == '1') {
         // product
         if ($product_info['quantity'] <= 0 && !$template_info['stock_checkout']) {
             return;
         }
         $this->data['product_info'] = array('name' => $product_info['name'], 'option' => array(), 'quantity' => $product_info['minimum']);
         if ($template_info['use_option'] && $template_info['show_option']) {
             foreach ($this->model_catalog_product->getProductOptions($this->request->get['product_id']) as $option) {
                 if (in_array($option['type'], array('text', 'textarea', 'date', 'datetime', 'time')) && !empty($option['option_value'])) {
                     $this->data['product_info']['option'][] = array('name' => $option['name'], 'value' => utf8_strlen($option['option_value']) > 20 ? utf8_substr($option['option_value'], 0, 20) . '..' : $option['option_value']);
                 }
             }
         }
         if ($template_info['show_total']) {
             if ($this->config->get('config_customer_price') && $this->customer->isLogged() || !$this->config->get('config_customer_price')) {
                 $total = $product_info['price'];
             }
             if ((double) $product_info['special']) {
                 $total = $product_info['special'];
             }
             $quantity = $product_info['minimum'];
             if ($total && $quantity) {
                 $this->data['total'] = $this->currency->format($this->calculateTax($total, $quantity, $product_info['tax_class_id']));
             }
         }
     } else {
         if ($template_info['show_total']) {
             // Totals
             $this->load->model('setting/extension');
             $total_data = array();
             $total = 0;
             $taxes = $this->cart->getTaxes();
             // Display prices
             if ($this->config->get('config_customer_price') && $this->customer->isLogged() || !$this->config->get('config_customer_price')) {
                 $sort_order = array();
                 $results = $this->model_setting_extension->getExtensions('total');
                 foreach ($results as $key => $value) {
                     $sort_order[$key] = $this->config->get($value['code'] . '_sort_order');
                 }
                 array_multisort($sort_order, SORT_ASC, $results);
                 foreach ($results as $result) {
                     if ($this->config->get($result['code'] . '_status')) {
                         $this->load->model('total/' . $result['code']);
                         $this->{'model_total_' . $result['code']}->getTotal($total_data, $total, $taxes);
                     }
                 }
             }
             $this->data['total'] = $this->currency->format($total);
         }
     }
     $this->document->addScript('catalog/view/javascript/quick_order_pro/quick_order_pro.js');
     if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/stylesheet/quick_order_pro.css')) {
         $this->document->addStyle('catalog/view/theme/' . $this->config->get('config_template') . '/stylesheet/quick_order_pro.css');
     } else {
         $this->document->addStyle('catalog/view/theme/default/stylesheet/quick_order_pro.css');
     }
     $language_id = $this->config->get('config_language_id');
     $this->data['text_process'] = $this->language->get('text_process');
     $this->data['text_required'] = $this->language->get('text_required');
     $this->data['text_total'] = $this->language->get('text_total');
     if (!empty($template_info['button'][$language_id])) {
         $this->data['button_send'] = $template_info['button'][$language_id];
     } else {
         $this->data['button_send'] = $this->language->get('button_send');
     }
     if (array_key_exists($language_id, $template_info['title']) && $this->_stripText($template_info['title'][$language_id]) != '') {
         $this->data['heading_title'] = $template_info['title'][$language_id];
     } else {
         $this->data['heading_title'] = FALSE;
     }
     if (array_key_exists($language_id, $template_info['description']) && $this->_stripText($template_info['description'][$language_id]) != '') {
         $this->data['description'] = html_entity_decode($template_info['description'][$language_id], ENT_QUOTES, 'UTF-8');
     } else {
         $this->data['description'] = FALSE;
     }
     $class = $position;
     if ($this->_stripText($template_info['class']) != '') {
         $class .= ' ' . $this->_stripText($template_info['class']);
     }
     $this->data['class'] = $class;
     $this->data['template_info'] = $template_info;
     $this->data['item_id'] = self::$item_id;
     if (!empty(oc::registry()->message->data['error'])) {
         if (array_key_exists('fields', oc::registry()->message->data['error'])) {
             unset(oc::registry()->message->data['error']['fields']);
         }
         $this->data['error'] = oc::registry()->message->data['error'];
     } else {
         $this->data['error'] = NULL;
     }
     $this->data['success'] = message::getState('success', $this->form_id, 'success');
     $this->template = tpl::find($position, id::decode($this->form_id));
     $this->render();
 }