public function all()
 {
     $this->setHeaders();
     $this->load->library('json');
     if ($this->request->server['REQUEST_METHOD'] == 'GET') {
         $cached = $this->cache->get('product.admin.api.json.all');
         if ($cached) {
             echo $cached;
         } else {
             $filter_name = isset($this->request->get['filter_name']) ? $this->request->get['filter_name'] : null;
             $filter_model = isset($this->request->get['filter_model']) ? $this->request->get['filter_model'] : null;
             $filter_quantity = isset($this->request->get['filter_quantity']) ? $this->request->get['filter_quantity'] : null;
             $filter_status = isset($this->request->get['filter_status']) ? $this->request->get['filter_status'] : null;
             $filter_date_start = isset($this->request->get['filter_date_start']) ? $this->request->get['filter_date_start'] : null;
             $filter_date_end = isset($this->request->get['filter_date_end']) ? $this->request->get['filter_date_end'] : null;
             $page = isset($this->request->get['page']) ? $this->request->get['page'] : 1;
             $sort = isset($this->request->get['sort']) ? $this->request->get['sort'] : 'pd.name';
             $order = isset($this->request->get['order']) ? $this->request->get['order'] : 'ASC';
             $limit = !empty($this->request->get['limit']) ? $this->request->get['limit'] : $this->config->get('config_admin_limit');
             $data = array('filter_name' => $filter_name, 'filter_model' => $filter_model, 'filter_quantity' => $filter_quantity, 'filter_status' => $filter_status, 'filter_date_start' => $filter_date_start, 'filter_date_end' => $filter_date_end, 'sort' => $sort, 'order' => $order, 'start' => ($page - 1) * $limit, 'limit' => $limit);
             $this->load->auto('store/product');
             $this->load->auto('library');
             //$this->data['total'] = $this->modelProduct->getAllTotal($data);
             $results = $this->modelProduct->getAll($data);
             foreach ($results as $result) {
                 if ($result['pimage'] && file_exists(DIR_IMAGE . $result['pimage'])) {
                     $image = NTImage::resizeAndSave($result['pimage'], 40, 40);
                 } else {
                     $image = NTImage::resizeAndSave('no_image.jpg', 40, 40);
                 }
                 $this->data['products'][] = array('product_id' => $result['product_id'], 'id' => $result['product_id'], 'name' => $result['pname'], 'model' => $result['model'], 'meta_keywords' => $result['meta_keywords'], 'meta_description' => $result['meta_description'], 'description' => $result['pdescription'], 'sku' => $result['sku'], 'ssname' => $result['ssname'], 'mname' => $result['mname'], 'shipping' => $result['shipping'], 'price' => $result['price'], 'tctitle' => $result['tctitle'], 'date_available' => $result['date_available'], 'weight' => $result['weight'], 'wctitle' => $result['wctitle'], 'length' => $result['length'], 'width' => $result['width'], 'height' => $result['height'], 'lctitle' => $result['lctitle'], 'date_added' => $result['date_added'], 'date_modified' => $result['date_modified'], 'viewed' => $result['viewed'], 'subtract' => $result['subtract'], 'minimum' => $result['minimum'], 'cost' => $result['cost'], 'sort_order' => $result['sort_order'], 'image' => $image, 'quantity' => $result['quantity'], 'status' => $result['status'] ? $this->language->get('text_enabled') : $this->language->get('text_disabled'), 'selected' => isset($this->request->post['selected']) && in_array($result['product_id'], $this->request->post['selected']));
             }
             /*
                             $this->data['filters']['name'] = $filter_name;
                             $this->data['filters']['model'] = $filter_model;
                             $this->data['filters']['qty'] = $filter_quantity;
                             $this->data['filters']['status'] = $filter_status;
             * 
             */
             //$this->cache->set('product.admin.api.json.all', Json::encode($this->data));
         }
     } else {
         $this->error401();
     }
     var_dump(headers_list());
     flush();
     ob_end_flush();
     headers_sent($f, $l);
     echo $f . ': ' . $l;
     var_dump(get_headers(HTTP_CATALOG, 1));
     header('Location:http://www.google.com');
     $this->response->setOutput(Json::encode($this->data), $this->config->get('config_compression'));
 }
 public function index()
 {
     $this->load->language('payment/pp_standard');
     $this->document->title = $this->language->get('heading_title');
     $this->load->model('setting/setting');
     if ($this->request->server['REQUEST_METHOD'] == 'POST' && $this->validate()) {
         $this->modelSetting->update('pp_standard', $this->request->post);
         $this->session->data['success'] = $this->language->get('text_success');
         if ($_POST['to'] == "saveAndKeep") {
             $this->redirect(Url::createAdminUrl('payment/pp_standard'));
         } else {
             $this->redirect(Url::createAdminUrl('extension/payment'));
         }
     }
     $this->data['error_warning'] = isset($this->error['warning']) ? $this->error['warning'] : '';
     $this->data['error_email'] = isset($this->error['email']) ? $this->error['email'] : '';
     $this->document->breadcrumbs = array();
     $this->document->breadcrumbs[] = array('href' => HTTP_HOME . 'index.php?r=common/home&token=' . $this->session->data['token'], 'text' => $this->language->get('text_home'), 'separator' => FALSE);
     $this->document->breadcrumbs[] = array('href' => HTTP_HOME . 'index.php?r=extension/payment&token=' . $this->session->data['token'], 'text' => $this->language->get('text_payment'), 'separator' => ' :: ');
     $this->document->breadcrumbs[] = array('href' => HTTP_HOME . 'index.php?r=payment/pp_standard&token=' . $this->session->data['token'], 'text' => $this->language->get('heading_title'), 'separator' => ' :: ');
     $this->data['action'] = HTTP_HOME . 'index.php?r=payment/pp_standard&token=' . $this->session->data['token'];
     $this->data['cancel'] = HTTP_HOME . 'index.php?r=extension/payment&token=' . $this->session->data['token'];
     $this->setvar('pp_standard_image');
     $this->setvar('pp_standard_order_status_id');
     $this->setvar('pp_standard_newsletter_id');
     $this->setvar('pp_standard_email');
     $this->setvar('pp_standard_test');
     $this->setvar('pp_standard_transaction');
     $this->setvar('pp_standard_app_id');
     $this->setvar('pp_standard_app _secret');
     $this->setvar('pp_standard_geo_zone_id');
     $this->setvar('pp_standard_status');
     $this->setvar('pp_standard_sort_order');
     if ($this->data['pp_standard_image'] && file_exists(DIR_IMAGE . $this->data['pp_standard_image'])) {
         $this->data['preview'] = NTImage::resizeAndSave($this->data['pp_standard_image'], 100, 100);
     } else {
         $this->data['preview'] = NTImage::resizeAndSave('no_image.jpg', 100, 100);
     }
     $this->load->model('localisation/orderstatus');
     $this->data['order_statuses'] = $this->modelOrderstatus->getAll();
     $this->load->model('localisation/geozone');
     $this->data['geo_zones'] = $this->modelGeozone->getAll();
     $this->load->model('marketing/newsletter');
     $this->data['newsletters'] = $this->modelNewsletter->getAll();
     $scripts[] = array('id' => 'categoryFunctions', 'method' => 'function', 'script' => "function image_delete(field, preview) {\r\n                \$('#' + field).val('');\r\n                \$('#' + preview).attr('src','" . HTTP_IMAGE . "cache/no_image-100x100.jpg');\r\n            }\r\n            \r\n            function image_upload(field, preview) {\r\n                var height = \$(window).height() * 0.8;\r\n                var width = \$(window).width() * 0.8;\r\n                \r\n            \t\$('#dialog').remove();\r\n            \t\$('.box').prepend('<div id=\"dialog\" style=\"padding: 3px 0px 0px 0px;z-index:10000;\"><iframe src=\"" . Url::createAdminUrl("common/filemanager") . "&field=' + encodeURIComponent(field) + '\" style=\"padding:0; margin: 0; display: block; width: 100%; height: 100%;z-index:10000;\" frameborder=\"no\" scrolling=\"auto\"></iframe></div>');\r\n                \r\n                \$('#dialog').dialog({\r\n            \t\ttitle: '" . $this->data['text_image_manager'] . "',\r\n            \t\tclose: function (event, ui) {\r\n            \t\t\tif (\$('#' + field).attr('value')) {\r\n            \t\t\t\t\$.ajax({\r\n            \t\t\t\t\turl: '" . Url::createAdminUrl("common/filemanager/image") . "',\r\n            \t\t\t\t\ttype: 'POST',\r\n            \t\t\t\t\tdata: 'image=' + encodeURIComponent(\$('#' + field).val()),\r\n            \t\t\t\t\tdataType: 'text',\r\n            \t\t\t\t\tsuccess: function(data) {\r\n            \t\t\t\t\t\t\$('#' + preview).replaceWith('<img src=\"' + data + '\" id=\"' + preview + '\" class=\"image\" onclick=\"image_upload(\\'' + field + '\\', \\'' + preview + '\\');\">');\r\n            \t\t\t\t\t}\r\n            \t\t\t\t});\r\n            \t\t\t}\r\n            \t\t},\t\r\n            \t\tbgiframe: false,\r\n            \t\twidth: width,\r\n            \t\theight: height,\r\n            \t\tresizable: false,\r\n            \t\tmodal: false\r\n            \t});}");
     $this->scripts = array_merge($this->scripts, $scripts);
     $this->template = 'payment/pp_standard.tpl';
     $this->children[] = 'common/header';
     $this->children[] = 'common/nav';
     $this->children[] = 'common/footer';
     $this->response->setOutput($this->render(TRUE), $this->config->get('config_compression'));
 }
 /**
  * Controller::setImageVar
  * Asigna el valor del campo de imagen del formulario
  * @param string $varname el nombre de la variable a definir
  * @param array $group el nombre del grupo de estilos
  * @return void
  * */
 public function setImageVar($varname, $group)
 {
     $this->load->model("image");
     $this->load->model("style/style");
     $model = $this->model_style_style->getStyles($group);
     if (!empty($model['background-image']) && file_exists(DIR_IMAGE . $model['background-image'])) {
         $this->data[$varname] = NTImage::resizeAndSave($model['background-image'], 100, 100);
         $this->data["_" . $varname] = $model['background-image'];
     } else {
         $this->data[$varname] = NTImage::resizeAndSave('sin_fondo.jpg', 100, 100);
         $this->data["_" . $varname] = "";
     }
 }
 public function run()
 {
     $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "stat s \r\n        LEFT JOIN " . DB_PREFIX . "customer c ON (s.customer_id=c.customer_id) \r\n        LEFT JOIN " . DB_PREFIX . "product p ON (s.object_id=p.product_id) \r\n        LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id=pd.product_id) \r\n        WHERE DAY(s.date_added) = '" . $this->db->escape(date('d')) . "' \r\n            AND MONTH(s.date_added) = '" . $this->db->escape(date('m')) . "'\r\n            AND YEAR(s.date_added) = '" . $this->db->escape(date('Y')) . "'\r\n            AND s.object_type = 'product'\r\n            AND s.status = 1\r\n            AND s.customer_id <> 0\r\n            AND pd.language_id = 1\r\n        GROUP BY s.customer_id\r\n        LIMIT 40");
     if ($query->num_rows && (int) $this->config->get('marketing_email_recommended_products')) {
         $this->load->library('tax');
         $this->load->library('currency');
         $this->load->library('image');
         $this->load->library('url');
         $this->tax = new Tax($this->registry);
         $this->currency = new Currency($this->registry);
         $products = array();
         foreach ($query->rows as $product) {
             $image = !empty($product['image']) ? $product['image'] : 'no_image.jpg';
             $price = $this->currency->format($this->tax->calculate($product['price'], $product['tax_class_id'], $this->config->get('config_tax')), '', '', false);
             $products[] = array('product_id' => $product['product_id'], 'name' => $product['name'], 'image' => NTImage::resizeAndSave($image, 150, 150), 'model' => $product['model'], 'href' => Url::createUrl('store/product', array('product_id' => $product['product_id'])));
         }
         $params = array('job' => 'send_recommended_products', 'newsletter_id' => (int) $this->config->get('marketing_email_recommended_products'));
         $this->load->library('task');
         $task = new Task($this->registry);
         $task->object_id = (int) $this->config->get('marketing_email_recommended_products');
         $task->object_type = 'newsletter';
         $task->task = 'recommended_products';
         $task->type = 'send';
         $task->time_exec = date('Y-m-d') . ' 08:00:00';
         $task->params = $params;
         $task->time_interval = "";
         $task->time_last_exec = "";
         $task->run_once = true;
         $task->status = 1;
         $task->date_start_exec = date('Y-m-d') . ' 08:00:00';
         $task->date_end_exec = date('Y-m-d') . ' 23:00:00';
         foreach ($query->rows as $customer) {
             $params = array('customer_id' => $customer['customer_id'], 'fullname' => $customer['firstname'] . " " . $customer['lastname'], 'company' => $customer['company'], 'rif' => $customer['rif'], 'telephone' => $customer['telephone'], 'email' => $customer['email'], 'products' => $products);
             $queue = array("params" => $params, "status" => 1, "time_exec" => date('Y-m-d') . ' 08:00:00');
             $task->addQueue($queue);
             $this->db->query("UPDATE " . DB_PREFIX . "stat SET status = 0 \r\n                WHERE customer_id = '" . (int) $product['customer_id'] . "'\r\n                    AND DAY(date_added) = '" . $this->db->escape(date('d')) . "' \r\n                    AND MONTH(date_added) = '" . $this->db->escape(date('m')) . "'\r\n                    AND YEAR(date_added) = '" . $this->db->escape(date('Y')) . "'");
         }
         $task->createSendTask();
     }
 }
 public function carousel()
 {
     $json = array();
     $this->load->model('content/banner');
     $this->load->auto('image');
     $this->load->auto('json');
     $this->data['Image'] = new NTImage();
     $banner = $this->modelBanner->getById($this->request->getQuery('banner_id'));
     $json['results'] = $banner['items'];
     $width = isset($_GET['width']) ? $_GET['width'] : 80;
     $height = isset($_GET['height']) ? $_GET['height'] : 80;
     foreach ($json['results'] as $k => $v) {
         if (!file_exists(DIR_IMAGE . $v['image'])) {
             $json['results'][$k]['image'] = HTTP_IMAGE . "no_image.jpg";
         }
         $json['results'][$k]['thumb'] = NTImage::resizeAndSave($v['image'], $width, $height);
     }
     if (!count($json['results'])) {
         $json['error'] = 1;
     }
     $this->response->setOutput(Json::encode($json), $this->config->get('config_compression'));
 }
 /**
  * ControllerSalePayment::getForm()
  * 
  * @see Load
  * @see Document
  * @see Language
  * @see Session
  * @see Response
  * @see Request     
  * @return void 
  */
 private function getForm()
 {
     $this->data['heading_title'] = $this->language->get('heading_title');
     $this->data['text_enabled'] = $this->language->get('text_enabled');
     $this->data['text_disabled'] = $this->language->get('text_disabled');
     $this->data['text_select'] = $this->language->get('text_select');
     $this->data['entry_name'] = $this->language->get('entry_name');
     $this->data['entry_image'] = $this->language->get('entry_image');
     $this->data['help_name'] = $this->language->get('help_name');
     $this->data['help_image'] = $this->language->get('help_image');
     $this->data['button_cancel'] = $this->language->get('button_cancel');
     $this->data['button_save_and_new'] = $this->language->get('button_save_and_new');
     $this->data['button_save_and_exit'] = $this->language->get('button_save_and_exit');
     $this->data['button_save_and_keep'] = $this->language->get('button_save_and_keep');
     $this->data['error_warning'] = $this->error['warning'] ? $this->error['warning'] : '';
     $this->data['error_name'] = $this->error['name'] ? $this->error['name'] : '';
     $this->document->breadcrumbs = array();
     $this->document->breadcrumbs[] = array('href' => Url::createAdminUrl('common/home'), 'text' => $this->language->get('text_home'), 'separator' => false);
     $this->document->breadcrumbs[] = array('href' => Url::createAdminUrl('sale/payment') . $url, 'text' => $this->language->get('heading_title'), 'separator' => ' :: ');
     if (!isset($this->request->get['payment_id'])) {
         $this->data['action'] = Url::createAdminUrl('sale/payment/insert') . $url;
     } else {
         $this->data['action'] = Url::createAdminUrl('sale/payment/update') . '&payment_id=' . $this->request->get['payment_id'] . $url;
     }
     $this->data['cancel'] = Url::createAdminUrl('sale/payment') . $url;
     if (isset($this->request->get['payment_id']) && $this->request->server['REQUEST_METHOD'] != 'POST') {
         $payment_info = $this->modelPayment->getById($this->request->get['payment_id']);
     }
     $this->setvar('name', $payment_info, '');
     $this->setvar('image', $payment_info, '');
     if (isset($payment_info) && $payment_info['image'] && file_exists(DIR_IMAGE . $payment_info['image'])) {
         $this->data['preview'] = NTImage::resizeAndSave($payment_info['image'], 100, 100);
     } else {
         $this->data['preview'] = NTImage::resizeAndSave('no_image.jpg', 100, 100);
     }
     $this->data['Url'] = new Url();
     $scripts[] = array('id' => 'paymentScripts', 'method' => 'ready', 'script' => " \$('#form').ntForm({\r\n                submitButton:false,\r\n                cancelButton:false,\r\n                lockButton:false\r\n            });\r\n            \$('textarea').ntTextArea();\r\n            \r\n            var form_clean = \$('#form').serialize();  \r\n            \r\n            window.onbeforeunload = function (e) {\r\n                var form_dirty = \$('#form').serialize();\r\n                if(form_clean != form_dirty) {\r\n                    return 'There is unsaved form data.';\r\n                }\r\n            };");
     $scripts[] = array('id' => 'paymentFunctions', 'method' => 'function', 'script' => "function saveAndExit() { \r\n                window.onbeforeunload = null;\r\n                \$('#form').append(\"<input type='hidden' name='to' value='saveAndExit'>\").submit(); \r\n            }\r\n            \r\n            function saveAndKeep() { \r\n                window.onbeforeunload = null;\r\n                \$('#form').append(\"<input type='hidden' name='to' value='saveAndKeep'>\").submit(); \r\n            }\r\n            \r\n            function saveAndNew() { \r\n                window.onbeforeunload = null;\r\n                \$('#form').append(\"<input type='hidden' name='to' value='saveAndNew'>\").submit(); \r\n            }\r\n            \r\n            function image_delete(field, preview) {\r\n                \$('#' + field).val('');\r\n                \$('#' + preview).attr('src','" . HTTP_IMAGE . "cache/no_image-100x100.jpg');\r\n            }\r\n            \r\n            function image_upload(field, preview) {\r\n                var height = \$(window).height() * 0.8;\r\n                var width = \$(window).width() * 0.8;\r\n                \r\n            \t\$('#dialog').remove();\r\n            \t\$('.box').prepend('<div id=\"dialog\" style=\"padding: 3px 0px 0px 0px;z-index:10000;\"><iframe src=\"" . Url::createAdminUrl("common/filemanager") . "&field=' + encodeURIComponent(field) + '\" style=\"padding:0; margin: 0; display: block; width: 100%; height: 100%;z-index:10000;\" frameborder=\"no\" scrolling=\"auto\"></iframe></div>');\r\n                \r\n                \$('#dialog').dialog({\r\n            \t\ttitle: '" . $this->data['text_image_manager'] . "',\r\n            \t\tclose: function (event, ui) {\r\n            \t\t\tif (\$('#' + field).attr('value')) {\r\n            \t\t\t\t\$.ajax({\r\n            \t\t\t\t\turl: '" . Url::createAdminUrl("common/filemanager/image") . "',\r\n            \t\t\t\t\ttype: 'POST',\r\n            \t\t\t\t\tdata: 'image=' + encodeURIComponent(\$('#' + field).val()),\r\n            \t\t\t\t\tdataType: 'text',\r\n            \t\t\t\t\tsuccess: function(data) {\r\n            \t\t\t\t\t\t\$('#' + preview).replaceWith('<img src=\"' + data + '\" id=\"' + preview + '\" class=\"image\" onclick=\"image_upload(\\'' + field + '\\', \\'' + preview + '\\');\">');\r\n            \t\t\t\t\t}\r\n            \t\t\t\t});\r\n            \t\t\t}\r\n            \t\t},\t\r\n            \t\tbgiframe: false,\r\n            \t\twidth: width,\r\n            \t\theight: height,\r\n            \t\tresizable: false,\r\n            \t\tmodal: false\r\n            \t});}");
     $this->scripts = array_merge($this->scripts, $scripts);
     $this->template = 'sale/payment_form.tpl';
     $this->children[] = 'common/header';
     $this->children[] = 'common/nav';
     $this->children[] = 'common/footer';
     $this->response->setOutput($this->render(true), $this->config->get('config_compression'));
 }
 public function read()
 {
     if (!$this->customer->isLogged()) {
         $this->session->set('redirect', Url::createUrl("account/review"));
         $this->redirect(Url::createUrl("account/login"));
     }
     $this->language->load('account/review');
     $this->load->model('store/review');
     $review_id = $this->request->get['review_id'];
     $review = $this->modelReview->getById($review_id);
     if ($review) {
         $this->document->breadcrumbs = array();
         $this->document->breadcrumbs[] = array('href' => Url::createUrl("common/home"), 'text' => $this->language->get('text_home'), 'separator' => false);
         $this->document->breadcrumbs[] = array('href' => Url::createUrl("account/review"), 'text' => $this->language->get('text_review'), 'separator' => $this->language->get('text_separator'));
         $this->document->breadcrumbs[] = array('href' => Url::createUrl("account/review/read") . '&review_id=' . $this->request->get['review_id'], 'text' => $this->language->get('text_review') . $this->request->get['review_id'], 'separator' => $this->language->get('text_separator'));
         $this->document->title = $this->data['heading_title'] = $this->language->get('heading_title');
         $review_id = $this->request->get['review_id'];
         $this->data['review'] = array();
         if ((int) $review_id) {
             $this->data['heading_title'] = "Comentario #" . $review_id;
             $this->data['review'] = $this->modelReview->getById($review_id);
             $this->data['replies'] = $this->modelReview->getReplies($review_id);
             $this->load->auto('image');
             $image = !empty($this->data['review']['image']) ? $this->data['review']['image'] : 'no_image.jpg';
             $this->data['review']['thumb'] = NTImage::resizeAndSave($image, $this->config->get('config_image_additional_width'), $this->config->get('config_image_additional_height'));
             $this->data['review']['description'] = html_entity_decode($this->data['review']['description'], ENT_QUOTES, 'UTF-8');
         }
         $this->data['action'] = Url::createUrl("account/review/reply");
         // style files
         $csspath = defined("CDN_CSS") ? CDN_CSS : HTTP_CSS;
         str_replace('%theme%', $this->config->get('config_template'), HTTP_THEME_CSS);
         if (file_exists(str_replace('%theme%', $this->config->get('config_template'), HTTP_THEME_CSS) . 'neco.form.css')) {
             $styles[] = array('media' => 'all', 'href' => str_replace('%theme%', $this->config->get('config_template'), HTTP_THEME_CSS) . 'neco.form.css');
         } else {
             $styles[] = array('media' => 'all', 'href' => $csspath . 'neco.form.css');
         }
         $this->styles = array_merge($styles, $this->styles);
         // javascript files
         $jspath = defined("CDN_JS") ? CDN_JS : HTTP_JS;
         $javascripts[] = $jspath . "necojs/neco.form.js";
         $this->javascripts = array_merge($this->javascripts, $javascripts);
         // SCRIPTS
         $scripts[] = array('id' => 'reviewScripts', 'method' => 'ready', 'script' => "\$('#reviewForm').ntForm({\r\n                ajax:true,\r\n                url:'{$this->data['action']}',\r\n                success:function(data) {\r\n                    if (data.success) {\r\n                        window.location.href = '" . Url::createUrl('account/review/read', array('review_id' => $review_id)) . "';\r\n                    }\r\n                    if (data.error) {\r\n                        \$('#reviewForm').append(data.msg);\r\n                    }\r\n                }\r\n            });\r\n            \r\n            \$('#reviewForm textarea').ntInput();\r\n            \r\n            var cache = {};\r\n            \$( '#addresses' ).on( 'keydown', function( event ) {\r\n                if ( event.keyCode === \$.ui.keyCode.TAB && \$( this ).data( 'autocomplete' ).menu.active ) {\r\n                    event.preventDefault();\r\n                }\r\n            })\r\n            .autocomplete({\r\n                source: function( request, response ) {\r\n                    var term = request.term;\r\n                    if ( term in cache ) {\r\n                        response( cache[ term ] );\r\n                        return;\r\n                    }\r\n                    \$.getJSON( '" . Url::createUrl('account/review/getcustomers') . "', {\r\n                        term: extractLast( request.term )\r\n                    }, \r\n                    function( data, status, xhr ) {\r\n                        cache[ term ] = data;\r\n                        response( data );\r\n                    });\r\n                },\r\n                search: function() {\r\n                    var term = extractLast( this.value );\r\n                    if ( term.length < 2 ) {\r\n                        return false;\r\n                    }\r\n                },\r\n                focus: function() {\r\n                    return false;\r\n                },\r\n                select: function( event, ui ) {\r\n                    \r\n                    var ids = split( \$('#to').val() );\r\n                    ids.pop();\r\n                    ids.push( ui.item.id );\r\n                    ids.push( '' );\r\n                    \$('#to').val(ids.join( '; ' ));\r\n                    \r\n                    var terms = split( this.value );\r\n                    terms.pop();\r\n                    terms.push( ui.item.value );\r\n                    terms.push( '' );\r\n                    this.value = terms.join( '; ' );\r\n                    \r\n                    return false;\r\n                }\r\n            });");
         $scripts[] = array('id' => 'reviewFunctions', 'method' => 'function', 'script' => "function split( val ) { \r\n                return val.split( /;\\s*/ ); \r\n            }\r\n            function extractLast( term ) {\r\n                return split( term ).pop();\r\n            }");
         $this->scripts = array_merge($this->scripts, $scripts);
         $this->loadWidgets();
         if ($scripts) {
             $this->scripts = array_merge($this->scripts, $scripts);
         }
         $this->children[] = 'account/column_left';
         $this->children[] = 'common/nav';
         $this->children[] = 'common/header';
         $this->children[] = 'common/footer';
         $template = $this->config->get('default_view_account_review_read') ? $this->config->get('default_view_account_review_read') : 'account/review_read.tpl';
         if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/' . $template)) {
             $this->template = $this->config->get('config_template') . '/' . $template;
         } else {
             $this->template = 'choroni/' . $template;
         }
     } else {
         $this->document->title = $this->data['heading_title'] = $this->language->get('text_error');
         $this->data['continue'] = Url::createUrl('account/review');
         $this->loadWidgets();
         if ($scripts) {
             $this->scripts = array_merge($this->scripts, $scripts);
         }
         $this->children[] = 'account/column_left';
         $this->children[] = 'common/nav';
         $this->children[] = 'common/header';
         $this->children[] = 'common/footer';
         $template = $this->config->get('default_view_account_review_read_error') ? $this->config->get('default_view_account_review_read_error') : 'error/not_found.tpl';
         if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/' . $template)) {
             $this->template = $this->config->get('config_template') . '/' . $template;
         } else {
             $this->template = 'choroni/' . $template;
         }
         $this->response->setOutput($this->render(true), $this->config->get('config_compression'));
     }
     $this->response->setOutput($this->render(TRUE), $this->config->get('config_compression'));
 }
 public function carousel()
 {
     $json = array();
     $Url = new Url($this->registry);
     $this->load->auto("store/product");
     $this->load->auto('image');
     $this->load->auto('json');
     $json['results'] = $this->modelProduct->getRandomProducts(isset($_GET['limit']) ? $_GET['limit'] : 40);
     $width = isset($_GET['width']) ? $_GET['width'] : 80;
     $height = isset($_GET['height']) ? $_GET['height'] : 80;
     foreach ($json['results'] as $k => $v) {
         if (!file_exists(DIR_IMAGE . $v['image'])) {
             $json['results'][$k]['image'] = HTTP_IMAGE . "no_image.jpg";
         }
         $json['results'][$k]['thumb'] = NTImage::resizeAndSave($v['image'], $width, $height);
         if ((!$this->config->get('config_customer_price') || $this->customer->isLogged()) && $this->config->get('config_store_mode') === 'store') {
             $json['results'][$k]['price'] = $this->currency->format($this->tax->calculate($v['price'], $v['tax_class_id'], $this->config->get('config_tax')));
         } else {
             $json['results'][$k]['price'] = null;
         }
         $json['results'][$k]['config_store_mode'] = $this->config->get('config_store_mode');
         $json['results'][$k]['seeProduct_url'] = $Url::createUrl('store/product', array('product_id' => $v['product_id']));
         $json['results'][$k]['addToCart_url'] = $Url::createUrl('checkout/cart') . '?product_id=' . $v['product_id'];
     }
     if (!count($json['results'])) {
         $json['error'] = 1;
     }
     $this->response->setOutput(Json::encode($json), $this->config->get('config_compression'));
 }
 public function carousel()
 {
     if ($this->request->hasQuery('func') && in_array($this->request->getQuery('func'), array('random', 'bestseller', 'latest', 'featured', 'recommended', 'special'))) {
         $func = $this->request->getQuery('func');
     } else {
         $func = 'random';
     }
     if ($this->request->hasQuery('limit') && is_numeric($this->request->getQuery('limit'))) {
         $limit = $this->request->getQuery('limit');
     } else {
         $limit = 24;
     }
     $json = array();
     $Url = new Url($this->registry);
     $this->load->auto("store/product");
     $this->load->auto('image');
     $this->load->auto('json');
     switch ($func) {
         case 'random':
         default:
             $json['results'] = $this->modelProduct->getRandomProducts($limit);
             break;
         case 'latest':
             $json['results'] = $this->modelProduct->getLatestProducts($limit);
             break;
         case 'featured':
             $json['results'] = $this->modelProduct->getFeaturedProducts($limit);
             break;
         case 'bestseller':
             $json['results'] = $this->modelProduct->getBestSellerProducts($limit);
             break;
         case 'recommended':
             $json['results'] = $this->modelProduct->getRecommendedProducts($limit);
             break;
         case 'special':
             $json['results'] = $this->modelProduct->getProductSpecials('pd.name', 'ASC', 0, $limit);
             break;
     }
     $width = isset($_GET['width']) ? $_GET['width'] : 80;
     $height = isset($_GET['height']) ? $_GET['height'] : 80;
     foreach ($json['results'] as $k => $v) {
         if (!file_exists(DIR_IMAGE . $v['image'])) {
             $json['results'][$k]['image'] = HTTP_IMAGE . "no_image.jpg";
         }
         $json['results'][$k]['thumb'] = NTImage::resizeAndSave($v['image'], $width, $height);
         if ((!$this->config->get('config_customer_price') || $this->customer->isLogged()) && $this->config->get('config_store_mode') === 'store') {
             $json['results'][$k]['price'] = $this->currency->format($this->tax->calculate($v['price'], $v['tax_class_id'], $this->config->get('config_tax')));
         } else {
             $json['results'][$k]['price'] = null;
         }
         $json['results'][$k]['config_store_mode'] = $this->config->get('config_store_mode');
         $json['results'][$k]['seeProduct_url'] = $Url::createUrl('store/product', array('product_id' => $v['product_id']));
         $json['results'][$k]['addToCart_url'] = $Url::createUrl('checkout/cart') . '?product_id=' . $v['product_id'];
     }
     if (!count($json['results'])) {
         $json['error'] = 1;
     }
     $this->response->setOutput(Json::encode($json), $this->config->get('config_compression'));
 }
 /**
  * ControllerContentPage::getForm()
  * 
  * @see Load
  * @see Document
  * @see Model
  * @see Request
  * @see Session
  * @see Redirect
  * @see Language
  * @see Response
  * @see Pagination
  * @return void
  */
 private function getForm()
 {
     $this->data['error_warning'] = isset($this->error['warning']) ? $this->error['warning'] : '';
     $this->data['error_title'] = isset($this->error['title']) ? $this->error['title'] : '';
     $this->data['error_description'] = isset($this->error['description']) ? $this->error['description'] : '';
     $url = '';
     if (isset($this->request->get['page'])) {
         $url .= '&page=' . $this->request->get['page'];
     }
     if (isset($this->request->get['sort'])) {
         $url .= '&sort=' . $this->request->get['sort'];
     }
     if (isset($this->request->get['order'])) {
         $url .= '&order=' . $this->request->get['order'];
     }
     $this->document->breadcrumbs = array();
     $this->document->breadcrumbs[] = array('href' => Url::createAdminUrl('common/home'), 'text' => $this->language->get('text_home'), 'separator' => false);
     $this->document->breadcrumbs[] = array('href' => Url::createAdminUrl('content/page') . $url, 'text' => $this->language->get('heading_title'), 'separator' => ' :: ');
     if (!$this->request->hasQuery('page_id')) {
         $this->data['action'] = Url::createAdminUrl('content/page/insert') . $url;
     } else {
         $this->data['action'] = Url::createAdminUrl('content/page/update') . '&page_id=' . $this->request->getQuery('page_id') . $url;
     }
     $this->data['cancel'] = Url::createAdminUrl('content/page') . $url;
     if ($this->request->hasQuery('page_id') && $this->request->server['REQUEST_METHOD'] != 'POST') {
         $page_info = $this->modelPage->getPage($this->request->getQuery('page_id'));
     }
     $this->setvar('post_id', $page_info, '');
     $this->setvar('parent_id', $page_info, '');
     $this->setvar('image', $page_info, '');
     $this->data['languages'] = $this->modelLanguage->getAll();
     $this->data['pages'] = $this->modelPage->getAll();
     $this->data['stores'] = $this->modelStore->getAll();
     $this->data['_stores'] = $this->modelPage->getStores($this->request->getQuery('page_id'));
     $this->data['customerGroups'] = $this->modelCustomergroup->getAll();
     $this->data['customer_groups'] = $this->modelPage->getProperty($this->request->getQuery('page_id'), 'customer_groups', 'customer_groups');
     $this->data['layout'] = $this->modelPage->getProperty($this->request->getQuery('page_id'), 'style', 'view');
     if (!empty($page_info['image']) && file_exists(DIR_IMAGE . $page_info['image'])) {
         $this->data['preview'] = NTImage::resizeAndSave($page_info['image'], 100, 100);
     } else {
         $this->data['preview'] = NTImage::resizeAndSave('no_image.jpg', 100, 100);
     }
     if (file_exists(DIR_CATALOG . 'view/theme/' . $this->config->get('config_template') . '/common/home.tpl')) {
         $folderTPL = DIR_CATALOG . 'view/theme/' . $this->config->get('config_template') . '/';
     } else {
         $folderTPL = DIR_CATALOG . 'view/theme/default/';
     }
     $directories = glob($folderTPL . "*", GLOB_ONLYDIR);
     $this->data['templates'] = array();
     foreach ($directories as $key => $directory) {
         $this->data['views'][$key]['folder'] = basename($directory);
         $files = glob($directory . "/*.tpl", GLOB_NOSORT);
         foreach ($files as $k => $file) {
             $this->data['views'][$key]['files'][$k] = str_replace("\\", "/", $file);
         }
     }
     if (isset($this->request->post['page_description'])) {
         $this->data['page_description'] = $this->request->post['page_description'];
     } elseif ($this->request->hasQuery('page_id')) {
         $this->data['page_description'] = $this->modelPage->getDescriptions($this->request->getQuery('page_id'));
     } else {
         $this->data['page_description'] = array();
     }
     if (isset($this->request->post['date_publish_start'])) {
         $this->data['date_publish_start'] = date('d-m-Y', strtotime($this->request->post['date_publish_start']));
     } elseif (isset($page_info['date_publish_start']) && $page_info['date_publish_start'] != '0000-00-00 00:00:00') {
         $this->data['date_publish_start'] = date('d-m-Y', strtotime($page_info['date_publish_start']));
     } else {
         $this->data['date_publish_start'] = date('d-m-Y');
     }
     if (isset($this->request->post['date_publish_end'])) {
         $this->data['date_publish_end'] = date('d-m-Y', strtotime($this->request->post['date_publish_end']));
     } elseif (isset($page_info['date_publish_end']) && $page_info['date_publish_end'] != '0000-00-00 00:00:00') {
         $this->data['date_publish_end'] = date('d-m-Y', strtotime($page_info['date_publish_end']));
     } else {
         $this->data['date_publish_end'] = '';
     }
     $scripts[] = array('id' => 'pageForm', 'method' => 'ready', 'script' => "\$('#q').on('change',function(e){\r\n                var that = this;\r\n                var valor = \$(that).val().toLowerCase();\r\n                if (valor.length <= 0) {\r\n                    \$('#customerGroupsWrapper li').show();\r\n                } else {\r\n                    \$('#customerGroupsWrapper li b').each(function(){\r\n                        if (\$(this).text().toLowerCase().indexOf( valor ) != -1) {\r\n                            \$(this).closest('li').show();\r\n                        } else {\r\n                            \$(this).closest('li').hide();\r\n                        }\r\n                    });\r\n                }\r\n            });");
     foreach ($this->data['languages'] as $language) {
         $code = "var editor" . $language["language_id"] . " = CKEDITOR.replace('description" . $language["language_id"] . "', {" . "filebrowserBrowseUrl: '" . Url::createAdminUrl("common/filemanager") . "'," . "filebrowserImageBrowseUrl: '" . Url::createAdminUrl("common/filemanager") . "'," . "filebrowserFlashBrowseUrl: '" . Url::createAdminUrl("common/filemanager") . "'," . "filebrowserUploadUrl: '" . Url::createAdminUrl("common/filemanager") . "'," . "filebrowserImageUploadUrl: '" . Url::createAdminUrl("common/filemanager") . "'," . "filebrowserFlashUploadUrl: '" . Url::createAdminUrl("common/filemanager") . "'," . "height:600" . "});" . "editor" . $language["language_id"] . ".products = '" . $json['products'] . "';" . "editor" . $language["language_id"] . ".config.allowedContent = true;";
         $cssrules = "assets/theme/" . ($this->config->get('config_template') ? $this->config->get('config_template') : 'choroni') . "/css/theme.css";
         if (file_exists(DIR_ROOT . $cssrules)) {
             $code .= "editor" . $language["language_id"] . ".config.contentsCss = '" . HTTP_CATALOG . $cssrules . "';";
         }
         $code .= "\$('#description_" . $language["language_id"] . "_title').change(function(e){" . "\$.getJSON('" . Url::createAdminUrl('common/home/slug') . "'," . "{" . "slug : \$(this).val()," . "query : 'page_id=" . $this->request->getQuery('page_id') . "'," . "}," . "function(data){" . "\$('#description_" . $language["language_id"] . "_keyword').val(data.slug);" . "});" . "});";
         $scripts[] = array('id' => 'pageLanguage' . $language["language_id"], 'method' => 'ready', 'script' => $code);
     }
     $this->scripts = array_merge($this->scripts, $scripts);
     // javascript files
     $jspath = defined("CDN_JS") ? CDN_JS : HTTP_JS;
     $javascripts[] = "js/vendor/ckeditor/ckeditor.js";
     $this->javascripts = array_merge($javascripts, $this->javascripts);
     $this->template = 'content/page_form.tpl';
     $this->children[] = 'common/header';
     $this->children[] = 'common/nav';
     $this->children[] = 'common/footer';
     $this->response->setOutput($this->render(true), $this->config->get('config_compression'));
 }
 public function index()
 {
     $Url = new Url($this->registry);
     if ($this->config->get('config_store_mode') != 'store') {
         $this->redirect(HTTP_HOME);
     }
     $this->language->load('account/register');
     $this->language->load('checkout/cart');
     $this->load->model('localisation/country');
     $this->load->library('image');
     $this->session->set('redirect', Url::createUrl('checkout/cart'));
     if ($this->request->server['REQUEST_METHOD'] == 'GET' && isset($this->request->get['product_id'])) {
         if (isset($this->request->get['option'])) {
             $option = $this->request->get['option'];
         } else {
             $option = array();
         }
         if (isset($this->request->get['quantity'])) {
             $quantity = $this->request->get['quantity'];
         } else {
             $quantity = 1;
         }
         $this->session->clear('shipping_methods');
         $this->session->clear('shipping_method');
         $this->session->clear('payment_methods');
         $this->session->clear('payment_method');
         $this->cart->add($this->request->get['product_id'], $quantity, $option);
         $this->redirect(Url::createUrl("checkout/cart"));
     }
     if ($this->request->server['REQUEST_METHOD'] == 'POST') {
         if (isset($this->request->post['quantity'])) {
             if (!is_array($this->request->post['quantity'])) {
                 if (isset($this->request->post['option'])) {
                     $option = $this->request->post['option'];
                 } else {
                     $option = array();
                 }
                 $this->cart->add($this->request->post['product_id'], $this->request->post['quantity'], $option);
             } else {
                 foreach ($this->request->post['quantity'] as $key => $value) {
                     $this->cart->update($key, $value);
                 }
             }
             $this->session->clear('shipping_methods');
             $this->session->clear('shipping_method');
             $this->session->clear('payment_methods');
             $this->session->clear('payment_method');
         }
         if (isset($this->request->post['redirect'])) {
             $this->session->set('redirect', $this->request->post['redirect']);
         }
         $this->redirect(Url::createUrl("checkout/cart"));
     }
     $this->document->title = $this->data['heading_title'] = $this->language->get('heading_title');
     $this->document->breadcrumbs = array();
     $this->document->breadcrumbs[] = array('href' => Url::createUrl("common/home"), 'text' => $this->language->get('text_home'), 'separator' => false);
     $this->document->breadcrumbs[] = array('href' => Url::createUrl("checkout/cart"), 'text' => $this->language->get('text_basket'), 'separator' => $this->language->get('text_separator'));
     $this->data['breadcrumbs'] = $this->document->breadcrumbs;
     if ($this->cart->hasProducts()) {
         if (isset($this->error['warning'])) {
             $this->data['error_warning'] = $this->error['warning'];
         } elseif (!$this->cart->hasStock() && !$this->config->get('config_stock_checkout')) {
             $this->data['error_warning'] = $this->language->get('error_stock');
         } else {
             $this->data['error_warning'] = '';
         }
         $this->data['action'] = Url::createUrl('checkout/confirm');
         $this->data['products'] = array();
         foreach ($this->cart->getProducts() as $result) {
             $option_data = array();
             foreach ($result['option'] as $option) {
                 $option_data[] = array('name' => $option['name'], 'value' => $option['value']);
             }
             if ($result['image']) {
                 $image = $result['image'];
             } else {
                 $image = 'no_image.jpg';
             }
             $this->data['products'][] = array('key' => $result['key'], 'product_id' => $result['key'], 'name' => $result['name'], 'model' => $result['model'], 'thumb' => NTImage::resizeAndSave($image, $this->config->get('config_image_cart_width'), $this->config->get('config_image_cart_height')), 'option' => $option_data, 'quantity' => $result['quantity'], 'stock' => $result['stock'], 'price' => $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax'))), 'total' => $this->currency->format($this->tax->calculate($result['total'], $result['tax_class_id'], $this->config->get('config_tax'))), 'href' => Url::createUrl("store/product", array("product_id" => $result['product_id'])));
         }
         if (!$this->config->get('config_customer_price') || $this->customer->isLogged()) {
             $this->data['display_price'] = true;
         } else {
             $this->data['display_price'] = false;
         }
         if ($this->config->get('config_cart_weight')) {
             $this->data['weight'] = $this->weight->format($this->cart->getWeight(), $this->config->get('config_weight_class'));
         } else {
             $this->data['weight'] = false;
         }
         $total_data = array();
         $total = 0;
         $taxes = $this->cart->getTaxes();
         $this->load->model('checkout/extension');
         $sort_order = array();
         $results = $this->modelExtension->getExtensions('total');
         foreach ($results as $key => $value) {
             $sort_order[$key] = $this->config->get($value['key'] . '_sort_order');
         }
         array_multisort($sort_order, SORT_ASC, $results);
         foreach ($results as $result) {
             $this->load->model('total/' . $result['key']);
             $this->{'model_total_' . $result['key']}->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->data['totals'] = $total_data;
         if ($this->session->has('message')) {
             $this->data['message'] = $this->session->get('message');
             $this->session->clear('message');
         }
         $this->data['countries'] = $this->modelCountry->getCountries();
         if ($this->customer->isLogged()) {
             $this->data['email'] = $this->customer->getEmail();
             $this->data['firstname'] = $this->customer->getFirstName();
             $this->data['lastname'] = $this->customer->getLastName();
             $this->data['company'] = $this->customer->getCompany();
             $this->data['telephone'] = $this->customer->getTelephone();
             $this->data['rif_type'] = substr($this->customer->getRif(), 0, 1);
             $this->data['rif'] = substr($this->customer->getRif(), 1);
             $this->data['riff'] = $this->customer->getRif();
             $this->data['isLogged'] = $this->customer->isLogged();
             $this->load->auto('account/address');
             $address = $this->modelAddress->getAddress($this->customer->getAddressId());
             if ($address) {
                 $this->data['payment_country_id'] = $address['country_id'];
                 $this->data['payment_zone_id'] = $address['zone_id'];
                 $this->data['payment_city'] = $address['city'];
                 $this->data['payment_street'] = $address['street'];
                 $this->data['payment_address_1'] = $address['address_1'];
                 $this->data['payment_postcode'] = $address['postcode'];
                 $this->data['payment_address'] = $address['address_1'] . " " . $address['street'] . ", " . $address['city'] . ". " . $address['zone'] . " - " . $address['country'];
                 $this->session->set('payment_address_id', $this->customer->getAddressId());
                 $this->data['shipping_country_id'] = $address['country_id'];
                 $this->data['shipping_zone_id'] = $address['zone_id'];
                 $this->data['shipping_city'] = $address['city'];
                 $this->data['shipping_street'] = $address['street'];
                 $this->data['shipping_address_1'] = $address['address_1'];
                 $this->data['shipping_postcode'] = $address['postcode'];
                 $this->data['shipping_address'] = $address['address_1'] . " " . $address['street'] . ", " . $address['city'] . ". " . $address['zone'] . " - " . $address['country'];
                 $this->session->set('shipping_address_id', $this->customer->getAddressId());
             } else {
                 $this->data['no_address'] = true;
             }
             $this->tax->setZone($address['country_id'], $address['zone_id']);
         } else {
             $this->tax->setZone($this->config->get('config_country_id'), $this->config->get('config_zone_id'));
         }
         /*             * ****************** shipping methods ********************** */
         $quote_data = array();
         $results = $this->modelExtension->getExtensions('shipping');
         foreach ($results as $result) {
             $this->load->model('shipping/' . $result['key']);
             $quote = $this->{'model_shipping_' . $result['key']}->getQuote($address);
             if ($quote) {
                 $quote_data[$result['key']] = array('title' => $quote['title'], 'quote' => $quote['quote'], 'sort_order' => $quote['sort_order'], 'error' => $quote['error']);
             }
         }
         $sort_order = array();
         foreach ($quote_data as $key => $value) {
             $sort_order[$key] = $value['sort_order'];
         }
         array_multisort($sort_order, SORT_ASC, $quote_data);
         $this->session->set('shipping_methods', $quote_data);
         $this->data['shipping_methods'] = $quote_data;
         $script = "";
         // SCRIPTS
         if (!$this->customer->isLogged()) {
             $scripts[] = array('id' => 'custom_0_Cart', 'method' => 'ready', 'script' => "\$('#email').on('change',function(e){\r\n                \t\$.post('" . Url::createUrl("account/register/checkemail") . "', {email: \$(this).val()},\r\n                  \t\tfunction(response){\r\n                  \t\t    \$('#tempLink').remove();\r\n                  \t\t    var data = \$.parseJSON(response);\r\n                \t\t\tif (typeof data.error != 'undefined') {\r\n                \t\t\t\t\$('#email').removeClass('neco-input-success').addClass('neco-input-error');\r\n                                \$('#email').parent().find('.neco-form-error').attr({'title':\"Este email ya existe!\"});\r\n                                \$('#email').closest('.property').after('<p id=\"tempLink\" class=\"error\">'+ data.msg +'</p>');\r\n                \t\t\t} else {\r\n                \t\t\t\t\$('#email').addClass('neco-input-success').removeClass('neco-input-error');\r\n                                \$('#email').parent().find('.neco-form-error').attr({'title':\"No hay errores en este campo\"});\r\n                                \$('#tempLink').remove();\r\n                \t\t\t}\r\n                  \t});\r\n                });");
             //TODO: cargar los nombres de los paises y estados en la tabla de confirmacion
             $script = "if (!\$('#email').attr('disabled')) { \r\n                    \$.post('" . Url::createUrl("account/register/register") . "', {\r\n                        email: \$('#email').val(),\r\n                        firstname: \$('#firstname').val(),\r\n                        lastname: \$('#lastname').val(),\r\n                        company: \$('#company').val(),\r\n                        rif: \$('#rif').val(),\r\n                        telephone: \$('#telephone').val(),\r\n                        country_id: \$('#payment_country_id').val(),\r\n                        zone_id: \$('#payment_zone_id').val(),\r\n                        city: \$('#payment_city').val(),\r\n                        street: \$('#payment_street').val(),\r\n                        postcode: \$('#payment_postcode').val(),\r\n                        address_1: \$('#payment_address_1').val(),\r\n                        session_address_var: 'shipping_address_id'\r\n                    },\r\n                    function(data) {\r\n                        \$.post('" . Url::createUrl("checkout/cart/islogged") . "',function(data){\r\n                            if (data) { \r\n                                \$('#email').attr('disabled','disabled');\r\n                                \$('#firstname').attr('disabled','disabled');\r\n                                \$('#lastname').attr('disabled','disabled');\r\n                                \$('#company').attr('disabled','disabled');\r\n                                \$('#rif').attr('disabled','disabled');\r\n                                \$('#telephone').attr('disabled','disabled');\r\n                                \r\n                                \$('#shipping_country_id').val( \$('#payment_country_id').val() );\r\n                                \$('#shipping_zone_id').load('" . Url::createUrl("account/register/zone") . "&country_id='+ \$('#payment_country_id').val() +'&zone_id='+ \$('#payment_zone_id').val());\r\n                                \$('#shipping_street').val( \$('#payment_street').val() );\r\n                                \$('#shipping_city').val( \$('#payment_city').val() );\r\n                                \$('#shipping_postcode').val( \$('#payment_postcode').val() );\r\n                                \$('#shipping_address_1').val( \$('#payment_address_1').val() );\r\n                                \r\n                                \$('#confirmCompany').text(\$('#company').val());\r\n                                \$('#confirmRif').text(\$('#rif').val());\r\n                                \r\n                               var confirmPaymentAddress = \$('#payment_address_1').val() +' '+ \$('#payment_street').val() +', '+ \$('#payment_city').val() +'.';\r\n                                \$('#confirmPaymentAddress').text(confirmPaymentAddress);\r\n                                \$('#confirmShippingAddress').text(confirmPaymentAddress);\r\n                            }\r\n                        });\r\n                    });\r\n                    }";
             $scriptShippingAddress = "\$.post('" . Url::createUrl("account/register/addAddress") . "', {\r\n                        country_id: \$('#shipping_country_id').val(),\r\n                        zone_id: \$('#shipping_zone_id').val(),\r\n                        street: \$('#shipping_street').val(),\r\n                        city: \$('#shipping_city').val(),\r\n                        postcode: \$('#shipping_postcode').val(),\r\n                        address_1: \$('#shipping_address_1').val(),\r\n                        session_address_var: 'shipping_address_id'\r\n                    },\r\n                    function(data) {\r\n                        hasAddress = 1;\r\n                        var confirmShippingAddress = \$('#shipping_address_1').val()  +' '+ \$('#payment_street').val() +', '+ \$('#shipping_city').val() +'.';\r\n                        \$('#confirmShippingAddress').text(confirmShippingAddress);\r\n                    });";
         } elseif ($this->customer->isLogged() && !$this->data['shipping_country_id']) {
             $script = "\$.post('" . Url::createUrl("account/register/addAddress") . "', {\r\n                        country_id: \$('#shipping_country_id').val(),\r\n                        zone_id: \$('#shipping_zone_id').val(),\r\n                        street: \$('#shipping_street').val(),\r\n                        city: \$('#shipping_city').val(),\r\n                        postcode: \$('#shipping_postcode').val(),\r\n                        address_1: \$('#shipping_address_1').val(),\r\n                        session_address_var: 'shipping_address_id'\r\n                    },\r\n                    function(data) {\r\n                        hasAddress = 1;\r\n                        \$('#payment_country_id').val(\$('#shipping_country_id').val());\r\n                        \$('#payment_zone_id').val(\$('#shipping_zone_id').val());\r\n                        \$('#payment_street').val(\$('#shipping_street').val());\r\n                        \$('#payment_city').val(\$('#shipping_city').val());\r\n                        \$('#payment_postcode').val(\$('#shipping_postcode').val());\r\n                        \$('#payment_address_1').val(\$('#shipping_address_1').val());\r\n                        \r\n                        var confirmShippingAddress = \$('#shipping_address_1').val() +', '+ \$('#shipping_city').val() +'.';\r\n                        \r\n                        \$('#confirmShippingAddress').text(confirmShippingAddress);\r\n                        \$('#confirmPaymentAddress').text(confirmShippingAddress);\r\n                    });";
         }
         $scripts[] = array('id' => 'scriptsCart', 'method' => 'ready', 'script' => "\$('#orderForm').ntForm({\r\n                lockButton: false,\r\n                cancelButton: false,\r\n                submitButton: false\r\n            });\r\n            \r\n            \$('select[name=\\'payment_zone_id\\']').load('" . Url::createUrl("account/register/zone") . "&country_id=" . $address['country_id'] . "&zone_id=" . $address['zone_id'] . "');\r\n            \$('select[name=\\'shipping_zone_id\\']').load('" . Url::createUrl("account/register/zone") . "&country_id=" . $address['country_id'] . "&zone_id=" . $address['zone_id'] . "');\r\n            \r\n            var shippingMethods = " . (int) $this->data['shipping_methods'] . ";\r\n            var isLogged = " . (int) $this->customer->isLogged() . ";\r\n            var hasAddress = " . (int) $this->data['shipping_country_id'] . ";\r\n            \$('#contentWrapper').ntWizard({\r\n                next:function(data) {\r\n                    var stepId = \$('.neco-wizard-step-active').attr('id');\r\n                    \$(data.element).find('.neco-wizard-next').text('Siguiente');\r\n                    \$(data.element).find('.neco-wizard-prev').show();\r\n                    \r\n                    if (stepId == 'necoWizardStep_1') {\r\n                        \$(this).find('.neco-wizard-next').text('" . $this->data['button_checkout'] . "');\r\n                        return false;\r\n                    }\r\n                            \r\n                    \r\n                    if (stepId == 'necoWizardStep_2') {\r\n                        var error = false;\r\n                        \r\n                        \$(data.element).find('.neco-wizard-prev').show();\r\n                        \r\n                        /* si hay metodos de envios configurados y debe seleccionar uno */\r\n                        if (shippingMethods && isLogged) {\r\n                            var isChecked = \$('input[name=shipping_method]:checked').val();\r\n                                \r\n                            if (!isChecked) {\r\n                                error = true;\r\n                                alert('Debes seleccionar un m\\u00E9todo de env\\u00EDo');\r\n                            }\r\n                        }\r\n                        \r\n                        if (!isLogged) {\r\n                            \$('#email,#firstname,#lastname,#company,#rif,#telephone,#city,#postcode,#address_1').each(function(e){\r\n                                var value    = !!\$(this).val();\r\n                                var required = \$(this).attr('required');\r\n                                var type     = \$(this).attr('type');\r\n                                var top      = \$(this).offset().top;\r\n                                \r\n                                if (!value) {\r\n                                    error = true;\r\n                                    \$(\"#tempError\").remove();\r\n                                    msg = \$(document.createElement('p')).attr('id','tempError').addClass('neco-submit-error').text('Debes rellenar todos los campos obligatorios identificados con asterisco (*)');\r\n                                    \$(this).removeClass('neco-input-success').addClass('neco-input-error')\r\n                                        .parent()\r\n                                        .find('.neco-form-error')\r\n                                        .attr({'title':'Debes rellenar este campo con la informaci\\u00F3n correspondiente'});\r\n                                }\r\n                                    \r\n                                var pattern = new RegExp(/.[\"\\\\/\\{\\}\\[\\]\\+']/i);\r\n                                if (pattern.test(\$(this).val()) && !error) {\r\n                                    error = true;\r\n                                    \$(\"#tempError\").remove();\r\n                                    msg = \$(document.createElement('p')).attr('id','tempError').addClass('neco-submit-error').text('No se permiten ninguno de estos caracteres especiales [\"#\$/\\'+}{\\u003C\\u003E] en este formulario');\r\n                                    \$(this).removeClass('neco-input-success').addClass('neco-input-error')\r\n                                        .parent()\r\n                                        .find('.neco-form-error')\r\n                                        .attr({'title':'No se permiten ninguno de estos caracteres especiales [\"#\$&/?\\'+}{\\u003C\\u003E] en este campo'});\r\n                                        top = \$(this).offset().top;\r\n                                }\r\n                                    \r\n                                if (type == 'email' && \$(this).val()=='@') {\r\n                                    error = true;\r\n                                    \$(this).removeClass('neco-input-success').addClass('neco-input-error')\r\n                                        .parent()\r\n                                        .find('.neco-form-error')\r\n                                        .attr({'title':'Debes ingresar una direcci\\u00F3n de email v\\u00E1lida'});\r\n                                }\r\n                                \r\n                                if (type == 'email') {\r\n                                    pattern = /^[_a-zA-Z0-9-]+(\\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\\.[a-zA-Z0-9-]+)*\\.(([0-9]{1,3})|([a-zA-Z]{2,4})|(aero|coop|info|museum|name))\$/i;\r\n                                    \$(this).on('change',function(event){\r\n                                        err = checkPattern(pattern,\$(this).val());\r\n                                        if (!err) {\r\n                                            \$(this).removeClass('neco-input-success').addClass('neco-input-error');\r\n                                            \$(this).parent().find('.neco-form-error').attr({'title':\"Debes ingresar una direcci\\u00F3n de email v\\u00E1lida y que exista realmente\"});\r\n                                            error = true;\r\n                                        } else {\r\n                                            \$(this).parent().find('.neco-form-error').attr({'title':\"No hay errores en este campo\"});\r\n                                            \$(this).addClass('neco-input-success').removeClass('neco-input-error');\r\n                                        }\r\n                                    });\r\n                                }\r\n                                    \r\n                                if (type == 'rif') {\r\n                                    var pattern = /\\b[JGVE]-[0-9]{8}-[0-9]{1}\\b/i;\r\n                                    \$(this).on('change',function(event){\r\n                                        err = checkPattern(pattern,\$(this).val());\r\n                                        if (!err) {\r\n                                            \$(this).parent().find('.neco-form-error').attr({'title':\"Debes ingresar un n\\u00FAmero de C\\u00E9dula o RIF v\\u00E1lido para poder continuar\"});\r\n                                            \$(this).removeClass('neco-input-success').addClass('neco-input-error');\r\n                                            error = true;\r\n                                        } else {\r\n                                            \$(this).parent().find('.neco-form-error').attr({'title':\"No hay errores en este campo\"});\r\n                                            \$(this).addClass('neco-input-success').removeClass('neco-input-error');\r\n                                        }\r\n                                    });\r\n                                }\r\n                                    \r\n                                if (\$(this).hasClass('neco-input-error') && !error) {\r\n                                    error = true;\r\n                                    \$(\"#tempError\").remove();\r\n                                    msg = \$(document.createElement('p')).attr('id','tempError').addClass('neco-submit-error').text('Hay errores en el formulario, por favor revise y corr\\u00EDjalos todos para poder continuar');\r\n                                }                        \r\n                            });\r\n                                \r\n                            if (!error) { " . $script . " }\r\n                        } else if (isLogged && !hasAddress) {\r\n                            \$('#shipping_country_id,#shipping_zone_id,#shipping_city,#shipping_street,#shipping_postcode,#shipping_address_1').each(function(e){\r\n                                var value    = !!\$(this).val();\r\n                                var required = \$(this).attr('required');\r\n                                var type     = \$(this).attr('type');\r\n                                var top      = \$(this).offset().top;\r\n                                \r\n                                if (!value) {\r\n                                    error = true;\r\n                                    \$(\"#tempError\").remove();\r\n                                    msg = \$(document.createElement('p')).attr('id','tempError').addClass('neco-submit-error').text('Debes rellenar todos los campos obligatorios identificados con asterisco (*)');\r\n                                    \$(this).removeClass('neco-input-success').addClass('neco-input-error')\r\n                                        .parent()\r\n                                        .find('.neco-form-error')\r\n                                        .attr({'title':'Debes rellenar este campo con la informaci\\u00F3n correspondiente'});\r\n                                }\r\n                                \r\n                                var pattern = new RegExp(/.[\"\\\\/\\{\\}\\[\\]\\+']/i);\r\n                                if (pattern.test(\$(this).val()) && !error) {\r\n                                    error = true;\r\n                                    \$(\"#tempError\").remove();\r\n                                    msg = \$(document.createElement('p')).attr('id','tempError').addClass('neco-submit-error').text('No se permiten ninguno de estos caracteres especiales [\"#\$/\\'+}{\\u003C\\u003E] en este formulario');\r\n                                    \$(this).removeClass('neco-input-success').addClass('neco-input-error')\r\n                                        .parent()\r\n                                        .find('.neco-form-error')\r\n                                        .attr({'title':'No se permiten ninguno de estos caracteres especiales [\"#\$&/?\\'+}{\\u003C\\u003E] en este campo'});\r\n                                    top = \$(this).offset().top;\r\n                                }\r\n                                \r\n                                if (\$(this).hasClass('neco-input-error') && !error) {\r\n                                    error = true;\r\n                                    \$(\"#tempError\").remove();\r\n                                    msg = \$(document.createElement('p')).attr('id','tempError').addClass('neco-submit-error').text('Hay errores en el formulario, por favor revise y corr\\u00EDjalos todos para poder continuar');\r\n                                }                        \r\n                            });\r\n                            \r\n                            if (!error) { " . $script . " }\r\n                                \r\n                        } else if(isLogged && hasAddress && !shippingMethods) {\r\n                            \$.post('" . Url::createUrl("checkout/confirm") . "&resp=json',\r\n                                \$('#orderForm').serialize(),\r\n                                function(data) {\r\n                                    data = \$.parseJSON(data);\r\n                                    location.href = '" . Url::createUrl("checkout/success") . "&order_id='+ order_id;\r\n                                }\r\n                            );\r\n                        }\r\n                        return error;\r\n                    } \r\n                            \r\n                    \r\n                    if (stepId == 'necoWizardStep_3') {\r\n                        var error = false;\r\n                        \r\n                        /* si hay metodos de envios configurados y debe seleccionar uno */\r\n                        if (shippingMethods) {\r\n                            var isChecked = \$('input[name=shipping_method]:checked').val();\r\n                                \r\n                            if (!isChecked) {\r\n                                error = true;\r\n                                alert('Debes seleccionar un m\\u00E9todo de env\\u00EDo');\r\n                            }\r\n                        }\r\n                        \r\n                        if (isLogged === 0 || hasAddress === 0) {\r\n                            \$('#shipping_country_id,#shipping_zone_id,#shipping_city,#shipping_street,#shipping_postcode,#shipping_address_1').each(function(e){\r\n                                var value    = !!\$(this).val();\r\n                                var required = \$(this).attr('required');\r\n                                var type     = \$(this).attr('type');\r\n                                var top      = \$(this).offset().top;\r\n                                \r\n                                if (!value) {\r\n                                    error = true;\r\n                                    \$(\"#tempError\").remove();\r\n                                    msg = \$(document.createElement('p')).attr('id','tempError').addClass('neco-submit-error').text('Debes rellenar todos los campos obligatorios identificados con asterisco (*)');\r\n                                    \$(this).removeClass('neco-input-success').addClass('neco-input-error')\r\n                                        .parent()\r\n                                        .find('.neco-form-error')\r\n                                        .attr({'title':'Debes rellenar este campo con la informaci\\u00F3n correspondiente'});\r\n                                }\r\n                                    \r\n                                var pattern = new RegExp(/.[\"\\\\/\\{\\}\\[\\]\\+']/i);\r\n                                if (pattern.test(\$(this).val()) && !error) {\r\n                                    error = true;\r\n                                    \$(\"#tempError\").remove();\r\n                                    msg = \$(document.createElement('p')).attr('id','tempError').addClass('neco-submit-error').text('No se permiten ninguno de estos caracteres especiales [\"#\$/\\'+}{\\u003C\\u003E] en este formulario');\r\n                                    \$(this).removeClass('neco-input-success').addClass('neco-input-error')\r\n                                        .parent()\r\n                                        .find('.neco-form-error')\r\n                                        .attr({'title':'No se permiten ninguno de estos caracteres especiales [\"#\$&/?\\'+}{\\u003C\\u003E] en este campo'});\r\n                                        top = \$(this).offset().top;\r\n                                }\r\n                                    \r\n                                if (\$(this).hasClass('neco-input-error') && !error) {\r\n                                    error = true;\r\n                                    \$(\"#tempError\").remove();\r\n                                    msg = \$(document.createElement('p')).attr('id','tempError').addClass('neco-submit-error').text('Hay errores en el formulario, por favor revise y corr\\u00EDjalos todos para poder continuar');\r\n                                }                        \r\n                            });\r\n                            \r\n                            if (!error) { " . $scriptShippingAddress . " }\r\n                        } else {\r\n                            \$.post('" . Url::createUrl("checkout/confirm") . "&resp=json',\r\n                                \$('#orderForm').serialize(),\r\n                                function(data) {\r\n                                    data = \$.parseJSON(data);\r\n                                    location.href = '" . Url::createUrl("checkout/success") . "&order_id='+ data.order_id;\r\n                                }\r\n                            );\r\n                        }\r\n                        return error;\r\n                    }\r\n                    \r\n                    if (stepId == 'necoWizardStep_4') {\r\n                        var error = false;\r\n                        var isLogged = " . (int) $this->customer->isLogged() . ";\r\n                        if (isLogged > 0) {\r\n                            \$.post('" . Url::createUrl("checkout/confirm") . "&resp=json',\r\n                                \$('#orderForm').serialize(),\r\n                                function(data) {\r\n                                    data = \$.parseJSON(data);\r\n                                    location.href = '" . Url::createUrl("checkout/success") . "&order_id='+ data.order_id;\r\n                                }\r\n                            );\r\n                        }\r\n                        return error;\r\n                    }\r\n                },\r\n                prev:function(data) {\r\n                    var stepId = \$('.neco-wizard-step-active').attr('id');\r\n                    if (stepId == 'necoWizardStep_2') {\r\n                        \$('#contentWrapper').find('.neco-wizard-prev').hide();\r\n                        \$('#contentWrapper').find('.neco-wizard-next').text('Procesar Pedido');\r\n                        \$(this).find('.neco-wizard-next').text('" . $this->data['button_checkout'] . "');\r\n                    }\r\n                    if (stepId == 'necoWizardStep_3') {\r\n                        \$('input').each(function(){ \r\n                            \$(this).removeClass('neco-input-success'); \r\n                        }); \r\n                    }\r\n                },\r\n                create: function(e) {\r\n                    \$(e).find('.neco-wizard-next').text('" . $this->data['button_checkout'] . "');\r\n                }\r\n            }).find('.neco-wizard-next').text('Procesar Pedido');\r\n            \$('#contentWrapper').find('.neco-wizard-prev').hide();\r\n                    \r\n            \$('input[name=shipping_method]').on('change',function(e){\r\n                var tr = \$('input[name=shipping_method]:checked').closest('tr');\r\n                var title = tr.find('b:eq(0)').text();\r\n                var price = tr.find('b:eq(1)').text();\r\n                \$('#shipping_method').html(title + ' ' + price);\r\n            });\r\n            ");
         $scripts[] = array('id' => 'functionsCart', 'method' => 'function', 'script' => "function deleteCart(e,k) {\r\n                \$('#totals').html('<img src=\"" . HTTP_IMAGE . "load.gif\" alt=\"Cargando...\" />'); \r\n                \$(e).closest('tr').remove();\r\n                \$('#confirmItem'+ k).remove();\r\n                \$.getJSON('" . Url::createUrl('checkout/cart/delete') . "',\r\n                    {\r\n                        key:k\r\n                    },\r\n                    function(data){\r\n                        if (!data.error) { \r\n                            \$('#weight').html(data.weight);\r\n                            \$('#totals').html(data.totals);\r\n                            \$('#totalsConfirm').html(data.totals); \r\n                        } else { \r\n                            \$('#cart').html(data.error); \r\n                            \$('#weight').html('0.00kg');\r\n                        } \r\n                    }\r\n                );\r\n            }\r\n            function refreshCart(e,k) {\r\n                \$('#totals').html('<img src=\"" . HTTP_IMAGE . "load.gif\" alt=\"Cargando...\" />'); \r\n                if (e.tagName != 'INPUT') {\r\n                    e = \$(e).prev('input');\r\n                }\r\n                var price = \$(e).closest('tr').find('td:nth-child(6)');\r\n                \r\n                var values = price.text().split(',');\r\n                values[0] = values[0].replace(/\\./g,'').replace(/\\D+/,'');\r\n                var intValue = Number( values[0].replace(/[^0-9\\.]+/g,'') );\r\n                var floatValue = parseInt( Number( values[1].replace(/[^0-9\\.]+/g,'') ) );\r\n                price = parseFloat( intValue + '.' + floatValue );\r\n                var totalValue = Math.round( (parseInt( \$(e).val() ) * price) * 100) / 100;\r\n                \$(e).closest('tr').find('td:nth-child(7)').text('Bs. ' + totalValue );\r\n                \r\n                \$('#confirmTotal'+ k).text( 'Bs. ' + totalValue );\r\n                \$('#confirmQty'+ k).text( \$(e).val() );\r\n                \r\n                \$.getJSON('" . Url::createUrl('checkout/cart/refresh') . "',\r\n                    {\r\n                        key:k,\r\n                        quantity:\$(e).val()\r\n                    },\r\n                    function(data){\r\n                        if (!data.error) { \r\n                            \$('#weight').html(data.weight);\r\n                            \$('#totals').html(data.totals); \r\n                            \$('#totalsConfirm').html(data.totals); \r\n                        } else { \r\n                            \$('#cart').html(data.error); \r\n                            \$('#weight').html('0.00kg');\r\n                        } \r\n                    }\r\n                );\r\n            }\r\n            function checkPattern(pat,value) {\r\n                pattern = new RegExp(pat);\r\n                return pattern.test(value);  \r\n            }");
         $this->scripts = array_merge($this->scripts, $scripts);
         // javascript files
         $jspath = defined("CDN_JS") ? CDN_JS : HTTP_JS;
         $javascripts[] = $jspath . "necojs/neco.form.js";
         $javascripts[] = $jspath . "necojs/neco.wizard.js";
         $javascripts[] = $jspath . "vendor/jquery-ui.min.js";
         $this->javascripts = array_merge($this->javascripts, $javascripts);
         // style files
         $csspath = defined("CDN") ? CDN . CSS : HTTP_CSS;
         $styles[] = array('media' => 'all', 'href' => $csspath . 'jquery-ui/jquery-ui.min.css');
         $styles[] = array('media' => 'all', 'href' => $csspath . 'neco.form.css');
         $styles[] = array('media' => 'all', 'href' => $csspath . 'neco.wizard.css');
         $this->data['styles'] = $this->styles = array_merge($this->styles, $styles);
         $this->loadWidgets();
         if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/checkout/cart.tpl')) {
             $this->template = $this->config->get('config_template') . '/checkout/cart.tpl';
         } else {
             $this->template = 'choroni/checkout/cart.tpl';
         }
     } else {
         $this->data['heading_title'] = $this->language->get('heading_title');
         $this->data['text_error'] = $this->language->get('text_error');
         $this->data['button_continue'] = $this->language->get('button_continue');
         $this->data['continue'] = Url::createUrl("common/home");
         $this->loadWidgets();
         if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/error/not_found.tpl')) {
             $this->template = $this->config->get('config_template') . '/error/not_found.tpl';
         } else {
             $this->template = 'choroni/error/not_found.tpl';
         }
     }
     $this->children[] = 'common/column_left';
     $this->children[] = 'common/column_right';
     $this->children[] = 'common/nav';
     $this->children[] = 'common/header';
     $this->children[] = 'common/footer';
     $this->response->setOutput($this->render(true), $this->config->get('config_compression'));
 }
 public function index()
 {
     $this->document->title = $this->language->get('heading_title');
     if ($this->request->server['REQUEST_METHOD'] == 'POST' && $this->validate()) {
         if (isset($this->request->post['config_token_ignore'])) {
             $this->request->post['config_token_ignore'] = serialize($this->request->post['config_token_ignore']);
         }
         $this->modelSetting->update('config', $this->request->post);
         if ($this->config->get('config_currency_auto')) {
             $this->modelCurrency->updateAll();
         }
         $this->session->set('success', $this->language->get('text_success'));
         $this->redirect(Url::createAdminUrl('setting/setting'));
     }
     if (isset($this->request->post['config_maintenance'])) {
         $this->modelSetting->editMaintenance($this->request->post['config_maintenance']);
     }
     $this->data['error_warning'] = isset($this->error['warning']) ? $this->error['warning'] : null;
     $this->data['error_name'] = isset($this->error['name']) ? $this->error['name'] : null;
     $this->data['error_rif'] = isset($this->error['rif']) ? $this->error['rif'] : null;
     $this->data['error_url'] = isset($this->error['url']) ? $this->error['url'] : null;
     $this->data['error_owner'] = isset($this->error['owner']) ? $this->error['owner'] : null;
     $this->data['error_address'] = isset($this->error['address']) ? $this->error['address'] : null;
     $this->data['error_email'] = isset($this->error['email']) ? $this->error['email'] : null;
     $this->data['error_telephone'] = isset($this->error['telephone']) ? $this->error['telephone'] : null;
     $this->data['error_title'] = isset($this->error['title']) ? $this->error['title'] : null;
     $this->data['error_image_thumb'] = isset($this->error['image_thumb']) ? $this->error['image_thumb'] : null;
     $this->data['error_image_popup'] = isset($this->error['image_popup']) ? $this->error['image_popup'] : null;
     $this->data['error_image_category'] = isset($this->error['image_category']) ? $this->error['image_category'] : null;
     $this->data['error_image_product'] = isset($this->error['image_product']) ? $this->error['image_product'] : null;
     $this->data['error_image_additional'] = isset($this->error['image_additional']) ? $this->error['image_additional'] : null;
     $this->data['error_image_related'] = isset($this->error['image_related']) ? $this->error['image_related'] : null;
     $this->data['error_image_cart'] = isset($this->error['image_cart']) ? $this->error['image_cart'] : null;
     $this->data['error_error_filename'] = isset($this->error['error_filename']) ? $this->error['error_filename'] : null;
     $this->data['error_catalog_limit'] = isset($this->error['catalog_limit']) ? $this->error['catalog_limit'] : null;
     $this->data['error_admin_limit'] = isset($this->error['admin_limit']) ? $this->error['admin_limit'] : null;
     $this->data['error_thousands_separator'] = isset($this->error['thousands_separator']) ? $this->error['thousands_separator'] : null;
     $this->data['error_decimal_separator'] = isset($this->error['decimal_separator']) ? $this->error['decimal_separator'] : null;
     $this->data['error_smtp_host'] = isset($this->error['smtp_host']) ? $this->error['smtp_host'] : null;
     $this->data['error_pop3_host'] = isset($this->error['pop3_host']) ? $this->error['pop3_host'] : null;
     $this->data['error_pop3_port'] = isset($this->error['pop3_port']) ? $this->error['pop3_port'] : null;
     $this->data['error_smtp_port'] = isset($this->error['smtp_port']) ? $this->error['smtp_port'] : null;
     $this->data['error_smtp_from_email'] = isset($this->error['smtp_from_email']) ? $this->error['smtp_from_email'] : null;
     $this->data['error_smtp_timeout'] = isset($this->error['smtp_timeout']) ? $this->error['smtp_timeout'] : null;
     $this->data['error_bounce_email'] = isset($this->error['bounce_email']) ? $this->error['bounce_email'] : null;
     $this->data['error_replyto_email'] = isset($this->error['replyto_email']) ? $this->error['replyto_email'] : null;
     $this->document->breadcrumbs = array();
     $this->document->breadcrumbs[] = array('href' => Url::createAdminUrl('common/home'), 'text' => $this->language->get('text_home'), 'separator' => false);
     $this->document->breadcrumbs[] = array('href' => Url::createAdminUrl('setting/setting'), 'text' => $this->language->get('heading_title'), 'separator' => ' :: ');
     if ($this->session->has('success')) {
         $this->data['success'] = $this->session->get('success');
         $this->session->clear('success');
     } else {
         $this->data['success'] = '';
     }
     $this->data['cancel'] = Url::createAdminUrl('setting/setting');
     $this->data['action'] = Url::createAdminUrl('setting/setting');
     $model = $this->modelSetting->getSetting('config');
     $this->setvar('config_name', $model);
     $this->setvar('config_rif', $model);
     $this->setvar('config_url', $model);
     $this->setvar('config_owner', $model);
     $this->setvar('config_address', $model);
     $this->setvar('config_email', $model);
     $this->setvar('config_telephone', $model);
     $this->setvar('config_fax', $model);
     $this->setvar('config_title', $model);
     $this->setvar('config_meta_description', $model);
     $this->setvar('config_template', $model);
     $this->setvar('config_mobile_template', $model);
     $this->setvar('config_tablet_template', $model);
     $this->setvar('config_facebook_template', $model);
     $this->setvar('config_mobile_url', $model);
     $this->setvar('config_tablet_url', $model);
     $this->setvar('config_facebbok_url', $model);
     $this->setvar('config_redirect_when_mobile', $model);
     $this->setvar('config_redirect_when_tablet', $model);
     $this->setvar('config_redirect_when_facebook', $model);
     $this->setvar('config_decimal_separator', $model);
     $this->setvar('config_thousands_separator', $model);
     $this->setvar('config_country_id', $model);
     $this->setvar('config_zone_id', $model);
     $this->setvar('config_language', $model);
     $this->setvar('config_admin_language', $model);
     $this->setvar('config_currency', $model);
     $this->setvar('config_currency_auto', $model);
     $this->setvar('config_tax', $model);
     $this->setvar('config_customer_group_id', $model);
     $this->setvar('config_customer_price', $model);
     $this->setvar('config_customer_approval', $model);
     $this->setvar('config_account_id', $model);
     $this->setvar('config_store_mode', $model);
     $this->setvar('config_checkout_id', $model);
     $this->setvar('config_stock_display', $model);
     $this->setvar('config_stock_checkout', $model);
     $this->setvar('config_order_status_id', $model);
     $this->setvar('config_order_status_paid', $model);
     $this->setvar('config_order_status_nulled', $model);
     $this->setvar('config_order_status_shipping', $model);
     $this->setvar('config_order_status_delivered', $model);
     $this->setvar('config_order_status_aborted', $model);
     $this->setvar('config_order_status_loading', $model);
     $this->setvar('config_order_status_returned', $model);
     $this->setvar('config_order_payment_status_id', $model);
     $this->setvar('config_order_payment_status_approved', $model);
     $this->setvar('config_order_payment_status_no_approved', $model);
     $this->setvar('config_order_payment_status_returned', $model);
     $this->setvar('config_shipping_session', $model);
     $this->setvar('config_admin_limit', $model);
     $this->setvar('config_catalog_limit', $model);
     $this->setvar('config_new_days', $model);
     $this->setvar('config_cart_weight', $model);
     $this->setvar('config_review', $model);
     $this->setvar('config_review_approve', $model);
     $this->setvar('config_logo', $model);
     $this->setvar('config_email_logo', $model);
     $this->setvar('config_mobile_logo', $model);
     $this->setvar('config_icon', $model);
     $this->setvar('config_image_thumb_width', $model);
     $this->setvar('config_image_thumb_height', $model);
     $this->setvar('config_image_popup_width', $model);
     $this->setvar('config_image_popup_height', $model);
     $this->setvar('config_image_category_width', $model);
     $this->setvar('config_image_category_height', $model);
     $this->setvar('config_image_post_width', $model);
     $this->setvar('config_image_post_height', $model);
     $this->setvar('config_image_product_width', $model);
     $this->setvar('config_image_product_height', $model);
     $this->setvar('config_image_additional_width', $model);
     $this->setvar('config_image_additional_height', $model);
     $this->setvar('config_image_related_width', $model);
     $this->setvar('config_image_related_height', $model);
     $this->setvar('config_image_cart_width', $model);
     $this->setvar('config_image_cart_height', $model);
     $this->setvar('config_mail_protocol', $model);
     $this->setvar('config_smtp_host', $model);
     $this->setvar('config_pop3_host', $model);
     $this->setvar('config_smtp_from_email', $model);
     $this->setvar('config_smtp_from_name', $model);
     $this->setvar('config_smtp_username', $model);
     $this->setvar('config_smtp_password', $model);
     $this->setvar('config_smtp_method', $model, 'mail');
     $this->setvar('config_smtp_port', $model, 25);
     $this->setvar('config_pop3_protocol', $model, 'pop3');
     $this->setvar('config_pop3_port', $model, 110);
     $this->setvar('config_smtp_timeout', $model, 5);
     $this->setvar('config_smtp_maxsize', $model, 0);
     $this->setvar('config_smtp_charset', $model, 'iso-8859-1');
     $this->setvar('config_alert_mail', $model);
     $this->setvar('config_smtp_auth', $model);
     $this->setvar('config_alert_emails');
     $this->setvar('config_mail_parameter', $model);
     $this->setvar('config_ssl', $model);
     $this->setvar('config_pop3_ssl', $model);
     $this->setvar('config_smtp_ssl', $model);
     $this->setvar('config_bounce_email', $model, $this->config->get('config_pop3_email'));
     $this->setvar('config_replyto_email', $model, '');
     $this->setvar('config_bounce_server', $model, '');
     $this->setvar('config_bounce_username', $model, '');
     $this->setvar('config_bounce_password', $model, '');
     $this->setvar('config_bounce_protocol', $model, '');
     $this->setvar('config_bounce_extra_settings', $model, '');
     $this->setvar('config_bounce_protocol', $model, 'pop3');
     $this->setvar('config_bounce_process', $model, 0);
     $this->setvar('config_bounce_agree_delete', $model, 0);
     $this->setvar('config_bounce_extra_settings', $model, '');
     $this->setvar('config_bounce_extra_settings', $model, '');
     $this->setvar('config_maintenance', $model);
     $this->setvar('config_encryption', $model);
     $this->setvar('config_js_security', $model);
     $this->setvar('config_js_security', $model);
     $this->setvar('config_server_security', $model);
     $this->setvar('config_password_security', $model);
     $this->setvar('config_seo_url', $model);
     $this->setvar('config_compression', $model);
     $this->setvar('config_error_display', $model);
     $this->setvar('config_error_log', $model);
     $this->setvar('config_error_filename', $model);
     $this->setvar('config_dir_export', $model);
     $directories = glob(DIR_CATALOG . 'view/theme/*', GLOB_ONLYDIR);
     $this->data['templates'] = array();
     foreach ($directories as $directory) {
         $this->data['templates'][] = basename($directory);
     }
     $languages = $this->data['languages'] = $this->modelLanguage->getAll();
     foreach ($languages as $language) {
         if (isset($this->request->post['config_title_' . $language['language_id']])) {
             $this->data['config_title_' . $language['language_id']] = $this->request->post['config_title_' . $language['language_id']];
         } elseif ($model['config_title_' . $language['language_id']]) {
             $this->data['config_title_' . $language['language_id']] = $model['config_title_' . $language['language_id']];
         } else {
             $this->data['config_title_' . $language['language_id']] = $this->config->get('config_title_' . $language['language_id']);
         }
         if (isset($this->request->post['config_meta_description_' . $language['language_id']])) {
             $this->data['config_meta_description_' . $language['language_id']] = $this->request->post['config_meta_description_' . $language['language_id']];
         } elseif ($model['config_meta_description_' . $language['language_id']]) {
             $this->data['config_meta_description_' . $language['language_id']] = $model['config_meta_description_' . $language['language_id']];
         } else {
             $this->data['config_meta_description_' . $language['language_id']] = $this->config->get('config_meta_description_' . $language['language_id']);
         }
         if (isset($this->request->post['config_description_' . $language['language_id']])) {
             $this->data['config_description_' . $language['language_id']] = $this->request->post['config_description_' . $language['language_id']];
         } elseif ($model['config_description_' . $language['language_id']]) {
             $this->data['config_description_' . $language['language_id']] = $model['config_description_' . $language['language_id']];
         } else {
             $this->data['config_description_' . $language['language_id']] = $this->config->get('config_description_' . $language['language_id']);
         }
     }
     $this->data['countries'] = $this->modelCountry->getAll();
     $this->data['currencies'] = $this->modelCurrency->getAll();
     $this->data['customer_groups'] = $this->modelCustomergroup->getAll();
     $this->data['order_statuses'] = $this->modelOrderstatus->getAll();
     $this->data['order_payment_statuses'] = $this->modelOrderpaymentstatus->getAll();
     $this->data['stock_statuses'] = $this->modelStockstatus->getAll();
     if (!empty($this->request->post['config_logo']) && file_exists(DIR_IMAGE . $this->request->post['config_logo'])) {
         $this->data['preview_logo'] = HTTP_IMAGE . $this->request->post['config_logo'];
     } elseif (!empty($model['config_logo']) && file_exists(DIR_IMAGE . $model['config_logo'])) {
         $this->data['preview_logo'] = HTTP_IMAGE . $model['config_logo'];
     } else {
         $this->data['preview_logo'] = NTImage::resizeAndSave('no_image.jpg', 100, 100);
     }
     if (!empty($this->request->post['config_email_logo']) && file_exists(DIR_IMAGE . $this->request->post['config_email_logo'])) {
         $this->data['preview_email_logo'] = HTTP_IMAGE . $this->request->post['config_email_logo'];
     } elseif (!empty($model['config_email_logo']) && file_exists(DIR_IMAGE . $model['config_email_logo'])) {
         $this->data['preview_email_logo'] = HTTP_IMAGE . $model['config_email_logo'];
     } else {
         $this->data['preview_email_logo'] = NTImage::resizeAndSave('no_image.jpg', 100, 100);
     }
     if (!empty($this->request->post['config_mobile_logo']) && file_exists(DIR_IMAGE . $this->request->post['config_mobile_logo'])) {
         $this->data['preview_mobile_logo'] = HTTP_IMAGE . $this->request->post['config_mobile_logo'];
     } elseif (!empty($model['config_mobile_logo']) && file_exists(DIR_IMAGE . $model['config_mobile_logo'])) {
         $this->data['preview_mobile_logo'] = HTTP_IMAGE . $model['config_mobile_logo'];
     } else {
         $this->data['preview_mobile_logo'] = NTImage::resizeAndSave('no_image.jpg', 100, 100);
     }
     if (!empty($this->request->post['config_icon']) && file_exists(DIR_IMAGE . $this->request->post['config_icon'])) {
         $this->data['preview_icon'] = HTTP_IMAGE . $this->request->post['config_icon'];
     } elseif (!empty($model['config_logo']) && file_exists(DIR_IMAGE . $model['config_icon'])) {
         $this->data['preview_icon'] = HTTP_IMAGE . $model['config_icon'];
     } else {
         $this->data['preview_icon'] = NTImage::resizeAndSave('no_image.jpg', 100, 100);
     }
     $ignore = array('common/login', 'common/logout', 'error/not_found', 'error/permission');
     $this->data['tokens'] = array();
     $files = glob(DIR_APPLICATION . 'controller/*/*.php');
     foreach ($files as $file) {
         $data = explode('/', dirname($file));
         $token = end($data) . '/' . basename($file, '.php');
         if (!in_array($token, $ignore)) {
             $this->data['tokens'][] = $token;
         }
     }
     if (isset($this->request->post['config_token_ignore'])) {
         $this->data['config_token_ignore'] = $this->request->post['config_token_ignore'];
     } elseif (isset($model['config_token_ignore'])) {
         $this->data['config_token_ignore'] = unserialize($model['config_token_ignore']);
     } else {
         $this->data['config_token_ignore'] = array();
     }
     foreach ($this->data['languages'] as $language) {
         $code = "var editor" . $language["language_id"] . " = CKEDITOR.replace('description" . $language["language_id"] . "', {" . "filebrowserBrowseUrl: '" . Url::createAdminUrl("common/filemanager") . "'," . "filebrowserImageBrowseUrl: '" . Url::createAdminUrl("common/filemanager") . "'," . "filebrowserFlashBrowseUrl: '" . Url::createAdminUrl("common/filemanager") . "'," . "filebrowserUploadUrl: '" . Url::createAdminUrl("common/filemanager") . "'," . "filebrowserImageUploadUrl: '" . Url::createAdminUrl("common/filemanager") . "'," . "filebrowserFlashUploadUrl: '" . Url::createAdminUrl("common/filemanager") . "'," . "height:600" . "});" . "editor" . $language["language_id"] . ".products = '" . $json['products'] . "';" . "editor" . $language["language_id"] . ".config.allowedContent = true;";
         $cssrules = "assets/theme/" . ($this->config->get('config_template') ? $this->config->get('config_template') : 'choroni') . "/css/theme.css";
         if (file_exists(DIR_ROOT . $cssrules)) {
             $code .= "editor" . $language["language_id"] . ".config.contentsCss = '" . HTTP_CATALOG . $cssrules . "';";
         }
         $scripts[] = array('id' => 'pageLanguage' . $language["language_id"], 'method' => 'ready', 'script' => $code);
     }
     $scripts[] = array('id' => 'Functions', 'method' => 'function', 'script' => "function image_delete(field, preview) {\r\n                \$('#' + field).val('');\r\n                \$('#' + preview).attr('src','" . HTTP_IMAGE . "cache/no_image-100x100.jpg');\r\n            }");
     $this->scripts = array_merge($this->scripts, $scripts);
     // javascript files
     $jspath = defined("CDN_JS") ? CDN_JS : HTTP_JS;
     $javascripts[] = "js/vendor/ckeditor/ckeditor.js";
     $this->javascripts = array_merge($javascripts, $this->javascripts);
     $this->template = 'setting/setting.tpl';
     $this->children[] = 'common/header';
     $this->children[] = 'common/nav';
     $this->children[] = 'common/footer';
     $this->response->setOutput($this->render(true), $this->config->get('config_compression'));
 }
 public function getById()
 {
     $product_id = $this->request->get['product_id'];
     $this->load->auto('store/product');
     $this->load->auto('image');
     $this->load->auto('tax');
     $this->load->auto('currency');
     $tax = new Tax($this->registry);
     $currency = new Currency($this->registry);
     $strProducts = '';
     $product = $this->modelProduct->getById($product_id);
     $tags = $this->modelProduct->getTags($product_id);
     if (isset($this->request->get['format']) && !empty($this->request->get['format'])) {
         $strProducts .= "Producto: " . $product['name'] . "\n";
         $strProducts .= "Precio: " . $currency->format($tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax'))) . "\n";
         //TODO: cureency format
         $strProducts .= "URL: " . Url::createUrl("product/product", array("product_id" => $product['product_id']), "NONSSL", HTTP_CATALOG . "/");
         if ($tags) {
             foreach ($tags as $key => $tag) {
                 $ntag = $key + 1;
                 $strProducts .= "\nTag " . $ntag . ": " . Url::createUrl("product/search", array("keyword" => $tag['tag']), "NONSSL", HTTP_CATALOG . "/") . "\n";
             }
         }
         $strProducts .= "\n";
         echo $strProducts;
     } else {
         $strProducts .= "<div style='margin:5px;padding:3px;background:#FFF;float:left;border:dotted 1px #ccc;width:100px;display:block;text-align:center'>";
         $strProducts .= "<br><p><a href='" . Url::createUrl("product/product", array("product_id" => $product['product_id']), "NONSSL", HTTP_CATALOG . "/") . "'>" . $product['name'] . "</a></p>";
         if (empty($product['image'])) {
             $strProducts .= "<a href='" . Url::createUrl("product/product", array("product_id" => $product['product_id']), "NONSSL", HTTP_CATALOG . "/") . "'>";
             $strProducts .= "<img src='" . NTImage::resizeAndSave('no_image.jpg', 50, 50) . "' alt='" . $product['name'] . "'>";
             $strProducts .= "</a>";
         } else {
             $strProducts .= "<a href='" . Url::createUrl("product/product", array("product_id" => $product['product_id'])) . "'>";
             $strProducts .= "<img src='" . NTImage::resizeAndSave($product['image'], 50, 50) . "' alt='" . $product['name'] . "'>";
             $strProducts .= "</a>";
         }
         $strProducts .= "<input type='hidden' name='" . $product['product_id'] . "' value='" . $product['product_id'] . "'>";
         $strProducts .= "<br><b>" . $currency->format($tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax'))) . "</b><br>";
         if ($tags) {
             foreach ($tags as $key => $tag) {
                 $strProducts .= "&nbsp;&nbsp;<a href='" . Url::createUrl("product/search", array("keyword" => $tag['tag']), "NONSSL", HTTP_CATALOG . "/") . "' style='font:normal 9px verdana'>" . $tag['tag'] . "</a>&nbsp;&nbsp;";
             }
         }
         $strProducts .= "<br></div>";
         echo $strProducts;
     }
 }
 public function promote()
 {
     if ($this->google->getAccessToken()) {
         $reqUrl = 'https://www.google.com/m8/feeds/contacts/default/full?max-results=1000';
         $req = new Google_HttpRequest($reqUrl);
         $googleAuth = $this->google->getIo()->authenticatedRequest($req);
         $xml = simplexml_load_string($googleAuth->getResponseBody());
         $response = json_encode($xml);
         $reqUrl = 'https://www.googleapis.com/oauth2/v2/userinfo';
         $req = new Google_HttpRequest($reqUrl);
         $userInfo = json_decode($this->google->getIo()->authenticatedRequest($req)->getResponseBody());
         $xml->registerXPathNamespace('gd', 'http://schemas.google.com/g/2005');
         $list = $this->db->query("SELECT * \n            FROM " . DB_PREFIX . "contact_list \n            WHERE name = \"Amigos de " . $this->db->escape(addslashes($userInfo->name)) . " (" . $this->db->escape(addslashes($userInfo->email)) . ") en Google\"");
         if ($list->num_rows) {
             $list_id = $list->row['contact_list_id'];
         } else {
             $this->db->query("INSERT INTO " . DB_PREFIX . "contact_list SET \n                name        = \"Amigos de " . $this->db->escape(addslashes($userInfo->name)) . " (" . $this->db->escape(addslashes($userInfo->email)) . ") en Google\",\n                description = \"Amigos de " . $this->db->escape(addslashes($userInfo->name)) . " (" . $this->db->escape(addslashes($userInfo->email)) . ") en Google\",\n                date_added  = NOW()");
             $list_id = $this->db->getLastId();
         }
         $to = array();
         $control = array();
         foreach ($xml->entry as $entry) {
             foreach ($entry->xpath('gd:email') as $value) {
                 $name = str_replace("'", '', (string) $entry->title);
                 $email = (string) $value->attributes()->address;
                 if (empty($email)) {
                     continue;
                 }
                 $customer = $this->db->query("SELECT * FROM " . DB_PREFIX . "customer WHERE email = '" . $this->db->escape($email) . "'");
                 $contact = $this->db->query("SELECT * FROM " . DB_PREFIX . "contact WHERE email = '" . $this->db->escape($email) . "'");
                 if (!$contact->row) {
                     $this->db->query("INSERT INTO " . DB_PREFIX . "contact SET \n                              name        = '" . $this->db->escape($name) . "',\n                              email       = '" . $this->db->escape($email) . "', \n                              customer_id = '" . (int) $customer->row['customer_id'] . "',\n                              date_added  = NOW()");
                     $contact_id = $this->db->getLastId();
                     $this->db->query("INSERT INTO " . DB_PREFIX . "contact_to_list SET \n                            contact_id     = '" . (int) $contact_id . "',\n                            contact_list_id= '" . (int) $list_id . "',\n                            date_added    = NOW()");
                 } else {
                     $contact_id = $contact->row['contact_id'];
                 }
                 if (!in_array($email, $control) && !empty($email)) {
                     $control[] = $email;
                     $to[] = array('contact_id' => $contact_id, 'name' => $name, 'email' => $email);
                 }
             }
         }
         if ($this->config->get('marketing_email_promote_product')) {
             $this->load->model('marketing/newsletter');
             $product = array();
             $product_id = $this->request->hasQuery('product_id') ? $this->request->getQuery('product_id') : $this->session->get('promote_product_id');
             $this->session->set('promote_product_id', $product_id);
             if ($product_id) {
                 $this->load->model('store/product');
                 $product = $this->modelProduct->getProduct($product_id);
                 if ($product) {
                     $this->load->model('store/product');
                     $Url = new Url($this->registry);
                     //Libs
                     $this->load->auto('image');
                     $this->load->auto('currency');
                     $this->load->auto('tax');
                     $product['url'] = $Url::createUrl('store/product', array('product_id' => $product['product_id']));
                     $image = isset($product['image']) ? $product['image'] : 'no_image.jpg';
                     $product['image'] = NTImage::resizeAndSave($image, $this->config->get('config_image_thumb_width'), $this->config->get('config_image_thumb_height'));
                     $discount = $this->modelProduct->getProductDiscount($product['product_id']);
                     if ($discount) {
                         $product['price'] = $this->currency->format($this->tax->calculate($discount, $product['tax_class_id'], $this->config->get('config_tax')));
                     } else {
                         $product['price'] = $this->currency->format($this->tax->calculate($product['price'], $product['tax_class_id'], $this->config->get('config_tax')));
                         $special = $this->modelProduct->getProductSpecial($product['product_id']);
                         if ($special) {
                             $product['special'] = $this->currency->format($this->tax->calculate($special, $product['tax_class_id'], $this->config->get('config_tax')));
                         }
                     }
                     $discounts = $this->modelProduct->getProductDiscounts($product['product_id']);
                     foreach ($discounts as $k => $discount) {
                         $product['discounts'][$k] = array('quantity' => $discount['quantity'], 'price' => $this->currency->format($this->tax->calculate($discount['price'], $product['tax_class_id'], $this->config->get('config_tax'))));
                     }
                     $results = $this->modelProduct->getProductImages($product['product_id']);
                     foreach ($results as $k => $result) {
                         $product['images'][$k] = array('thumb' => NTImage::resizeAndSave($result['image'], $this->config->get('config_image_additional_width'), $this->config->get('config_image_additional_height')));
                     }
                     $results = $this->modelProduct->getProductTags($product['product_id']);
                     foreach ($results as $k => $result) {
                         if ($result['tag']) {
                             $product['tags'][$k] = array('tag' => $result['tag'], 'href' => $Url::createUrl('store/search', array('q' => $result['tag'])));
                         }
                     }
                     $fullname = $userInfo->name ? addslashes($userInfo->name) : $this->config->get('config_title');
                     $newsletter = $this->modelNewsletter->getById($this->config->get('marketing_email_promote_product'));
                     if ($newsletter) {
                         $data = array('newsletter_id' => $newsletter['newsletter_id'], 'name' => "Invitar Amigos de " . $this->db->escape(addslashes($userInfo->name)) . " (" . $this->db->escape(addslashes($userInfo->email)) . ") en Google", 'subject' => 'Hola', 'from_name' => $this->db->escape($fullname), 'from_email' => $this->db->escape($this->config->get('config_email')), 'replyto_email' => $this->db->escape($this->config->get('config_email')), 'embed_image' => 0, 'trace_email' => 1, 'trace_click' => 0, 'contacts' => $to, 'repeat' => 'no_repeat', 'date_start' => date('Y-m-d h:i:s'), 'date_end' => date('Y-m-d h:i:s'), 'date_added' => date('Y-m-d h:i:s'));
                         $this->load->model('marketing/campaign');
                         $campaign_id = $this->modelCampaign->add($data);
                         $params = array('job' => 'send_campaign', 'product_id' => $product_id, 'campaign_id' => $campaign_id);
                         $this->load->library('task');
                         $task = new Task($this->registry);
                         $task->object_id = (int) $campaign_id;
                         $task->object_type = 'campaign';
                         $task->task = $campaign['name'];
                         $task->type = 'send';
                         $task->time_exec = date('Y-m-d H:i:s');
                         $task->params = $params;
                         $task->time_interval = 'no-repeat';
                         $task->time_last_exec = date('Y-m-d H:i:s');
                         $task->run_once = true;
                         $task->status = 1;
                         $task->date_start_exec = date('Y-m-d H:i:s');
                         $task->date_end_exec = date('Y-m-d H:i:s');
                         $task->addMinute(15);
                         $control = array();
                         foreach ($to as $sort_order => $contact) {
                             if (in_array($contact['email'], $control)) {
                                 continue;
                             }
                             $control[] = $contact['email'];
                             $params = array('contact_id' => $contact['contact_id'], 'name' => $contact['name'], 'email' => $contact['email'], 'product' => $product, 'campaign_id' => $campaign_id);
                             $queue = array("params" => $params, "status" => 1, "time_exec" => date('Y-m-d H:i:s'));
                             $task->addQueue($queue);
                         }
                         $task->createSendTask();
                     }
                 }
             }
             $this->session->set('success', $this->language->get('text_promote_product_success'));
         }
         $this->redirect($Url::createUrl('store/product', array('product_id' => $product['product_id'])));
     } else {
         $this->redirect($this->oauth_url);
     }
 }
 protected function renderHtml($results)
 {
     $this->language->load('module/catalog2pdf');
     $this->load->model('store/product');
     $this->load->model('store/review');
     $this->load->library('BarcodeQR');
     $qr = new BarcodeQR();
     $html = "<table>";
     $html .= "<thead>";
     $html .= "<tr>";
     $html .= "<td>" . $this->language->get('column_image') . "</td>";
     $html .= "<td>" . $this->language->get('column_description') . "</td>";
     $html .= "<td>" . $this->language->get('column_model') . "</td>";
     $html .= "<td>" . $this->language->get('column_rating') . "</td>";
     $html .= "<td>" . $this->language->get('column_price') . "</td>";
     $html .= "<td>" . $this->language->get('column_qr') . "</td>";
     $html .= "</tr>";
     $html .= "</thead>";
     $html .= "<tbody>";
     foreach ($results as $result) {
         $image = !empty($result['image']) ? $result['image'] : 'no_image.jpg';
         $rating = $this->config->get('config_review') ? $this->modelReview->getAverageRating($result['product_id']) : false;
         $special = false;
         $discount = $this->modelProduct->getProductDiscount($result['product_id']);
         if ($discount) {
             $price = $this->currency->format($this->tax->calculate($discount, $result['tax_class_id'], $this->config->get('config_tax')));
         } else {
             $price = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax')));
             $special = $this->modelProduct->getProductSpecial($result['product_id']);
             if ($special) {
                 $special = $this->currency->format($this->tax->calculate($special, $result['tax_class_id'], $this->config->get('config_tax')));
             }
         }
         $qr->url(Url::createUrl('store/product', array('product_id' => $result['product_id'])));
         $qr->draw(100, DIR_IMAGE . "cache/" . str_replace(".", "_", "qr_code_product_" . $result['product_id']) . '.png');
         $html .= '<tr>';
         $html .= '<td><img src="' . NTImage::resizeAndSave($image, $this->config->get('config_image_product_width'), $this->config->get('config_image_product_height')) . '" /></td>';
         $html .= '<td>' . $result['name'] . '</td>';
         $html .= '<td>' . $result['model'] . '</td>';
         $html .= '<td><img src="' . HTTP_IMAGE . 'stars_' . (int) $rating . '.png" /></td>';
         $html .= '<td>' . $price;
         if ($special) {
             $html .= '<br /><b>' . $this->language->get('text_special') . '</b>';
         }
         $html .= '</td>';
         $html .= '<td><img src="' . HTTP_IMAGE . "cache/" . str_replace(".", "_", "qr_code_product_" . $result['product_id']) . '.png' . '" /></td>';
         $html .= '</tr>';
     }
     $html .= "</tbody>";
     $html .= "<tfoot>";
     $html .= "<tr>";
     $html .= '<td colspan="6" style="text-align:center">Powered By NecoTienda&reg;</td>';
     $html .= "</tr>";
     $html .= "</tfoot>";
     $html .= "</table>";
     return $html;
 }
 public function quickViewJson()
 {
     $this->load->auto('store/product');
     $this->product_id = $product_id = isset($this->request->get['product_id']) ? (int) $this->request->get['product_id'] : ($product_id = 0);
     $product_info = $this->modelProduct->getProduct($product_id);
     if ($product_info) {
         $cached = $this->cache->get('product.json.callback' . $product_id . $this->config->get('config_language_id') . "." . $this->request->hasQuery('hl') . "." . $this->request->hasQuery('cc') . "." . $this->customer->getId() . "." . $this->config->get('config_currency') . "." . (int) $this->config->get('config_store_id'));
         $this->load->library('user');
         if ($cached && !$this->user->isLogged()) {
             $this->response->setOutput($cached, $this->config->get('config_compression'));
         } else {
             $this->load->auto('store/category');
             $this->load->auto('store/manufacturer');
             $this->load->auto('tool/image');
             $this->load->auto('store/review');
             $this->load->auto('currency');
             $this->load->auto('tax');
             $this->load->auto('json');
             $this->load->auto('url');
             $this->language->load('store/product');
             $Url = new Url($this->registry);
             $average = $this->config->get('config_review') ? $this->modelReview->getAverageRating($product_id) : false;
             $image = isset($product_info['image']) ? $product_info['image'] : ($image = 'no_image.jpg');
             $this->data['popup'] = NTImage::resizeAndSave($image, $this->config->get('config_image_popup_width'), $this->config->get('config_image_popup_height'));
             $this->data['thumb'] = NTImage::resizeAndSave($image, $this->config->get('config_image_thumb_width'), $this->config->get('config_image_thumb_height'));
             $imgProduct = array('popup' => NTImage::resizeAndSave($image, $this->config->get('config_image_popup_width'), $this->config->get('config_image_popup_height')), 'preview' => NTImage::resizeAndSave($image, $this->config->get('config_image_thumb_width'), $this->config->get('config_image_thumb_height')), 'thumb' => NTImage::resizeAndSave($image, $this->config->get('config_image_additional_width'), $this->config->get('config_image_additional_height')));
             $this->data['productInfo'] = $product_info;
             $discount = $this->modelProduct->getProductDiscount($product_id);
             if ($discount) {
                 $this->data['price'] = $this->currency->format($this->tax->calculate($discount, $product_info['tax_class_id'], $this->config->get('config_tax')));
                 $this->data['special'] = false;
             } else {
                 $this->data['price'] = $this->currency->format($this->tax->calculate($product_info['price'], $product_info['tax_class_id'], $this->config->get('config_tax')));
                 $special = $this->modelProduct->getProductSpecial($product_id);
                 if ($special) {
                     $this->data['special'] = $this->currency->format($this->tax->calculate($special, $product_info['tax_class_id'], $this->config->get('config_tax')));
                 } else {
                     $this->data['special'] = false;
                 }
             }
             $discounts = $this->modelProduct->getProductDiscounts($product_id);
             if ($discounts) {
                 $this->data['discounts'] = array();
                 foreach ($discounts as $discount) {
                     $this->data['discounts'][] = array('quantity' => $discount['quantity'], 'price' => $this->currency->format($this->tax->calculate($discount['price'], $product_info['tax_class_id'], $this->config->get('config_tax'))));
                 }
             }
             if ($product_info['quantity'] <= 0) {
                 $this->data['stock'] = $product_info['stock'];
             } else {
                 if ($this->config->get('config_stock_display')) {
                     $this->data['stock'] = $product_info['quantity'];
                 } else {
                     $this->data['stock'] = $this->language->get('text_instock');
                 }
             }
             if ($product_info['minimum']) {
                 $this->data['minimum'] = $product_info['minimum'];
             } else {
                 $this->data['minimum'] = 1;
             }
             $this->data['model'] = $product_info['model'];
             $this->data['href'] = $Url::createUrl('store/product', array('product_id' => $product_info['product_id']));
             $this->data['description'] = html_entity_decode($product_info['description'], ENT_QUOTES, 'UTF-8');
             $this->data['product_id'] = $product_id;
             $this->data['average'] = $average;
             $this->data['button_add_to_cart'] = $this->language->get('button_add_to_cart');
             $this->data['button_see_product'] = $this->language->get('button_see_product');
             $this->data['images'] = array();
             $results = $this->modelProduct->getProductImages($product_id);
             foreach ($results as $k => $result) {
                 $this->data['images'][$k] = array('popup' => NTImage::resizeAndSave($result['image'], $this->config->get('config_image_popup_width'), $this->config->get('config_image_popup_height')), 'preview' => NTImage::resizeAndSave($result['image'], $this->config->get('config_image_thumb_width'), $this->config->get('config_image_thumb_height')), 'thumb' => NTImage::resizeAndSave($result['image'], $this->config->get('config_image_additional_width'), $this->config->get('config_image_additional_height')));
             }
             $k = count($this->data['images']) + 1;
             $this->data['images'][$k] = $imgProduct;
             if (!$this->config->get('config_customer_price')) {
                 $this->data['display_price'] = true;
             } elseif ($this->customer->isLogged()) {
                 $this->data['display_price'] = true;
             } else {
                 $this->data['display_price'] = false;
             }
             list($dia, $mes, $ano) = explode('-', date('d-m-Y'));
             list($pdia, $pmes, $pano) = explode('-', date('d-m-Y', strtotime($product_info['created'])));
             $l = (int) $this->config->get('config_new_days') > 30 ? 30 : $this->config->get('config_new_days');
             if (($dia = $dia - $l) <= 0) {
                 $dia = $dia + 30;
                 if ($dia <= 0) {
                     $dia = 1;
                 }
                 $mes = $mes - 1;
                 if ($mes <= 0) {
                     $mes = $mes + 12;
                     $ano = $ano - 1;
                 }
             }
             if ($special && $this->data['display_price']) {
                 $this->data['sticker'] = "<div class='oferta'></div>";
             } elseif ($discount && $this->data['display_price']) {
                 $this->data['sticker'] = "<div class='descuento'></div>";
             } elseif (strtotime($dia . "-" . $mes . "-" . $ano) <= strtotime($pdia . "-" . $pmes . "-" . $pano)) {
                 $this->data['sticker'] = "<div class='nuevo'></div>";
             } else {
                 $this->data['sticker'] = "";
             }
             $this->data['config_image_popup_width'] = $this->config->get('config_image_popup_width');
             $this->data['config_image_popup_height'] = $this->config->get('config_image_popup_height');
             $this->data['config_image_thumb_width'] = $this->config->get('config_image_thumb_width');
             $this->data['config_image_thumb_height'] = $this->config->get('config_image_thumb_height');
             $this->data['config_image_additional_width'] = $this->config->get('config_image_additional_width');
             $this->data['config_image_additional_height'] = $this->config->get('config_image_additional_height');
             $this->modelProduct->updateStats($this->request->getQuery('product_id'), (int) $this->customer->getId());
             if (!$this->user->isLogged()) {
                 $this->cacheId = 'product.json.callback' . $product_id . $this->config->get('config_language_id') . "." . $this->request->hasQuery('hl') . "." . $this->request->hasQuery('cc') . "." . $this->customer->getId() . "." . $this->config->get('config_currency') . "." . (int) $this->config->get('config_store_id');
             }
             $this->response->setOutput(Json::encode($this->data), $this->config->get('config_compression'));
         }
     } else {
         $this->data = array();
         $this->data['error'] = 1;
         $this->load->auto('json');
         $this->response->setOutput(Json::encode($this->data), $this->config->get('config_compression'));
     }
 }
 public function uploader()
 {
     header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
     header("Last-Modified: " . gmdate("D, d M Y H:i:s") . "GMT");
     header("Cache-Control: no-cache, must-revalidate");
     header("Pragma: no-cache");
     header("Content-type: application/json");
     $this->load->language('common/filemanager');
     $json = array();
     $prevPath = 'data/' . str_replace('../', '', $this->request->post['directory']);
     $directory = rtrim(DIR_IMAGE . 'data/' . str_replace('../', '', $this->request->post['directory']), '/');
     if (!is_dir($directory)) {
         $json['error'] = $this->language->get('error_directory');
     }
     $files = $this->request->files['files'];
     if (isset($files) && !$json['error']) {
         $name = $files['name'][0];
         $ext = strtolower(substr($files['name'][0], strrpos($files['name'][0], '.') + 1));
         $tmp_name = $files['tmp_name'][0];
         $size = $files['size'][0];
         $type = $files['type'][0];
         $error = $files['error'][0];
         $name = str_replace('.' . $ext, '', $name);
         $name = $name . "-" . $this->config->get('config_name');
         $name = strtolower($name);
         $name = str_replace(' ', '-', $name);
         $name = str_replace('á', 'a', $name);
         $name = str_replace('é', 'e', $name);
         $name = str_replace('í', 'i', $name);
         $name = str_replace('ó', 'o', $name);
         $name = str_replace('ú', 'u', $name);
         $name = str_replace('ñ', 'n', $name);
         if ($name !== mb_convert_encoding(mb_convert_encoding($name, 'UTF-32', 'UTF-8'), 'UTF-8', 'UTF-32')) {
             $name = mb_convert_encoding($name, 'UTF-8', mb_detect_encoding($name));
         }
         $name = htmlentities($name, ENT_NOQUOTES, 'UTF-8');
         $name = preg_replace('`&([a-z]{1,2})(acute|uml|circ|grave|ring|cedil|slash|tilde|caron|lig);`i', '\\1', $name);
         $name = html_entity_decode($name, ENT_NOQUOTES, 'UTF-8');
         $name = preg_replace(array('`[^a-z0-9]`i', '`[-]+`'), '-', $name);
         $name = strtolower(trim($name, '-'));
         if ($size > 5000000) {
             $json['error'] = $this->language->get('error_file_size') . __LINE__;
         }
         $mime_types_allowed = array('image/jpg', 'image/jpeg', 'image/pjpeg', 'image/png', 'image/x-png', 'image/gif', "text/csv", "text/comma-separated-values", "text/tab-separated-values", "text/plain", 'application/msword', 'application/pdf', 'application/x-pdf', 'application/msexcel', 'audio/x-mpeg');
         if (!in_array(strtolower($type), $mime_types_allowed)) {
             $return['error'] = 1;
             $return['msg'] = "Archivo no permitido, debe seleccionar un archivo .CSV o .TXT";
         }
         $extension_allowed = array('jpg', 'jpeg', 'pjpeg', 'png', 'gif', "csv", "txt", 'doc', 'docx', 'xls', 'xlsx', 'pdf', 'mp3');
         if (!in_array(strtolower($ext), $extension_allowed)) {
             $return['error'] = 1;
             $return['msg'] = "Archivo no permitido, debe seleccionar un archivo .CSV o .TXT";
         }
         if ($size == 0 && !$return['error']) {
             $return['error'] = 1;
             $return['msg'] = "El archivo est&aacute; vac&iacute;o";
         }
         if ($size / 1024 / 1024 > 50 && !$return['error']) {
             $return['error'] = 1;
             $return['msg'] = "El tama&ntilde;o del archivo es muy grande, solo se permiten archivos hasta 50MB";
         }
         if ($error > 0 && !$return['error']) {
             $return['error'] = 1;
             $return['msg'] = $error;
         }
         if ($error == UPLOAD_ERR_INI_SIZE) {
             $json['error'] = $this->language->get('UPLOAD_ERR_INI_SIZE') . __LINE__;
         }
         if ($error == UPLOAD_ERR_FORM_SIZE) {
             $json['error'] = $this->language->get('UPLOAD_ERR_FORM_SIZE') . __LINE__;
         }
         if ($error == UPLOAD_ERR_PARTIAL) {
             $json['error'] = $this->language->get('UPLOAD_ERR_PARTIAL') . __LINE__;
         }
         if ($error == UPLOAD_ERR_NO_FILE) {
             $json['error'] = $this->language->get('UPLOAD_ERR_NO_FILE') . __LINE__;
         }
         if ($error == UPLOAD_ERR_NO_TMP_DIR) {
             $json['error'] = $this->language->get('UPLOAD_ERR_NO_TMP_DIR') . __LINE__;
         }
         if ($error == UPLOAD_ERR_CANT_WRITE) {
             $json['error'] = $this->language->get('UPLOAD_ERR_CANT_WRITE') . __LINE__;
         }
         if ($error == UPLOAD_ERR_EXTENSION) {
             $json['error'] = $this->language->get('UPLOAD_ERR_EXTENSION') . __LINE__;
         }
         if (!isset($json['error'])) {
             $filename = basename($name . '.' . $ext);
             if (@move_uploaded_file($tmp_name, $directory . '/' . $filename)) {
                 $json['success'] = $this->language->get('text_uploaded');
                 $json['name'] = $name . '.' . $ext;
                 $json['size'] = $size;
                 $json['type'] = $type;
                 $json['url'] = $this->request->get['directory'] . $name . '.' . $ext;
                 $json['thumbnail_url'] = NTImage::resizeAndSave($prevPath . '/' . $filename, 60, 60);
                 $json['delete_url'] = Url::createAdminUrl("common/filemanager/uploader");
                 $json['delete_type'] = 'DELETE';
             } else {
                 $json['error'] = $this->language->get('error_uploaded');
             }
         }
     } else {
         $json['error'] = $this->language->get('error_file') . __LINE__;
     }
     $this->load->auto('json');
     $this->response->setOutput(Json::encode($json));
 }
        $price = $this->currency->format($this->tax->calculate($discount, $result['tax_class_id'], $this->config->get('config_tax')));
    } else {
        $price = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax')));
        $special = $this->modelProduct->getProductSpecial($result['product_id']);
        if ($special) {
            $special = $this->currency->format($this->tax->calculate($special, $result['tax_class_id'], $this->config->get('config_tax')));
        }
    }
    $options = $this->modelProduct->getProductOptions($result['product_id']);
    if ($options) {
        $add = Url::createUrl('store/product', array('product_id' => $result['product_id']));
    } else {
        $add = Url::createUrl('checkout/cart', array('product_id' => $result['product_id']));
    }
    list($pdia, $pmes, $pano) = explode('-', date('d-m-Y', strtotime($result['created'])));
    if ($special) {
        $sticker = '<b class="oferta"></b>';
    } elseif ($discount) {
        $sticker = '<b class="descuento"></b>';
    } elseif (strtotime($dia . "-" . $mes . "-" . $ano) <= strtotime($pdia . "-" . $pmes . "-" . $pano)) {
        $sticker = '<b class="nuevo"></b>';
    } else {
        $sticker = "";
    }
    $this->load->auto('image');
    $this->data['products'][$k] = array('product_id' => $result['product_id'], 'name' => $result['name'], 'model' => $result['model'], 'overview' => $result['meta_description'], 'rating' => $rating, 'stars' => sprintf($this->language->get('text_stars'), $rating), 'sticker' => $sticker, 'options' => $options, 'image' => NTImage::resizeAndSave($image, 38, 38), 'lazyImage' => NTImage::resizeAndSave('no_image.jpg', $this->config->get('config_image_product_width'), $this->config->get('config_image_product_height')), 'thumb' => NTImage::resizeAndSave($image, $this->config->get('config_image_product_width'), $this->config->get('config_image_product_height')), 'href' => Url::createUrl('store/product', array('product_id' => $result['product_id'])), 'add' => $add, 'created' => $result['created']);
    if ($this->config->get('config_store_mode') === 'store') {
        $this->data['products'][$k]['price'] = $price;
        $this->data['products'][$k]['special'] = $special;
    }
}
 public function index($q)
 {
     $criteria = array();
     $criteria['page'] = $this->request->hasQuery('page') ? $this->request->getQuery('page') : 1;
     $criteria['sort'] = $this->request->hasQuery('sort') ? $this->request->getQuery('sort') : 'pd.name';
     $criteria['order'] = $this->request->hasQuery('order') ? $this->request->getQuery('order') : 'ASC';
     $criteria['limit'] = $this->request->hasQuery('limit') ? $this->request->getQuery('limit') : $this->config->get('config_catalog_limit');
     $criteria['start'] = ($criteria['page'] - 1) * $criteria['limit'];
     $this->data['urlQuery'] = array();
     $this->data['urlQuery']['page'] = $this->request->hasQuery('page') ? '&page=' . $this->request->getQuery('page') : '';
     $this->data['urlQuery']['sort'] = $this->request->hasQuery('sort') ? '&sort=' . $this->request->getQuery('sort') : '';
     $this->data['urlQuery']['order'] = $this->request->hasQuery('order') ? '&order=' . $this->request->getQuery('order') : '';
     $this->data['urlQuery']['limit'] = $this->request->hasQuery('limit') ? '&limit=' . $this->request->getQuery('limit') : '';
     if ($this->config->get('config_seo_url')) {
         $this->data['urlBase'] = HTTP_HOME . 'buscar/' . $_GET['q'];
         $this->data['urlSearch'] = HTTP_HOME . 'buscar/' . $_GET['q'] . '?' . implode('', $this->data['urlQuery']);
     } else {
         $this->data['urlBase'] = HTTP_HOME . 'index.php?r=store/search&q=' . $_GET['q'];
         $this->data['urlSearch'] = HTTP_HOME . 'index.php?r=store/search&q=' . $_GET['q'] . '&' . implode('', $this->data['urlQuery']);
     }
     $this->cacheId = 'search_page_' . md5($this->data['urlSearch']) . $this->config->get('config_language_id') . "." . $this->request->hasQuery('hl') . "." . $this->request->hasQuery('cc') . "." . $this->customer->getId() . "." . $this->config->get('config_currency') . "." . (int) $this->config->get('config_store_id');
     $this->load->library('user');
     $cached = $this->cache->get($this->cacheId);
     if ($cached && !$this->user->isLogged()) {
         $this->response->setOutput($cached, $this->config->get('config_compression'));
     } else {
         $this->language->load('store/search');
         $this->load->model("store/search");
         $this->document->breadcrumbs = array();
         $this->document->breadcrumbs[] = array('href' => Url::createUrl("common/home"), 'text' => $this->language->get('text_home'), 'separator' => false);
         $this->data['urlCriterias'] = array();
         list($keyword) = explode('_', $_GET['q']);
         $params = explode('_', strtolower($_GET['q']));
         $queries[1] = $queries[2] = trim(trim($params[0], '-'));
         $this->data['urlCriterias']['forCategories'] = $this->data['urlCriterias']['forZones'] = $this->data['urlCriterias']['forSellers'] = $this->data['urlCriterias']['forManufacturers'] = $this->data['urlCriterias']['forStores'] = $this->data['urlCriterias']['forPrices'] = $this->data['urlCriterias']['forShipping'] = $this->data['urlCriterias']['forPayments'] = $this->data['urlCriterias']['forStatus'] = $this->data['urlCriterias']['forStockStatus'] = $this->data['urlCriterias']['forDates'] = $queries[1];
         $this->document->title = $this->data['heading_title'] = $this->language->get('heading_title') . ' ' . str_replace('-', ' ', $keyword);
         if (in_array('cat', $params)) {
             foreach ($params as $key => $value) {
                 if ($value == 'cat') {
                     $name = $params[$key + 1];
                     unset($params[$key], $params[$key + 1]);
                 }
             }
             //TODO: clean the query
             $criteria['category'] = str_replace('-', ' ', $name);
             $this->data['urlCriterias']['forZones'] .= '_Cat_' . $name;
             $this->data['urlCriterias']['forSellers'] .= '_Cat_' . $name;
             $this->data['urlCriterias']['forManufacturers'] .= '_Cat_' . $name;
             $this->data['urlCriterias']['forStores'] .= '_Cat_' . $name;
             $this->data['urlCriterias']['forPrices'] .= '_Cat_' . $name;
             $this->data['urlCriterias']['forShipping'] .= '_Cat_' . $name;
             $this->data['urlCriterias']['forPayments'] .= '_Cat_' . $name;
             $this->data['urlCriterias']['forStatus'] .= '_Cat_' . $name;
             $this->data['urlCriterias']['forStockStatus'] .= '_Cat_' . $name;
             $this->data['urlCriterias']['forDates'] .= '_Cat_' . $name;
         }
         if (in_array('estado', $params)) {
             $this->load->model('localisation/zone');
             foreach ($params as $key => $value) {
                 if ($value == 'estado') {
                     $name = $params[$key + 1];
                     unset($params[$key], $params[$key + 1]);
                 }
             }
             //TODO: clean the query
             $criteria['zone'] = str_replace('-', ' ', $name);
             $this->data['urlCriterias']['forCategories'] .= '_Estado_' . $name;
             $this->data['urlCriterias']['forSellers'] .= '_Estado_' . $name;
             $this->data['urlCriterias']['forManufacturers'] .= '_Estado_' . $name;
             $this->data['urlCriterias']['forStores'] .= '_Estado_' . $name;
             $this->data['urlCriterias']['forPrices'] .= '_Estado_' . $name;
             $this->data['urlCriterias']['forShipping'] .= '_Estado_' . $name;
             $this->data['urlCriterias']['forPayments'] .= '_Estado_' . $name;
             $this->data['urlCriterias']['forStatus'] .= '_Estado_' . $name;
             $this->data['urlCriterias']['forStockStatus'] .= '_Estado_' . $name;
             $this->data['urlCriterias']['forDates'] .= '_Estado_' . $name;
         }
         if (in_array('vendedor', $params)) {
             foreach ($params as $key => $value) {
                 if ($value == 'vendedor') {
                     $name = $params[$key + 1];
                     unset($params[$key], $params[$key + 1]);
                 }
             }
             //TODO: clean the query
             $criteria['seller'] = str_replace('-', ' ', $name);
             $this->data['urlCriterias']['forCategories'] .= '_Vendedor_' . $name;
             $this->data['urlCriterias']['forZones'] .= '_Vendedor_' . $name;
             $this->data['urlCriterias']['forManufacturers'] .= '_Vendedor_' . $name;
             $this->data['urlCriterias']['forStores'] .= '_Vendedor_' . $name;
             $this->data['urlCriterias']['forPrices'] .= '_Vendedor_' . $name;
             $this->data['urlCriterias']['forShipping'] .= '_Vendedor_' . $name;
             $this->data['urlCriterias']['forPayments'] .= '_Vendedor_' . $name;
             $this->data['urlCriterias']['forStatus'] .= '_Vendedor_' . $name;
             $this->data['urlCriterias']['forStockStatus'] .= '_Vendedor_' . $name;
             $this->data['urlCriterias']['forDates'] .= '_Vendedor_' . $name;
         }
         if (in_array('marca', $params)) {
             foreach ($params as $key => $value) {
                 if ($value == 'marca') {
                     $name = $params[$key + 1];
                     unset($params[$key], $params[$key + 1]);
                 }
             }
             //TODO: clean the query
             $criteria['manufacturer'] = $name;
             $this->data['urlCriterias']['forCategories'] .= '_Marca_' . $name;
             $this->data['urlCriterias']['forZones'] .= '_Marca_' . $name;
             $this->data['urlCriterias']['forSellers'] .= '_Marca_' . $name;
             $this->data['urlCriterias']['forStores'] .= '_Marca_' . $name;
             $this->data['urlCriterias']['forPrices'] .= '_Marca_' . $name;
             $this->data['urlCriterias']['forShipping'] .= '_Marca_' . $name;
             $this->data['urlCriterias']['forPayments'] .= '_Marca_' . $name;
             $this->data['urlCriterias']['forStatus'] .= '_Marca_' . $name;
             $this->data['urlCriterias']['forStockStatus'] .= '_Marca_' . $name;
             $this->data['urlCriterias']['forDates'] .= '_Marca_' . $name;
         }
         if (in_array('tienda', $params)) {
             foreach ($params as $key => $value) {
                 if ($value == 'tienda') {
                     $name = $params[$key + 1];
                     unset($params[$key], $params[$key + 1]);
                 }
             }
             //TODO: clean the query
             $criteria['stores'] = str_replace('-', ' ', $name);
             $this->data['urlCriterias']['forCategories'] .= '_Tienda_' . $name;
             $this->data['urlCriterias']['forZones'] .= '_Tienda_' . $name;
             $this->data['urlCriterias']['forSellers'] .= '_Tienda_' . $name;
             $this->data['urlCriterias']['forManufacturers'] .= '_Tienda_' . $name;
             $this->data['urlCriterias']['forPrices'] .= '_Tienda_' . $name;
             $this->data['urlCriterias']['forShipping'] .= '_Tienda_' . $name;
             $this->data['urlCriterias']['forPayments'] .= '_Tienda_' . $name;
             $this->data['urlCriterias']['forStatus'] .= '_Tienda_' . $name;
             $this->data['urlCriterias']['forStockStatus'] .= '_Tienda_' . $name;
             $this->data['urlCriterias']['forDates'] .= '_Tienda_' . $name;
         }
         if (in_array('precio', $params)) {
             foreach ($params as $key => $value) {
                 if ($value == 'precio') {
                     $name = $params[$key + 1];
                     unset($params[$key], $params[$key + 1]);
                 }
             }
             //TODO: clean the query
             list($criteria['price_start'], $criteria['price_end']) = explode('-', $name);
             $this->data['urlCriterias']['forCategories'] .= '_Precio_' . $name;
             $this->data['urlCriterias']['forZones'] .= '_Precio_' . $name;
             $this->data['urlCriterias']['forSellers'] .= '_Precio_' . $name;
             $this->data['urlCriterias']['forManufacturers'] .= '_Precio_' . $name;
             $this->data['urlCriterias']['forStores'] .= '_Precio_' . $name;
             $this->data['urlCriterias']['forShipping'] .= '_Precio_' . $name;
             $this->data['urlCriterias']['forPayments'] .= '_Precio_' . $name;
             $this->data['urlCriterias']['forStatus'] .= '_Precio_' . $name;
             $this->data['urlCriterias']['forStockStatus'] .= '_Precio_' . $name;
             $this->data['urlCriterias']['forDates'] .= '_Precio_' . $name;
         }
         if (in_array('envio', $params)) {
             foreach ($params as $key => $value) {
                 if ($value == 'envio') {
                     $name = $params[$key + 1];
                     unset($params[$key], $params[$key + 1]);
                 }
             }
             //TODO: clean the query
             $criteria['shipping_method'] = str_replace('-', ' ', $name);
             $this->data['urlCriterias']['forCategories'] .= '_Envio_' . $name;
             $this->data['urlCriterias']['forZones'] .= '_Envio_' . $name;
             $this->data['urlCriterias']['forSellers'] .= '_Envio_' . $name;
             $this->data['urlCriterias']['forManufacturers'] .= '_Envio_' . $name;
             $this->data['urlCriterias']['forStores'] .= '_Envio_' . $name;
             $this->data['urlCriterias']['forPrices'] .= '_Envio_' . $name;
             $this->data['urlCriterias']['forPayments'] .= '_Envio_' . $name;
             $this->data['urlCriterias']['forStatus'] .= '_Envio_' . $name;
             $this->data['urlCriterias']['forStockStatus'] .= '_Envio_' . $name;
             $this->data['urlCriterias']['forDates'] .= '_Envio_' . $name;
         }
         if (in_array('pago', $params)) {
             foreach ($params as $key => $value) {
                 if ($value == 'pago') {
                     $name = $params[$key + 1];
                     unset($params[$key], $params[$key + 1]);
                 }
             }
             //TODO: clean the query
             $criteria['payment_method'] = str_replace('-', ' ', $name);
             $this->data['urlCriterias']['forCategories'] .= '_Pago_' . $name;
             $this->data['urlCriterias']['forZones'] .= '_Pago_' . $name;
             $this->data['urlCriterias']['forSellers'] .= '_Pago_' . $name;
             $this->data['urlCriterias']['forManufacturers'] .= '_Pago_' . $name;
             $this->data['urlCriterias']['forStores'] .= '_Pago_' . $name;
             $this->data['urlCriterias']['forPrices'] .= '_Pago_' . $name;
             $this->data['urlCriterias']['forShipping'] .= '_Pago_' . $name;
             $this->data['urlCriterias']['forStatus'] .= '_Pago_' . $name;
             $this->data['urlCriterias']['forStockStatus'] .= '_Pago_' . $name;
             $this->data['urlCriterias']['forDates'] .= '_Pago_' . $name;
         }
         if (in_array('disp', $params)) {
             foreach ($params as $key => $value) {
                 if ($value == 'disp') {
                     $name = $params[$key + 1];
                     unset($params[$key], $params[$key + 1]);
                 }
             }
             //TODO: clean the query
             $criteria['stock_status'] = str_replace('-', ' ', $name);
             $this->data['urlCriterias']['forCategories'] .= '_Disp_' . $name;
             $this->data['urlCriterias']['forZones'] .= '_Disp_' . $name;
             $this->data['urlCriterias']['forSellers'] .= '_Disp_' . $name;
             $this->data['urlCriterias']['forManufacturers'] .= '_Disp_' . $name;
             $this->data['urlCriterias']['forStores'] .= '_Disp_' . $name;
             $this->data['urlCriterias']['forPrices'] .= '_Disp_' . $name;
             $this->data['urlCriterias']['forShipping'] .= '_Disp_' . $name;
             $this->data['urlCriterias']['forPayments'] .= '_Disp_' . $name;
             $this->data['urlCriterias']['forStatus'] .= '_Disp_' . $name;
             $this->data['urlCriterias']['forDates'] .= '_Disp_' . $name;
         }
         if (in_array('status', $params)) {
             foreach ($params as $key => $value) {
                 if ($value == 'status') {
                     $name = $params[$key + 1];
                     unset($params[$key], $params[$key + 1]);
                 }
             }
             //TODO: clean the query
             $criteria['product_status'] = str_replace('-', ' ', $name);
             $this->data['urlCriterias']['forCategories'] .= '_Status_' . $name;
             $this->data['urlCriterias']['forZones'] .= '_Status_' . $name;
             $this->data['urlCriterias']['forSellers'] .= '_Status_' . $name;
             $this->data['urlCriterias']['forManufacturers'] .= '_Status_' . $name;
             $this->data['urlCriterias']['forStores'] .= '_Status_' . $name;
             $this->data['urlCriterias']['forPrices'] .= '_Status_' . $name;
             $this->data['urlCriterias']['forShipping'] .= '_Status_' . $name;
             $this->data['urlCriterias']['forPayments'] .= '_Status_' . $name;
             $this->data['urlCriterias']['forStockStatus'] .= '_Status_' . $name;
             $this->data['urlCriterias']['forDates'] .= '_Status_' . $name;
         }
         if (in_array('fecha', $params)) {
             foreach ($params as $key => $value) {
                 if ($value == 'fecha') {
                     $name = $params[$key + 1];
                     unset($params[$key], $params[$key + 1]);
                 }
             }
             //TODO: clean the query
             $name = str_replace(' ', '+', trim($name));
             list($criteria['date_start'], $criteria['date_end']) = explode('+', $name);
             $this->data['urlCriterias']['forCategories'] .= '_Fecha_' . $name;
             $this->data['urlCriterias']['forZones'] .= '_Fecha_' . $name;
             $this->data['urlCriterias']['forSellers'] .= '_Fecha_' . $name;
             $this->data['urlCriterias']['forManufacturers'] .= '_Fecha_' . $name;
             $this->data['urlCriterias']['forStores'] .= '_Fecha_' . $name;
             $this->data['urlCriterias']['forPrices'] .= '_Fecha_' . $name;
             $this->data['urlCriterias']['forShipping'] .= '_Fecha_' . $name;
             $this->data['urlCriterias']['forPayments'] .= '_Fecha_' . $name;
             $this->data['urlCriterias']['forStatus'] .= '_Fecha_' . $name;
             $this->data['urlCriterias']['forStockStatus'] .= '_Fecha_' . $name;
         }
         $queries[2] = str_replace('-', ' ', $queries[2]);
         if ($queries[2] !== mb_convert_encoding(mb_convert_encoding($queries[2], 'UTF-32', 'UTF-8'), 'UTF-8', 'UTF-32')) {
             $queries[2] = mb_convert_encoding($queries[2], 'UTF-8', mb_detect_encoding($queries[2]));
         }
         $queries[2] = htmlentities($queries[2], ENT_NOQUOTES, 'UTF-8');
         $queries[2] = preg_replace('`&([a-z]{1,2})(acute|uml|circ|grave|ring|cedil|slash|tilde|caron|lig);`i', '\\1', $queries[2]);
         $queries[2] = html_entity_decode($queries[2], ENT_NOQUOTES, 'UTF-8');
         $queries[2] = preg_replace(array('`[^a-z0-9]`i', '`[-]+`'), ' ', $queries[2]);
         if (str_word_count($queries[2], 0) > 1) {
             $queries[4] = str_replace(' ', '', $queries[2]);
         }
         if ($queries[1] == $queries[2]) {
             unset($queries[2]);
         }
         if (str_word_count($queries[1], 0) > 1) {
             $a1 = explode(' ', $queries[1]);
         }
         if ($queries[2]) {
             $a2 = explode(' ', $queries[2]);
         }
         if ($a1) {
             $queries = array_merge($queries, $a1);
         }
         if ($a2) {
             $queries = array_merge($queries, $a2);
         }
         $deleteFromArray = array('a', 'e', 'i', 'o', 'u', 'y', 'con', 'de', 'desde', 'en', 'entre', 'hacia', 'hasta', 'mediante', 'para', 'por', 'sin', 'sobre', 'tras', 'versus', 'seg�n', 'segun', 'un', 'uno', 'una', 'el', 'la', 'los', 'las', 'ellos', 'es');
         $queries = array_unique($queries);
         foreach ($queries as $key => $value) {
             foreach ($deleteFromArray as $toDelete) {
                 if (in_array(trim($value), $toDelete) || strlen(trim($value)) <= 2) {
                     unset($queries[$key]);
                 }
             }
         }
         $criteria['queries'] = $queries;
         if (isset($criteria['category'])) {
             $this->data['filters']['category'] = array('name' => $criteria['category'], 'href' => rtrim($this->data['urlCriterias']['forCategories'] . '?' . implode('', $this->data['urlQuery']), '?'));
         }
         if (isset($criteria['zone'])) {
             $this->data['filters']['zone'] = array('name' => $criteria['zone'], 'href' => rtrim($this->data['urlCriterias']['forZones'] . '?' . implode('', $this->data['urlQuery']), '?'));
         }
         if (isset($criteria['seller'])) {
             $this->data['filters']['seller'] = array('name' => $criteria['seller'], 'href' => rtrim($this->data['urlCriterias']['forSellers'] . '?' . implode('', $this->data['urlQuery']), '?'));
         }
         if (isset($criteria['manufacturer'])) {
             $this->data['filters']['manufacturer'] = array('name' => $criteria['manufacturer'], 'href' => rtrim($this->data['urlCriterias']['forManufacturers'] . '?' . implode('', $this->data['urlQuery']), '?'));
         }
         if (isset($criteria['stores'])) {
             $this->data['filters']['stores'] = array('name' => $criteria['stores'], 'href' => rtrim($this->data['urlCriterias']['forStores'] . '?' . implode('', $this->data['urlQuery']), '?'));
         }
         if (isset($criteria['shipping_methods'])) {
             $this->data['filters']['shipping_methods'] = array('name' => $criteria['shipping_methods'], 'href' => rtrim($this->data['urlCriterias']['forShippingMethods'] . '?' . implode('', $this->data['urlQuery']), '?'));
         }
         if (isset($criteria['payment_methods'])) {
             $this->data['filters']['payment_methods'] = array('name' => $criteria['payment_methods'], 'href' => rtrim($this->data['urlCriterias']['forPaymentMethods'] . '?' . implode('', $this->data['urlQuery']), '?'));
         }
         if (isset($criteria['stock_statuses'])) {
             $this->data['filters']['stock_statuses'] = array('name' => $criteria['stock_statuses'], 'href' => rtrim($this->data['urlCriterias']['forStockStatuses'] . '?' . implode('', $this->data['urlQuery']), '?'));
         }
         if (isset($criteria['status'])) {
             $this->data['filters']['status'] = array('name' => $criteria['status'], 'href' => rtrim($this->data['urlCriterias']['forStatus'] . '?' . implode('', $this->data['urlQuery']), '?'));
         }
         if (isset($criteria['price_start']) && isset($criteria['price_end'])) {
             $this->data['filters']['price'] = array('name' => $this->currency->format($this->tax->calculate($criteria['price_start'])) . ' - ' . $this->currency->format($this->tax->calculate($criteria['price_end'])), 'href' => rtrim($this->data['urlCriterias']['forPrices'] . '?' . implode('', $this->data['urlQuery']), '?'));
         }
         if (isset($criteria['date_start']) && isset($criteria['date_end'])) {
             $this->data['filters']['date'] = array('name' => $criteria['date_start'] . ' / ' . $criteria['date_end'], 'href' => rtrim($this->data['urlCriterias']['forDates'] . '?' . implode('', $this->data['urlQuery']), '?'));
         } elseif (isset($criteria['date_start'])) {
             $this->data['filters']['date'] = array('name' => $criteria['date_start'] . ' / ' . date('d-m-Y'), 'href' => rtrim($this->data['urlCriterias']['forDates'] . '?' . implode('', $this->data['urlQuery']), '?'));
         } elseif (isset($criteria['date_end'])) {
             $this->data['filters']['date'] = array('name' => date('d-m-Y') . ' / ' . $criteria['date_end'], 'href' => rtrim($this->data['urlCriterias']['forDates'] . '?' . implode('', $this->data['urlQuery']), '?'));
         }
         $sortDeafultQuery = "";
         $sortDeafultQuery .= $this->data['urlQuery']['page'];
         $sortDeafultQuery .= $this->data['urlQuery']['limit'];
         $sortOrderAscQuery = $this->data['urlBase'] . '?&sort=p.sort_order&order=ASC' . $sortDeafultQuery;
         $nameAscQuery = $this->data['urlBase'] . '?&sort=pd.name&order=ASC' . $sortDeafultQuery;
         $nameDescQuery = $this->data['urlBase'] . '?&sort=pd.name&order=ASC' . $sortDeafultQuery;
         $priceAscQuery = $this->data['urlBase'] . '?&sort=p.price&order=ASC' . $sortDeafultQuery;
         $priceDescQuery = $this->data['urlBase'] . '?&sort=p.price&order=ASC' . $sortDeafultQuery;
         $productRatingAscQuery = $this->data['urlBase'] . '?&sort=p.rating&order=ASC' . $sortDeafultQuery;
         $productRatingDescQuery = $this->data['urlBase'] . '?&sort=p.rating&order=ASC' . $sortDeafultQuery;
         $this->data['sorts'] = array();
         $this->data['sorts'][] = array('text' => $this->language->get('text_default'), 'value' => 'p.sort_order-ASC', 'href' => $sortOrderAscQuery);
         $this->data['sorts'][] = array('text' => $this->language->get('text_name_asc'), 'value' => 'pd.name-ASC', 'href' => $nameAscQuery);
         $this->data['sorts'][] = array('text' => $this->language->get('text_name_desc'), 'value' => 'pd.name-DESC', 'href' => $nameDescQuery);
         $this->data['sorts'][] = array('text' => $this->language->get('text_price_asc'), 'value' => 'p.price-ASC', 'href' => $priceAscQuery);
         $this->data['sorts'][] = array('text' => $this->language->get('text_price_desc'), 'value' => 'p.price-DESC', 'href' => $priceDescQuery);
         $this->data['sorts'][] = array('text' => $this->language->get('text_rating_asc'), 'value' => 'p.rating-ASC', 'href' => $productRatingAscQuery);
         $this->data['sorts'][] = array('text' => $this->language->get('text_rating_desc'), 'value' => 'p.rating-DESC', 'href' => $productRatingDescQuery);
         $this->load->model('store/search');
         $total = $this->modelSearch->getAllProductsTotal($criteria);
         if ($total) {
             if (!$criteria['categories']) {
                 $this->data['filterCategories'] = $this->modelSearch->getCategoriesByProduct($criteria);
             }
             if (!$criteria['manufacturer']) {
                 $this->data['filterManufacturers'] = $this->modelSearch->getManufacturersByProduct($criteria);
             }
             if (!$criteria['zone']) {
                 $this->data['filterZones'] = $this->modelSearch->getZonesByProduct($criteria);
             }
             if (!$criteria['stores']) {
                 $this->data['filterStores'] = $this->modelSearch->getStoresByProduct($criteria);
             }
             $results = $this->modelSearch->getAllProducts($criteria);
             $this->load->auto('store/review');
             $this->data['products'] = array();
             $topPrice = 0;
             $bottomPrice = 1000000000;
             foreach ($results as $result) {
                 $image = !empty($result['image']) ? $result['image'] : 'no_image.jpg';
                 $rating = $this->config->get('config_review') ? $this->modelReview->getAverageRating($result['product_id']) : false;
                 if ($result['price'] > $topPrice) {
                     $this->data['topPrice'] = array('value' => $result['price'], 'tax_class_id' => $result['tax_class_id']);
                     $topPrice = $result['price'];
                 }
                 if ($result['price'] < $bottomPrice) {
                     $this->data['bottomPrice'] = array('value' => $result['price'], 'tax_class_id' => $result['tax_class_id']);
                     $bottomPrice = $result['price'];
                 }
                 $price = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax')));
                 $this->load->auto('image');
                 $this->data['products'][] = array('product_id' => $result['product_id'], 'name' => $result['name'], 'model' => $result['model'], 'overview' => $result['meta_description'], 'rating' => $rating, 'stars' => sprintf($this->language->get('text_stars'), $rating), 'price' => $price, 'image' => NTImage::resizeAndSave($image, 38, 38), 'lazyImage' => NTImage::resizeAndSave('no_image.jpg', $this->config->get('config_image_product_width'), $this->config->get('config_image_product_height')), 'thumb' => NTImage::resizeAndSave($image, $this->config->get('config_image_product_width'), $this->config->get('config_image_product_height')));
             }
             $topPrice = $this->data['topPrice']['value'];
             $bottomPrice = $this->data['bottomPrice']['value'];
             $diff = ($topPrice - $bottomPrice) * 0.2;
             if ($diff > 0) {
                 while (true) {
                     $topPrice = $bottomPrice + $diff - +0.01;
                     if ($topPrice >= $this->data['topPrice']['value']) {
                         $topPrice = $this->data['topPrice']['value'];
                         $break = true;
                     }
                     $this->data['filterPrices'][] = array('bottomValue' => round($bottomPrice, 2), 'bottomText' => $this->currency->format($this->tax->calculate($bottomPrice, $this->data['topPrice']['tax_class_id'], $this->config->get('config_tax'))), 'topValue' => round($topPrice, 2), 'topText' => $this->currency->format($this->tax->calculate($topPrice, $this->data['topPrice']['tax_class_id'], $this->config->get('config_tax'))));
                     if ($break) {
                         break;
                     }
                     $bottomPrice = $topPrice + 0.01;
                 }
             }
             $this->load->library('pagination');
             $pagination = new Pagination(true);
             $pagination->total = $total;
             $pagination->page = $criteria['page'];
             $pagination->limit = $criteria['limit'];
             $pagination->text = $this->language->get('text_pagination');
             unset($this->data['urlQuery']['page']);
             $pagination->url = $this->data['urlBase'] . '?page={page}' . implode('', $this->data['urlQuery']);
             $this->session->set('redirect', $this->data['urlBase'] . '?page=' . $criteria['page'] . implode('', $this->data['urlQuery']));
             $this->data['pagination'] = $pagination->render();
             $this->modelSearch->add();
         } else {
             $this->data['noResults'] = true;
         }
         $this->data['breadcrumbs'] = $this->document->breadcrumbs;
         // SCRIPTS
         $scripts[] = array('id' => 'search-1', 'method' => 'ready', 'script' => "\$('#content_search input').keydown(function(e) {\r\n                   \tif (e.keyCode == 13 && \$(this).val().length > 0) {\r\n                  \t\tcontentSearch();\r\n                   \t}\r\n                });\r\n                if (window.location.hash.length > 0) {\r\n                    \$('#products').load('" . Url::createUrl("store/search") . "&q='+ window.location.hash.replace('#', ''));\r\n                }");
         $scripts[] = array('id' => 'search-2', 'method' => 'window', 'script' => "\$('.filter').mCustomScrollbar({\r\n                    scrollButtons:{\r\n                        enable:true\r\n                    },\r\n                    theme:'dark'\r\n                });");
         $this->loadWidgets();
         if ($scripts) {
             $this->scripts = array_merge($this->scripts, $scripts);
         }
         $template = $this->config->get('default_view_search') ? $this->config->get('default_view_search') : 'store/search.tpl';
         if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/' . $template)) {
             $this->template = $this->config->get('config_template') . '/' . $template;
         } else {
             $this->template = 'choroni/' . $template;
         }
         $this->children[] = 'common/footer';
         $this->children[] = 'common/column_left';
         $this->children[] = 'common/nav';
         $this->children[] = 'common/header';
         $this->response->setOutput($this->render(true), $this->config->get('config_compression'));
     }
 }
 public function promote()
 {
     if ($this->session->has('liveAccessToken')) {
         $token = json_decode($this->session->get('liveAccessToken'));
         $url = 'https://apis.live.net/v5.0/me?access_token=' . $token->access_token;
         $response = $this->handler->fetch($url);
         $profile = json_decode($response['body'], true);
         if ($profile['error']) {
             $this->session->clear('ltoken');
             $this->session->clear('lcode');
             $this->session->clear('liveAccessToken');
             $this->session->clear('action');
             $this->redirect($this->oauth_url);
         }
         $list = $this->db->query("SELECT * \n            FROM " . DB_PREFIX . "contact_list \n            WHERE name = \"Amigos de " . $this->db->escape(addslashes($profile['name'])) . " (" . $this->db->escape(addslashes($profile['emails']['preferred'])) . ") en Hotmail\"");
         if ($list->num_rows) {
             $list_id = $list->row['contact_list_id'];
         } else {
             $this->db->query("INSERT INTO " . DB_PREFIX . "contact_list SET \n                name        = \"Amigos de " . $this->db->escape(addslashes($profile['name'])) . " (" . $this->db->escape(addslashes($profile['emails']['preferred'])) . ") en Hotmail\",\n                description = \"Amigos de " . $this->db->escape(addslashes($profile['name'])) . " (" . $this->db->escape(addslashes($profile['emails']['preferred'])) . ") en Hotmail\",\n                date_added  = NOW()");
             $list_id = $this->db->getLastId();
         }
         $url = 'https://apis.live.net/v5.0/me/contacts?access_token=' . $token->access_token . '&limit=1000';
         $response = $this->handler->fetch($url);
         if ($response['body']) {
             $xml = json_decode($response['body'], true);
             if ($xml['error']) {
                 $this->redirect($this->oauth_url);
             }
             $to = array();
             $control = array();
             foreach ($xml['data'] as $emails) {
                 $contacts[] = array($emails['name'], $emails['emails']['preferred']);
                 $name = addslashes(str_replace("'", '', $emails['name']));
                 $email = $emails['emails']['preferred'];
                 if (empty($email)) {
                     continue;
                 }
                 $customer = $this->db->query("SELECT * FROM " . DB_PREFIX . "customer WHERE email = '" . $this->db->escape($email) . "'");
                 $contact = $this->db->query("SELECT * FROM " . DB_PREFIX . "contact WHERE email = '" . $this->db->escape($email) . "'");
                 if (!$contact->row) {
                     $this->db->query("INSERT INTO " . DB_PREFIX . "contact SET \n                              name        = '" . $this->db->escape($name) . "',\n                              email       = '" . $this->db->escape($email) . "', \n                              customer_id = '" . (int) $customer->row['customer_id'] . "',\n                              date_added  = NOW()");
                     $contact_id = $this->db->getLastId();
                     $this->db->query("INSERT INTO " . DB_PREFIX . "contact_to_list SET \n                            contact_id     = '" . (int) $contact_id . "',\n                            contact_list_id= '" . (int) $list_id . "',\n                            date_added    = NOW()");
                 } else {
                     $contact_id = $contact->row['contact_id'];
                 }
                 if (!in_array($email, $control) && !empty($email)) {
                     $control[] = $email;
                     $to[] = array('contact_id' => (int) $contact_id, 'name' => $name, 'email' => $email);
                 }
             }
             if ($this->config->get('marketing_email_promote_product')) {
                 $this->load->model('marketing/newsletter');
                 $product = array();
                 $product_id = $this->request->hasQuery('product_id') ? $this->request->getQuery('product_id') : $this->session->get('promote_product_id');
                 $this->session->set('promote_product_id', $product_id);
                 if ($product_id) {
                     $product_id;
                     $this->load->model('store/product');
                     $product = $this->modelProduct->getProduct($product_id);
                     if ($product) {
                         $this->load->model('store/product');
                         $Url = new Url($this->registry);
                         //Libs
                         $this->load->auto('image');
                         $this->load->auto('currency');
                         $this->load->auto('tax');
                         $product['url'] = $Url::createUrl('store/product', array('product_id' => $product['product_id']));
                         $image = isset($product['image']) ? $product['image'] : 'no_image.jpg';
                         $product['image'] = NTImage::resizeAndSave($image, $this->config->get('config_image_thumb_width'), $this->config->get('config_image_thumb_height'));
                         $discount = $this->modelProduct->getProductDiscount($product['product_id']);
                         if ($discount) {
                             $product['price'] = $this->currency->format($this->tax->calculate($discount, $product['tax_class_id'], $this->config->get('config_tax')));
                         } else {
                             $product['price'] = $this->currency->format($this->tax->calculate($product['price'], $product['tax_class_id'], $this->config->get('config_tax')));
                             $special = $this->modelProduct->getProductSpecial($product['product_id']);
                             if ($special) {
                                 $product['special'] = $this->currency->format($this->tax->calculate($special, $product['tax_class_id'], $this->config->get('config_tax')));
                             }
                         }
                         $discounts = $this->modelProduct->getProductDiscounts($product['product_id']);
                         foreach ($discounts as $k => $discount) {
                             $product['discounts'][$k] = array('quantity' => $discount['quantity'], 'price' => $this->currency->format($this->tax->calculate($discount['price'], $product['tax_class_id'], $this->config->get('config_tax'))));
                         }
                         $results = $this->modelProduct->getProductImages($product['product_id']);
                         foreach ($results as $k => $result) {
                             $product['images'][$k] = array('thumb' => NTImage::resizeAndSave($result['image'], $this->config->get('config_image_additional_width'), $this->config->get('config_image_additional_height')));
                         }
                         $results = $this->modelProduct->getProductTags($product['product_id']);
                         foreach ($results as $k => $result) {
                             if ($result['tag']) {
                                 $product['tags'][$k] = array('tag' => $result['tag'], 'href' => $Url::createUrl('store/search', array('q' => $result['tag'])));
                             }
                         }
                         $fullname = $profile['name'] ? addslashes($profile['name']) : $this->config->get('config_title');
                         $newsletter = $this->modelNewsletter->getById($this->config->get('marketing_email_promote_product'));
                         if ($newsletter) {
                             $data = array('newsletter_id' => $newsletter['newsletter_id'], 'name' => "Invitar Amigos de " . $this->db->escape(addslashes($profile['name'])) . " (" . $this->db->escape(addslashes($profile['emails']['preferred'])) . ") en Outlook", 'subject' => 'Hola', 'from_name' => $this->db->escape($fullname), 'from_email' => $this->db->escape($this->config->get('config_email')), 'replyto_email' => $this->db->escape($this->config->get('config_email')), 'embed_image' => 0, 'trace_email' => 1, 'trace_click' => 0, 'contacts' => $to, 'repeat' => 'no_repeat', 'date_start' => date('Y-m-d h:i:s'), 'date_end' => date('Y-m-d h:i:s'), 'date_added' => date('Y-m-d h:i:s'));
                             $this->load->model('marketing/campaign');
                             $campaign_id = $this->modelCampaign->add($data);
                             $params = array('job' => 'send_campaign', 'product_id' => $product_id, 'campaign_id' => $campaign_id);
                             $this->load->library('task');
                             $task = new Task($this->registry);
                             $task->object_id = (int) $campaign_id;
                             $task->object_type = 'campaign';
                             $task->task = $campaign['name'];
                             $task->type = 'send';
                             $task->time_exec = date('Y-m-d H:i:s');
                             $task->params = $params;
                             $task->time_interval = 'no-repeat';
                             $task->time_last_exec = date('Y-m-d H:i:s');
                             $task->run_once = true;
                             $task->status = 1;
                             $task->date_start_exec = date('Y-m-d H:i:s');
                             $task->date_end_exec = date('Y-m-d H:i:s');
                             $task->addMinute(15);
                             $control = array();
                             foreach ($to as $sort_order => $contact) {
                                 if (in_array($contact['email'], $control)) {
                                     continue;
                                 }
                                 $control[] = $contact['email'];
                                 $params = array('contact_id' => $contact['contact_id'], 'name' => $contact['name'], 'email' => $contact['email'], 'product' => $product, 'campaign_id' => $campaign_id);
                                 $queue = array("params" => $params, "status" => 1, "time_exec" => date('Y-m-d H:i:s'));
                                 $task->addQueue($queue);
                             }
                             $task->createSendTask();
                         }
                     }
                 }
                 $this->session->set('success', $this->language->get('text_promote_product_success'));
             }
             $this->redirect($Url::createUrl('store/product', array('product_id' => $product['product_id'])));
         }
     } else {
         $this->redirect($this->oauth_url);
     }
 }
 public function relatedJson()
 {
     $json = array();
     $this->load->auto("content/page");
     $this->load->auto('image');
     $this->load->auto('json');
     $json['results'] = $this->modelPage->getRelated($this->request->get['page_id']);
     $width = isset($_GET['width']) ? $_GET['width'] : 80;
     $height = isset($_GET['height']) ? $_GET['height'] : 80;
     foreach ($json['results'] as $k => $v) {
         if (!file_exists(DIR_IMAGE . $v['image'])) {
             $json['results'][$k]['image'] = HTTP_IMAGE . "no_image.jpg";
         }
         $json['results'][$k]['thumb'] = NTImage::resizeAndSave($v['image'], $width, $height);
     }
     if (!count($json['results'])) {
         $json['error'] = 1;
     }
     $this->response->setOutput(Json::encode($json), $this->config->get('config_compression'));
 }
 public function index()
 {
     if ($this->config->get('google_base_status')) {
         $output = '<?xml version="1.0" encoding="UTF-8" ';
         $output .= '<rss version="2.0" xmlns:g="http://base.google.com/ns/1.0">';
         $output .= '<channel>';
         $output .= '<title>' . $this->config->get('config_name') . '</title>';
         $output .= '<description>' . $this->config->get('config_meta_description') . '</description>';
         $output .= '<link>' . HTTP_HOME . '</link>';
         $this->load->model('store/category');
         $this->load->model('store/product');
         $products = $this->modelProduct->getProducts();
         foreach ($products as $product) {
             if ($product['description']) {
                 $output .= '<item>';
                 $output .= '<title>' . html_entity_decode($product['name'], ENT_QUOTES, 'UTF-8') . '</title>';
                 $output .= '<link>' . Url::createUrl("store/product") . '&amp;product_id=' . $product['product_id'] . '</link>';
                 $output .= '<description>' . $product['description'] . '</description>';
                 $output .= '<g:brand>' . html_entity_decode($product['manufacturer'], ENT_QUOTES, 'UTF-8') . '</g:brand>';
                 $output .= '<g:condition>new</g:condition>';
                 $output .= '<g:id>' . $product['product_id'] . '</g:id>';
                 if ($product['image']) {
                     $output .= '<g:image_link>' . NTImage::resizeAndSave($product['image'], 500, 500) . '</g:image_link>';
                 } else {
                     $output .= '<g:image_link>' . NTImage::resizeAndSave('no_image.jpg', 500, 500) . '</g:image_link>';
                 }
                 $output .= '<g:mpn>' . $product['model'] . '</g:mpn>';
                 $special = $this->modelProduct->getProductSpecial($product['product_id']);
                 if ($special) {
                     $output .= '<g:price>' . $this->tax->calculate($special, $product['tax_class_id']) . '</g:price>';
                 } else {
                     $output .= '<g:price>' . $this->tax->calculate($product['price'], $product['tax_class_id']) . '</g:price>';
                 }
                 $categories = $this->modelProduct->getCategories($product['product_id']);
                 foreach ($categories as $category) {
                     $path = $this->getPath($category['category_id']);
                     if ($path) {
                         $string = '';
                         foreach (explode('_', $path) as $path_id) {
                             $category_info = $this->modelCategory->getCategory($path_id);
                             if ($category_info) {
                                 if (!$string) {
                                     $string = $category_info['name'];
                                 } else {
                                     $string .= ' &gt; ' . $category_info['name'];
                                 }
                             }
                         }
                         $output .= '<g:product_type>' . $string . '</g:product_type>';
                     }
                 }
                 $output .= '<g:quantity>' . $product['quantity'] . '</g:quantity>';
                 $output .= '<g:upc>' . $product['model'] . '</g:upc>';
                 $output .= '<g:weight>' . $this->weight->format($product['weight'], $product['weight_class']) . '</g:weight>';
                 $output .= '</item>';
             }
         }
         $output .= '</channel>';
         $output .= '</rss>';
         $this->response->addHeader('Content-Type: application/rss+xml');
         $this->response->setOutput($output, 0);
     }
 }
 public function manufacturers()
 {
     header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
     header("Last-Modified: " . gmdate("D, d M Y H:i:s") . "GMT");
     header("Cache-Control: no-cache, must-revalidate");
     header("Pragma: no-cache");
     header("Content-type: application/json");
     $this->load->auto("store/store");
     $this->load->auto("store/manufacturer");
     if ($this->request->hasQuery('store_id')) {
         $rows = $this->modelStore->getAllManufacturers($this->request->getQuery('store_id'));
         $manufacturers_by_store = array();
         foreach ($rows as $row) {
             $manufacturers_by_store[] = $row['manufacturer_id'];
         }
     }
     $cache = $this->cache->get("manufacturers.for.store.form." . $this->request->getQuery('store_id'));
     if ($cache) {
         $manufacturers = unserialize($cache);
     } else {
         $manufacturers = $this->modelManufacturer->getAll();
         $this->cache->set("manufacturers.for.store.form." . $this->request->getQuery('store_id'), serialize($manufacturers));
     }
     $output = array();
     foreach ($manufacturers as $manufacturer) {
         if (!empty($manufacturers_by_store) && in_array($manufacturer['manufacturer_id'], $manufacturers_by_store)) {
             $output[] = array('id' => $manufacturer['manufacturer_id'], 'image' => NTImage::resizeAndSave($manufacturer['image'], 50, 50), 'name' => $manufacturer['name'], 'class' => 'added', 'value' => 1);
         } else {
             $output[] = array('id' => $manufacturer['manufacturer_id'], 'image' => NTImage::resizeAndSave($manufacturer['image'], 50, 50), 'name' => $manufacturer['name'], 'class' => 'add', 'value' => 0);
         }
     }
     $this->load->auto('json');
     $this->response->setOutput(Json::encode($output), $this->config->get('config_compression'));
 }
 public function products()
 {
     header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
     header("Last-Modified: " . gmdate("D, d M Y H:i:s") . "GMT");
     header("Cache-Control: no-cache, must-revalidate");
     header("Pragma: no-cache");
     header("Content-type: application/json");
     if ($this->request->hasQuery('coupon_id')) {
         $rows = $this->modelCoupon->getCouponProducts($this->request->getQuery('coupon_id'));
         $products_by_coupon = array();
         foreach ($rows as $row) {
             $products_by_coupon[] = $row['product_id'];
         }
     }
     $cache = $this->cache->get("products.for.coupon.form");
     if ($cache) {
         $products = unserialize($cache);
     } else {
         $model = $this->modelProduct->getAll();
         $products = $model->obj;
         $this->cache->set("products.for.coupon.form", serialize($products));
     }
     $this->data['Image'] = new NTImage();
     $this->data['Url'] = new Url();
     $output = array();
     foreach ($products as $product) {
         if (!empty($products_by_coupon) && in_array($product->product_id, $products_by_coupon)) {
             $output[] = array('product_id' => $product->product_id, 'pimage' => NTImage::resizeAndSave($product->pimage, 50, 50), 'pname' => $product->pname, 'class' => 'added', 'value' => 1);
         } else {
             $output[] = array('product_id' => $product->product_id, 'pimage' => NTImage::resizeAndSave($product->pimage, 50, 50), 'pname' => $product->pname, 'class' => 'add', 'value' => 0);
         }
     }
     $this->load->auto('json');
     $this->response->setOutput(Json::encode($output), $this->config->get('config_compression'));
 }
 public function all()
 {
     $this->language->load('store/category');
     $this->document->breadcrumbs = array();
     $this->document->breadcrumbs[] = array('href' => Url::createUrl('common/home'), 'text' => $this->language->get('text_home'), 'separator' => false);
     $this->data['breadcrumbs'] = $this->document->breadcrumbs;
     $this->document->title = $this->data['heading_title'] = $this->language->get('heading_title');
     $this->document->description = $this->language->get('meta_description');
     $this->document->keywords = $this->language->get('meta_keywords');
     $this->data['categories'] = array();
     $results = $this->modelCategory->getCategories(0);
     foreach ($results as $result) {
         if ($result['image']) {
             $image = $result['image'];
         } else {
             $image = 'no_image.jpg';
         }
         $this->data['categories'][] = array('name' => $result['name'], 'href' => Url::createUrl('store/category', array("path" => $result['category_id'])), 'thumb' => NTImage::resizeAndSave($image, $this->config->get('config_image_category_width'), $this->config->get('config_image_category_height')));
     }
     $this->loadWidgets();
     $template = $this->config->get('default_view_product_category_all') ? $this->config->get('default_view_product_category_all') : 'store/categories.tpl';
     if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/' . $template)) {
         $this->template = $this->config->get('config_template') . '/' . $template;
     } else {
         $this->template = 'choroni/' . $template;
     }
     $this->children[] = 'common/nav';
     $this->children[] = 'common/column_left';
     $this->children[] = 'common/column_right';
     $this->children[] = 'common/footer';
     $this->children[] = 'common/header';
     $this->response->setOutput($this->render(true), $this->config->get('config_compression'));
 }
 public function index()
 {
     $this->language->load('content/category');
     $this->load->model('content/category');
     $this->load->model('content/post');
     $this->document->breadcrumbs = array();
     $this->document->breadcrumbs[] = array('href' => Url::createUrl("common/home"), 'text' => $this->language->get('text_home'), 'separator' => false);
     $this->document->breadcrumbs[] = array('href' => Url::createUrl("content/category"), 'text' => $this->language->get('text_posts'), 'separator' => false);
     $this->document->title = $this->language->get('heading_title') . " - " . $this->config->get('config_title');
     $this->data['heading_title'] = $this->language->get('heading_title');
     $this->setvar('post_category_id', null, 0);
     if ($this->data['post_category_id']) {
         $category_info = $this->modelCategory->getById($this->data['post_category_id']);
     }
     if ($category_info) {
         $this->document->title = $category_info['seo_title'];
         $this->document->description = $category_info['meta_description'];
         $this->document->keywords = $category_info['meta_keywords'];
         $this->document->breadcrumbs[] = array('href' => Url::createUrl("content/category") . '&post_category_id=' . $this->request->get['post_category_id'], 'text' => $category_info['title'], 'separator' => $this->language->get('text_separator'));
         $this->data['breadcrumbs'] = $this->document->breadcrumbs;
         $this->data['heading_title'] = $category_info['title'];
         $this->data['description'] = html_entity_decode($category_info['description']);
         $this->data['keywords'] = explode(";", $category_info['meta_keywords']);
         $this->setvar('title', $category_info);
         $categories_total = $this->modelCategory->getTotalById($category_info['post_category_id']);
         $this->data['categories'] = array();
         if ($categories_total) {
             $results = $this->modelCategory->getAllById($category_info['post_category_id']);
             foreach ($results as $result) {
                 $image = $result['image'] ? $image = $result['image'] : 'no_image.jpg';
                 $this->data['categories'][] = array('name' => $result['name'], 'total' => $result['total'], 'href' => Url::createUrl('content/category', array("post_category_id" => $result['post_category_id'])), 'thumb' => NTImage::resizeAndSave($image, $this->config->get('config_image_category_width'), $this->config->get('config_image_category_height')));
             }
         }
     }
     $this->setvar('sort');
     $this->setvar('order');
     $this->setvar('page');
     $this->setvar('post_category_id');
     $data['post_category_id'] = $this->request->hasQuery('post_category_id') ? $this->request->getQuery('post_category_id') : null;
     $data['page'] = $this->request->hasQuery('page') ? $this->request->getQuery('page') : 1;
     $data['limit'] = $this->request->hasQuery('limit') ? $this->request->getQuery('limit') : $this->config->get('config_catalog_limit');
     $data['sort'] = $this->request->hasQuery('sort') ? $this->request->getQuery('sort') : 'p.date_publish_start';
     $data['order'] = $this->request->hasQuery('order') ? $this->request->getQuery('order') : 'DESC';
     $paramId = $this->request->hasQuery('post_category_id') ? '&post_category_id=' . $this->request->getQuery('post_category_id') : "";
     $paramLimit = $this->request->hasQuery('limit') ? '&limit=' . $this->request->getQuery('limit') : "";
     $paramSort = $this->request->hasQuery('sort') ? '&sort=' . $this->request->getQuery('sort') : "";
     $paramOrder = $this->request->hasQuery('order') ? '&order=' . $this->request->getQuery('order') : "";
     $paramPage = $this->request->hasQuery('page') ? '&page=' . $this->request->getQuery('page') : "";
     $url = $paramId . $paramSort . $paramOrder . $paramPage;
     $this->data['sorts'] = array();
     $this->data['sorts'][] = array('text' => $this->language->get('text_default'), 'value' => 'p.sort_order-ASC', 'href' => Url::createUrl('content/category', '&sort=p.sort_order&order=ASC' . $paramId . $paramPage . $paramLimit));
     $this->data['sorts'][] = array('text' => $this->language->get('text_name_asc'), 'value' => 'pd.name-ASC', 'href' => Url::createUrl('content/category', '&sort=pd.title&order=ASC' . $paramId . $paramPage . $paramLimit));
     $this->data['sorts'][] = array('text' => $this->language->get('text_name_desc'), 'value' => 'pd.name-DESC', 'href' => Url::createUrl('content/category', '&sort=pd.title&order=DESC' . $paramId . $paramPage . $paramLimit));
     $data['start'] = ($data['page'] - 1) * $data['limit'];
     $post_total = $this->modelPost->getTotalByCategoryId($data);
     if ($post_total) {
         $posts = $this->modelPost->getAllByCategoryId($data);
         foreach ($posts as $result) {
             $image = $result['image'] ? $image = $result['image'] : '';
             $this->data['posts'][] = array('post_id' => $result['post_id'], 'title' => $result['title'], 'seo_title' => $result['seo_title'], 'tags' => explode(";", $result['meta_keywords']), 'description' => html_entity_decode($result['description']), 'meta_description' => $result['meta_description'], 'thumb' => NTImage::resizeAndSave($image, $this->config->get('config_image_post_width'), $this->config->get('config_image_post_height')), 'date_added' => date('d-m-Y', strtotime($result['date_publish_start'])));
         }
     }
     $this->load->library('pagination');
     $pagination = new Pagination(true);
     $pagination->total = $post_total;
     $pagination->page = $data['page'];
     $pagination->limit = $data['limit'];
     $pagination->text = $this->language->get('text_pagination');
     $pagination->url = Url::createUrl("content/category") . $paramId . $paramSort . $paramOrder . $paramLimit . '&page={page}';
     $this->session->set('redirect', Url::createUrl('content/category') . $paramId . $paramSort . $paramOrder . $paramLimit . '&page=' . $data['page']);
     $this->data['pagination'] = $pagination->render();
     $this->loadWidgets();
     if ($scripts) {
         $this->scripts = array_merge($this->scripts, $scripts);
     }
     $template = $this->modelCategory->getProperty($this->data['post_category_id'], 'style', 'view');
     $default_template = $this->config->get('default_view_post_category') ? $this->config->get('default_view_post_category') : 'content/category.tpl';
     $template = empty($template) ? $default_template : $template;
     if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/' . $template)) {
         $this->template = $this->config->get('config_template') . '/' . $template;
     } else {
         $this->template = 'choroni/' . $template;
     }
     $this->children[] = 'common/column_left';
     $this->children[] = 'common/column_right';
     $this->children[] = 'common/nav';
     $this->children[] = 'common/header';
     $this->children[] = 'common/footer';
     $this->response->setOutput($this->render(true), $this->config->get('config_compression'));
 }
 public function products()
 {
     header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
     header("Last-Modified: " . gmdate("D, d M Y H:i:s") . "GMT");
     header("Cache-Control: no-cache, must-revalidate");
     header("Pragma: no-cache");
     header("Content-type: application/json");
     if ($this->request->hasQuery('category_id')) {
         $rows = $this->modelProduct->getAllByCategoryId($this->request->getQuery('category_id'));
         $products_by_category = array();
         foreach ($rows as $row) {
             $products_by_category[] = $row['product_id'];
         }
     }
     $cache = $this->cache->get("products.for.category.form");
     if ($cache) {
         $products = $cache;
     } else {
         $products = $this->modelProduct->getAll();
         $this->cache->set("products.for.category.form", $products);
     }
     $output = array();
     foreach ($products as $product) {
         if (!empty($products_by_category) && in_array($product['product_id'], $products_by_category)) {
             $output[] = array('product_id' => $product['product_id'], 'pimage' => NTImage::resizeAndSave($product['image'], 50, 50), 'pname' => $product['name'], 'class' => 'added', 'value' => 1);
         } else {
             $output[] = array('product_id' => $product['product_id'], 'pimage' => NTImage::resizeAndSave($product['image'], 50, 50), 'pname' => $product['name'], 'class' => 'add', 'value' => 0);
         }
     }
     $this->load->auto('json');
     $this->response->setOutput(Json::encode($output), $this->config->get('config_compression'));
 }
 public function all()
 {
     $this->setHeaders();
     if ($this->request->server['REQUEST_METHOD'] == 'GET') {
         $data['page'] = $this->request->hasQuery('page') ? $this->request->getQuery('page') : 1;
         $data['limit'] = $this->request->hasQuery('limit') ? $this->request->getQuery('limit') : $this->config->get('config_catalog_limit');
         $this->load->model('store/product');
         $this->load->model('store/review');
         $data['start'] = ($data['page'] - 1) * $data['limit'];
         $product_total = $this->modelProduct->getTotalByKeyword($data);
         if ($product_total) {
             $results = $this->modelProduct->getByKeyword($data);
             foreach ($results as $result) {
                 $image = !empty($result['image']) ? $result['image'] : 'no_image.jpg';
                 if ($this->config->get('config_review')) {
                     $rating = $this->modelReview->getAverageRating($result['product_id']);
                 } else {
                     $rating = false;
                 }
                 $special = false;
                 $discount = $this->modelProduct->getProductDiscount($result['product_id']);
                 if ($discount) {
                     $price = $this->currency->format($this->tax->calculate($discount, $result['tax_class_id'], $this->config->get('config_tax')));
                 } else {
                     $price = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax')));
                     $special = $this->modelProduct->getProductSpecial($result['product_id']);
                     if ($special) {
                         $special = $this->currency->format($this->tax->calculate($special, $result['tax_class_id'], $this->config->get('config_tax')));
                     }
                 }
                 $options = $this->modelProduct->getProductOptions($result['product_id']);
                 if ($options) {
                     $add = Url::createUrl('store/product', array('product_id' => $result['product_id']));
                 } else {
                     $add = Url::createUrl('checkout/cart') . '&product_id=' . $result['product_id'];
                 }
                 $this->data['results'][] = array('product_id' => $result['product_id'], 'name' => $result['name'], 'model' => $result['model'], 'overview' => $result['meta_description'], 'rating' => $rating, 'stars' => sprintf($this->language->get('text_stars'), $rating), 'price' => $price, 'options' => $options, 'special' => $special, 'image' => NTImage::resizeAndSave($image, 38, 38), 'lazyImage' => NTImage::resizeAndSave('no_image.jpg', $this->config->get('config_image_product_width'), $this->config->get('config_image_product_height')), 'thumb' => NTImage::resizeAndSave($image, $this->config->get('config_image_product_width'), $this->config->get('config_image_product_height')), 'href' => Url::createUrl('store/product', array('product_id' => $result['product_id'])), 'add' => $add);
             }
         }
     } else {
     }
     $this->load->library('json');
     $this->response->setOutput(Json::encode($this->data), $this->config->get('config_compression'));
 }