public function render() { $output = ''; if (!empty($this->field)) { $data = array(); $data += parent::setGeneralData(); if (isset($this->field['type']['maxlength']) && $this->field['type']['maxlength']) { $data['maxlength'] = $this->field['type']['maxlength']; } else { $data['maxlength'] = 32; } if ($this->field['code'] == 'captcha') { $setting = oc::registry()->config->get('quick_order_pro_setting'); $data['maxlength'] = $setting['captcha_count_items']; $data['text_captcha_reload'] = oc::registry()->load->language->get('text_captcha_reload'); } $data['mask'] = $data['placeholder'] = ''; if (!empty($this->field['type']['use_mask']) && $this->field['type']['use_mask'] && !empty($this->field['type']['mask'])) { $data['mask'] = $this->field['type']['mask']; oc::registry()->document->addScript('catalog/view/javascript/quick_order_pro/jquery.maskedinput.min.js'); } if (!empty($this->field['type']['placeholder'])) { $data['placeholder'] = $this->field['type']['placeholder']; } $output = $this->renderField($data); } return $output; }
public static function registry() { if (empty(self::$_instance)) { self::$_instance = new oc(); } return self::$_instance; }
public function render() { $output = ''; if (!empty($this->field)) { $data = array(); $data += parent::setGeneralData(); $data['text_select'] = oc::registry()->load->language->get('text_select'); $data['multiple'] = $this->field['type']['multiple']; if ($data['multiple']) { $data['class'] .= ($data['class'] ? ' ' : '') . 'multiple'; } $data['selected'] = array(); if ($data['value']) { if (is_array($data['value'])) { $data['selected'] = $data['value']; } else { $data['selected'][] = $data['value']; } } elseif (!empty($this->field['type']['selected'])) { $data['selected'][] = $this->field['type']['selected']; } if (!empty($this->field['type']['option']) && $this->field['type']['option']) { $data['option'] = $this->field['type']['option']; } else { return $output; } $output = $this->renderField($data); } return $output; }
public static function find($file, $setting = array()) { $template = ''; $available_directories = array(); $available_directories[] = DIRECTORY_SEPARATOR; if (isset($setting['position'])) { $available_directories[] = ($setting['position'] ? 'content' : 'sidebar') . DIRECTORY_SEPARATOR; } if (isset($setting['template_id'])) { $available_directories[] = 'template_' . $setting['template_id'] . DIRECTORY_SEPARATOR; } if (isset($setting['layout_id'])) { $available_directories[] = 'layout_' . $setting['layout_id'] . DIRECTORY_SEPARATOR; } foreach (array(oc::registry()->config->get('config_template'), 'default') as $theme) { $directory = $theme . DIRECTORY_SEPARATOR . 'template' . DIRECTORY_SEPARATOR . 'module' . DIRECTORY_SEPARATOR . 'quick_order_pro'; $iterations = $available_directories; while (!empty($iterations)) { $available_directory = implode('', $iterations); if (file_exists(DIR_TEMPLATE . $directory . $available_directory . $file . '.tpl')) { $template = $directory . $available_directory . $file . '.tpl'; } if ($template) { break 2; } array_pop($iterations); } } return $template; }
public function validate($value) { $validate = TRUE; $form_id = oc::registry()->message->data['form_id']; if (!$form_id || !isset(oc::registry()->session->data['quick_order_pro_captcha'][$form_id]) || oc::registry()->session->data['quick_order_pro_captcha'][$form_id] != $value) { $validate = FALSE; } return $validate; }
public function get_customer() { $this->response->setOutput(json_encode(oc::customer()->isLogged() ? array('id' => oc::customer()->getId(), 'firstname' => oc::customer()->getFirstName(), 'lastname' => oc::customer()->getLastName(), 'addressid' => oc::customer()->getAddressId()) : array())); }
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(); }
public static function add_address($params) { return oc::model('account_address')->addAddress($params); }
public function confirm($order_id, $order_status_id, $data) { $this->load->model('checkout/order'); $order_info = $this->model_checkout_order->getOrder($order_id); if ($order_info && !$order_info['order_status_id']) { $setting = $this->getSetting(); $sql = "UPDATE `" . DB_PREFIX . "order` SET "; $sql .= "order_status_id = '" . (int) $order_status_id . "', "; $sql .= "date_modified = NOW() "; $sql .= "WHERE order_id = '" . (int) $order_id . "'"; $this->db->query($sql); $sql = "INSERT INTO " . DB_PREFIX . "order_history SET "; $sql .= "order_id = '" . (int) $order_id . "', "; $sql .= "order_status_id = '" . (int) $order_status_id . "', "; $sql .= "notify = '1', "; $sql .= "comment = '', "; $sql .= "date_added = NOW()"; $this->db->query($sql); $order_product_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_product WHERE order_id = '" . (int) $order_id . "'"); if ($setting['subtract']) { if ($setting['subtract'] == 'default') { $subtract = ' AND subtract = "1"'; } else { $subtract = ''; } foreach ($order_product_query->rows as $order_product) { $this->db->query("UPDATE " . DB_PREFIX . "product SET quantity = (quantity - " . (int) $order_product['quantity'] . ") WHERE product_id = '" . (int) $order_product['product_id'] . "'" . $subtract); $order_option_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_option WHERE order_id = '" . (int) $order_id . "' AND order_product_id = '" . (int) $order_product['order_product_id'] . "'"); foreach ($order_option_query->rows as $option) { $this->db->query("UPDATE " . DB_PREFIX . "product_option_value SET quantity = (quantity - " . (int) $order_product['quantity'] . ") WHERE product_option_value_id = '" . (int) $option['product_option_value_id'] . "'" . $subtract); } } $this->cache->delete('product'); } $order_total_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_total WHERE order_id = '" . (int) $order_id . "' ORDER BY sort_order ASC"); $order_download_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_download WHERE order_id = '" . (int) $order_id . "'"); $order_status_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_status WHERE order_status_id = '" . (int) $order_status_id . "' AND language_id = '" . (int) $order_info['language_id'] . "'"); if ($order_status_query->num_rows) { $order_status = $order_status_query->row['name']; } else { $order_status = ''; } // Send out order confirmation mail $language = new Language($order_info['language_directory']); $language->load($order_info['language_filename']); $language->load('mail/quick_order_pro'); $subject = sprintf($language->get('text_new_subject'), $order_info['store_name'], $order_id); // HTML Mail $template = new Template(); $template->data['title'] = sprintf($language->get('text_new_subject'), html_entity_decode($order_info['store_name'], ENT_QUOTES, 'UTF-8'), $order_id); $template->data['text_greeting'] = sprintf($language->get('text_new_greeting'), $order_info['store_url'], html_entity_decode($order_info['store_name'], ENT_QUOTES, 'UTF-8')); $template->data['text_greeting_detail'] = $language->get('text_new_greeting_detail'); $template->data['text_order_detail'] = $language->get('text_new_order_detail'); $template->data['text_instruction'] = $language->get('text_new_instruction'); $template->data['text_date_added'] = $language->get('text_new_date_added'); $template->data['text_ip'] = $language->get('text_new_ip'); $template->data['text_product'] = $language->get('text_new_product'); $template->data['text_model'] = $language->get('text_new_model'); $template->data['text_quantity'] = $language->get('text_new_quantity'); $template->data['text_price'] = $language->get('text_new_price'); $template->data['text_total'] = $language->get('text_new_total'); $template->data['text_footer'] = $language->get('text_new_footer'); $template->data['store_name'] = $order_info['store_name']; $template->data['store_url'] = $order_info['store_url']; $template->data['fields'] = array(); foreach ($data['custom_fields'] as $code => $field_info) { if ($code == 'comment') { continue; } $template->data['fields'][] = array('name' => $field_info['title'], 'value' => $field_info['value']); } if ($setting['customer_email_show_date_added']) { $template->data['date_added'] = date($language->get('date_format_short'), strtotime($order_info['date_added'])); } if ($setting['customer_email_show_ip']) { $template->data['ip'] = $order_info['ip']; } $template->data['comment'] = $order_info['comment']; $template->data['products'] = array(); foreach ($order_product_query->rows as $product) { $option_data = array(); $order_option_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_option WHERE order_id = '" . (int) $order_id . "' AND order_product_id = '" . (int) $product['order_product_id'] . "'"); foreach ($order_option_query->rows as $option) { if ($option['type'] != 'file') { $option_data[] = array('name' => $option['name'], 'value' => utf8_strlen($option['value']) > 20 ? utf8_substr($option['value'], 0, 20) . '..' : $option['value']); } else { $filename = substr($option['value'], 0, strrpos($option['value'], '.')); $option_data[] = array('name' => $option['name'], 'value' => utf8_strlen($filename) > 20 ? utf8_substr($filename, 0, 20) . '..' : $filename); } } $template->data['products'][] = array('name' => $product['name'], 'href' => $this->url->link('product/product', 'product_id=' . $product['product_id']), 'model' => $product['model'], 'option' => $option_data, 'quantity' => $product['quantity'], 'price' => $this->currency->format($product['price'], $order_info['currency_code'], $order_info['currency_value']), 'total' => $this->currency->format($product['total'], $order_info['currency_code'], $order_info['currency_value'])); } $template->data['totals'] = $order_total_query->rows; if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/mail/quick_order_pro.tpl')) { $html = $template->fetch($this->config->get('config_template') . '/template/mail/quick_order_pro.tpl'); } else { $html = $template->fetch('default/template/mail/quick_order_pro.tpl'); } // Text Mail $text = sprintf($language->get('text_new_greeting'), $order_info['store_url'], html_entity_decode($order_info['store_name'], ENT_QUOTES, 'UTF-8')) . "\n\n"; $text .= $language->get('text_new_greeting_detail') . "\n\n"; foreach ($data['custom_fields'] as $code => $field_info) { if ($code == 'comment') { continue; } $text .= $field_info['title'] . ': ' . $field_info['value'] . "\n"; } $text .= $language->get('text_new_date_added') . ' ' . date($language->get('date_format_short'), strtotime($order_info['date_added'])) . "\n"; $text .= "\n\n"; $text .= $language->get('text_new_products') . "\n"; foreach ($order_product_query->rows as $result) { $text .= $result['quantity'] . 'x ' . $result['name'] . ' (' . $result['model'] . ') ' . html_entity_decode($this->currency->format($result['total'], $order_info['currency_code'], $order_info['currency_value']), ENT_NOQUOTES, 'UTF-8') . "\n"; $order_option_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_option WHERE order_id = '" . (int) $order_id . "' AND order_product_id = '" . $result['order_product_id'] . "'"); foreach ($order_option_query->rows as $option) { $text .= chr(9) . '-' . $option['name'] . ' ' . (utf8_strlen($option['value']) > 20 ? utf8_substr($option['value'], 0, 20) . '..' : $option['value']) . "\n"; } } $text .= "\n"; $text .= $language->get('text_new_order_total') . "\n"; foreach ($order_total_query->rows as $result) { $text .= $result['title'] . ' ' . html_entity_decode($result['text'], ENT_NOQUOTES, 'UTF-8') . "\n"; } $text .= "\n"; if ($order_info['comment']) { $text .= $language->get('text_new_comment') . "\n\n"; $text .= $order_info['comment'] . "\n\n"; } $text .= $language->get('text_new_footer') . "\n\n"; $mail = new Mail(); $mail->protocol = $this->config->get('config_mail_protocol'); $mail->parameter = $this->config->get('config_mail_parameter'); $mail->hostname = $this->config->get('config_smtp_host'); $mail->username = $this->config->get('config_smtp_username'); $mail->password = $this->config->get('config_smtp_password'); $mail->port = $this->config->get('config_smtp_port'); $mail->timeout = $this->config->get('config_smtp_timeout'); $mail->setTo($order_info['email']); $mail->setFrom($this->config->get('config_email')); $mail->setSender($order_info['store_name']); $mail->setSubject($subject); $mail->setHtml($html); $mail->setText(html_entity_decode($text, ENT_QUOTES, 'UTF-8')); if ($setting['alert_customer'] && $order_info['email'] != '') { $mail->send(); } // Admin Alert Mail if ($setting['alert_admin']) { $subject = sprintf($language->get('text_new_subject_admin'), html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8'), $order_id); // Text $text = $language->get('text_new_received') . "\n\n"; $text .= $language->get('text_new_order_id') . ' ' . $order_id . "\n"; $text .= $language->get('text_new_date_added') . ' ' . date($language->get('date_format_short'), strtotime($order_info['date_added'])) . "\n"; $text .= $language->get('text_new_order_status') . ' ' . $order_status . "\n\n"; $text .= $language->get('text_new_customer_fields') . "\n"; foreach ($data['custom_fields'] as $code => $field_info) { if ($code == 'comment') { continue; } $text .= $field_info['title'] . ': ' . $field_info['value'] . "\n"; } $text .= "\n\n"; if ($setting['admin_email_send_password'] && $setting['create_customer']) { $text .= $language->get('text_customer_password') . ' ' . oc::registry()->message->data['customer_password'] . "\n\n"; } $text .= $language->get('text_new_products') . "\n"; foreach ($order_product_query->rows as $result) { $text .= $result['quantity'] . 'x ' . $result['name'] . ' (' . $result['model'] . ') ' . html_entity_decode($this->currency->format($result['total'], $order_info['currency_code'], $order_info['currency_value']), ENT_NOQUOTES, 'UTF-8') . "\n"; $order_option_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_option WHERE order_id = '" . (int) $order_id . "' AND order_product_id = '" . $result['order_product_id'] . "'"); foreach ($order_option_query->rows as $option) { $text .= chr(9) . '-' . $option['name'] . ' ' . (utf8_strlen($option['value']) > 20 ? utf8_substr($option['value'], 0, 20) . '..' : $option['value']) . "\n"; } } $text .= "\n"; $text .= $language->get('text_new_order_total') . "\n"; foreach ($order_total_query->rows as $result) { $text .= $result['title'] . ' ' . html_entity_decode($result['text'], ENT_NOQUOTES, 'UTF-8') . "\n"; } $text .= "\n"; $comment = ''; if ($order_info['comment'] != '') { $comment = $order_info['comment'] . "\n\n"; } if ($comment) { $text .= $language->get('text_new_comment') . "\n\n"; $text .= $comment . "\n\n"; } if ($setting['admin_email_type'] == 'config') { $email_to = $this->config->get('config_email'); } else { $email_to = $setting['alert_email']; } $mail = new Mail(); $mail->protocol = $this->config->get('config_mail_protocol'); $mail->parameter = $this->config->get('config_mail_parameter'); $mail->hostname = $this->config->get('config_smtp_host'); $mail->username = $this->config->get('config_smtp_username'); $mail->password = $this->config->get('config_smtp_password'); $mail->port = $this->config->get('config_smtp_port'); $mail->timeout = $this->config->get('config_smtp_timeout'); $mail->setTo($email_to); $mail->setFrom($email_to); $mail->setSender($order_info['store_name']); $mail->setSubject($subject); if ($setting['admin_email_same_customer']) { $mail->setHtml($html); } $mail->setText($text); $mail->send(); // Send to additional alert emails $emails = explode(',', $setting['admin_emails']); foreach ($emails as $email) { if ($email && preg_match('/^[^\\@]+@.*\\.[a-z]{2,6}$/i', $email)) { $mail->setTo($email); $mail->send(); } } } // Send Admins SMS if configure if ($this->config->get('config_sms_alert')) { $options = array('to' => $this->config->get('config_sms_to'), 'copy' => $this->config->get('config_sms_copy'), 'from' => $this->config->get('config_sms_from'), 'username' => $this->config->get('config_sms_gate_username'), 'password' => $this->config->get('config_sms_gate_password'), 'message' => str_replace(array('{ID}', '{DATE}', '{TIME}', '{SUM}', '{PHONE}'), array($order_id, date('d.m.Y'), date('H:i'), floatval($order_info['total']), $order_info['telephone']), $this->config->get('config_sms_message'))); $this->load->library('sms'); $sms = new Sms($this->config->get('config_sms_gatename'), $options); $sms->send(); } } }
public static function display($tpl, &$params = array()) { $loader = new Twig_Loader_Filesystem(); $paths = scandir(self::$twig); foreach ($paths as $path) { if ($path != '.' && $path != '..' && is_dir(self::$twig . "/{$path}")) { $loader->addPath(self::$twig . "/{$path}", $path); } } $twig = new Twig_Environment($loader, array('cache' => $_SERVER['DOCUMENT_ROOT'] . '/twig_cache', 'autoescape' => false, 'debug' => true, 'auto_reload' => true)); $twig->addExtension(new Twig_Extension_Debug()); $thumb = new Twig_SimpleFunction('thumb', function ($img, $w, $h) { return oc::model('tool_image')->resize($img, $w, $h); }); $twig->addFunction($thumb); $watermark = new Twig_SimpleFilter('watermark', function ($img, $type = 'tiles', $hide = 100) { return oc::image_watermark($img, $type, $hide); }); $twig->addFilter($watermark); $image_url = new Twig_SimpleFilter('image_url', function ($path) { return oc::image_url($path); }); $twig->addFilter($image_url); $showPrice = new Twig_SimpleFilter('price', function ($n, $decimals = 0, $dec_point = '.', $thousands_sep = ' ') { return number_format($n, $decimals, $dec_point, $thousands_sep); }); $twig->addFilter($showPrice); $showdate = new Twig_SimpleFunction('show_date', function ($dt, $to = 'full', $from = 'mysql') { static $months = array('января', 'февраля', 'марта', 'апреля', 'мая', 'июня', 'июля', 'августа', 'сентября', 'октября', 'ноября', 'декабря'); $parts = array(); if ($from == 'mysql') { //2011-09-30 01:06:53 preg_match("/^(\\d{4})-(\\d{2})-(\\d{2})/", $dt, $parts); } if ($to == 'full') { return $parts[3] . ' ' . $months[$parts[2] - 1] . ' ' . $parts[1] . ' г.'; } else { if ($to == 'short') { return $parts[3] . '.' . $parts[2] . '.' . $parts[1]; } } }); $twig->addFunction($showdate); $repeat = new Twig_SimpleFilter('repeat', function ($s, $n) { return str_repeat($s, $n); }); $twig->addFilter($repeat); $firstp = new Twig_SimpleFilter('firstp', function ($s) { return substr($s, 0, strpos($s, "</p>") + 4); }); $twig->addFilter($firstp); $replaceURI = new Twig_SimpleFilter('replaceURI', function ($url, $nm, $val) { return preg_match("/[?&]{1}{$nm}=/", $url) ? preg_replace("/([?&]{1}{$nm})=[^&]*/", "\$1={$val}", $url) : $url . (strpos($url, '?') === false ? '?' : '&') . "{$nm}={$val}"; }); $twig->addFilter($replaceURI); $findAttribute = new Twig_SimpleFilter('attribute', function ($allAttributes, $name) { list($groupName, $attrName) = explode(':', $name); foreach ($allAttributes as $group) { if (mb_strtolower($group['name'], 'UTF-8') == mb_strtolower($groupName, 'UTF-8')) { foreach ($group['attribute'] as $attribute) { if (mb_strtolower($attribute['name'], 'UTF-8') == mb_strtolower($attrName, 'UTF-8')) { return $attribute['text']; } } } } return ''; }); $twig->addFilter($findAttribute); self::$params['path'] = self::$root; self::$params['server'] = array('request_uri' => html_entity_decode($_SERVER['REQUEST_URI'])); self::$params['cart'] = array('total_products' => oc::cart()->countProducts(), 'total_sum' => oc::cart()->getTotal()); self::$params['uname'] = oc::customer()->isLogged() ? oc::customer()->getLastName() . ' ' . oc::customer()->getFirstName() : null; $twig->display("@{$tpl}.html", self::$params); }
protected function getTokens() { return array('{field_name}' => $this->field_info['title'][oc::registry()->config->get('config_language_id')]); }
private function init() { $this->setting = $this->getSetting(); spl_autoload_register(array($this, 'autoloader')); spl_autoload_extensions('.php'); oc::registry()->message = new message(); }
<?php require_once dirname(__FILE__) . '/vendor/autoload.php'; require_once dirname(__FILE__) . '/oc/oc.php'; tpl::$root = '/catalog/view/theme/proimport/'; tpl::$twig = dirname(__FILE__) . '/catalog/view/theme/proimport/template/twig'; ocshop::init(); function getProducts(&$categories) { foreach ($categories as &$cat) { $cat['products'] = ocshop::products($cat['id'], false); foreach ($cat['products'] as &$product) { $product['active'] = $product['product_id'] == ocshop::$pid; } getProducts($cat['children']); } } getProducts(ocshop::$tree); tpl::set('topMenu', oc::menu(array('Каталог', 'Услуги', 'Доставка|Доставка и оплата', 'Лизинг', 'Гарантии', 'О компании', 'Контакты'))); tpl::set('bottomMenu', array('col1' => oc::menu(array('Контакты', 'О компании', 'Доставка и оплата', 'Связаться с нами:/contact-us/', 'Рассчитать стоимость доставки:javascript:sendDeliveryCalc()')), 'col2' => oc::menu(array('Акции', 'Скидки', 'Карта сайта:/sitemap/')), 'col3' => oc::menu(array('Оптовикам', 'Гарантии', 'Политика безопасности', 'Возврат товара', 'Партнерам', 'Производители:/brands/')))); tpl::set('root', ocshop::$root); tpl::set('catTree', ocshop::$tree); tpl::set('google', oc::settings('config', 'config_google_analytics'));
function getGroupID($name) { $groupID = false; $sortOrder = 1; $model = oc::model('catalog_attribute_group'); $list = $model->getAttributeGroups(array('sort' => 'ag.sort_order')); foreach ($list as $group) { if (mb_strtolower($group['name'], 'UTF-8') == mb_strtolower($name, 'UTF-8')) { $groupID = $group['attribute_group_id']; } $sortOrder = $group['sort_order']; } if (!$groupID) { $model->addAttributeGroup(array('sort_order' => $sortOrder + 10, 'attribute_group_description' => array(1 => array('name' => $name)))); return getGroupID($name); } return $groupID; }