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; } }
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(); }
private function doCreateOrder($post = array()) { $total_data = array(); $total = 0; $taxes = $this->cart->getTaxes(); $this->load->model('setting/extension'); $this->load->model('localisation/country'); $this->load->model('localisation/zone'); $this->load->model('module/quick_order_pro'); $setting = id::decode($post['form_id']); $template_info = $this->getTemplate($setting['template_id']); $stored_cart = $this->session->data['cart']; if ($setting['type'] == 1) { // product page $this->cart->clear(); if (isset($this->request->get['product_id'])) { $product_id = $this->request->get['product_id']; } elseif (isset($this->request->post['product_id'])) { $product_id = $this->request->post['product_id']; } else { $product_id = 0; } $product_info = $this->model_catalog_product->getProduct($product_id); if (!$product_info) { return; } if (isset($this->request->post['quantity'])) { $quantity = $this->request->post['quantity']; } else { $quantity = $product_info['minimum']; } if (isset($this->request->post['option'])) { $option = array_filter($this->request->post['option']); } else { $option = array(); } $profile_id = 0; if (strpos(VERSION, '1.6') !== FALSE) { if (isset($this->request->post['profile_id'])) { $profile_id = $this->request->post['profile_id']; } } $this->cart->add($product_id, $quantity, $option, $profile_id); } $sort_order = array(); // Totals $total_data = array(); $total = 0; $taxes = $this->cart->getTaxes(); $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); } $sort_order = array(); foreach ($total_data as $key => $value) { $sort_order[$key] = $value['sort_order']; } array_multisort($sort_order, SORT_ASC, $total_data); } $this->language->load('checkout/checkout'); $data = array(); $data['invoice_prefix'] = $this->config->get('config_invoice_prefix'); $data['store_id'] = $this->config->get('config_store_id'); $data['store_name'] = $this->config->get('config_name'); if ($data['store_id']) { $data['store_url'] = $this->config->get('config_url'); } else { $data['store_url'] = HTTP_SERVER; } $language_id = $this->config->get('config_language_id'); $data['custom_fields'] = array(); foreach ($template_info['fields'] as $field_id => $field_info) { $isEmpty = $value === FALSE || empty($value) && $value !== '0'; if (isset($post['fields'][$field_id]) && !in_array($field_info['code'], array('captcha'))) { $value = $post['fields'][$field_id]; $isEmpty = $value === FALSE || empty($value) && $value !== '0'; if (!$isEmpty) { if (in_array($field_info['type']['type'], array('select', 'radio', 'checkbox'))) { $result = array(); $options = is_array($value) ? $value : array($value); foreach ($options as $option_id) { if (array_key_exists($option_id, $field_info['type']['option'])) { $result[] = $field_info['type']['option'][$option_id]['value']; } } $result = array_filter($result); if (!$result) { continue; } $value = implode(', ', $result); } $key = $field_info['code'] == 'custom_field' ? $field_id : $field_info['code']; $data['custom_fields'][$key] = array('title' => $field_info['title'][$language_id], 'value' => $this->_stripText($value), 'weight' => $field_info['weight']); } } } $sort_order = array(); foreach ($data['custom_fields'] as $key => $value) { $sort_order[$key] = $value['weight']; } array_multisort($sort_order, SORT_ASC, $data['custom_fields']); foreach (array('firstname', 'lastname', 'telephone', 'email', 'address', 'comment') as $field) { if (array_key_exists($field, $data['custom_fields'])) { $data[$field] = $data['custom_fields'][$field]['value']; } else { $data[$field] = ''; } } if (!$data['email'] && $this->customer->isLogged()) { $data['email'] = $this->customer->getEmail(); } if ($this->customer->isLogged()) { $data['customer_id'] = $this->customer->getId(); $data['customer_group_id'] = $this->customer->getCustomerGroupId(); $data['fax'] = $this->customer->getFax(); } else { $data['fax'] = ''; if ($this->setting['create_customer']) { $data['customer_group_id'] = $this->setting['new_customer_group']; if (!empty($this->setting['new_customer_random_password'])) { $password = substr(sha1(uniqid(mt_rand(), true)), 6, 32); } elseif ($this->setting['new_customer_password']) { $password = $this->setting['new_customer_password']; } else { $password = '******'; } oc::registry()->message->data['customer_password'] = $password; $customer_data = $data + array('password' => $password, 'company' => '', 'address_1' => '', 'address_2' => '', 'city' => '', 'postcode' => '', 'country_id' => $this->config->get('config_country_id'), 'zone_id' => $this->config->get('config_zone_id')); $data['customer_id'] = $this->model_module_quick_order_pro->addCustomer($customer_data); } else { $data['customer_id'] = 0; $data['customer_group_id'] = $this->config->get('config_customer_group_id'); } } $country_info = $this->model_localisation_country->getCountry($this->config->get('config_country_id')); if ($country_info) { $country_name = $country_info['name']; } else { $country_name = ''; } $zone_info = $this->model_localisation_zone->getZone($this->config->get('config_zone_id')); if ($zone_info) { $zone_name = $zone_info['name']; } else { $zone_name = ''; } $data['payment_firstname'] = $data['shipping_firstname'] = $data['firstname']; $data['payment_lastname'] = $data['shipping_lastname'] = $data['lastname']; $data['payment_company'] = $data['shipping_company'] = ''; $data['payment_company_id'] = ''; $data['payment_tax_id'] = ''; $data['payment_address_1'] = $data['shipping_address_1'] = $data['address']; $data['payment_address_2'] = $data['shipping_address_2'] = ''; $data['payment_city'] = $data['shipping_city'] = ''; $data['payment_postcode'] = $data['shipping_postcode'] = ''; $data['payment_zone'] = $data['shipping_zone'] = $zone_name; $data['payment_zone_id'] = $data['shipping_zone_id'] = $this->config->get('config_zone_id'); $data['payment_country'] = $data['shipping_country'] = $country_name; $data['payment_country_id'] = $data['shipping_country_id'] = $this->config->get('config_country_id'); $data['payment_address_format'] = $data['shipping_address_format'] = ''; $data['payment_method'] = $data['shipping_method'] = ''; $data['payment_code'] = $data['shipping_code'] = ''; $this->load->library('encryption'); $product_data = array(); foreach ($this->cart->getProducts() as $product) { $option_data = array(); foreach ($product['option'] as $option) { if ($option['type'] != 'file') { $value = $option['option_value']; } else { $encryption = new Encryption($this->config->get('config_encryption')); $value = $encryption->decrypt($option['option_value']); } $option_data[] = array('product_option_id' => $option['product_option_id'], 'product_option_value_id' => $option['product_option_value_id'], 'option_id' => $option['option_id'], 'option_value_id' => $option['option_value_id'], 'name' => $option['name'], 'value' => $value, 'type' => $option['type']); } $product_data[] = array('product_id' => $product['product_id'], 'name' => $product['name'], 'model' => $product['model'], 'option' => $option_data, 'download' => $product['download'], 'quantity' => $product['quantity'], 'subtract' => $product['subtract'], 'price' => $product['price'], 'total' => $product['total'], 'tax' => $this->tax->getTax($product['total'], $product['tax_class_id']), 'reward' => isset($product['reward']) ? $product['reward'] : ''); } $data['vouchers'] = array(); $data['products'] = $product_data; $data['totals'] = $total_data; $data['total'] = $total; if (method_exists($this->cart, 'getTotalRewardPoints')) { $data['reward'] = $this->cart->getTotalRewardPoints(); } if (isset($this->request->cookie['tracking'])) { $this->load->model('affiliate/affiliate'); $affiliate_info = $this->model_affiliate_affiliate->getAffiliateByCode($this->request->cookie['tracking']); if ($affiliate_info) { $data['affiliate_id'] = $affiliate_info['affiliate_id']; $data['commission'] = $total / 100 * $affiliate_info['commission']; } else { $data['affiliate_id'] = 0; $data['commission'] = 0; } } else { $data['affiliate_id'] = 0; $data['commission'] = 0; } $data['language_id'] = $this->config->get('config_language_id'); $data['currency_id'] = $this->currency->getId(); $data['currency_code'] = $this->currency->getCode(); $data['currency_value'] = $this->currency->getValue($this->currency->getCode()); $data['ip'] = $this->request->server['REMOTE_ADDR']; if (!empty($this->request->server['HTTP_X_FORWARDED_FOR'])) { $data['forwarded_ip'] = $this->request->server['HTTP_X_FORWARDED_FOR']; } elseif (!empty($this->request->server['HTTP_CLIENT_IP'])) { $data['forwarded_ip'] = $this->request->server['HTTP_CLIENT_IP']; } else { $data['forwarded_ip'] = ''; } if (isset($this->request->server['HTTP_USER_AGENT'])) { $data['user_agent'] = $this->request->server['HTTP_USER_AGENT']; } else { $data['user_agent'] = ''; } if (isset($this->request->server['HTTP_ACCEPT_LANGUAGE'])) { $data['accept_language'] = $this->request->server['HTTP_ACCEPT_LANGUAGE']; } else { $data['accept_language'] = ''; } $this->load->model('checkout/order'); if (method_exists($this->model_checkout_order, 'addOrder')) { $this->session->data['order_id'] = $this->model_checkout_order->addOrder($data); } elseif (method_exists($this->model_checkout_order, 'create')) { $this->session->data['order_id'] = $this->model_checkout_order->create($data); } else { $this->session->data['cart'] = $stored_cart; return FALSE; } $this->model_module_quick_order_pro->confirm($this->session->data['order_id'], $this->setting['order_status_id'], $data); if ($setting['type'] == 1) { // product page $this->session->data['cart'] = $stored_cart; // restore cart } }