Example #1
0
 public function main()
 {
     //init controller data
     $this->extensions->hk_InitData($this, __FUNCTION__);
     $this->loadLanguage('catalog/product');
     $this->loadModel('catalog/product');
     $this->loadModel('tool/image');
     //Clean up parametres if needed
     if (isset($this->request->get['keyword']) && $this->request->get['keyword'] == $this->language->get('filter_product')) {
         unset($this->request->get['keyword']);
     }
     if (isset($this->request->get['pfrom']) && $this->request->get['pfrom'] == 0) {
         unset($this->request->get['pfrom']);
     }
     if (isset($this->request->get['pto']) && $this->request->get['pto'] == $this->language->get('filter_price_max')) {
         unset($this->request->get['pto']);
     }
     //Prepare filter config
     $filter_params = array('category', 'status', 'keyword', 'match', 'pfrom', 'pto');
     $grid_filter_params = array('name', 'sort_order', 'model');
     $filter_form = new AFilter(array('method' => 'get', 'filter_params' => $filter_params));
     $filter_grid = new AFilter(array('method' => 'post', 'grid_filter_params' => $grid_filter_params));
     $data = array_merge($filter_form->getFilterData(), $filter_grid->getFilterData());
     $total = $this->model_catalog_product->getTotalProducts($data);
     $response = new stdClass();
     $response->page = $filter_grid->getParam('page');
     $response->total = $filter_grid->calcTotalPages($total);
     $response->records = $total;
     $response->userdata = new stdClass();
     $response->userdata->classes = array();
     $results = $this->model_catalog_product->getProducts($data);
     $product_ids = array();
     foreach ($results as $result) {
         $product_ids[] = (int) $result['product_id'];
     }
     $resource = new AResource('image');
     $thumbnails = $resource->getMainThumbList('products', $product_ids, $this->config->get('config_image_grid_width'), $this->config->get('config_image_grid_height'));
     $i = 0;
     foreach ($results as $result) {
         $thumbnail = $thumbnails[$result['product_id']];
         $response->rows[$i]['id'] = $result['product_id'];
         if (dateISO2Int($result['date_available']) > time()) {
             $response->userdata->classes[$result['product_id']] = 'warning';
         }
         if ($result['call_to_order'] > 0) {
             $price = $this->language->get('text_call_to_order');
         } else {
             $price = $this->html->buildInput(array('name' => 'price[' . $result['product_id'] . ']', 'value' => moneyDisplayFormat($result['price'])));
         }
         $response->rows[$i]['cell'] = array($thumbnail['thumb_html'], $this->html->buildInput(array('name' => 'product_description[' . $result['product_id'] . '][name]', 'value' => $result['name'])), $this->html->buildInput(array('name' => 'model[' . $result['product_id'] . ']', 'value' => $result['model'])), $price, $this->html->buildInput(array('name' => 'quantity[' . $result['product_id'] . ']', 'value' => $result['quantity'])), $this->html->buildCheckbox(array('name' => 'status[' . $result['product_id'] . ']', 'value' => $result['status'], 'style' => 'btn_switch')));
         $i++;
     }
     //update controller data
     $this->extensions->hk_UpdateData($this, __FUNCTION__);
     $this->load->library('json');
     $this->response->setOutput(AJson::encode($response));
 }
Example #2
0
 public function main()
 {
     if ($this->html_cache()) {
         return;
     }
     //init controller data
     $this->extensions->hk_InitData($this, __FUNCTION__);
     $this->loadLanguage('blocks/manufacturer');
     $this->view->assign('heading_title', $this->language->get('heading_title', 'blocks/manufacturer'));
     $this->view->assign('text_select', $this->language->get('text_select'));
     $resource = new AResource('image');
     //For product page show only brand icon
     if (isset($this->request->get['product_id']) && is_int($this->request->get['product_id'])) {
         $product_id = $this->request->get['product_id'];
         $this->view->assign('product_id', $product_id);
         $result = $this->model_catalog_manufacturer->getManufacturerByProductId($product_id);
         $manuf_detls = $result[0];
         $thumbnail = $resource->getMainThumb('manufacturers', $manuf_detls['manufacturer_id'], (int) $this->config->get('config_image_grid_width'), (int) $this->config->get('config_image_grid_height'));
         $manufacturer = array('manufacturer_id' => $manuf_detls['manufacturer_id'], 'name' => $manuf_detls['name'], 'href' => $this->html->getSEOURL('product/manufacturer', '&manufacturer_id=' . $manuf_detls['manufacturer_id'], '&encode'), 'icon' => $thumbnail['thumb_url']);
         $this->view->assign('manufacturer', $manufacturer);
     } else {
         if (isset($this->request->get['manufacturer_id']) && is_int($this->request->get['manufacturer_id'])) {
             $manufacturer_id = $this->request->get['manufacturer_id'];
         } else {
             $manufacturer_id = 0;
         }
         $this->view->assign('manufacturer_id', $manufacturer_id);
         $this->loadModel('catalog/manufacturer');
         $manufacturers = $manufacturer_ids = array();
         $results = $this->model_catalog_manufacturer->getManufacturers();
         foreach ($results as $result) {
             $manufacturer_ids[] = (int) $result['manufacturer_id'];
         }
         $thumbnails = $resource->getMainThumbList('manufacturers', $manufacturer_ids, $this->config->get('config_image_grid_width'), $this->config->get('config_image_grid_height'));
         foreach ($results as $result) {
             $thumbnail = $thumbnails[$result['manufacturer_id']];
             $manufacturers[] = array('manufacturer_id' => $result['manufacturer_id'], 'name' => $result['name'], 'href' => $this->html->getSEOURL('product/manufacturer', '&manufacturer_id=' . $result['manufacturer_id'], '&encode'), 'icon' => $thumbnail);
         }
         $this->view->assign('manufacturers', $manufacturers);
     }
     // framed needs to show frames for generic block.
     //If tpl used by listing block framed was set by listing block settings
     $this->view->assign('block_framed', true);
     $this->processTemplate('blocks/manufacturer.tpl');
     //init controller data
     $this->extensions->hk_UpdateData($this, __FUNCTION__);
 }
Example #3
0
 public function main()
 {
     $request = $this->request->get;
     //init controller data
     $this->extensions->hk_InitData($this, __FUNCTION__);
     //HTML cache only for non-customer
     if (!$this->customer->isLogged() && !$this->customer->isUnauthCustomer()) {
         $allowed_cache_keys = array('path');
         $cache_val = array('path' => $request['path']);
         $this->buildHTMLCacheKey($allowed_cache_keys, $cache_val);
         if ($this->html_cache()) {
             return;
         }
     }
     $this->view->assign('heading_title', $this->language->get('heading_title', 'blocks/category'));
     $this->loadModel('catalog/category');
     if (isset($request['path'])) {
         $this->path = explode('_', $request['path']);
         $this->category_id = end($this->path);
     }
     $this->view->assign('selected_category_id', $this->category_id);
     $this->view->assign('path', $request['path']);
     //load main lavel categories
     $all_categories = $this->model_catalog_category->getAllCategories();
     //build thumbnails list
     $category_ids = array();
     foreach ($all_categories as $category) {
         $category_ids[] = $category['category_id'];
     }
     $resource = new AResource('image');
     $this->thumbnails = $resource->getMainThumbList('categories', $category_ids, $this->config->get('config_image_category_width'), $this->config->get('config_image_category_height'));
     //Build category tree
     $this->_buildCategoryTree($all_categories);
     $categories = $this->_buildNestedCategoryList();
     $this->view->assign('categories', $categories);
     //Framed needs to show frames for generic block.
     //If tpl used by listing block framed was set by listing block settings
     $this->view->assign('block_framed', true);
     $this->view->assign('home_href', $this->html->getSEOURL('index/home'));
     $this->processTemplate();
     //init controller data
     $this->extensions->hk_UpdateData($this, __FUNCTION__);
 }
Example #4
0
 public function products()
 {
     $products = array();
     $products_data = array();
     //init controller data
     $this->extensions->hk_InitData($this, __FUNCTION__);
     $this->loadModel('catalog/product');
     if (isset($this->request->post['coupon_product'])) {
         $products = $this->request->post['coupon_product'];
         foreach ($products as $product_id) {
             $product_info = $this->model_catalog_product->getProduct($product_id);
             if ($product_info) {
                 $products_data[] = array('id' => $product_info['product_id'], 'name' => $product_info['name'], 'meta' => $product_info['model'], 'sort_order' => (int) $product_info['sort_order']);
             }
         }
     } else {
         if (isset($this->request->post['term'])) {
             $filter = array('limit' => 20, 'content_language_id' => $this->session->data['content_language_id'], 'filter' => array('keyword' => $this->request->post['term'], 'match' => 'all'));
             $products = $this->model_catalog_product->getProducts($filter);
             $product_ids = array();
             foreach ($products as $result) {
                 $product_ids[] = (int) $result['product_id'];
             }
             $resource = new AResource('image');
             $thumbnails = $resource->getMainThumbList('products', $product_ids, $this->config->get('config_image_grid_width'), $this->config->get('config_image_grid_height'));
             foreach ($products as $pdata) {
                 $thumbnail = $thumbnails[$pdata['product_id']];
                 if ($this->request->get['currency_code']) {
                     $price = round($this->currency->convert($pdata['price'], $this->config->get('config_currency'), $this->request->get['currency_code']), 2);
                 } else {
                     $price = $pdata['price'];
                 }
                 $frmt_price = $this->currency->format($pdata['price'], $this->request->get['currency_code'] ? $this->request->get['currency_code'] : $this->config->get('config_currency'));
                 $products_data[] = array('image' => $thumbnail['thumb_html'], 'id' => $pdata['product_id'], 'name' => $pdata['name'] . ' - ' . $frmt_price, 'price' => $price, 'meta' => $pdata['model'], 'sort_order' => (int) $pdata['sort_order']);
             }
         }
     }
     //update controller data
     $this->extensions->hk_UpdateData($this, __FUNCTION__);
     $this->load->library('json');
     $this->response->addJSONHeader();
     $this->response->setOutput(AJson::encode($products_data));
 }
Example #5
0
 public function getCategories($parent_categ_id = 0)
 {
     $this->extensions->hk_InitData($this, __FUNCTION__);
     $this->loadModel('catalog/category');
     $results = $this->model_catalog_category->getCategories($parent_categ_id);
     $category_ids = array();
     foreach ($results as $result) {
         $category_ids[] = (int) $result['category_id'];
     }
     //get thumbnails by one pass
     $resource = new AResource('image');
     $thumbnails = $resource->getMainThumbList('categories', $category_ids, $this->config->get('config_image_category_width'), $this->config->get('config_image_category_height'));
     foreach ($results as $result) {
         $thumbnail = $thumbnails[$result['category_id']];
         $categories[] = array('name' => $result['name'], 'category_id' => $result['category_id'], 'sort_order' => $result['sort_order'], 'thumb' => $thumbnail['thumb_url']);
     }
     $this->extensions->hk_UpdateData($this, __FUNCTION__);
     return $categories;
 }
Example #6
0
 public function get()
 {
     $this->extensions->hk_InitData($this, __FUNCTION__);
     $this->loadModel('catalog/product');
     $filter_data = array('method' => 'get');
     $filter = new AFilter($filter_data);
     $filters = $filter->getFilterData();
     $results = $this->model_catalog_product->getLatestProducts($filters['limit']);
     $response = new stdClass();
     $response->page = $filter->getParam('page');
     $response->total = $total_pages;
     $response->records = $filters['limit'];
     $response->limit = $filters['limit'];
     $response->sidx = $filters['sort'];
     $response->sord = $filters['order'];
     $response->params = $filters;
     $i = 0;
     if ($results) {
         $product_ids = array();
         foreach ($results as $result) {
             $product_ids[] = (int) $result['product_id'];
         }
         $resource = new AResource('image');
         $thumbnails = $resource->getMainThumbList('products', $product_ids, $this->config->get('config_image_thumb_width'), $this->config->get('config_image_thumb_height'));
         foreach ($results as $result) {
             $thumbnail = $thumbnails[$result['product_id']];
             $response->rows[$i]['id'] = $result['product_id'];
             $response->rows[$i]['cell']['thumb'] = $thumbnail['thumb_url'];
             $response->rows[$i]['cell']['name'] = $result['name'];
             $response->rows[$i]['cell']['description'] = $result['description'];
             $response->rows[$i]['cell']['model'] = $result['model'];
             $response->rows[$i]['cell']['price'] = $this->currency->convert($result['final_price'], $this->config->get('config_currency'), $this->currency->getCode());
             $response->rows[$i]['cell']['currency_code'] = $this->currency->getCode();
             $response->rows[$i]['cell']['rating'] = $result['rating'];
             $i++;
         }
     }
     $this->extensions->hk_UpdateData($this, __FUNCTION__);
     $this->rest->setResponseData($response);
     $this->rest->sendResponse(200);
 }
Example #7
0
 public function main()
 {
     //init controller data
     $this->extensions->hk_InitData($this, __FUNCTION__);
     $this->loadLanguage('catalog/review');
     $this->loadModel('catalog/review');
     $this->loadModel('tool/image');
     //Prepare filter config
     $filter_params = array('product_id', 'status');
     $grid_filter_params = array('name', 'author');
     $filter_form = new AFilter(array('method' => 'get', 'filter_params' => $filter_params));
     $filter_grid = new AFilter(array('method' => 'post', 'grid_filter_params' => $grid_filter_params));
     $total = $this->model_catalog_review->getTotalReviews(array_merge($filter_form->getFilterData(), $filter_grid->getFilterData()));
     $response = new stdClass();
     $response->page = $filter_grid->getParam('page');
     $response->total = $filter_grid->calcTotalPages($total);
     $response->records = $total;
     $results = $this->model_catalog_review->getReviews(array_merge($filter_form->getFilterData(), $filter_grid->getFilterData()));
     $product_ids = array();
     foreach ($results as $result) {
         $product_ids[] = (int) $result['product_id'];
     }
     $resource = new AResource('image');
     $thumbnails = $resource->getMainThumbList('products', $product_ids, $this->config->get('config_image_grid_width'), $this->config->get('config_image_grid_height'));
     $i = 0;
     foreach ($results as $result) {
         $thumbnail = $thumbnails[$result['product_id']];
         $response->rows[$i]['id'] = $result['review_id'];
         $response->rows[$i]['cell'] = array($thumbnail['thumb_html'], $result['name'], $result['author'], $result['rating'], $this->html->buildCheckbox(array('name' => 'status[' . $result['review_id'] . ']', 'value' => $result['status'], 'style' => 'btn_switch')), dateISO2Display($result['date_added'], $this->language->get('date_format_short')));
         $i++;
     }
     //update controller data
     $this->extensions->hk_UpdateData($this, __FUNCTION__);
     $this->load->library('json');
     $this->response->setOutput(AJson::encode($response));
 }
Example #8
0
 public function main()
 {
     //init controller data
     $this->extensions->hk_InitData($this, __FUNCTION__);
     if (isset($this->request->get['order_id'])) {
         $order_id = (int) $this->request->get['order_id'];
     } else {
         $order_id = 0;
     }
     $this->loadModel('account/order');
     $guest = false;
     if (isset($this->request->get['ot']) && $this->config->get('config_guest_checkout')) {
         //try to decrypt order token
         $ot = $this->request->get['ot'];
         $decrypted = AEncryption::mcrypt_decode($ot);
         list($order_id, $email) = explode('~~~', $decrypted);
         $order_id = (int) $order_id;
         if (!$decrypted || !$order_id || !$email) {
             if ($order_id) {
                 $this->session->data['redirect'] = $this->html->getSecureURL('account/invoice', '&order_id=' . $order_id);
             }
             $this->redirect($this->html->getSecureURL('account/login'));
         }
         $order_info = $this->model_account_order->getOrder($order_id, '', 'view');
         //compare emails
         if ($order_info['email'] != $email) {
             $this->redirect($this->html->getSecureURL('account/login'));
         }
         $guest = true;
     }
     if ($this->request->is_POST() && $this->_validate()) {
         $guest = true;
         $order_id = $this->request->post['order_id'];
         $email = $this->request->post['email'];
         $ot = AEncryption::mcrypt_encode($order_id . '~~~' . $email);
         $order_info = $this->model_account_order->getOrder($order_id, '', 'view');
         //compare emails
         if ($order_info['email'] != $email) {
             unset($order_info, $order_id, $email);
         }
     }
     $this->view->assign('error', $this->error);
     if (!$this->customer->isLogged() && !$guest) {
         $this->session->data['redirect'] = $this->html->getSecureURL('account/invoice', '&order_id=' . $order_id);
         $this->getForm();
         return null;
     }
     if (!$order_id && $this->customer->isLogged()) {
         $this->redirect($this->html->getSecureURL('account/history'));
     }
     //get info for registered customers
     if (!$order_info) {
         $order_info = $this->model_account_order->getOrder($order_id);
     }
     $this->document->setTitle($this->language->get('heading_title'));
     $this->document->resetBreadcrumbs();
     $this->document->addBreadcrumb(array('href' => $this->html->getURL('index/home'), 'text' => $this->language->get('text_home'), 'separator' => false));
     $this->document->addBreadcrumb(array('href' => $this->html->getURL('account/account'), 'text' => $this->language->get('text_account'), 'separator' => $this->language->get('text_separator')));
     if (!$guest) {
         $this->document->addBreadcrumb(array('href' => $this->html->getURL('account/history'), 'text' => $this->language->get('text_history'), 'separator' => $this->language->get('text_separator')));
     }
     $this->document->addBreadcrumb(array('href' => $this->html->getURL('account/invoice', '&order_id=' . $order_id), 'text' => $this->language->get('text_invoice'), 'separator' => $this->language->get('text_separator')));
     $this->data['success'] = '';
     if (isset($this->session->data['success'])) {
         $this->data['success'] = $this->session->data['success'];
         unset($this->session->data['success']);
     }
     if ($order_info) {
         $this->data['order_id'] = $order_id;
         $this->data['invoice_id'] = $order_info['invoice_id'] ? $order_info['invoice_prefix'] . $order_info['invoice_id'] : '';
         $this->data['email'] = $order_info['email'];
         $this->data['telephone'] = $order_info['telephone'];
         $this->data['fax'] = $order_info['fax'];
         $this->data['status'] = $this->model_account_order->getOrderStatus($order_id);
         $shipping_data = array('firstname' => $order_info['shipping_firstname'], 'lastname' => $order_info['shipping_lastname'], 'company' => $order_info['shipping_company'], 'address_1' => $order_info['shipping_address_1'], 'address_2' => $order_info['shipping_address_2'], 'city' => $order_info['shipping_city'], 'postcode' => $order_info['shipping_postcode'], 'zone' => $order_info['shipping_zone'], 'zone_code' => $order_info['shipping_zone_code'], 'country' => $order_info['shipping_country']);
         $this->data['shipping_address'] = $this->customer->getFormattedAddress($shipping_data, $order_info['shipping_address_format']);
         $this->data['shipping_method'] = $order_info['shipping_method'];
         $payment_data = array('firstname' => $order_info['payment_firstname'], 'lastname' => $order_info['payment_lastname'], 'company' => $order_info['payment_company'], 'address_1' => $order_info['payment_address_1'], 'address_2' => $order_info['payment_address_2'], 'city' => $order_info['payment_city'], 'postcode' => $order_info['payment_postcode'], 'zone' => $order_info['payment_zone'], 'zone_code' => $order_info['payment_zone_code'], 'country' => $order_info['payment_country']);
         $this->data['payment_address'] = $this->customer->getFormattedAddress($payment_data, $order_info['payment_address_format']);
         $this->data['payment_method'] = $order_info['payment_method'];
         $products = array();
         $order_products = $this->model_account_order->getOrderProducts($order_id);
         $product_ids = array();
         foreach ($order_products as $product) {
             $product_ids[] = (int) $product['product_id'];
         }
         //get thumbnails by one pass
         $resource = new AResource('image');
         $thumbnails = $resource->getMainThumbList('products', $product_ids, $this->config->get('config_image_cart_width'), $this->config->get('config_image_cart_width'), false);
         foreach ($order_products as $product) {
             $options = $this->model_account_order->getOrderOptions($order_id, $product['order_product_id']);
             $thumbnail = $thumbnails[$product['product_id']];
             $option_data = array();
             foreach ($options as $option) {
                 if ($option['element_type'] == 'H') {
                     continue;
                 }
                 //hide hidden options
                 $value = $option['value'];
                 $title = '';
                 // hide binary value for checkbox
                 if ($option['element_type'] == 'C' && in_array($value, array(0, 1))) {
                     $value = '';
                 }
                 // strip long textarea value
                 if ($option['element_type'] == 'T') {
                     $title = strip_tags($value);
                     $title = str_replace('\\r\\n', "\n", $title);
                     $value = str_replace('\\r\\n', "\n", $value);
                     if (mb_strlen($value) > 64) {
                         $value = mb_substr($value, 0, 64) . '...';
                     }
                 }
                 $option_data[] = array('name' => $option['name'], 'value' => $value, 'title' => $title);
             }
             $products[] = array('id' => $product['product_id'], 'thumbnail' => $thumbnail, 'name' => $product['name'], 'model' => $product['model'], 'option' => $option_data, 'quantity' => $product['quantity'], 'price' => $this->currency->format($product['price'], $order_info['currency'], $order_info['value']), 'total' => $this->currency->format($product['total'], $order_info['currency'], $order_info['value']));
         }
         $this->data['products'] = $products;
         $this->data['totals'] = $this->model_account_order->getOrderTotals($order_id);
         $this->data['comment'] = $order_info['comment'];
         $this->data['product_link'] = $this->html->getSecureURL('product/product', '&product_id=%ID%');
         $historys = array();
         $results = $this->model_account_order->getOrderHistories($order_id);
         foreach ($results as $result) {
             $historys[] = array('date_added' => dateISO2Display($result['date_added'], $this->language->get('date_format_short') . ' ' . $this->language->get('time_format')), 'status' => $result['status'], 'comment' => nl2br($result['comment']));
         }
         $this->data['historys'] = $historys;
         if ($guest) {
             $this->data['continue'] = $this->html->getSecureURL('index/home');
         } else {
             $this->data['continue'] = $this->html->getSecureURL('account/history');
         }
         $this->data['button_print'] = $this->html->buildElement(array('type' => 'button', 'name' => 'print_button', 'text' => $this->language->get('button_print'), 'icon' => 'fa fa-print', 'style' => 'button'));
         //button for order cancelation
         if ($this->config->get('config_customer_cancelation_order_status_id')) {
             $order_cancel_ids = unserialize($this->config->get('config_customer_cancelation_order_status_id'));
             if (in_array($order_info['order_status_id'], $order_cancel_ids)) {
                 $this->data['button_order_cancel'] = $this->html->buildElement(array('type' => 'button', 'name' => 'button_order_cancelation', 'text' => $this->language->get('text_order_cancelation'), 'icon' => 'fa fa-ban', 'style' => 'button'));
                 if (!$guest) {
                     $this->data['order_cancelation_url'] = $this->html->getSecureURL('account/invoice/CancelOrder', '&order_id=' . $order_id);
                 } else {
                     $this->data['order_cancelation_url'] = $this->html->getSecureURL('account/invoice/CancelOrder', '&ot=' . $ot);
                 }
             }
         }
         $this->view->setTemplate('pages/account/invoice.tpl');
     } else {
         if ($guest) {
             $this->data['continue'] = $this->html->getSecureURL('index/home');
         } else {
             $this->data['continue'] = $this->html->getSecureURL('account/account');
         }
         $this->view->setTemplate('pages/error/not_found.tpl');
     }
     $this->data['button_continue'] = $this->html->buildElement(array('type' => 'button', 'name' => 'continue_button', 'text' => $this->language->get('button_continue'), 'icon' => 'fa fa-arrow-right', 'style' => 'button'));
     $this->view->batchAssign($this->data);
     $this->processTemplate();
     //update controller data
     $this->extensions->hk_UpdateData($this, __FUNCTION__);
 }
Example #9
0
 public function getCustomListingSubForm()
 {
     //init controller data
     $this->extensions->hk_InitData($this, __FUNCTION__);
     $this->load->library('json');
     $lm = new ALayoutManager();
     $form_name = has_value($this->request->get['form_name']) ? $this->request->get['form_name'] : 'BlockFrm';
     $custom_block_id = (int) $this->request->get['custom_block_id'];
     $listing_datasource = $this->request->post_or_get('listing_datasource');
     // need to get data of custom listing
     if ($custom_block_id) {
         $content = $lm->getBlockDescriptions($custom_block_id);
         $content = $content[$this->language->getContentLanguageID()]['content'];
         $content = unserialize($content);
         if ($content['listing_datasource'] == $listing_datasource) {
             $lm = new AListingManager($custom_block_id);
             $list = $lm->getCustomList();
             $options_list = array();
             if ($list) {
                 foreach ($list as $row) {
                     $options_list[(int) $row['id']] = array();
                 }
                 $ids = array_keys($options_list);
                 switch ($listing_datasource) {
                     case 'custom_products':
                         $this->loadModel('catalog/product');
                         $filter = array('subsql_filter' => 'p.product_id in (' . implode(',', $ids) . ')');
                         $results = $this->model_catalog_product->getProducts($filter);
                         $id_name = 'product_id';
                         $rl_object_name = 'products';
                         break;
                     case 'custom_categories':
                         $this->loadModel('catalog/category');
                         $filter = array('subsql_filter' => 'c.category_id in (' . implode(',', $ids) . ')');
                         $results = $this->model_catalog_category->getCategoriesData($filter);
                         $id_name = 'category_id';
                         $rl_object_name = 'categories';
                         break;
                     case 'custom_manufacturers':
                         $this->loadModel('catalog/manufacturer');
                         $filter = array('subsql_filter' => 'm.manufacturer_id in (' . implode(',', $ids) . ')');
                         $results = $this->model_catalog_manufacturer->getManufacturers($filter);
                         $id_name = 'manufacturer_id';
                         $rl_object_name = 'manufacturers';
                         break;
                 }
                 //get thumbnails by one pass
                 $resource = new AResource('image');
                 $thumbnails = $resource->getMainThumbList($rl_object_name, $ids, $this->config->get('config_image_grid_width'), $this->config->get('config_image_grid_height'), false);
                 foreach ($results as $item) {
                     $id = $item[$id_name];
                     if (in_array($id, $ids)) {
                         $thumbnail = $thumbnails[$id];
                         $icon = $thumbnail['thumb_html'] ? $thumbnail['thumb_html'] : '<i class="fa fa-code fa-4x"></i>&nbsp;';
                         $options_list[$id] = array('image' => $icon, 'id' => $id, 'name' => $item['name'], 'meta' => $item['model'], 'sort_order' => (int) $item['sort_order']);
                     }
                 }
             }
         }
     }
     switch ($listing_datasource) {
         case 'custom_products':
             $ajax_url = $this->html->getSecureURL('r/product/product/products');
             break;
         case 'custom_categories':
             $ajax_url = $this->html->getSecureURL('r/listing_grid/category/categories');
             break;
         case 'custom_manufacturers':
             $ajax_url = $this->html->getSecureURL('r/listing_grid/manufacturer/manufacturers');
             break;
     }
     $form = new AForm('ST');
     $form->setForm(array('form_name' => $form_name));
     $multivalue_html = $form->getFieldHtml(array('type' => 'multiselectbox', 'name' => 'selected[]', 'value' => $ids, 'options' => $options_list, 'style' => 'chosen', 'ajax_url' => $ajax_url, 'placeholder' => $this->language->get('text_select_from_lookup')));
     $this->view->assign('multivalue_html', $multivalue_html);
     $this->view->assign('form_name', $form_name);
     //update controller data
     $this->extensions->hk_UpdateData($this, __FUNCTION__);
     $this->processTemplate('responses/design/block_custom_listing_subform.tpl');
 }
Example #10
0
 public function main()
 {
     //init controller data
     $this->extensions->hk_InitData($this, __FUNCTION__);
     //is this an embed mode
     $cart_rt = 'checkout/cart';
     if ($this->config->get('embed_mode') == true) {
         $cart_rt = 'r/checkout/cart/embed';
     }
     if (!$this->cart->hasProducts() || !$this->cart->hasStock() && !$this->config->get('config_stock_checkout')) {
         $this->redirect($this->html->getSecureURL($cart_rt));
     }
     //validate if order min/max are met
     if (!$this->cart->hasMinRequirement() || !$this->cart->hasMaxRequirement()) {
         $this->redirect($this->html->getSecureURL($cart_rt));
     }
     if ($this->customer->isLogged()) {
         $this->redirect($this->html->getSecureURL('checkout/shipping'));
     }
     if (!isset($this->session->data['guest'])) {
         $this->redirect($this->html->getSecureURL('checkout/guest_step_1'));
     }
     if ($this->cart->hasShipping()) {
         if (!isset($this->session->data['shipping_method'])) {
             $this->redirect($this->html->getSecureURL('checkout/guest_step_2'));
         }
     } else {
         unset($this->session->data['shipping_method']);
         unset($this->session->data['shipping_methods']);
         //$this->tax->setZone($this->config->get('config_country_id'), $this->config->get('config_zone_id'));
         $this->tax->setZone($this->session->data['country_id'], $this->session->data['zone_id']);
     }
     if (!isset($this->session->data['payment_method'])) {
         $this->redirect($this->html->getSecureURL('checkout/guest_step_2'));
     }
     $this->loadLanguage('checkout/confirm');
     $this->document->setTitle($this->language->get('heading_title'));
     //build and save order
     $this->data = array();
     $order = new AOrder($this->registry);
     $this->data = $order->buildOrderData($this->session->data);
     $this->session->data['order_id'] = $order->saveOrder();
     $this->document->resetBreadcrumbs();
     $this->document->addBreadcrumb(array('href' => $this->html->getURL('index/home'), 'text' => $this->language->get('text_home'), 'separator' => FALSE));
     $this->document->addBreadcrumb(array('href' => $this->html->getURL($cart_rt), 'text' => $this->language->get('text_basket'), 'separator' => $this->language->get('text_separator')));
     $this->document->addBreadcrumb(array('href' => $this->html->getSecureURL('checkout/guest_step_1'), 'text' => $this->language->get('text_guest_step_1'), 'separator' => $this->language->get('text_separator')));
     $this->document->addBreadcrumb(array('href' => $this->html->getSecureURL('checkout/guest_step_2'), 'text' => $this->language->get('text_guest_step_2'), 'separator' => $this->language->get('text_separator')));
     $this->document->addBreadcrumb(array('href' => $this->html->getSecureURL('checkout/guest_step_3'), 'text' => $this->language->get('text_confirm'), 'separator' => $this->language->get('text_separator')));
     $this->view->assign('error_warning', $this->error['warning']);
     $this->view->assign('success', $this->session->data['success']);
     if (isset($this->session->data['success'])) {
         unset($this->session->data['success']);
     }
     if ($this->cart->hasShipping()) {
         if (isset($this->session->data['guest']['shipping'])) {
             $shipping_address = $this->session->data['guest']['shipping'];
         } else {
             $shipping_address = $this->session->data['guest'];
         }
         $this->data['shipping_address'] = $this->customer->getFormattedAddress($shipping_address, $shipping_address['address_format']);
     } else {
         $this->data['shipping_address'] = '';
     }
     if (isset($this->session->data['shipping_method']['title'])) {
         $this->data['shipping_method'] = $this->session->data['shipping_method']['title'];
     } else {
         $this->data['shipping_method'] = '';
     }
     $this->data['checkout_shipping'] = $this->html->getSecureURL('checkout/guest_step_2');
     $this->data['checkout_shipping_edit'] = $this->html->getSecureURL('checkout/guest_step_2', '&mode=edit', true);
     $this->data['checkout_shipping_address'] = $this->html->getSecureURL('checkout/guest_step_1');
     $payment_address = $this->session->data['guest'];
     if ($payment_address) {
         $this->data['payment_address'] = $this->customer->getFormattedAddress($payment_address, $payment_address['address_format']);
     } else {
         $this->data['payment_address'] = '';
     }
     if ($this->session->data['payment_method']['id'] != 'no_payment_required') {
         $this->data['payment_method'] = $this->session->data['payment_method']['title'];
     } else {
         $this->data['payment_method'] = '';
     }
     $this->data['checkout_payment'] = $this->html->getSecureURL('checkout/guest_step_2');
     $this->data['checkout_payment_edit'] = $this->html->getSecureURL('checkout/guest_step_2', '&mode=edit', true);
     $this->data['cart'] = $this->html->getSecureURL($cart_rt);
     $this->data['checkout_payment_address'] = $this->html->getSecureURL('checkout/guest_step_1');
     $this->loadModel('tool/seo_url');
     $product_ids = array();
     foreach ($this->data['products'] as $result) {
         $product_ids[] = (int) $result['product_id'];
     }
     //Format product data specific for confirmation page
     $resource = new AResource('image');
     $thumbnails = $resource->getMainThumbList('products', $product_ids, $this->config->get('config_image_cart_width'), $this->config->get('config_image_cart_height'));
     for ($i = 0; $i < sizeof($this->data['products']); $i++) {
         $product_id = $this->data['products'][$i]['product_id'];
         $thumbnail = $thumbnails[$product_id];
         $tax = $this->tax->calcTotalTaxAmount($this->data['products'][$i]['total'], $this->data['products'][$i]['tax_class_id']);
         $this->data['products'][$i] = array_merge($this->data['products'][$i], array('thumb' => $thumbnail, 'tax' => $this->currency->format($tax), 'price' => $this->currency->format($this->data['products'][$i]['price']), 'total' => $this->currency->format($this->data['products'][$i]['total']), 'href' => $this->html->getSEOURL('product/product', '&product_id=' . $product_id, true)));
     }
     if ($this->config->get('config_checkout_id')) {
         $this->loadModel('catalog/content');
         $content_info = $this->model_catalog_content->getContent($this->config->get('config_checkout_id'));
         if ($content_info) {
             $this->data['text_accept_agree'] = $this->language->get('text_accept_agree');
             $this->data['text_accept_agree_href'] = $this->html->getSEOURL('r/content/content/loadInfo', '&content_id=' . $this->config->get('config_checkout_id'), true);
             $this->data['text_accept_agree_href_link'] = $content_info['title'];
         } else {
             $this->data['text_accept_agree'] = '';
         }
     } else {
         $this->data['text_accept_agree'] = '';
     }
     if ($this->session->data['payment_method']['id'] != 'no_payment_required') {
         $this->addChild('responses/extension/' . $this->session->data['payment_method']['id'], 'payment');
     } else {
         $this->addChild('responses/checkout/no_payment', 'payment');
     }
     $this->view->batchAssign($this->data);
     $this->processTemplate('pages/checkout/confirm.tpl');
     //init controller data
     $this->extensions->hk_UpdateData($this, __FUNCTION__);
 }
 public function main()
 {
     //init controller data
     $this->extensions->hk_InitData($this, __FUNCTION__);
     $this->loadLanguage('catalog/product');
     $this->document->setTitle($this->language->get('heading_title'));
     $this->loadModel('catalog/product');
     if (isset($this->request->get['product_id']) && $this->request->is_GET()) {
         $product_info = $this->model_catalog_product->getProduct($this->request->get['product_id']);
         if (!$product_info) {
             $this->session->data['warning'] = $this->language->get('error_product_not_found');
             $this->redirect($this->html->getSecureURL('catalog/product'));
         }
     }
     if ($this->request->is_POST()) {
         $this->model_catalog_product->updateProductLinks($this->request->get['product_id'], $this->request->post);
         $this->session->data['success'] = $this->language->get('text_success');
         $this->redirect($this->html->getSecureURL('catalog/product_relations', '&product_id=' . $this->request->get['product_id']));
     }
     $this->data['product_description'] = $this->model_catalog_product->getProductDescriptions($this->request->get['product_id']);
     $this->view->assign('error_warning', $this->error['warning']);
     $this->view->assign('success', $this->session->data['success']);
     if (isset($this->session->data['success'])) {
         unset($this->session->data['success']);
     }
     $this->document->initBreadcrumb(array('href' => $this->html->getSecureURL('index/home'), 'text' => $this->language->get('text_home'), 'separator' => FALSE));
     $this->document->addBreadcrumb(array('href' => $this->html->getSecureURL('catalog/product'), 'text' => $this->language->get('heading_title'), 'separator' => ' :: '));
     $this->document->addBreadcrumb(array('href' => $this->html->getSecureURL('catalog/product/update', '&product_id=' . $this->request->get['product_id']), 'text' => $this->language->get('text_edit') . '&nbsp;' . $this->language->get('text_product') . ' - ' . $this->data['product_description'][$this->session->data['content_language_id']]['name'], 'separator' => ' :: '));
     $this->document->addBreadcrumb(array('href' => $this->html->getSecureURL('catalog/product_relations', '&product_id=' . $this->request->get['product_id']), 'text' => $this->language->get('tab_relations'), 'separator' => ' :: ', 'current' => true));
     $this->loadModel('catalog/category');
     $this->data['categories'] = array();
     $results = $this->model_catalog_category->getCategories(0);
     foreach ($results as $r) {
         $this->data['categories'][$r['category_id']] = $r['name'];
     }
     $this->loadModel('setting/store');
     $this->data['stores'] = array(0 => $this->language->get('text_default'));
     $results = $this->model_setting_store->getStores();
     foreach ($results as $r) {
         $this->data['stores'][$r['store_id']] = $r['name'];
     }
     $this->data['product_category'] = $this->model_catalog_product->getProductCategories($this->request->get['product_id']);
     $this->data['product_store'] = $this->model_catalog_product->getProductStores($this->request->get['product_id']);
     $this->data['product_related'] = $this->model_catalog_product->getProductRelated($this->request->get['product_id']);
     $this->data['active'] = 'relations';
     //load tabs controller
     $tabs_obj = $this->dispatch('pages/catalog/product_tabs', array($this->data));
     $this->data['product_tabs'] = $tabs_obj->dispatchGetOutput();
     unset($tabs_obj);
     $this->data['category_products'] = $this->html->getSecureURL('product/product/category');
     $this->data['related_products'] = $this->html->getSecureURL('product/product/related');
     $this->data['action'] = $this->html->getSecureURL('catalog/product_relations', '&product_id=' . $this->request->get['product_id']);
     $this->data['form_title'] = $this->language->get('text_edit') . '&nbsp;' . $this->language->get('text_product');
     $this->data['update'] = $this->html->getSecureURL('listing_grid/product/update_relations_field', '&id=' . $this->request->get['product_id']);
     $form = new AForm('HS');
     $form->setForm(array('form_name' => 'productFrm', 'update' => $this->data['update']));
     $this->data['form']['id'] = 'productFrm';
     $this->data['form']['form_open'] = $form->getFieldHtml(array('type' => 'form', 'name' => 'productFrm', 'action' => $this->data['action'], 'attr' => 'data-confirm-exit="true" class="aform form-horizontal"'));
     $this->data['form']['submit'] = $form->getFieldHtml(array('type' => 'button', 'name' => 'submit', 'text' => $this->language->get('button_save'), 'style' => 'button1'));
     $this->data['form']['cancel'] = $form->getFieldHtml(array('type' => 'button', 'href' => $this->html->getSecureURL('catalog/product/update', '&product_id=' . $this->request->get['product_id']), 'name' => 'cancel', 'text' => $this->language->get('button_cancel'), 'style' => 'button2'));
     $this->data['cancel'] = $this->html->getSecureURL('catalog/product');
     $this->loadModel('catalog/category');
     $this->data['categories'] = array();
     $results = $this->model_catalog_category->getCategories(0);
     foreach ($results as $r) {
         $this->data['categories'][$r['category_id']] = $r['name'];
     }
     $this->data['form']['fields']['category'] = $form->getFieldHtml(array('type' => 'checkboxgroup', 'name' => 'product_category[]', 'value' => $this->data['product_category'], 'options' => $this->data['categories'], 'style' => 'chosen', 'placeholder' => $this->language->get('text_select_category')));
     //load only prior saved products
     $resource = new AResource('image');
     $this->data['products'] = array();
     if (count($this->data['product_related'])) {
         $this->loadModel('catalog/product');
         $filter = array('subsql_filter' => 'p.product_id in (' . implode(',', $this->data['product_related']) . ')');
         $results = $this->model_catalog_product->getProducts($filter);
         $product_ids = array();
         foreach ($results as $result) {
             $product_ids[] = (int) $result['product_id'];
         }
         //get thumbnails by one pass
         $resource = new AResource('image');
         $thumbnails = $resource->getMainThumbList('products', $product_ids, $this->config->get('config_image_grid_width'), $this->config->get('config_image_grid_height'));
         foreach ($results as $r) {
             $thumbnail = $thumbnails[$r['product_id']];
             $this->data['products'][$r['product_id']]['name'] = $r['name'] . " (" . $r['model'] . ")";
             $this->data['products'][$r['product_id']]['image'] = $thumbnail['thumb_html'];
         }
     }
     $this->data['form']['fields']['related'] = $form->getFieldHtml(array('type' => 'multiselectbox', 'name' => 'product_related[]', 'value' => $this->data['product_related'], 'options' => $this->data['products'], 'style' => 'chosen', 'ajax_url' => $this->html->getSecureURL('r/product/product/products'), 'placeholder' => $this->language->get('text_select_from_lookup')));
     $this->data['form']['fields']['store'] = $form->getFieldHtml(array('type' => 'checkboxgroup', 'name' => 'product_store[]', 'value' => $this->data['product_store'], 'options' => $this->data['stores'], 'style' => 'chosen'));
     if ($this->config->get('config_embed_status')) {
         $this->data['embed_url'] = $this->html->getSecureURL('common/do_embed/product', '&product_id=' . $this->request->get['product_id']);
     }
     $this->addChild('pages/catalog/product_summary', 'summary_form', 'pages/catalog/product_summary.tpl');
     $this->view->assign('help_url', $this->gen_help_url('product_relations'));
     $this->view->batchAssign($this->data);
     $this->processTemplate('pages/catalog/product_relations.tpl');
     //update controller data
     $this->extensions->hk_UpdateData($this, __FUNCTION__);
 }
Example #12
0
 public function main()
 {
     //init controller data
     $this->extensions->hk_InitData($this, __FUNCTION__);
     if (!$this->customer->isLogged()) {
         $this->session->data['redirect'] = $this->html->getSecureURL('account/download');
         $this->redirect($this->html->getSecureURL('account/login'));
     }
     //if disabled downloads redirect to
     if (!$this->config->get('config_download')) {
         $this->redirect($this->html->getSecureURL('account/account'));
     }
     $this->document->setTitle($this->language->get('heading_title'));
     $this->document->resetBreadcrumbs();
     $this->document->addBreadcrumb(array('href' => $this->html->getSecureURL('index/home'), 'text' => $this->language->get('text_home'), 'separator' => FALSE));
     $this->document->addBreadcrumb(array('href' => $this->html->getSecureURL('account/account'), 'text' => $this->language->get('text_account'), 'separator' => $this->language->get('text_separator')));
     $this->document->addBreadcrumb(array('href' => $this->html->getSecureURL('account/download'), 'text' => $this->language->get('text_downloads'), 'separator' => $this->language->get('text_separator')));
     if (isset($this->request->get['limit'])) {
         $limit = (int) $this->request->get['limit'];
         $limit = $limit > 50 ? 50 : $limit;
     } else {
         $limit = $this->config->get('config_catalog_limit');
     }
     if ($this->config->get('config_download')) {
         if (isset($this->request->get['page'])) {
             $page = $this->request->get['page'];
         } else {
             $page = 1;
         }
         $downloads = array();
         //get only enabled, not expired, which have remaining count > 0 and available
         $customer_downloads = $this->download->getCustomerDownloads(($page - 1) * $limit, $limit);
         $product_ids = array();
         foreach ($customer_downloads as $result) {
             $product_ids[] = (int) $result['product_id'];
         }
         $resource = new AResource('image');
         $thumbnails = $resource->getMainThumbList('products', $product_ids, $this->config->get('config_image_cart_width'), $this->config->get('config_image_cart_height'), false);
         foreach ($customer_downloads as $download_info) {
             $text_status = $this->download->getTextStatusForOrderDownload($download_info);
             $size = filesize(DIR_RESOURCE . $download_info['filename']);
             $i = 0;
             $suffix = array('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
             while ($size / 1024 > 1) {
                 $size = $size / 1024;
                 $i++;
             }
             if (!$text_status) {
                 $download_button = $this->html->buildElement(array('type' => 'button', 'name' => 'download_button_' . $download_info['order_download_id'], 'title' => $this->language->get('text_download'), 'text' => $this->language->get('text_download'), 'style' => 'button', 'href' => $this->html->getSecureURL('account/download/startdownload', '&order_download_id=' . $download_info['order_download_id']), 'icon' => 'fa fa-download-alt'));
             } else {
                 $download_text = $text_status;
             }
             $thumbnail = $thumbnails[$download_info['product_id']];
             $attributes = $this->download->getDownloadAttributesValuesForCustomer($download_info['download_id']);
             $downloads[] = array('thumbnail' => $thumbnail, 'attributes' => $attributes, 'order_id' => $download_info['order_id'], 'date_added' => dateISO2Display($download_info['date_added'], $this->language->get('date_format_short')), 'name' => $download_info['name'], 'remaining' => $download_info['remaining_count'], 'size' => round(substr($size, 0, strpos($size, '.') + 4), 2) . $suffix[$i], 'button' => $download_button, 'text' => $download_text, 'expire_date' => dateISO2Display($download_info['expire_date'], $this->language->get('date_format_short') . ' ' . $this->language->get('time_format_short')));
         }
         $this->data['downloads'] = $downloads;
         $this->data['pagination_bootstrap'] = HtmlElementFactory::create(array('type' => 'Pagination', 'name' => 'pagination', 'text' => $this->language->get('text_pagination'), 'text_limit' => $this->language->get('text_per_page'), 'total' => sizeof($downloads), 'page' => $page, 'limit' => $limit, 'url' => $this->html->getURL('account/download&page={page}', '&encode'), 'style' => 'pagination'));
         if ($downloads) {
             $template = 'pages/account/download.tpl';
         } else {
             $template = 'pages/error/not_found.tpl';
         }
     } else {
         $template = 'pages/error/not_found.tpl';
     }
     $continue = HtmlElementFactory::create(array('type' => 'button', 'name' => 'continue_button', 'text' => $this->language->get('button_continue'), 'style' => 'button', 'icon' => 'fa fa-arrow-right', 'href' => $this->html->getSecureURL('account/account')));
     $this->data['button_continue'] = $continue;
     $this->view->batchAssign($this->data);
     $this->processTemplate($template);
     //init controller data
     $this->extensions->hk_UpdateData($this, __FUNCTION__);
 }
Example #13
0
 /**
  * @throws AException
  * NOTE: this method have a few hk_processData calls.
  */
 public function main()
 {
     $error_msg = array();
     $cart_rt = 'checkout/cart';
     $product_rt = 'product/product';
     $checkout_rt = 'checkout/shipping';
     $home_rt = 'index/home';
     //is this an embed mode
     if ($this->config->get('embed_mode') == true) {
         $cart_rt = 'r/checkout/cart/embed';
     }
     //init controller data
     $this->extensions->hk_InitData($this, __FUNCTION__);
     //process all possible requests first
     if ($this->request->is_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;
         }
         unset($this->session->data['shipping_methods']);
         unset($this->session->data['shipping_method']);
         unset($this->session->data['payment_methods']);
         unset($this->session->data['payment_method']);
         $this->cart->add($this->request->get['product_id'], $quantity, $option);
         $this->extensions->hk_ProcessData($this, 'add_product');
         $this->redirect($this->html->getSecureURL($cart_rt));
     } else {
         if ($this->request->is_GET() && isset($this->request->get['remove'])) {
             //remove product with button claick.
             $this->cart->remove($this->request->get['remove']);
             $this->extensions->hk_ProcessData($this, 'remove_product');
             $this->redirect($this->html->getSecureURL($cart_rt));
         } else {
             if ($this->request->is_POST()) {
                 //if this is coupon, validate and apply
                 if (isset($this->request->post['coupon']) && $this->_validateCoupon()) {
                     $this->session->data['coupon'] = $this->request->post['coupon'];
                     $this->data['success'] = $this->session->data['success'] = $this->language->get('text_coupon_success');
                     unset($this->session->data['success']);
                     //process data
                     $this->extensions->hk_ProcessData($this, 'apply_coupon');
                 }
                 if ($this->error['error_warning']) {
                     $error_msg[] = $this->error['error_warning'];
                 }
                 if (isset($this->request->post['quantity'])) {
                     //we update cart
                     if (!is_array($this->request->post['quantity'])) {
                         $this->loadModel('catalog/product', 'storefront');
                         $product_id = $this->request->post['product_id'];
                         if (isset($this->request->post['option'])) {
                             $options = $this->request->post['option'];
                         } else {
                             $options = array();
                         }
                         //for FILE-attributes
                         if (has_value($this->request->files['option']['name'])) {
                             $fm = new AFile();
                             foreach ($this->request->files['option']['name'] as $id => $name) {
                                 $attribute_data = $this->model_catalog_product->getProductOption($product_id, $id);
                                 $attribute_data['settings'] = unserialize($attribute_data['settings']);
                                 $file_path_info = $fm->getUploadFilePath($attribute_data['settings']['directory'], $name);
                                 $options[$id] = $file_path_info['name'];
                                 if (!has_value($name)) {
                                     continue;
                                 }
                                 if ($attribute_data['required'] && !$this->request->files['option']['size'][$id]) {
                                     $this->session->data['error'] = $this->language->get('error_required_options');
                                     $this->redirect($_SERVER['HTTP_REFERER']);
                                 }
                                 $file_data = array('option_id' => $id, 'name' => $file_path_info['name'], 'path' => $file_path_info['path'], 'type' => $this->request->files['option']['type'][$id], 'tmp_name' => $this->request->files['option']['tmp_name'][$id], 'error' => $this->request->files['option']['error'][$id], 'size' => $this->request->files['option']['size'][$id]);
                                 $file_errors = $fm->validateFileOption($attribute_data['settings'], $file_data);
                                 if (has_value($file_errors)) {
                                     $this->session->data['error'] = implode('<br/>', $file_errors);
                                     $this->redirect($_SERVER['HTTP_REFERER']);
                                 } else {
                                     $result = move_uploaded_file($file_data['tmp_name'], $file_path_info['path']);
                                     if (!$result || $this->request->files['package_file']['error']) {
                                         $this->session->data['error'] .= '<br>Error: ' . getTextUploadError($this->request->files['option']['error'][$id]);
                                         $this->redirect($_SERVER['HTTP_REFERER']);
                                     }
                                 }
                                 $dataset = new ADataset('file_uploads', 'admin');
                                 $dataset->addRows(array('date_added' => date("Y-m-d H:i:s", time()), 'name' => $file_path_info['name'], 'type' => $file_data['type'], 'section' => 'product_option', 'section_id' => $attribute_data['attribute_id'], 'path' => $file_path_info['path']));
                             }
                         }
                         if ($text_errors = $this->model_catalog_product->validateProductOptions($product_id, $options)) {
                             $this->session->data['error'] = $text_errors;
                             //send options values back via _GET
                             $url = '&' . http_build_query(array('option' => $this->request->post['option']));
                             $this->redirect($this->html->getSecureURL($product_rt, '&product_id=' . $this->request->post['product_id'] . $url));
                         }
                         $this->cart->add($this->request->post['product_id'], $this->request->post['quantity'], $options);
                     } else {
                         foreach ($this->request->post['quantity'] as $key => $value) {
                             $this->cart->update($key, $value);
                         }
                     }
                     unset($this->session->data['shipping_methods']);
                     unset($this->session->data['shipping_method']);
                     unset($this->session->data['payment_methods']);
                     unset($this->session->data['payment_method']);
                 }
                 if (isset($this->request->post['remove'])) {
                     foreach (array_keys($this->request->post['remove']) as $key) {
                         $this->cart->remove($key);
                     }
                 }
                 $this->extensions->hk_ProcessData($this);
                 //next page is requested after cart update
                 if (isset($this->request->post['next_step'])) {
                     $this->redirect($this->html->getSecureURL($this->request->post['next_step']));
                 }
                 if (isset($this->request->post['redirect'])) {
                     $this->session->data['redirect'] = $this->request->post['redirect'];
                 }
                 if (isset($this->request->post['quantity']) || isset($this->request->post['remove'])) {
                     unset($this->session->data['shipping_methods']);
                     unset($this->session->data['shipping_method']);
                     unset($this->session->data['payment_methods']);
                     unset($this->session->data['payment_method']);
                     $this->redirect($this->html->getSecureURL($cart_rt));
                 }
             }
         }
     }
     $this->document->setTitle($this->language->get('heading_title'));
     $this->document->resetBreadcrumbs();
     $this->document->addBreadcrumb(array('href' => $this->html->getURL('index/home'), 'text' => $this->language->get('text_home'), 'separator' => false));
     $this->document->addBreadcrumb(array('href' => $this->html->getURL('checkout/cart'), 'text' => $this->language->get('text_basket'), 'separator' => $this->language->get('text_separator')));
     if ($this->cart->hasProducts()) {
         if (!$this->cart->hasStock() && !$this->config->get('config_stock_checkout')) {
             $error_msg[] = $this->language->get('error_stock');
         }
         $this->loadModel('tool/seo_url', 'storefront');
         $form = new AForm();
         $form->setForm(array('form_name' => 'cart'));
         $this->data['form']['form_open'] = $form->getFieldHtml(array('type' => 'form', 'name' => 'cart', 'action' => $this->html->getSecureURL($cart_rt)));
         $cart_products = $this->cart->getProducts();
         $product_ids = array();
         foreach ($cart_products as $result) {
             $product_ids[] = (int) $result['product_id'];
         }
         $resource = new AResource('image');
         $thumbnails = $resource->getMainThumbList('products', $product_ids, $this->config->get('config_image_cart_width'), $this->config->get('config_image_cart_height'));
         $products = array();
         foreach ($cart_products as $result) {
             $option_data = array();
             $thumbnail = $thumbnails[$result['product_id']];
             foreach ($result['option'] as $option) {
                 $title = '';
                 if ($option['element_type'] == 'H') {
                     continue;
                 }
                 //hide hidden options
                 $value = $option['value'];
                 // hide binary value for checkbox
                 if ($option['element_type'] == 'C' && in_array($value, array(0, 1))) {
                     $value = '';
                 }
                 // strip long textarea value
                 if ($option['element_type'] == 'T') {
                     $title = strip_tags($value);
                     $title = str_replace('\\r\\n', "\n", $title);
                     $value = str_replace('\\r\\n', "\n", $value);
                     if (mb_strlen($value) > 64) {
                         $value = mb_substr($value, 0, 64) . '...';
                     }
                 }
                 $option_data[] = array('name' => $option['name'], 'value' => $value, 'title' => $title);
             }
             $products[] = array('remove' => $form->getFieldHtml(array('type' => 'checkbox', 'name' => 'remove[' . $result['key'] . ']')), 'remove_url' => $this->html->getSecureURL($cart_rt, '&remove=' . $result['key']), 'key' => $result['key'], 'name' => $result['name'], 'model' => $result['model'], 'thumb' => $thumbnail, 'option' => $option_data, 'quantity' => $form->getFieldHtml(array('type' => 'input', 'name' => 'quantity[' . $result['key'] . ']', 'value' => $result['quantity'], 'attr' => ' size="3" ', 'style' => 'short')), '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' => $this->html->getSEOURL($product_rt, '&key=' . $result['key'], true));
         }
         $this->data['products'] = $products;
         $this->data['form']['update'] = $form->getFieldHtml(array('type' => 'submit', 'name' => $this->language->get('button_update')));
         $this->data['form']['checkout'] = $form->getFieldHtml(array('type' => 'button', 'name' => 'checkout', 'text' => $this->language->get('button_checkout'), 'style' => 'button'));
         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;
         }
         $display_totals = $this->cart->buildTotalDisplay();
         $this->data['totals'] = $display_totals['total_data'];
         if (isset($this->session->data['redirect'])) {
             $this->data['continue'] = str_replace('&amp;', '&', $this->session->data['redirect']);
             unset($this->session->data['redirect']);
         } else {
             $this->data['continue'] = $this->html->getURL($home_rt);
         }
         $this->data['form']['continue_shopping'] = $form->getFieldHtml(array('type' => 'button', 'name' => 'continue_shopping', 'text' => $this->language->get('button_shopping'), 'style' => 'button', 'href' => $this->data['continue']));
         $this->data['checkout'] = $this->html->getSecureURL($checkout_rt);
         $this->data['checkout_rt'] = $checkout_rt;
         #Check if order total max/min is set and met
         $cf_total_min = $this->config->get('total_order_minimum');
         $cf_total_max = $this->config->get('total_order_maximum');
         if (!$this->cart->hasMinRequirement()) {
             $this->data['form']['checkout'] = '';
             $error_msg[] = sprintf($this->language->get('error_order_minimum'), $this->currency->format($cf_total_min));
         }
         if (!$this->cart->hasMaxRequirement()) {
             $this->data['form']['checkout'] = '';
             $error_msg[] = sprintf($this->language->get('error_order_maximum'), $this->currency->format($cf_total_max));
         }
         //prepare coupon display
         if ($this->config->get('config_coupon_on_cart_page')) {
             $this->view->assign('coupon_status', $this->config->get('coupon_status'));
             $action = $this->html->getSecureURL($cart_rt);
             $coupon_form = $this->dispatch('blocks/coupon_codes', array('action' => $action));
             $this->view->assign('coupon_form', $coupon_form->dispatchGetOutput());
         }
         if ($this->config->get('config_shipping_tax_estimate')) {
             $form = new AForm();
             $form->setForm(array('form_name' => 'estimate'));
             $this->data['form_estimate']['form_open'] = $form->getFieldHtml(array('type' => 'form', 'name' => 'estimate', 'action' => $this->html->getSecureURL($cart_rt)));
             $this->data['estimates_enabled'] = true;
         }
         //try to get shipping address details if we have them
         $country_id = $this->config->get('config_country_id');
         if ($this->session->data['shipping_address_id']) {
             $this->loadModel('account/address', 'storefront');
             $shipping_address = $this->model_account_address->getAddress($this->session->data['shipping_address_id']);
             $postcode = $shipping_address['postcode'];
             $country_id = $shipping_address['country_id'];
             $zone_id = $shipping_address['zone_id'];
         }
         // use default address of customer for estimate form whe shipping address is unknown
         if (!$zone_id && $this->customer->isLogged()) {
             $this->loadModel('account/address', 'storefront');
             $payment_address = $this->model_account_address->getAddress($this->customer->getAddressId());
             $postcode = $payment_address['postcode'];
             $country_id = $payment_address['country_id'];
             $zone_id = $payment_address['zone_id'];
         }
         if ($this->request->post['postcode']) {
             $postcode = $this->request->post['postcode'];
         }
         if ($this->request->post['country'][0]) {
             $country_id = $this->request->post['country'][0];
         }
         if ($this->request->post['country_zones'][0]) {
             $zone_id = $this->request->post['country_zones'][0];
         }
         if ($zone_id) {
             $this->loadModel('localisation/zone', 'storefront');
             $zone_data = $this->model_localisation_zone->getZone($zone_id);
         }
         $this->data['form_estimate']['postcode'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'postcode', 'value' => $postcode, 'style' => 'short'));
         $this->data['form_estimate']['country_zones'] = $form->getFieldHtml(array('type' => 'zones', 'name' => 'country', 'submit_mode' => 'id', 'value' => $country_id, 'zone_name' => $zone_data['name'], 'zone_value' => $zone_id));
         $this->data['form_estimate']['submit'] = $form->getFieldHtml(array('type' => 'submit', 'name' => $this->language->get('button_text_estimate')));
         if ($this->session->data['error']) {
             $error_msg[] = $this->session->data['error'];
             unset($this->session->data['error']);
         }
         $this->view->assign('error_warning', $error_msg);
         $this->view->setTemplate('pages/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->html->buildElement(array('name' => 'continue', 'type' => 'button', 'text' => $this->language->get('button_continue'), 'href' => $this->html->getURL($home_rt), 'style' => 'button'));
         if ($this->config->get('embed_mode') == true) {
             $this->data['back_url'] = $this->html->getURL('r/product/category');
         }
         $this->view->setTemplate('pages/error/not_found.tpl');
     }
     $this->view->batchAssign($this->data);
     $this->processTemplate();
     //init controller data
     $this->extensions->hk_UpdateData($this, __FUNCTION__);
 }
Example #14
0
 public function post()
 {
     //init controller data
     $this->extensions->hk_InitData($this, __FUNCTION__);
     $request = $this->rest->getRequestParams();
     if (!$this->customer->isLoggedWithToken($request['token'])) {
         $this->rest->sendResponse(401, array('error' => 'Not logged in or Login attempt failed!'));
         return null;
     }
     if (!$this->cart->hasProducts()) {
         //No products in the cart.
         $this->rest->sendResponse(200, array('status' => 2, 'error' => 'Nothing in the cart!'));
         return null;
     }
     if (!$this->cart->hasStock() && !$this->config->get('config_stock_checkout')) {
         //No stock for products in the cart if tracked.
         $this->rest->sendResponse(200, array('status' => 3, 'error' => 'No stock for product!'));
         return null;
     }
     if ($this->cart->hasShipping()) {
         if (!isset($this->session->data['shipping_address_id']) || !$this->session->data['shipping_address_id']) {
             //Problem. Missing shipping address
             $this->rest->sendResponse(200, array('status' => 4, 'error' => 'Missing shipping address!'));
             return null;
         }
         if (!isset($this->session->data['shipping_method'])) {
             //Problem. Missing shipping address
             $this->rest->sendResponse(200, array('status' => 5, 'error' => 'Missing shipping method!'));
             return null;
         }
     } else {
         unset($this->session->data['shipping_address_id']);
         unset($this->session->data['shipping_method']);
         unset($this->session->data['shipping_methods']);
         $this->tax->setZone($this->session->data['country_id'], $this->session->data['zone_id']);
     }
     if (!isset($this->session->data['payment_address_id']) || !$this->session->data['payment_address_id']) {
         $this->rest->sendResponse(200, array('status' => 6, 'error' => 'Missing payment (billing) address!'));
         return null;
     }
     if (!isset($this->session->data['payment_method'])) {
         $this->rest->sendResponse(200, array('status' => 5, 'error' => 'Missing payment (billing) method!'));
         return null;
     }
     //build order and pre-save
     $order = new AOrder($this->registry);
     $this->data = $order->buildOrderData($this->session->data);
     $this->session->data['order_id'] = $order->saveOrder();
     //build confirmation data
     $this->loadModel('account/address');
     $shipping_address = $this->model_account_address->getAddress($this->session->data['shipping_address_id']);
     if ($this->cart->hasShipping()) {
         $this->data['shipping_address'] = $this->customer->getFormattedAddress($shipping_address, $shipping_address['address_format']);
     } else {
         $this->data['shipping_address'] = '';
     }
     $this->data['shipping_method'] = $this->session->data['shipping_method']['title'];
     $payment_address = $this->model_account_address->getAddress($this->session->data['payment_address_id']);
     if ($payment_address) {
         $this->data['payment_address'] = $this->customer->getFormattedAddress($payment_address, $payment_address['address_format']);
     } else {
         $this->data['payment_address'] = '';
     }
     if ($this->session->data['payment_method']['id'] != 'no_payment_required') {
         $this->data['payment_method'] = $this->session->data['payment_method']['title'];
     } else {
         $this->data['payment_method'] = '';
     }
     $this->loadModel('tool/seo_url');
     $this->loadModel('tool/image');
     $product_ids = array();
     foreach ($this->data['products'] as $result) {
         $product_ids[] = (int) $result['product_id'];
     }
     $resource = new AResource('image');
     $thumbnails = $resource->getMainThumbList('products', $product_ids, $this->config->get('config_image_cart_width'), $this->config->get('config_image_cart_height'));
     //Format product data specific for confirmation response
     for ($i = 0; $i < sizeof($this->data['products']); $i++) {
         $product_id = $this->data['products'][$i]['product_id'];
         $thumbnail = $thumbnails[$product_id];
         $tax = $this->tax->calcTotalTaxAmount($this->data['products'][$i]['total'], $this->data['products'][$i]['tax_class_id']);
         $this->data['products'][$i] = array_merge($this->data['products'][$i], array('thumb' => $thumbnail['thumb_url'], 'tax' => $this->currency->format($tax), 'price' => $this->currency->format($this->data['products'][$i]['price']), 'total' => $this->currency->format($this->data['products'][$i]['total'])));
     }
     if ($this->config->get('config_checkout_id')) {
         $this->loadModel('catalog/content');
         $content_info = $this->model_catalog_content->getContent($this->config->get('config_checkout_id'));
         if ($content_info) {
             $this->data['text_accept_agree'] = sprintf($this->language->get('text_accept_agree'), '', $content_info['title']);
         } else {
             $this->data['text_accept_agree'] = '';
         }
     } else {
         $this->data['text_accept_agree'] = '';
     }
     // Load selected paymnet required data from payment extension
     if ($this->session->data['payment_method']['id'] != 'no_payment_required') {
         $payment_controller = $this->dispatch('responses/extension/' . $this->session->data['payment_method']['id'] . '/api');
     } else {
         $payment_controller = $this->dispatch('responses/checkout/no_payment/api');
     }
     $this->load->library('json');
     $this->data['payment'] = AJson::decode($payment_controller->dispatchGetOutput(), TRUE);
     //set process_rt for process step to run the payment
     $this->session->data['process_rt'] = $this->data['payment']['process_rt'];
     //mark confirmation viewed
     $this->session->data['confirmed'] = TRUE;
     $this->extensions->hk_UpdateData($this, __FUNCTION__);
     $this->rest->setResponseData($this->data);
     $this->rest->sendResponse(200);
 }
Example #15
0
 private function getWishList()
 {
     $cart_rt = 'checkout/cart';
     //is this an embed mode
     if ($this->config->get('embed_mode') == true) {
         $cart_rt = 'r/checkout/cart/embed';
     }
     $this->document->setTitle($this->language->get('heading_title'));
     $this->document->resetBreadcrumbs();
     $this->document->addBreadcrumb(array('href' => $this->html->getURL('index/home'), 'text' => $this->language->get('text_home'), 'separator' => FALSE));
     $this->document->addBreadcrumb(array('href' => $this->html->getURL('account/account'), 'text' => $this->language->get('text_account'), 'separator' => $this->language->get('text_separator')));
     $this->document->addBreadcrumb(array('href' => $this->html->getURL('account/wishlist'), 'text' => $this->language->get('heading_title'), 'separator' => $this->language->get('text_separator')));
     $whishlist = $this->customer->getWishList();
     if ($whishlist) {
         $this->loadModel('tool/seo_url');
         $this->loadModel('catalog/product');
         //get thumbnails by one pass
         $resource = new AResource('image');
         $thumbnails = $resource->getMainThumbList('products', array_keys($whishlist), $this->config->get('config_image_cart_width'), $this->config->get('config_image_cart_width'));
         $products = array();
         foreach ($whishlist as $product_id => $timestamp) {
             $product_info = $this->model_catalog_product->getProduct($product_id);
             $thumbnail = $thumbnails[$product_id];
             $options = $this->model_catalog_product->getProductOptions($product_id);
             if ($options) {
                 $add = $this->html->getSEOURL('product/product', '&product_id=' . $product_id, '&encode');
             } else {
                 $add = $this->html->getSecureURL($cart_rt, '&product_id=' . $product_id, '&encode');
             }
             $products[] = array('product_id' => $product_id, 'name' => $product_info['name'], 'model' => $product_info['model'], 'thumb' => $thumbnail, 'added' => dateInt2Display($timestamp), 'price' => $this->currency->format($this->tax->calculate($product_info['price'], $product_info['tax_class_id'], $this->config->get('config_tax'))), 'href' => $this->html->getSEOURL('product/product', '&product_id=' . $product_id, true), 'call_to_order' => $product_info['call_to_order'], 'add' => $add);
         }
         $this->data['products'] = $products;
         if (isset($this->session->data['redirect'])) {
             $this->data['continue'] = str_replace('&amp;', '&', $this->session->data['redirect']);
             unset($this->session->data['redirect']);
         } else {
             $this->data['continue'] = $this->html->getURL('index/home');
         }
         $this->view->assign('error', '');
         if ($this->session->data['error']) {
             $this->view->assign('error', $this->session->data['error']);
             unset($this->session->data['error']);
         }
         if ($this->config->get('config_customer_price')) {
             $display_price = TRUE;
         } elseif ($this->customer->isLogged()) {
             $display_price = TRUE;
         } else {
             $display_price = FALSE;
         }
         $this->data['display_price'] = $display_price;
         $this->view->setTemplate('pages/account/wishlist.tpl');
     } else {
         $this->data['heading_title'] = $this->language->get('heading_title');
         $this->data['text_error'] = $this->language->get('text_empty_wishlist');
         $this->data['button_continue'] = HtmlElementFactory::create(array('name' => 'continue', 'type' => 'button', 'text' => $this->language->get('button_continue'), 'href' => $this->html->getURL('index/home'), 'style' => 'button'));
         $this->view->setTemplate('pages/error/not_found.tpl');
     }
     $this->data['cart'] = $this->html->getSecureURL($cart_rt);
     $this->view->batchAssign($this->data);
     $this->processTemplate();
 }
Example #16
0
 public function get_cart_details($totals)
 {
     //init controller data
     $this->extensions->hk_InitData($this, __FUNCTION__);
     if (!$this->view->isTemplateExists('responses/checkout/cart_details.tpl')) {
         return '';
     }
     $cart_products = $this->cart->getProducts();
     $product_ids = array();
     foreach ($cart_products as $result) {
         $product_ids[] = (int) $result['product_id'];
     }
     $resource = new AResource('image');
     $thumbnails = $resource->getMainThumbList('products', $product_ids, $this->config->get('config_image_product_width'), $this->config->get('config_image_product_height'));
     foreach ($cart_products as $result) {
         $option_data = array();
         $thumbnail = $thumbnails[$result['product_id']];
         foreach ($result['option'] as $option) {
             $value = $option['value'];
             // hide binary value for checkbox
             if ($option['element_type'] == 'C' && in_array($value, array(0, 1))) {
                 $value = '';
             }
             // strip long textarea value
             if ($option['element_type'] == 'T') {
                 $title = strip_tags($value);
                 $title = str_replace('\\r\\n', "\n", $title);
                 $value = str_replace('\\r\\n', "\n", $value);
                 if (mb_strlen($value) > 64) {
                     $value = mb_substr($value, 0, 64) . '...';
                 }
             }
             $option_data[] = array('name' => $option['name'], 'value' => $value, 'title' => $title);
         }
         $qty += $result['quantity'];
         $this->data['products'][] = array('key' => $result['key'], 'name' => $result['name'], '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'))), 'href' => $this->html->getSEOURL('product/product', '&product_id=' . $result['product_id']), 'thumb' => $thumbnail);
     }
     $this->data['totals'] = $totals['total_data'];
     $this->data['subtotal'] = $this->currency->format($this->tax->calculate($totals['total'], $result['tax_class_id'], $this->config->get('config_tax')));
     $this->data['taxes'] = $totals['taxes'];
     $this->data['view'] = $this->html->getURL('checkout/cart');
     $this->view->batchAssign($this->data);
     //update controller data
     $this->extensions->hk_UpdateData($this, __FUNCTION__);
     $this->processTemplate('responses/checkout/cart_details.tpl');
 }
Example #17
0
 public function main()
 {
     //init controller data
     $this->extensions->hk_InitData($this, __FUNCTION__);
     $cart_rt = 'checkout/cart';
     $checkout_rt = 'checkout/shipping';
     $payment_rt = 'checkout/payment';
     $login_rt = 'account/login';
     $home_rt = 'index/home';
     $pmt_address_rt = 'checkout/address/payment';
     $shp_address_rt = 'checkout/address/shipping';
     $confirm_rt = 'checkout/confirm';
     $success_rt = 'checkout/success';
     $product_rt = 'product/product';
     if ($this->config->get('embed_mode') == true) {
         $cart_rt = 'r/checkout/cart/embed';
     }
     if (!$this->cart->hasProducts() || !$this->cart->hasStock() && !$this->config->get('config_stock_checkout')) {
         $this->redirect($this->html->getSecureURL($cart_rt));
     }
     //validate if order min/max are met
     if (!$this->cart->hasMinRequirement() || !$this->cart->hasMaxRequirement()) {
         $this->redirect($this->html->getSecureURL($cart_rt));
     }
     if (!$this->customer->isLogged()) {
         $this->session->data['redirect'] = $this->html->getSecureURL($checkout_rt);
         $this->redirect($this->html->getSecureURL($login_rt));
     }
     if ($this->cart->hasShipping()) {
         if (!isset($this->session->data['shipping_address_id']) || !$this->session->data['shipping_address_id']) {
             $this->redirect($this->html->getSecureURL($checkout_rt));
         }
         if (!isset($this->session->data['shipping_method'])) {
             $this->redirect($this->html->getSecureURL($checkout_rt));
         }
     } else {
         unset($this->session->data['shipping_address_id']);
         unset($this->session->data['shipping_method']);
         unset($this->session->data['shipping_methods']);
         $this->tax->setZone($this->session->data['country_id'], $this->session->data['zone_id']);
     }
     if (!isset($this->session->data['payment_address_id']) || !$this->session->data['payment_address_id']) {
         $this->redirect($this->html->getSecureURL($payment_rt));
     }
     if (!isset($this->session->data['payment_method'])) {
         $this->redirect($this->html->getSecureURL($payment_rt));
     }
     if ($this->request->get['balance'] == 'disapply') {
         unset($this->session->data['used_balance'], $this->request->get['balance'], $this->session->data['used_balance_full']);
     }
     $this->data = array();
     $order = new AOrder($this->registry);
     $this->data = $order->buildOrderData($this->session->data);
     $order_id = $order->saveOrder();
     if ($order_id === false) {
         // preventing rebuilding order of already processed orders
         //(by "back" button via browser history from external payment page(paypal, google_checkout etc))
         $this->redirect($this->html->getSecureURL($success_rt));
     }
     $this->session->data['order_id'] = $order_id;
     $this->document->setTitle($this->language->get('heading_title'));
     $this->document->resetBreadcrumbs();
     $this->document->addBreadcrumb(array('href' => $this->html->getURL('index/home'), 'text' => $this->language->get('text_home'), 'separator' => FALSE));
     $this->document->addBreadcrumb(array('href' => $this->html->getURL($cart_rt), 'text' => $this->language->get('text_basket'), 'separator' => $this->language->get('text_separator')));
     if ($this->cart->hasShipping()) {
         $this->document->addBreadcrumb(array('href' => $this->html->getURL($checkout_rt), 'text' => $this->language->get('text_shipping'), 'separator' => $this->language->get('text_separator')));
     }
     $this->document->addBreadcrumb(array('href' => $this->html->getURL($payment_rt, '&mode=edit', true), 'text' => $this->language->get('text_payment'), 'separator' => $this->language->get('text_separator')));
     $this->document->addBreadcrumb(array('href' => $this->html->getURL($confirm_rt), 'text' => $this->language->get('text_confirm'), 'separator' => $this->language->get('text_separator')));
     $this->data['error_warning'] = $this->error['warning'];
     $this->data['success'] = $this->session->data['success'];
     if (isset($this->session->data['success'])) {
         unset($this->session->data['success']);
     }
     //balance
     $balance_def_currency = $this->customer->getBalance();
     $balance = $this->currency->convert($balance_def_currency, $this->config->get('config_currency'), $this->session->data['currency']);
     if ($balance != 0 || $balance == 0 && $this->config->get('config_zero_customer_balance') && (double) $this->session->data['used_balance'] != 0) {
         $this->data['balance'] = $this->language->get('text_balance_checkout') . ' ' . $this->currency->format($balance, $this->session->data['currency'], 1);
         if ((double) $this->session->data['used_balance'] > 0) {
             $this->data['disapply_balance'] = array('href' => $this->html->getSecureURL($payment_rt, '&mode=edit&balance=disapply', true), 'text' => $this->language->get('button_disapply_balance'));
             $this->data['balance'] .= ' (' . $this->currency->format($balance_def_currency - (double) $this->session->data['used_balance']) . ')';
             $this->data['balance'] .= '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . $this->currency->format((double) $this->session->data['used_balance']) . ' ' . $this->language->get('text_applied_balance');
         } elseif ((double) $this->session->data['used_balance'] == 0 && $balance > 0) {
             $this->data['disapply_balance'] = array('href' => $this->html->getSecureURL($payment_rt, '&mode=edit&balance=apply', true), 'text' => $this->language->get('button_apply_balance'));
         }
     }
     $this->loadModel('account/address');
     $shipping_address = $this->model_account_address->getAddress($this->session->data['shipping_address_id']);
     if ($this->cart->hasShipping()) {
         $this->data['shipping_address'] = $this->customer->getFormattedAddress($shipping_address, $shipping_address['address_format']);
     } else {
         $this->data['shipping_address'] = '';
     }
     $this->data['shipping_method'] = $this->session->data['shipping_method']['title'];
     $this->data['shipping_method_price'] = $this->session->data['shipping_method']['title'];
     $this->data['checkout_shipping_edit'] = $this->html->getSecureURL($checkout_rt, '&mode=edit', true);
     $this->data['checkout_shipping_address'] = $this->html->getSecureURL($shp_address_rt);
     $payment_address = $this->model_account_address->getAddress($this->session->data['payment_address_id']);
     if ($payment_address) {
         $this->data['payment_address'] = $this->customer->getFormattedAddress($payment_address, $payment_address['address_format']);
     } else {
         $this->data['payment_address'] = '';
     }
     if ($this->session->data['payment_method']['id'] != 'no_payment_required') {
         $this->data['payment_method'] = $this->session->data['payment_method']['title'];
     } else {
         $this->data['payment_method'] = '';
     }
     $this->data['checkout_payment_edit'] = $this->html->getSecureURL($payment_rt, '&mode=edit', true);
     $this->data['checkout_payment_address'] = $this->html->getSecureURL($pmt_address_rt);
     $this->loadModel('tool/seo_url');
     $this->loadModel('tool/image');
     $product_ids = array();
     foreach ($this->data['products'] as $result) {
         $product_ids[] = (int) $result['product_id'];
     }
     $resource = new AResource('image');
     $thumbnails = $resource->getMainThumbList('products', $product_ids, $this->config->get('config_image_cart_width'), $this->config->get('config_image_cart_height'));
     //Format product data specific for confirmation page
     for ($i = 0; $i < sizeof($this->data['products']); $i++) {
         $product_id = $this->data['products'][$i]['product_id'];
         $opts = $this->data['products'][$i]['option'];
         $options = array();
         foreach ($opts as $option) {
             if ($option['element_type'] == 'H') {
                 continue;
             }
             //hide hidden options
             $value = $option['value'];
             // hide binary value for checkbox
             if ($option['element_type'] == 'C' && in_array($value, array(0, 1))) {
                 $value = '';
             }
             // strip long textarea value
             if ($option['element_type'] == 'T') {
                 $title = strip_tags($value);
                 $title = str_replace('\\r\\n', "\n", $title);
                 $value = str_replace('\\r\\n', "\n", $value);
                 if (mb_strlen($value) > 64) {
                     $value = mb_substr($value, 0, 64) . '...';
                 }
             }
             $options[] = array('name' => $option['name'], 'value' => $value, 'title' => $title);
         }
         $this->data['products'][$i]['option'] = $options;
         $thumbnail = $thumbnails[$product_id];
         $tax = $this->tax->calcTotalTaxAmount($this->data['products'][$i]['total'], $this->data['products'][$i]['tax_class_id']);
         $this->data['products'][$i] = array_merge($this->data['products'][$i], array('thumb' => $thumbnail, 'tax' => $this->currency->format($tax), 'price' => $this->currency->format($this->data['products'][$i]['price']), 'total' => $this->currency->format($this->data['products'][$i]['total']), 'href' => $this->html->getSEOURL($product_rt, '&product_id=' . $product_id, true)));
     }
     $display_totals = $this->cart->buildTotalDisplay();
     $this->data['totals'] = $display_totals['total_data'];
     $this->data['cart'] = $this->html->getSecureURL($cart_rt);
     if ($this->config->get('config_checkout_id')) {
         $this->loadModel('catalog/content');
         $content_info = $this->model_catalog_content->getContent($this->config->get('config_checkout_id'));
         if ($content_info) {
             $this->data['text_accept_agree'] = $this->language->get('text_accept_agree');
             $this->data['text_accept_agree_href'] = $this->html->getSEOURL('r/content/content/loadInfo', '&content_id=' . $this->config->get('config_checkout_id'), true);
             $this->data['text_accept_agree_href_link'] = $content_info['title'];
         } else {
             $this->data['text_accept_agree'] = '';
         }
     } else {
         $this->data['text_accept_agree'] = '';
     }
     if ($this->session->data['payment_method']['id'] != 'no_payment_required') {
         $this->addChild('responses/extension/' . $this->session->data['payment_method']['id'], 'payment');
     } else {
         $this->addChild('responses/checkout/no_payment', 'payment');
     }
     $this->view->batchAssign($this->data);
     if ($this->config->get('embed_mode') == true) {
         //load special headers
         $this->addChild('responses/embed/head', 'head');
         $this->addChild('responses/embed/footer', 'footer');
         $this->processTemplate('embed/checkout/confirm.tpl');
     } else {
         $this->processTemplate('pages/checkout/confirm.tpl');
     }
     //update data before render
     $this->extensions->hk_UpdateData($this, __FUNCTION__);
 }
Example #18
0
 public function main()
 {
     //init controller data
     $this->extensions->hk_InitData($this, __FUNCTION__);
     $this->loadModel('tool/seo_url');
     $this->loadLanguage('total/total');
     $this->data['heading_title'] = $this->language->get('heading_title', 'blocks/cart');
     $this->data['text_subtotal'] = $this->language->get('text_subtotal');
     $this->data['text_empty'] = $this->language->get('text_empty');
     $this->data['text_remove'] = $this->language->get('text_remove');
     $this->data['text_confirm'] = $this->language->get('text_confirm');
     $this->data['text_view'] = $this->language->get('text_view');
     $this->data['text_checkout'] = $this->language->get('text_checkout');
     $this->data['text_items'] = $this->language->get('text_items');
     $this->data['text_total'] = $this->language->get('text_total');
     $this->data['view'] = $this->html->getURL('checkout/cart');
     $this->data['remove'] = $this->html->getURL('r/checkout/cart');
     $this->data['checkout'] = $this->html->getURL('checkout/shipping');
     $products = array();
     $qty = 0;
     $cart_products = $this->cart->getProducts();
     $product_ids = array();
     foreach ($cart_products as $product) {
         $product_ids[] = $product['product_id'];
     }
     $resource = new AResource('image');
     $thumbnails = $resource->getMainThumbList('products', $product_ids, $this->config->get('config_image_additional_width'), $this->config->get('config_image_additional_width'));
     foreach ($cart_products as $result) {
         $option_data = array();
         $thumbnail = $thumbnails[$result['product_id']];
         foreach ($result['option'] as $option) {
             if ($option['element_type'] == 'H') {
                 continue;
             }
             //hide hidden options
             $value = $option['value'];
             // hide binary value for checkbox
             if ($option['element_type'] == 'C' && in_array($value, array(0, 1))) {
                 $value = '';
             }
             // strip long textarea value
             if ($option['element_type'] == 'T') {
                 $title = strip_tags($value);
                 $title = str_replace('\\r\\n', "\n", $title);
                 $value = str_replace('\\r\\n', "\n", $value);
                 if (mb_strlen($value) > 64) {
                     $value = mb_substr($value, 0, 64) . '...';
                 }
             }
             $option_data[] = array('name' => $option['name'], 'value' => $value, 'title' => $title);
         }
         $qty += $result['quantity'];
         $products[] = array('key' => $result['key'], 'name' => $result['name'], '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'))), 'href' => $this->html->getSEOURL('product/product', '&product_id=' . $result['product_id'], true), 'thumb' => $thumbnail);
     }
     $this->data['products'] = $products;
     $this->data['total_qty'] = $qty;
     $display_totals = $this->cart->buildTotalDisplay();
     $this->data['totals'] = $display_totals['total_data'];
     $this->data['subtotal'] = $this->currency->format($display_totals['total']);
     $this->data['taxes'] = $display_totals['taxes'];
     $this->data['ajax'] = $this->config->get('cart_ajax');
     $this->view->batchAssign($this->data);
     $this->processTemplate();
     //init controller data
     $this->extensions->hk_UpdateData($this, __FUNCTION__);
 }
Example #19
0
 public function main()
 {
     $request = $this->request->get;
     $this->path = explode(',', $request['category_id']);
     //is this an embed mode
     if ($this->config->get('embed_mode') == true) {
         $cart_rt = 'r/checkout/cart/embed';
     } else {
         $cart_rt = 'checkout/cart';
     }
     //init controller data
     $this->extensions->hk_InitData($this, __FUNCTION__);
     $this->document->setTitle($this->language->get('heading_title'));
     $this->document->resetBreadcrumbs();
     $this->document->addBreadcrumb(array('href' => $this->html->getURL('index/home'), 'text' => $this->language->get('text_home'), 'separator' => FALSE));
     $url = '';
     if (isset($request['keyword'])) {
         $url .= '&keyword=' . $request['keyword'];
     }
     if (isset($request['category_id'])) {
         $url .= '&category_id=' . $request['category_id'];
     }
     if (isset($request['description'])) {
         $url .= '&description=' . $request['description'];
     }
     if (isset($request['model'])) {
         $url .= '&model=' . $request['model'];
     }
     if (isset($request['sort'])) {
         $url .= '&sort=' . $request['sort'];
     }
     if (isset($request['order'])) {
         $url .= '&order=' . $request['order'];
     }
     if (isset($request['page'])) {
         $url .= '&page=' . $request['page'];
     }
     if (isset($request['limit'])) {
         $url .= '&limit=' . $request['limit'];
     }
     $this->document->addBreadcrumb(array('href' => $this->html->getURL('product/search', $url), 'text' => $this->language->get('heading_title'), 'separator' => $this->language->get('text_separator')));
     if (isset($request['page'])) {
         $page = $request['page'];
     } else {
         $page = 1;
     }
     if (isset($request['sort'])) {
         $sorting_href = $request['sort'];
     } else {
         $sorting_href = $this->config->get('config_product_default_sort_order');
     }
     list($sort, $order) = explode("-", $sorting_href);
     if ($sort == 'name') {
         $sort = 'pd.' . $sort;
     } elseif (in_array($sort, array('sort_order', 'price'))) {
         $sort = 'p.' . $sort;
     }
     $this->data['keyword'] = $this->html->buildElement(array('type' => 'input', 'name' => 'keyword', 'value' => $request['keyword']));
     $this->loadModel('catalog/category');
     $categories = $this->_getCategories(0);
     $options = array(0 => $this->language->get('text_category'));
     if ($categories) {
         foreach ($categories as $item) {
             $options[$item['category_id']] = $item['name'];
         }
     }
     $this->data['category'] = $this->html->buildElement(array('type' => 'selectbox', 'name' => 'category_id', 'options' => $options, 'value' => $request['category_id']));
     $this->data['description'] = $this->html->buildElement(array('type' => 'checkbox', 'id' => 'description', 'name' => 'description', 'checked' => (int) $request['description'], 'value' => 1, 'label_text' => $this->language->get('entry_description')));
     $this->data['model'] = $this->html->buildElement(array('type' => 'checkbox', 'id' => 'model', 'name' => 'model', 'checked' => (bool) $request['model'], 'value' => 1, 'label_text' => $this->language->get('entry_model')));
     $this->data['submit'] = $this->html->buildElement(array('type' => 'button', 'name' => 'search_button', 'text' => $this->language->get('button_search'), 'icon' => 'fa fa-search', 'style' => 'btn-default'));
     if (isset($request['keyword'])) {
         $this->loadModel('catalog/product');
         $promotion = new APromotion();
         if (isset($request['category_id'])) {
             $category_id = explode(',', $request['category_id']);
             end($category_id);
             $category_id = current($category_id);
         } else {
             $category_id = '';
         }
         $product_total = $this->model_catalog_product->getTotalProductsByKeyword($request['keyword'], $category_id, isset($request['description']) ? $request['description'] : '', isset($request['model']) ? $request['model'] : '');
         if ($product_total) {
             $url = '';
             if (isset($request['category_id'])) {
                 $url .= '&category_id=' . $request['category_id'];
             }
             if (isset($request['description'])) {
                 $url .= '&description=' . $request['description'];
             }
             if (isset($request['model'])) {
                 $url .= '&model=' . $request['model'];
             }
             $limit = $this->config->get('config_catalog_limit');
             if (isset($request['limit']) && intval($request['limit']) > 0) {
                 $limit = intval($request['limit']);
                 if ($limit > 50) {
                     $limit = 50;
                 }
             }
             $this->loadModel('catalog/review');
             $this->loadModel('tool/seo_url');
             $products = array();
             $products_result = $this->model_catalog_product->getProductsByKeyword($request['keyword'], $category_id, isset($request['description']) ? $request['description'] : '', isset($request['model']) ? $request['model'] : '', $sort, $order, ($page - 1) * $limit, $limit);
             //if single result, redirect to the product
             if (count($products_result) == 1) {
                 $this->redirect($this->html->getSEOURL('product/product', '&product_id=' . key($products_result), '&encode'));
             }
             if (is_array($products_result) && $products_result) {
                 $product_ids = array();
                 foreach ($products_result as $result) {
                     $product_ids[] = (int) $result['product_id'];
                 }
                 //Format product data specific for confirmation page
                 $resource = new AResource('image');
                 $thumbnails = $resource->getMainThumbList('products', $product_ids, $this->config->get('config_image_product_width'), $this->config->get('config_image_product_height'));
                 $stock_info = $this->model_catalog_product->getProductsStockInfo($product_ids);
                 foreach ($products_result as $result) {
                     $thumbnail = $thumbnails[$result['product_id']];
                     if ($this->config->get('enable_reviews')) {
                         $rating = $this->model_catalog_review->getAverageRating($result['product_id']);
                     } else {
                         $rating = false;
                     }
                     $special = FALSE;
                     $discount = $promotion->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 = $promotion->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->model_catalog_product->getProductOptions($result['product_id']);
                     if ($options) {
                         $add = $this->html->getSEOURL('product/product', '&product_id=' . $result['product_id'], '&encode');
                     } else {
                         if ($this->config->get('config_cart_ajax')) {
                             $add = '#';
                         } else {
                             $add = $this->html->getSecureURL($cart_rt, '&product_id=' . $result['product_id'], '&encode');
                         }
                     }
                     //check for stock status, availability and config
                     $track_stock = false;
                     $in_stock = false;
                     $no_stock_text = $result['stock'];
                     $total_quantity = 0;
                     if ($stock_info[$result['product_id']]['subtract']) {
                         $track_stock = true;
                         $total_quantity = $stock_info[$result['product_id']]['quantity'];
                         //we have stock or out of stock checkout is allowed
                         if ($total_quantity > 0 || $this->config->get('config_stock_checkout')) {
                             $in_stock = true;
                         }
                     }
                     $products[] = array('product_id' => $result['product_id'], 'name' => $result['name'], 'blurb' => $result['blurb'], 'model' => $result['model'], 'rating' => $rating, 'stars' => sprintf($this->language->get('text_stars'), $rating), 'thumb' => $thumbnail, 'price' => $price, 'call_to_order' => $result['call_to_order'], 'options' => $options, 'special' => $special, 'href' => $this->html->getSEOURL('product/product', '&keyword=' . $request['keyword'] . $url . '&product_id=' . $result['product_id'], '&encode'), 'add' => $add, 'description' => html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8'), 'track_stock' => $track_stock, 'in_stock' => $in_stock, 'no_stock_text' => $no_stock_text, 'total_quantity' => $total_quantity);
                 }
             }
             $this->data['products'] = $products;
             if ($this->config->get('config_customer_price')) {
                 $display_price = TRUE;
             } elseif ($this->customer->isLogged()) {
                 $display_price = TRUE;
             } else {
                 $display_price = FALSE;
             }
             $this->data['display_price'] = $display_price;
             $url = '';
             if (isset($request['keyword'])) {
                 $url .= '&keyword=' . $request['keyword'];
             }
             if (isset($request['category_id'])) {
                 $url .= '&category_id=' . $request['category_id'];
             }
             if (isset($request['description'])) {
                 $url .= '&description=' . $request['description'];
             }
             if (isset($request['model'])) {
                 $url .= '&model=' . $request['model'];
             }
             if (isset($request['page'])) {
                 $url .= '&page=' . $request['page'];
             }
             if (isset($request['limit'])) {
                 $url .= '&limit=' . $request['limit'];
             }
             $sorts = array();
             $sorts[] = array('text' => $this->language->get('text_default'), 'value' => 'p.sort_order-ASC', 'href' => $this->html->getURL('product/search', $url . '&sort=p.sort_order&order=ASC', '&encode'));
             $sorts[] = array('text' => $this->language->get('text_sorting_name_asc'), 'value' => 'pd.name-ASC', 'href' => $this->html->getURL('product/search', $url . '&sort=pd.name&order=ASC', '&encode'));
             $sorts[] = array('text' => $this->language->get('text_sorting_name_desc'), 'value' => 'pd.name-DESC', 'href' => $this->html->getURL('product/search', $url . '&sort=pd.name&order=DESC', '&encode'));
             $sorts[] = array('text' => $this->language->get('text_sorting_price_asc'), 'value' => 'p.price-ASC', 'href' => $this->html->getURL('product/search', $url . '&sort=p.price&order=ASC', '&encode'));
             $sorts[] = array('text' => $this->language->get('text_sorting_price_desc'), 'value' => 'p.price-DESC', 'href' => $this->html->getURL('product/search', $url . '&sort=p.price&order=DESC', '&encode'));
             $sorts[] = array('text' => $this->language->get('text_sorting_rating_desc'), 'value' => 'rating-DESC', 'href' => $this->html->getURL('product/search', $url . '&sort=rating&order=DESC', '&encode'));
             $sorts[] = array('text' => $this->language->get('text_sorting_rating_asc'), 'value' => 'rating-ASC', 'href' => $this->html->getURL('product/search', $url . '&sort=rating&order=ASC', '&encode'));
             $sorts[] = array('text' => $this->language->get('text_sorting_date_desc'), 'value' => 'date_modified-DESC', 'href' => $this->html->getSEOURL('product/search', $url . '&sort=date_modified&order=DESC', '&encode'));
             $sorts[] = array('text' => $this->language->get('text_sorting_date_asc'), 'value' => 'date_modified-ASC', 'href' => $this->html->getSEOURL('product/search', $url . '&sort=date_modified&order=ASC', '&encode'));
             $this->data['sorts'] = $sorts;
             $options = array();
             foreach ($sorts as $item) {
                 $options[$item['value']] = $item['text'];
             }
             $sorting = $this->html->buildElement(array('type' => 'selectbox', 'name' => 'sort', 'options' => $options, 'value' => $sort . '-' . $order));
             $this->data['sorting'] = $sorting;
             $url = '';
             if (isset($request['keyword'])) {
                 $url .= '&keyword=' . $request['keyword'];
             }
             if (isset($request['category_id'])) {
                 $url .= '&category_id=' . $request['category_id'];
             }
             if (isset($request['description'])) {
                 $url .= '&description=' . $request['description'];
             }
             if (isset($request['model'])) {
                 $url .= '&model=' . $request['model'];
             }
             if (isset($request['sort'])) {
                 $url .= '&sort=' . $request['sort'];
             }
             if (isset($request['order'])) {
                 $url .= '&order=' . $request['order'];
             }
             if (isset($request['limit'])) {
                 $url .= '&limit=' . $request['limit'];
             }
             $this->data['pagination_bootstrap'] = $this->html->buildElement(array('type' => 'Pagination', 'name' => 'pagination', 'text' => $this->language->get('text_pagination'), 'text_limit' => $this->language->get('text_per_page'), 'total' => $product_total, 'page' => $page, 'limit' => $limit, 'url' => $this->html->getURL('product/search', $url . '&page={page}', '&encode'), 'style' => 'pagination'));
             $this->data['sort'] = $sort;
             $this->data['order'] = $order;
             $this->data['limit'] = $limit;
         }
     }
     $this->data['review_status'] = $this->config->get('enable_reviews');
     $this->view->batchAssign($this->data);
     $this->processTemplate('pages/product/search.tpl');
     //init controller data
     $this->extensions->hk_UpdateData($this, __FUNCTION__);
 }
Example #20
0
 public function files()
 {
     $this->data = array();
     //init controller data
     $this->extensions->hk_InitData($this, __FUNCTION__);
     $this->document->setTitle($this->language->get('heading_title'));
     if (has_value($this->session->data['error'])) {
         $this->data['error']['warning'] = $this->session->data['error'];
         unset($this->session->data['error']);
     }
     if (isset($this->request->get['order_id'])) {
         $order_id = $this->request->get['order_id'];
     } else {
         $order_id = 0;
     }
     if ($this->request->is_POST() && $this->_validateForm()) {
         if (has_value($this->request->post['downloads'])) {
             $data = $this->request->post['downloads'];
             $this->loadModel('catalog/download');
             foreach ($data as $order_download_id => $item) {
                 if (isset($item['expire_date'])) {
                     $item['expire_date'] = $item['expire_date'] ? dateDisplay2ISO($item['expire_date'], $this->language->get('date_format_short')) : '';
                 }
                 $this->model_catalog_download->editOrderDownload($order_download_id, $item);
             }
         }
         //add download to order
         if (has_value($this->request->post['push'])) {
             $this->load->library('json');
             foreach ($this->request->post['push'] as $order_product_id => $download_id) {
                 if ($download_id) {
                     $download_info = $this->download->getDownloadInfo($download_id);
                     $download_info['attributes_data'] = serialize($this->download->getDownloadAttributesValues($download_id));
                     $this->download->addProductDownloadToOrder($order_product_id, $order_id, $download_info);
                 }
             }
         }
         $this->session->data['success'] = $this->language->get('text_success');
         $this->redirect($this->html->getSecureURL('sale/order/files', '&order_id=' . $this->request->get['order_id']));
     }
     $order_info = $this->model_sale_order->getOrder($order_id);
     $this->data['order_info'] = $order_info;
     //set content language to order language ID.
     if ($this->language->getContentLanguageID() != $order_info['language_id']) {
         //reset content language
         $this->language->setCurrentContentLanguage($order_info['language_id']);
     }
     if (empty($order_info)) {
         $this->session->data['error'] = $this->language->get('error_order_load');
         $this->redirect($this->html->getSecureURL('sale/order'));
     }
     $this->document->initBreadcrumb(array('href' => $this->html->getSecureURL('index/home'), 'text' => $this->language->get('text_home'), 'separator' => false));
     $this->document->addBreadcrumb(array('href' => $this->html->getSecureURL('sale/order'), 'text' => $this->language->get('heading_title'), 'separator' => ' :: '));
     $this->document->addBreadcrumb(array('href' => $this->html->getSecureURL('sale/order/files', '&order_id=' . $this->request->get['order_id']), 'text' => $this->language->get('heading_title') . ' #' . $order_info['order_id'], 'separator' => ' :: ', 'current' => true));
     if (isset($this->session->data['success'])) {
         $this->data['success'] = $this->session->data['success'];
         unset($this->session->data['success']);
     } else {
         $this->data['success'] = '';
     }
     $this->data['heading_title'] = $this->language->get('heading_title') . ' #' . $order_info['order_id'];
     $this->data['token'] = $this->session->data['token'];
     $this->data['invoice_url'] = $this->html->getSecureURL('sale/invoice', '&order_id=' . (int) $this->request->get['order_id']);
     $this->data['button_invoice'] = $this->html->buildButton(array('name' => 'btn_invoice', 'text' => $this->language->get('text_invoice')));
     $this->data['invoice_generate'] = $this->html->getSecureURL('sale/invoice/generate');
     $this->data['category_products'] = $this->html->getSecureURL('product/product/category');
     $this->data['product_update'] = $this->html->getSecureURL('catalog/product/update');
     $this->data['order_id'] = $this->request->get['order_id'];
     $this->data['action'] = $this->html->getSecureURL('sale/order/files', '&order_id=' . $this->request->get['order_id']);
     $this->data['cancel'] = $this->html->getSecureURL('sale/order');
     $this->_initTabs('files');
     $this->loadModel('localisation/order_status');
     $status = $this->model_localisation_order_status->getOrderStatus($order_info['order_status_id']);
     if ($status) {
         $this->data['order_status'] = $status['name'];
     } else {
         $this->data['order_status'] = '';
     }
     $this->loadModel('sale/customer_group');
     $customer_group_info = $this->model_sale_customer_group->getCustomerGroup($order_info['customer_group_id']);
     if ($customer_group_info) {
         $this->data['customer_group'] = $customer_group_info['name'];
     } else {
         $this->data['customer_group'] = '';
     }
     $this->data['form_title'] = $this->language->get('edit_title_files');
     $this->data['update'] = $this->html->getSecureURL('listing_grid/order/update_field', '&id=' . $this->request->get['order_id']);
     $form = new AForm('HS');
     $form->setForm(array('form_name' => 'orderFrm', 'update' => $this->data['update']));
     $this->data['form']['id'] = 'orderFrm';
     $this->data['form']['form_open'] = $form->getFieldHtml(array('type' => 'form', 'name' => 'orderFrm', 'attr' => 'data-confirm-exit="true" class="aform form-horizontal"', 'action' => $this->data['action']));
     $this->data['form']['submit'] = $form->getFieldHtml(array('type' => 'button', 'name' => 'submit', 'text' => $this->language->get('button_save'), 'style' => 'button1'));
     $this->data['form']['cancel'] = $form->getFieldHtml(array('type' => 'button', 'name' => 'cancel', 'text' => $this->language->get('button_cancel'), 'style' => 'button2'));
     $this->loadModel('catalog/download');
     $all_downloads = $this->model_catalog_download->getDownloads();
     $options = array('' => $this->language->get('text_push_download'));
     foreach ($all_downloads as $d) {
         $options[$d['download_id']] = $d['name'] . ' (' . $d['mask'] . ')';
     }
     $this->addChild('pages/sale/order_summary', 'summary_form', 'pages/sale/order_summary.tpl');
     /** ORDER DOWNLOADS */
     $this->data['downloads'] = array();
     $order_downloads = $this->model_sale_order->getOrderDownloads($this->request->get['order_id']);
     if ($order_downloads) {
         //get thumbnails by one pass
         $resource = new AResource('image');
         $thumbnails = $resource->getMainThumbList('products', array_keys($order_downloads), $this->config->get('config_image_grid_width'), $this->config->get('config_image_grid_height'));
         $this->loadModel('catalog/download');
         foreach ($order_downloads as $product_id => $order_download) {
             $downloads = (array) $order_download['downloads'];
             $this->data['order_downloads'][$product_id]['product_name'] = $order_download['product_name'];
             $this->data['order_downloads'][$product_id]['product_thumbnail'] = $thumbnails[$product_id];
             foreach ($downloads as $download_info) {
                 $download_info['order_status_id'] = $order_info['order_status_id'];
                 $attributes = $this->download->getDownloadAttributesValuesForDisplay($download_info['download_id']);
                 $order_product_id = $download_info['order_product_id'];
                 $is_file = $this->download->isFileAvailable($download_info['filename']);
                 foreach ($download_info['download_history'] as &$h) {
                     $h['time'] = dateISO2Display($h['time'], $this->language->get('date_format_short') . ' ' . $this->language->get('time_format'));
                 }
                 unset($h);
                 $status_text = $this->model_catalog_download->getTextStatusForOrderDownload($download_info);
                 if ($status_text) {
                     $status = $status_text;
                 } else {
                     $status = $form->getFieldHtml(array('type' => 'checkbox', 'name' => 'downloads[' . (int) $download_info['order_download_id'] . '][status]', 'value' => $download_info['status'], 'style' => 'btn_switch'));
                 }
                 $this->data['order_downloads'][$product_id]['downloads'][] = array('name' => $download_info['name'], 'attributes' => $attributes, 'href' => $this->html->getSecureURL('catalog/product_files', '&product_id=' . $product_id . '&download_id=' . $download_info['download_id']), 'resource' => $download_info['filename'], 'is_file' => $is_file, 'mask' => $download_info['mask'], 'status' => $status, 'remaining' => $form->getFieldHtml(array('type' => 'input', 'name' => 'downloads[' . (int) $download_info['order_download_id'] . '][remaining_count]', 'value' => $download_info['remaining_count'], 'placeholder' => '-', 'style' => 'small-field')), 'expire_date' => $form->getFieldHtml(array('type' => 'date', 'name' => 'downloads[' . (int) $download_info['order_download_id'] . '][expire_date]', 'value' => $download_info['expire_date'] ? dateISO2Display($download_info['expire_date']) : '', 'default' => '', 'dateformat' => format4Datepicker($this->language->get('date_format_short')), 'highlight' => 'future', 'style' => 'medium-field')), 'download_history' => $download_info['download_history']);
                 $this->data['order_downloads'][$product_id]['push_download'] = $form->getFieldHtml(array('type' => 'selectbox', 'name' => 'push[' . (int) $download_info['order_download_id'] . ']', 'value' => '', 'options' => $options, 'style' => 'chosen no-save', 'placeholder' => $this->language->get('text_push_download')));
             }
         }
     } else {
         $this->redirect($this->html->getSecureURL('sale/order/details', '&order_id=' . $this->request->get['order_id']));
     }
     $this->view->batchAssign($this->data);
     $this->view->assign('help_url', $this->gen_help_url('order_files'));
     $this->processTemplate('pages/sale/order_files.tpl');
     //update controller data
     $this->extensions->hk_UpdateData($this, __FUNCTION__);
 }
Example #21
0
 public function main()
 {
     $request = $this->request->get;
     //init controller data
     $this->extensions->hk_InitData($this, __FUNCTION__);
     if ($this->config->get('embed_mode') == true) {
         $cart_rt = 'r/checkout/cart/embed';
         //load special headers
         $this->addChild('responses/embed/head', 'head');
         $this->addChild('responses/embed/footer', 'footer');
     } else {
         $cart_rt = 'checkout/cart';
     }
     $this->loadLanguage('product/manufacturer');
     $this->loadModel('catalog/manufacturer');
     $this->loadModel('catalog/product');
     $this->loadModel('tool/seo_url');
     $this->loadModel('tool/image');
     $this->document->resetBreadcrumbs();
     $this->document->addBreadcrumb(array('href' => $this->html->getURL('index/home'), 'text' => $this->language->get('text_home'), 'separator' => FALSE));
     if (isset($request['manufacturer_id'])) {
         $manufacturer_id = $request['manufacturer_id'];
     } else {
         $manufacturer_id = 0;
     }
     $manufacturer_info = $this->model_catalog_manufacturer->getManufacturer($manufacturer_id);
     if ($manufacturer_info) {
         $this->document->addBreadcrumb(array('href' => $this->html->getSEOURL('product/manufacturer', '&manufacturer_id=' . $request['manufacturer_id'], '&encode'), 'text' => $manufacturer_info['name'], 'separator' => $this->language->get('text_separator')));
         $this->document->setTitle($manufacturer_info['name']);
         $this->view->assign('heading_title', $manufacturer_info['name']);
         $this->view->assign('text_sort', $this->language->get('text_sort'));
         $resource = new AResource('image');
         $thumbnail = $resource->getMainThumb('manufacturers', $manufacturer_info['manufacturer_id'], $this->config->get('config_image_grid_width'), $this->config->get('config_image_grid_height'));
         if (!preg_match('/no_image/', $thumbnail['thumb_url'])) {
             $this->view->assign('manufacturer_icon', $thumbnail['thumb_url']);
         }
         $product_total = $this->model_catalog_product->getTotalProductsByManufacturerId($request['manufacturer_id']);
         if ($product_total) {
             if (isset($request['page'])) {
                 $page = $request['page'];
             } else {
                 $page = 1;
             }
             if (isset($request['limit'])) {
                 $limit = (int) $request['limit'];
                 $limit = $limit > 50 ? 50 : $limit;
             } else {
                 $limit = $this->config->get('config_catalog_limit');
             }
             if (isset($request['sort'])) {
                 $sorting_href = $request['sort'];
             } else {
                 $sorting_href = $this->config->get('config_product_default_sort_order');
             }
             list($sort, $order) = explode("-", $sorting_href);
             if ($sort == 'name') {
                 $sort = 'pd.' . $sort;
             } elseif (in_array($sort, array('sort_order', 'price'))) {
                 $sort = 'p.' . $sort;
             }
             $this->loadModel('catalog/review');
             $this->view->assign('button_add_to_cart', $this->language->get('button_add_to_cart'));
             $product_ids = $products = array();
             $products_result = $this->model_catalog_product->getProductsByManufacturerId($request['manufacturer_id'], $sort, $order, ($page - 1) * $limit, $limit);
             foreach ($products_result as $result) {
                 $product_ids[] = (int) $result['product_id'];
             }
             $products_info = $this->model_catalog_product->getProductsAllInfo($product_ids);
             $thumbnails = $resource->getMainThumbList('products', $product_ids, (int) $this->config->get('config_image_product_width'), (int) $this->config->get('config_image_product_height'));
             $stock_info = $this->model_catalog_product->getProductsStockInfo($product_ids);
             foreach ($products_result as $result) {
                 $thumbnail = $thumbnails[$result['product_id']];
                 $rating = $products_info[$result['product_id']]['rating'];
                 $special = FALSE;
                 $discount = $products_info[$result['product_id']]['discount'];
                 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 = $products_info[$result['product_id']]['special'];
                     if ($special) {
                         $special = $this->currency->format($this->tax->calculate($special, $result['tax_class_id'], $this->config->get('config_tax')));
                     }
                 }
                 $options = $products_info[$result['product_id']]['options'];
                 if ($options) {
                     $add = $this->html->getSEOURL('product/product', '&product_id=' . $result['product_id'], '&encode');
                 } else {
                     if ($this->config->get('config_cart_ajax')) {
                         $add = '#';
                     } else {
                         $add = $this->html->getSecureURL($cart_rt, '&product_id=' . $result['product_id'], '&encode');
                     }
                 }
                 //check for stock status, availability and config
                 $track_stock = false;
                 $in_stock = false;
                 $no_stock_text = $result['stock'];
                 $total_quantity = 0;
                 if ($stock_info[$result['product_id']]['subtract']) {
                     $track_stock = true;
                     $total_quantity = $stock_info[$result['product_id']]['quantity'];
                     //we have stock or out of stock checkout is allowed
                     if ($total_quantity > 0 || $this->config->get('config_stock_checkout')) {
                         $in_stock = true;
                     }
                 }
                 $products[] = array('product_id' => $result['product_id'], 'name' => $result['name'], 'blurb' => $result['blurb'], 'model' => $result['model'], 'rating' => $rating, 'stars' => sprintf($this->language->get('text_stars'), $rating), 'thumb' => $thumbnail, 'price' => $price, 'call_to_order' => $result['call_to_order'], 'options' => $options, 'special' => $special, 'href' => $this->html->getSEOURL('product/product', '&manufacturer_id=' . $request['manufacturer_id'] . '&product_id=' . $result['product_id'], '&encode'), 'add' => $add, 'description' => html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8'), 'track_stock' => $track_stock, 'in_stock' => $in_stock, 'no_stock_text' => $no_stock_text, 'total_quantity' => $total_quantity);
             }
             $this->data['products'] = $products;
             if ($this->config->get('config_customer_price')) {
                 $display_price = TRUE;
             } elseif ($this->customer->isLogged()) {
                 $display_price = TRUE;
             } else {
                 $display_price = FALSE;
             }
             $this->view->assign('display_price', $display_price);
             $url = '';
             if (isset($request['page'])) {
                 $url .= '&page=' . $request['page'];
             }
             if (isset($request['limit'])) {
                 $url .= '&limit=' . $request['limit'];
             }
             $sorts = array();
             $sorts[] = array('text' => $this->language->get('text_default'), 'value' => 'p.sort_order-ASC', 'href' => $this->html->getSEOURL('product/manufacturer', '&path=' . $request['manufacturer_id'] . '&sort=p.sort_order&order=ASC' . $url, '&encode'));
             $sorts[] = array('text' => $this->language->get('text_sorting_name_asc'), 'value' => 'pd.name-ASC', 'href' => $this->html->getSEOURL('product/manufacturer', '&manufacturer_id=' . $request['manufacturer_id'] . '&sort=pd.name&order=ASC' . $url, '&encode'));
             $sorts[] = array('text' => $this->language->get('text_sorting_name_desc'), 'value' => 'pd.name-DESC', 'href' => $this->html->getSEOURL('product/manufacturer', '&manufacturer_id=' . $request['manufacturer_id'] . '&sort=pd.name&order=DESC' . $url, '&encode'));
             $sorts[] = array('text' => $this->language->get('text_sorting_price_asc'), 'value' => 'p.price-ASC', 'href' => $this->html->getSEOURL('product/manufacturer', '&manufacturer_id=' . $request['manufacturer_id'] . '&sort=p.price&order=ASC' . $url, '&encode'));
             $sorts[] = array('text' => $this->language->get('text_sorting_price_desc'), 'value' => 'p.price-DESC', 'href' => $this->html->getSEOURL('product/manufacturer', '&manufacturer_id=' . $request['manufacturer_id'] . '&sort=p.price&order=DESC' . $url, '&encode'));
             $sorts[] = array('text' => $this->language->get('text_sorting_rating_desc'), 'value' => 'rating-DESC', 'href' => $this->html->getSEOURL('product/manufacturer', '&manufacturer_id=' . $request['manufacturer_id'] . '&sort=rating&order=DESC' . $url, '&encode'));
             $sorts[] = array('text' => $this->language->get('text_sorting_rating_asc'), 'value' => 'rating-ASC', 'href' => $this->html->getSEOURL('product/manufacturer', '&manufacturer_id=' . $request['manufacturer_id'] . '&sort=rating&order=ASC' . $url, '&encode'));
             $sorts[] = array('text' => $this->language->get('text_sorting_date_desc'), 'value' => 'date_modified-DESC', 'href' => $this->html->getSEOURL('product/manufacturer', '&manufacturer_id=' . $request['manufacturer_id'] . '&sort=date_modified&order=DESC', '&encode'));
             $sorts[] = array('text' => $this->language->get('text_sorting_date_asc'), 'value' => 'date_modified-ASC', 'href' => $this->html->getSEOURL('product/manufacturer', '&manufacturer_id=' . $request['manufacturer_id'] . '&sort=date_modified&order=ASC', '&encode'));
             $options = array();
             foreach ($sorts as $item) {
                 $options[$item['value']] = $item['text'];
             }
             $sorting = $this->html->buildSelectbox(array('name' => 'sort', 'options' => $options, 'value' => $sort . '-' . $order));
             $this->view->assign('sorting', $sorting);
             $this->view->assign('url', $this->html->getSEOURL('product/manufacturer', '&manufacturer_id=' . $request['manufacturer_id']));
             $pagination_url = $this->html->getSEOURL('product/manufacturer', '&manufacturer_id=' . $request['manufacturer_id'] . '&sort=' . $sorting_href . '&page={page}' . '&limit=' . $limit, '&encode');
             $this->view->assign('pagination_bootstrap', $this->html->buildElement(array('type' => 'Pagination', 'name' => 'pagination', 'text' => $this->language->get('text_pagination'), 'text_limit' => $this->language->get('text_per_page'), 'total' => $product_total, 'page' => $page, 'limit' => $limit, 'url' => $pagination_url, 'style' => 'pagination')));
             $this->view->assign('sort', $sort);
             $this->view->assign('order', $order);
             $this->view->setTemplate('pages/product/manufacturer.tpl');
         } else {
             $this->document->setTitle($manufacturer_info['name']);
             $this->view->assign('heading_title', $manufacturer_info['name']);
             $this->view->assign('text_error', $this->language->get('text_empty'));
             $continue = $this->html->buildElement(array('type' => 'button', 'name' => 'continue_button', 'text' => $this->language->get('button_continue'), 'style' => 'button'));
             $this->view->assign('button_continue', $continue);
             $this->view->assign('continue', $this->html->getURL('index/home'));
             $this->view->setTemplate('pages/error/not_found.tpl');
         }
     } else {
         $url = '';
         if (isset($request['sort'])) {
             $url .= '&sort=' . $request['sort'];
         }
         if (isset($request['order'])) {
             $url .= '&order=' . $request['order'];
         }
         if (isset($request['page'])) {
             $url .= '&page=' . $request['page'];
         }
         $this->document->addBreadcrumb(array('href' => $this->html->getSEOURL('product/manufacturer', '&manufacturer_id=' . $manufacturer_id . $url, '&encode'), 'text' => $this->language->get('text_error'), 'separator' => $this->language->get('text_separator')));
         $this->document->setTitle($this->language->get('text_error'));
         $this->view->assign('heading_title', $this->language->get('text_error'));
         $this->view->assign('text_error', $this->language->get('text_error'));
         $continue = $this->html->buildElement(array('type' => 'button', 'name' => 'continue_button', 'text' => $this->language->get('button_continue'), 'style' => 'button'));
         $this->view->assign('button_continue', $continue);
         $this->view->assign('continue', $this->html->getURL('index/home'));
         $this->view->setTemplate('pages/error/not_found.tpl');
     }
     $this->data['review_status'] = $this->config->get('enable_reviews');
     $this->view->batchAssign($this->data);
     $this->processTemplate();
     //init controller data
     $this->extensions->hk_UpdateData($this, __FUNCTION__);
 }
Example #22
0
 private function _getForm()
 {
     $this->data['token'] = $this->session->data['token'];
     $this->data['cancel'] = $this->html->getSecureURL('sale/coupon');
     $this->data['error'] = $this->error;
     $cont_lang_id = $this->language->getContentLanguageID();
     $this->view->assign('category_products_url', $this->html->getSecureURL('r/product/product/category', '&language_id=' . $cont_lang_id));
     $this->document->initBreadcrumb(array('href' => $this->html->getSecureURL('index/home'), 'text' => $this->language->get('text_home'), 'separator' => FALSE));
     $this->document->addBreadcrumb(array('href' => $this->html->getSecureURL('sale/coupon'), 'text' => $this->language->get('heading_title'), 'separator' => ' :: '));
     if (has_value($this->request->get['coupon_id']) && $this->request->is_GET()) {
         $coupon_info = $this->model_sale_coupon->getCouponByID($this->request->get['coupon_id']);
     }
     $this->data['languages'] = $this->language->getAvailableLanguages();
     foreach ($this->fields as $f) {
         if (isset($this->request->post[$f])) {
             $this->data[$f] = $this->request->post[$f];
         } elseif (isset($coupon_info) && isset($coupon_info[$f])) {
             $this->data[$f] = $coupon_info[$f];
         } else {
             $this->data[$f] = '';
         }
     }
     if (!is_array($this->data['coupon_description'])) {
         if (isset($this->request->get['coupon_id'])) {
             $this->data['coupon_description'] = $this->model_sale_coupon->getCouponDescriptions($this->request->get['coupon_id']);
         } else {
             $this->data['coupon_description'] = array();
         }
     }
     if (!is_array($this->data['coupon_product'])) {
         if (isset($coupon_info)) {
             $this->data['coupon_product'] = $this->model_sale_coupon->getCouponProducts($this->request->get['coupon_id']);
         } else {
             $this->data['coupon_product'] = array();
         }
     }
     //check if coupon is active based on dates and update status
     $now = time();
     if ($this->data['date_start'] && dateISO2Int($this->data['date_start']) > $now || $this->data['date_end'] && dateISO2Int($this->data['date_end']) < $now) {
         $this->data['status'] = 0;
     }
     if (isset($this->request->post['date_start'])) {
         $this->data['date_start'] = dateDisplay2ISO($this->request->post['date_start'], $this->language->get('date_format_short'));
     } elseif (isset($coupon_info)) {
         $this->data['date_start'] = dateISO2Display($coupon_info['date_start'], $this->language->get('date_format_short'));
     } else {
         $this->data['date_start'] = dateInt2Display(time(), $this->language->get('date_format_short'));
     }
     if (isset($this->request->post['date_end'])) {
         $this->data['date_end'] = dateDisplay2ISO($this->request->post['date_end'], $this->language->get('date_format_short'));
     } elseif (isset($coupon_info)) {
         $this->data['date_end'] = dateISO2Display($coupon_info['date_end'], $this->language->get('date_format_short'));
     } else {
         $this->data['date_end'] = '';
     }
     if (isset($this->data['uses_total']) && $this->data['uses_total'] == -1) {
         $this->data['uses_total'] = '';
     } elseif (isset($this->data['uses_total']) && $this->data['uses_total'] == '') {
         $this->data['uses_total'] = 1;
     }
     if (isset($this->data['uses_customer']) && $this->data['uses_customer'] == -1) {
         $this->data['uses_customer'] = '';
     } elseif (isset($this->data['uses_customer']) && $this->data['uses_customer'] == '') {
         $this->data['uses_customer'] = 1;
     }
     if (!has_value($this->data['status'])) {
         $this->data['status'] = 1;
     }
     if (!has_value($this->request->get['coupon_id'])) {
         $this->data['action'] = $this->html->getSecureURL('sale/coupon/insert');
         $this->data['heading_title'] = $this->language->get('text_insert') . ' ' . $this->language->get('text_coupon');
         $this->data['update'] = '';
         $form = new AForm('ST');
     } else {
         $this->data['action'] = $this->html->getSecureURL('sale/coupon/update', '&coupon_id=' . $this->request->get['coupon_id']);
         $this->data['heading_title'] = $this->language->get('text_edit') . ' ' . $this->language->get('text_coupon') . ' - ' . $this->data['coupon_description'][$cont_lang_id]['name'];
         $this->data['update'] = $this->html->getSecureURL('listing_grid/coupon/update_field', '&id=' . $this->request->get['coupon_id']);
         $form = new AForm('HS');
     }
     $this->document->addBreadcrumb(array('href' => $this->data['action'], 'text' => $this->data['heading_title'], 'separator' => ' :: ', 'current' => true));
     $form->setForm(array('form_name' => 'couponFrm', 'update' => $this->data['update']));
     $this->data['form']['id'] = 'couponFrm';
     $this->data['form']['form_open'] = $form->getFieldHtml(array('type' => 'form', 'name' => 'couponFrm', 'attr' => 'data-confirm-exit="true"  class="aform form-horizontal"', 'action' => $this->data['action']));
     $this->data['form']['submit'] = $form->getFieldHtml(array('type' => 'button', 'name' => 'submit', 'text' => $this->language->get('button_save'), 'style' => 'button1'));
     $this->data['form']['cancel'] = $form->getFieldHtml(array('type' => 'button', 'name' => 'cancel', 'text' => $this->language->get('button_cancel'), 'style' => 'button2'));
     $this->data['form']['fields']['status'] = $form->getFieldHtml(array('type' => 'checkbox', 'name' => 'status', 'value' => $this->data['status'], 'style' => 'btn_switch'));
     $this->data['form']['fields']['name'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'coupon_description[' . $cont_lang_id . '][name]', 'value' => $this->data['coupon_description'][$cont_lang_id]['name'], 'required' => true, 'style' => 'large-field'));
     $this->data['form']['fields']['description'] = $form->getFieldHtml(array('type' => 'textarea', 'name' => 'coupon_description[' . $cont_lang_id . '][description]', 'value' => $this->data['coupon_description'][$cont_lang_id]['description'], 'required' => true, 'style' => 'large-field'));
     $this->data['form']['fields']['code'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'code', 'value' => $this->data['code'], 'required' => true));
     $this->data['form']['fields']['type'] = $form->getFieldHtml(array('type' => 'selectbox', 'name' => 'type', 'value' => $this->data['type'], 'options' => array('P' => $this->language->get('text_percent'), 'F' => $this->language->get('text_amount'))));
     $this->data['form']['fields']['discount'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'discount', 'value' => moneyDisplayFormat($this->data['discount'])));
     $this->data['form']['fields']['total'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'total', 'value' => moneyDisplayFormat($this->data['total'])));
     $this->data['form']['fields']['logged'] = $form->getFieldHtml(array('type' => 'selectbox', 'name' => 'logged', 'value' => $this->data['logged'], 'options' => array(1 => $this->language->get('text_yes'), 0 => $this->language->get('text_no'))));
     $this->data['form']['fields']['shipping'] = $form->getFieldHtml(array('type' => 'selectbox', 'name' => 'shipping', 'value' => $this->data['shipping'], 'options' => array(1 => $this->language->get('text_yes'), 0 => $this->language->get('text_no'))));
     $this->data['form']['fields']['date_start'] = $form->getFieldHtml(array('type' => 'date', 'name' => 'date_start', 'value' => $this->data['date_start'], 'default' => dateNowDisplay(), 'dateformat' => format4Datepicker($this->language->get('date_format_short')), 'highlight' => 'future', 'required' => true));
     $this->data['form']['fields']['date_end'] = $form->getFieldHtml(array('type' => 'date', 'name' => 'date_end', 'value' => $this->data['date_end'], 'default' => '', 'dateformat' => format4Datepicker($this->language->get('date_format_short')), 'highlight' => 'pased', 'required' => true));
     $this->data['form']['fields']['uses_total'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'uses_total', 'value' => $this->data['uses_total']));
     $this->data['form']['fields']['uses_customer'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'uses_customer', 'value' => $this->data['uses_customer']));
     if ($this->request->get['coupon_id']) {
         $this->loadModel('sale/order');
         $total = $this->model_sale_order->getTotalOrders(array('filter_coupon_id' => $this->request->get['coupon_id']));
         $this->data['form']['fields']['total_coupon_usage'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'total_coupon_usage', 'value' => (int) $total, 'attr' => 'disabled'));
     }
     //load only prior saved products
     $this->data['products'] = array();
     if (count($this->data['coupon_product'])) {
         $this->loadModel('catalog/product');
         $filter = array('subsql_filter' => 'p.product_id in (' . implode(',', $this->data['coupon_product']) . ')');
         $results = $this->model_catalog_product->getProducts($filter);
         $product_ids = array();
         foreach ($results as $result) {
             $product_ids[] = (int) $result['product_id'];
         }
         //get thumbnails by one pass
         $resource = new AResource('image');
         $thumbnails = $resource->getMainThumbList('products', $product_ids, $this->config->get('config_image_grid_width'), $this->config->get('config_image_grid_height'));
         foreach ($results as $r) {
             $thumbnail = $thumbnails[$r['product_id']];
             $this->data['products'][$r['product_id']]['name'] = $r['name'] . " (" . $r['model'] . ")";
             $this->data['products'][$r['product_id']]['image'] = $thumbnail['thumb_html'];
         }
     }
     $this->data['form']['fields']['product'] = $form->getFieldHtml(array('type' => 'multiselectbox', 'name' => 'coupon_product[]', 'value' => $this->data['coupon_product'], 'options' => $this->data['products'], 'style' => 'chosen', 'ajax_url' => $this->html->getSecureURL('r/product/product/products'), 'placeholder' => $this->language->get('text_select_from_lookup')));
     $this->view->assign('help_url', $this->gen_help_url('coupon_edit'));
     $this->view->batchAssign($this->data);
     $this->processTemplate('pages/sale/coupon_form.tpl');
 }
Example #23
0
 /**
  * @param array $data_source
  * @param array $result
  * @return array
  */
 private function _prepareCustomItems($data_source, $result)
 {
     if (!$data_source['rl_object_name']) {
         return $result;
     }
     $resource = new AResource('image');
     if ($result) {
         if ($data_source['rl_object_name']) {
             switch ($data_source['rl_object_name']) {
                 case 'products':
                     $image_sizes = array('thumb' => array('width' => $this->config->get('config_image_product_width'), 'height' => $this->config->get('config_image_product_height')));
                     break;
                 case 'categories':
                     $image_sizes = array('thumb' => array('width' => $this->config->get('config_image_category_width'), 'height' => $this->config->get('config_image_category_height')));
                     break;
                 case 'manufacturers':
                     $image_sizes = array('thumb' => array('width' => $this->config->get('config_image_manufacturer_width'), 'height' => $this->config->get('config_image_manufacturer_height')));
                     break;
                 default:
                     $image_sizes = array('thumb' => array('width' => $this->config->get('config_image_product_width'), 'height' => $this->config->get('config_image_product_height')));
             }
         }
         //build list of ids
         $ids = array();
         foreach ($result as $k => $item) {
             $ids[] = $item[$data_source['data_type']];
         }
         $thumbnails = $resource->getMainThumbList($data_source['rl_object_name'], $ids, $image_sizes['thumb']['width'], $image_sizes['thumb']['height']);
         foreach ($result as $k => $item) {
             $thumbnail = $thumbnails[$item[$data_source['data_type']]];
             $result[$k]['image'] = $result[$k]['thumb'] = $thumbnail;
             if (isset($item['price']) && preg_match('/^[0-9\\.]/', $item['price'])) {
                 $result[$k]['price'] = $this->currency->format($this->tax->calculate($item['price'], $item['tax_class_id'], $this->config->get('config_tax')));
             }
         }
     }
     return $result;
 }
Example #24
0
 public function post()
 {
     $request = $this->rest->getRequestParams();
     $this->extensions->hk_InitData($this, __FUNCTION__);
     $this->loadModel('catalog/product');
     $product_id = $request['product_id'];
     if (isset($request['quantity'])) {
         if (!is_array($request['quantity'])) {
             if (isset($request['option'])) {
                 $options = $request['option'];
             } else {
                 $options = array();
             }
             if ($errors = $this->model_catalog_product->validateProductOptions($product_id, $options)) {
                 $this->rest->setResponseData(array('error' => implode(' ', $errors)));
                 $this->rest->sendResponse(206);
             }
             $this->cart->add($product_id, $request['quantity'], $options);
         } else {
             foreach ($this->request->post['quantity'] as $key => $value) {
                 $this->cart->update($key, $value);
             }
         }
         unset($this->session->data['shipping_methods']);
         unset($this->session->data['shipping_method']);
         unset($this->session->data['payment_methods']);
         unset($this->session->data['payment_method']);
     }
     //request to remove
     if (isset($request['remove']) && is_array($request['remove'])) {
         foreach (array_keys($request['remove']) as $key) {
             if ($key) {
                 $this->cart->remove($key);
             }
         }
     }
     if ($this->cart->hasProducts()) {
         $this->view->assign('error_warning', $this->error['warning']);
         if (!$this->cart->hasStock() && !$this->config->get('config_stock_checkout')) {
             $this->view->assign('error_warning', $this->language->get('error_stock'));
         }
         $this->loadModel('tool/image');
         $products = array();
         $cart_products = $this->cart->getProducts();
         $product_ids = array();
         foreach ($cart_products as $result) {
             $product_ids[] = (int) $result['product_id'];
         }
         $resource = new AResource('image');
         $thumbnails = $resource->getMainThumbList('products', $product_ids, $this->config->get('config_image_cart_width'), $this->config->get('config_image_cart_height'));
         foreach ($cart_products as $result) {
             $option_data = array();
             $thumbnail = $thumbnails[$result['product_id']];
             foreach ($result['option'] as $option) {
                 $option_data[] = array('name' => $option['name'], 'value' => $option['value']);
             }
             $products[] = array('key' => $result['key'], 'name' => $result['name'], 'model' => $result['model'], 'thumb' => $thumbnail['thumb_url'], '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'))));
         }
         $this->data['products'] = $products;
         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;
         }
         $display_totals = $this->cart->buildTotalDisplay();
         $this->data['totals'] = $display_totals['total_data'];
     } else {
         //empty cart content
         $this->data['products'] = array();
         $this->data['totals'] = 0;
     }
     $this->extensions->hk_UpdateData($this, __FUNCTION__);
     $this->rest->setResponseData($this->data);
     $this->rest->sendResponse(200);
 }
Example #25
0
 public function banners()
 {
     //$products = array();
     $banners_data = array();
     //init controller data
     $this->extensions->hk_InitData($this, __FUNCTION__);
     $this->loadModel('extension/banner_manager');
     if (isset($this->request->post['term'])) {
         $rm = new AResourceManager();
         $rm->setType('image');
         $filter = array('subsql_filter' => "b.target_url LIKE '%" . $this->db->escape($this->request->post['term']) . "%'\n\t\t\t\t\t\t\t\t\t\t\t\tOR bd.name LIKE '%" . $this->db->escape($this->request->post['term']) . "%'\n\t\t\t\t\t\t\t\t\t\t\t\tOR bd.description LIKE '%" . $this->db->escape($this->request->post['term']) . "%'\n\t\t\t\t\t\t\t\t\t\t\t\tOR bd.meta LIKE '%" . $this->db->escape($this->request->post['term']) . "%'", 'limit' => 20);
         $banners = $this->model_extension_banner_manager->getBanners($filter);
         $ids = array();
         foreach ($banners as $result) {
             $ids[] = (int) $result['banner_id'];
         }
         $resource = new AResource('image');
         $thumbnails = $resource->getMainThumbList('banners', $ids, $this->config->get('config_image_grid_width'), $this->config->get('config_image_grid_height'), false);
         foreach ($banners as $banner) {
             $thumbnail = $thumbnails[$banner['banner_id']];
             $icon = $thumbnail['thumb_html'] ? $thumbnail['thumb_html'] : '<i class="fa fa-code fa-4x"></i>&nbsp;';
             $banners_data[] = array('image' => $icon, 'id' => $banner['banner_id'], 'name' => $banner['name'], 'sort_order' => (int) $banner['sort_order']);
         }
     }
     //update controller data
     $this->extensions->hk_UpdateData($this, __FUNCTION__);
     $this->load->library('json');
     $this->response->addJSONHeader();
     $this->response->setOutput(AJson::encode($banners_data));
 }
Example #26
0
 public function manufacturers()
 {
     $output = array();
     //init controller data
     $this->extensions->hk_InitData($this, __FUNCTION__);
     $this->loadModel('catalog/manufacturer');
     if (isset($this->request->post['term'])) {
         $filter = array('limit' => 20, 'language_id' => $this->language->getContentLanguageID(), 'subsql_filter' => "m.name LIKE '%" . $this->request->post['term'] . "%'");
         $results = $this->model_catalog_manufacturer->getManufacturers($filter);
         //build thumbnails list
         $ids = array();
         foreach ($results as $result) {
             $ids[] = $result['manufacturer_id'];
         }
         $resource = new AResource('image');
         $thumbnails = $resource->getMainThumbList('manufacturers', $ids, $this->config->get('config_image_grid_width'), $this->config->get('config_image_grid_height'));
         foreach ($results as $item) {
             $thumbnail = $thumbnails[$item['manufacturer_id']];
             $output[] = array('image' => $icon = $thumbnail['thumb_html'] ? $thumbnail['thumb_html'] : '<i class="fa fa-code fa-4x"></i>&nbsp;', 'id' => $item['manufacturer_id'], 'name' => $item['name'], 'meta' => '', 'sort_order' => (int) $item['sort_order']);
         }
     }
     //update controller data
     $this->extensions->hk_UpdateData($this, __FUNCTION__);
     $this->load->library('json');
     $this->response->addJSONHeader();
     $this->response->setOutput(AJson::encode($output));
 }
Example #27
0
 public function main()
 {
     if ($this->html_cache()) {
         return;
     }
     //init controller data
     $this->extensions->hk_InitData($this, __FUNCTION__);
     $this->data['heading_title'] = $this->language->get('heading_title', 'blocks/featured');
     $this->loadModel('catalog/product');
     $this->loadModel('catalog/review');
     $this->loadModel('tool/image');
     $this->data['button_add_to_cart'] = $this->language->get('button_add_to_cart');
     $this->data['products'] = array();
     $results = $this->model_catalog_product->getfeaturedProducts($this->config->get('config_featured_limit'));
     $product_ids = array();
     foreach ($results as $result) {
         $product_ids[] = (int) $result['product_id'];
     }
     $products_info = $this->model_catalog_product->getProductsAllInfo($product_ids);
     //get thumbnails by one pass
     $resource = new AResource('image');
     $thumbnails = $resource->getMainThumbList('products', $product_ids, $this->config->get('config_image_product_width'), $this->config->get('config_image_product_height'));
     $stock_info = $this->model_catalog_product->getProductsStockInfo($product_ids);
     foreach ($results as $result) {
         $thumbnail = $thumbnails[$result['product_id']];
         $rating = $products_info[$result['product_id']]['rating'];
         $special = FALSE;
         $discount = $products_info[$result['product_id']]['discount'];
         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 = $products_info[$result['product_id']]['special'];
             if ($special) {
                 $special = $this->currency->format($this->tax->calculate($special, $result['tax_class_id'], $this->config->get('config_tax')));
             }
         }
         $options = $products_info[$result['product_id']]['options'];
         if ($options) {
             $add = $this->html->getSEOURL('product/product', '&product_id=' . $result['product_id'], '&encode');
         } else {
             if ($this->config->get('config_cart_ajax')) {
                 $add = '#';
             } else {
                 $add = $this->html->getSecureURL('checkout/cart', '&product_id=' . $result['product_id'], '&encode');
             }
         }
         //check for stock status, availability and config
         $track_stock = false;
         $in_stock = false;
         $no_stock_text = $result['stock'];
         $total_quantity = 0;
         if ($stock_info[$result['product_id']]['subtract']) {
             $track_stock = true;
             $total_quantity = $stock_info[$result['product_id']]['quantity'];
             //we have stock or out of stock checkout is allowed
             if ($total_quantity > 0 || $this->config->get('config_stock_checkout')) {
                 $in_stock = true;
             }
         }
         $this->data['products'][] = array('product_id' => $result['product_id'], 'name' => $result['name'], 'blurb' => $result['blurb'], 'model' => $result['model'], 'rating' => $rating, 'stars' => sprintf($this->language->get('text_stars'), $rating), 'price' => $price, 'call_to_order' => $result['call_to_order'], 'options' => $options, 'special' => $special, 'thumb' => $thumbnail, 'href' => $this->html->getSEOURL('product/product', '&product_id=' . $result['product_id'], '&encode'), 'add' => $add, 'track_stock' => $track_stock, 'in_stock' => $in_stock, 'no_stock_text' => $no_stock_text, 'total_quantity' => $total_quantity, 'date_added' => $result['date_added']);
     }
     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;
     }
     $this->data['review_status'] = $this->config->get('enable_reviews');
     // framed needs to show frames for generic block.
     //If tpl used by listing block framed was set by listing block settings
     $this->data['block_framed'] = true;
     $this->view->batchAssign($this->data);
     $this->processTemplate();
     //init controller data
     $this->extensions->hk_UpdateData($this, __FUNCTION__);
 }
Example #28
0
 public function main()
 {
     //init controller data
     $this->extensions->hk_InitData($this, __FUNCTION__);
     if (!has_value($this->data['protocol'])) {
         $this->data['protocol'] = 'email';
     }
     $this->document->setTitle($this->language->get('text_send_' . $this->data['protocol']));
     $this->loadModel('sale/customer');
     $this->data['token'] = $this->session->data['token'];
     if (isset($this->error)) {
         $this->data['error_warning'] = '';
         foreach ($this->error as $message) {
             $this->data['error_warning'] .= $message . '<br/>';
         }
     } else {
         $this->data['error_warning'] = '';
     }
     if (isset($this->error['subject'])) {
         $this->data['error_subject'] = $this->error['subject'];
     } else {
         $this->data['error_subject'] = '';
     }
     if (isset($this->error['message'])) {
         $this->data['error_message'] = $this->error['message'];
     } else {
         $this->data['error_message'] = '';
     }
     if (isset($this->error['recipient'])) {
         $this->data['error_recipient'] = $this->error['recipient'];
     } else {
         $this->data['error_recipient'] = '';
     }
     $this->document->initBreadcrumb(array('href' => $this->html->getSecureURL('index/home'), 'text' => $this->language->get('text_home'), 'separator' => FALSE));
     $this->document->addBreadcrumb(array('href' => $this->html->getSecureURL('sale/contact'), 'text' => $this->language->get('text_send_' . $this->data['protocol']), 'separator' => ' :: ', 'current' => true));
     if (isset($this->session->data['success'])) {
         $this->data['success'] = $this->session->data['success'];
         unset($this->session->data['success']);
     } else {
         $this->data['success'] = '';
     }
     $this->data['action'] = $this->html->getSecureURL('sale/contact');
     $this->data['cancel'] = $this->html->getSecureURL('sale/contact');
     //get store from main switcher and current config
     $this->data['store_id'] = (int) $this->session->data['current_store_id'];
     $this->data['customers'] = array();
     $this->data['products'] = array();
     $this->loadModel('catalog/product');
     $customer_ids = $this->request->get_or_post('to');
     if (!$customer_ids && has_value($this->session->data['sale_contact_presave']['to'])) {
         $customer_ids = $this->session->data['sale_contact_presave']['to'];
     }
     $product_ids = $this->request->get_or_post('products');
     if (!$product_ids && has_value($this->session->data['sale_contact_presave']['products'])) {
         $product_ids = $this->session->data['sale_contact_presave']['products'];
     }
     //process list of customer or product IDs to be notified
     if (isset($customer_ids) && is_array($customer_ids)) {
         foreach ($customer_ids as $customer_id) {
             $customer_info = $this->model_sale_customer->getCustomer($customer_id);
             if ($customer_info) {
                 $this->data['customers'][$customer_info['customer_id']] = $customer_info['firstname'] . ' ' . $customer_info['lastname'] . ' (' . $customer_info['email'] . ')';
             }
         }
     }
     if (isset($product_ids) && is_array($product_ids)) {
         //get thumbnails by one pass
         $resource = new AResource('image');
         $thumbnails = $resource->getMainThumbList('products', $product_ids, $this->config->get('config_image_grid_width'), $this->config->get('config_image_grid_height'));
         foreach ($product_ids as $product_id) {
             $product_info = $this->model_catalog_product->getProduct($product_id);
             if ($product_info) {
                 $thumbnail = $thumbnails[$product_id];
                 $this->data['products'][$product_id] = array('name' => $product_info['name'], 'image' => $thumbnail['thumb_html']);
             }
         }
     }
     foreach (array('recipient', 'subject', 'message') as $n) {
         $this->data[$n] = $this->request->post_or_get($n);
         if (!$this->data[$n] && has_value($this->session->data['sale_contact_presave'][$n])) {
             $this->data[$n] = $this->session->data['sale_contact_presave'][$n];
         }
     }
     $form = new AForm('ST');
     $form->setForm(array('form_name' => 'sendFrm', 'update' => $this->data['update']));
     $this->data['form']['form_open'] = $form->getFieldHtml(array('type' => 'form', 'name' => 'sendFrm', 'action' => '', 'attr' => 'data-confirm-exit="true" class="form-horizontal"'));
     $this->data['form']['submit'] = $form->getFieldHtml(array('type' => 'button', 'name' => 'submit', 'text' => $this->language->get('button_send'), 'style' => 'button1'));
     $this->data['form']['cancel'] = $form->getFieldHtml(array('type' => 'button', 'name' => 'cancel', 'text' => $this->language->get('button_cancel'), 'style' => 'button2'));
     $this->data['form']['fields']['protocol'] = $form->getFieldHtml(array('type' => 'hidden', 'name' => 'protocol', 'value' => $this->data['protocol']));
     $this->data['form']['build_task_url'] = $this->html->getSecureURL('r/sale/contact/buildTask');
     $this->data['form']['complete_task_url'] = $this->html->getSecureURL('r/sale/contact/complete');
     $this->data['form']['abort_task_url'] = $this->html->getSecureURL('r/sale/contact/abort');
     //set store selector
     $this->view->assign('form_store_switch', $this->html->getStoreSwitcher());
     //build recipient filter
     $options = array('' => $this->language->get('text_custom_send'));
     $db_filter = array('status' => 1, 'approved' => 1);
     if ($this->data['protocol'] == 'sms') {
         $db_filter['filter']['only_with_mobile_phones'] = 1;
     }
     $newsletter_dbfilter = $db_filter;
     $newsletter_dbfilter['filter']['newsletter_protocol'] = $this->data['protocol'];
     $all_subscribers_count = $this->model_sale_customer->getTotalAllSubscribers($newsletter_dbfilter);
     if ($all_subscribers_count) {
         $options['all_subscribers'] = $this->language->get('text_all_subscribers') . ' ' . sprintf($this->language->get('text_total_to_be_sent'), $all_subscribers_count);
     }
     $only_subscribers_count = $this->model_sale_customer->getTotalOnlyNewsletterSubscribers($newsletter_dbfilter);
     if ($only_subscribers_count) {
         $options['only_subscribers'] = $this->language->get('text_subscribers_only') . ' ' . sprintf($this->language->get('text_total_to_be_sent'), $only_subscribers_count);
     }
     $only_customers_count = $this->model_sale_customer->getTotalOnlyCustomers($db_filter);
     if ($only_customers_count) {
         $options['only_customers'] = $this->language->get('text_customers_only') . ' ' . sprintf($this->language->get('text_total_to_be_sent'), $only_customers_count);
     }
     if (sizeof($options) == 1) {
         $this->data['error_warning'] = $this->language->get('error_' . $this->data['protocol'] . '_no_recipients');
     }
     $options['ordered'] = $this->language->get('text_customers_who_ordered');
     $this->data['form']['fields']['to'] = $form->getFieldHtml(array('type' => 'selectbox', 'name' => 'recipient', 'value' => $this->data['recipient'], 'options' => $options, 'required' => true));
     $this->data['recipients_count_url'] = $this->html->getSecureURL('r/sale/contact/getRecipientsCount');
     $this->data['form']['fields']['customers'] = $form->getFieldHtml(array('type' => 'multiselectbox', 'name' => 'to[]', 'value' => $customer_ids, 'options' => $this->data['customers'], 'style' => 'chosen', 'ajax_url' => $this->html->getSecureURL('r/listing_grid/customer/customers'), 'placeholder' => $this->language->get('text_customers_from_lookup')));
     $this->data['form']['fields']['product'] = $form->getFieldHtml(array('type' => 'multiselectbox', 'name' => 'products[]', 'value' => $product_ids, 'options' => $this->data['products'], 'style' => 'chosen', 'ajax_url' => $this->html->getSecureURL('r/product/product/products'), 'placeholder' => $this->language->get('text_products_from_lookup')));
     if ($this->data['protocol'] == 'email') {
         $this->data['form']['fields']['subject'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'subject', 'value' => $this->data['subject'], 'required' => true));
     }
     $this->data['form']['fields']['message'] = $form->getFieldHtml(array('type' => $this->data['protocol'] == 'email' ? 'texteditor' : 'textarea', 'name' => 'message', 'value' => $this->data['message'], 'style' => 'ml_ckeditor', 'required' => true));
     //if email address given
     if (has_value($this->request->get['email'])) {
         $this->data['emails'] = (array) $this->request->get['email'];
     }
     $this->data['category_products'] = $this->html->getSecureURL('product/product/category');
     $this->data['customers_list'] = $this->html->getSecureURL('user/customers');
     $this->data['presave_url'] = $this->html->getSecureURL('r/sale/contact/presave');
     $this->data['help_url'] = $this->gen_help_url('send_mail');
     if ($this->data['protocol'] == 'email') {
         $resources_scripts = $this->dispatch('responses/common/resource_library/get_resources_scripts', array('object_name' => 'contact', 'object_id' => '', 'types' => array('image')));
         $this->data['resources_scripts'] = $resources_scripts->dispatchGetOutput();
         $this->data['rl'] = $this->html->getSecureURL('common/resource_library', '&action=list_library&object_name=&object_id&type=image&mode=single');
     }
     //load tabs controller
     if ($this->data['protocol'] == 'email' || !has_value($this->data['protocol'])) {
         $this->data['active'] = 'email';
     } elseif ($this->data['protocol'] == 'sms') {
         $this->data['active'] = 'sms';
     }
     $this->data['protocols'] = array();
     $this->data['protocols']['email'] = array('title' => $this->language->get('text_email'), 'href' => $this->html->getSecureURL('sale/contact/email'), 'icon' => 'mail');
     $driver = $this->config->get('config_sms_driver');
     //if sms driver not set or disabled - redirect
     if ($driver && $this->config->get($driver . '_status')) {
         $this->data['protocols']['sms'] = array('title' => $this->language->get('text_sms'), 'href' => $this->html->getSecureURL('sale/contact/sms'));
     }
     //check for incompleted tasks
     $tm = new ATaskManager();
     $incompleted = $tm->getTasks(array('filter' => array('name' => 'send_now')));
     foreach ($incompleted as $incm_task) {
         //show all incompleted tasks for Top Administrator user group
         if ($this->user->getUserGroupId() != 1) {
             if ($incm_task['starter'] != $this->user->getId()) {
                 continue;
             }
             //rename task to prevent colission with new
             if ($incm_task['name'] == 'send_now') {
                 $tm->updateTask($incm_task['task_id'], array('name' => 'send_now_' . date('YmdHis')));
             }
         }
         //define incompleted tasks by last time run
         $max_exec_time = (int) $incm_task['max_execution_time'];
         if (!$max_exec_time) {
             //if no limitations for execution time for task - think it's 2 hours
             $max_exec_time = 7200;
         }
         if (time() - dateISO2Int($incm_task['last_time_run']) > $max_exec_time) {
             $this->data['incomplete_tasks_url'] = $this->html->getSecureURL('r/sale/contact/incompleted');
             break;
         }
     }
     $this->view->batchAssign($this->data);
     $this->processTemplate('pages/sale/contact.tpl');
     //update controller data
     $this->extensions->hk_UpdateData($this, __FUNCTION__);
 }
Example #29
0
 private function _getBlockForm()
 {
     if (isset($this->session->data['warning'])) {
         $this->data['error_warning'] = $this->session->data['warning'];
         $this->session->data['warning'] = '';
     } else {
         $this->data['error_warning'] = '';
     }
     $this->load->library('json');
     $this->view->assign('success', $this->session->data['success']);
     if (isset($this->session->data['success'])) {
         unset($this->session->data['success']);
     }
     $this->document->initBreadcrumb(array('href' => $this->html->getSecureURL('index/home'), 'text' => $this->language->get('text_home'), 'separator' => FALSE));
     $this->document->addBreadcrumb(array('href' => $this->html->getSecureURL('design/blocks'), 'text' => $this->language->get('heading_title'), 'separator' => ' :: '));
     $this->data['cancel'] = $this->html->getSecureURL('design/blocks');
     $custom_block_id = (int) $this->request->get['custom_block_id'];
     // need to get data of custom listing
     $options_list = array();
     if ($custom_block_id) {
         $lm = new ALayoutManager();
         $block_info = $lm->getBlockDescriptions($custom_block_id);
         $language_id = $this->session->data['content_language_id'];
         if (!isset($block_info[$language_id])) {
             $language_id = key($block_info);
         }
         foreach ($block_info[$language_id] as $k => $v) {
             $this->data[$k] = $v;
         }
         $content = $block_info[$this->language->getContentLanguageID()]['content'];
         if ($content) {
             $content = unserialize($content);
         } else {
             $content = current($block_info);
             $content = unserialize($content['content']);
         }
         $this->data['banner_group_name'] = $content['banner_group_name'];
         $lm = new AListingManager($this->request->get['custom_block_id']);
         $list = $lm->getCustomList();
         $options_list = array();
         if ($list) {
             foreach ($list as $row) {
                 $options_list[(int) $row['id']] = array();
             }
             $ids = array_keys($options_list);
             $assigned_banners = $this->model_extension_banner_manager->getBanners(array('subsql_filter' => 'b.banner_id IN (' . implode(', ', $ids) . ')'));
             $resource = new AResource('image');
             $thumbnails = $resource->getMainThumbList('banners', $ids, $this->config->get('config_image_grid_width'), $this->config->get('config_image_grid_height'), false);
             foreach ($assigned_banners as $banner) {
                 $id = $banner['banner_id'];
                 if (in_array($id, $ids)) {
                     $thumbnail = $thumbnails[$banner['banner_id']];
                     $icon = $thumbnail['thumb_html'] ? $thumbnail['thumb_html'] : '<i class="fa fa-code fa-4x"></i>&nbsp;';
                     $options_list[$id] = array('image' => $icon, 'id' => $id, 'name' => $banner['name'], 'sort_order' => (int) $banner['sort_order']);
                 }
             }
         }
     }
     if (!$custom_block_id) {
         $this->data['action'] = $this->html->getSecureURL('extension/banner_manager/insert_block');
         $this->data['form_title'] = $this->language->get('text_create_block', 'banner_manager/banner_manager');
         $this->data['update'] = '';
         $form = new AForm('ST');
     } else {
         $this->data['action'] = $this->html->getSecureURL('extension/banner_manager/edit_block', '&custom_block_id=' . $custom_block_id);
         $this->data['form_title'] = $this->language->get('text_edit') . ' ' . $this->data['name'];
         $this->data['update'] = $this->html->getSecureURL('listing_grid/blocks_grid/update_field', '&custom_block_id=' . $custom_block_id);
         $form = new AForm('HS');
     }
     $this->document->addBreadcrumb(array('href' => $this->data['action'], 'text' => $this->data['form_title'], 'separator' => ' :: ', 'current' => true));
     $form->setForm(array('form_name' => 'BannerBlockFrm', 'update' => $this->data['update']));
     $this->data['form']['form_open'] = $form->getFieldHtml(array('type' => 'form', 'name' => 'BannerBlockFrm', 'action' => $this->data['action'], 'attr' => 'data-confirm-exit="true" class="aform form-horizontal"'));
     $this->data['form']['submit'] = $form->getFieldHtml(array('type' => 'button', 'name' => 'submit', 'text' => $this->language->get('button_save'), 'style' => 'button1'));
     $this->data['form']['cancel'] = $form->getFieldHtml(array('type' => 'button', 'name' => 'cancel', 'text' => $this->language->get('button_cancel'), 'style' => 'button2'));
     if ($custom_block_id) {
         $this->data['form']['fields']['block_status'] = $form->getFieldHtml(array('type' => 'checkbox', 'name' => 'block_status', 'value' => $this->data['status'], 'style' => 'btn_switch'));
         $this->data['form']['text']['block_status'] = $this->html->convertLinks($this->language->get('entry_block_status'));
         $this->data['form']['fields']['block_status_note'] = '';
         $this->data['form']['text']['block_status_note'] = $this->html->convertLinks($this->language->get('entry_block_status_note'));
     }
     $this->data['form']['fields']['block_name'] = $form->getFieldHtml(array('type' => 'hidden', 'name' => 'block_id', 'value' => $this->data['block_id']));
     $this->data['form']['fields']['block_name'] .= $form->getFieldHtml(array('type' => 'input', 'name' => 'block_name', 'value' => $this->data['name'], 'multilingual' => true, 'required' => true));
     $this->data['form']['text']['block_name'] = $this->language->get('entry_block_name');
     $this->data['form']['fields']['block_title'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'block_title', 'required' => true, 'multilingual' => true, 'value' => $this->data['title']));
     $this->data['form']['text']['block_title'] = $this->language->get('entry_block_title');
     // list of templates for block
     $tmpl_ids = $this->extensions->getInstalled('template');
     $tmpl_ids[] = 'default';
     $this->data['block_wrappers'] = array();
     foreach ($tmpl_ids as $tmpl_id) {
         // for tpls of block that stores in db
         $layout_manager = new ALayoutManager($tmpl_id);
         $block = $layout_manager->getBlockByTxtId('banner_block');
         $block_templates = (array) $layout_manager->getBlockTemplates($block['block_id']);
         foreach ($block_templates as $item) {
             if ($item['template']) {
                 $this->data['block_wrappers'][$item['template']] = $item['template'];
             }
         }
         //Automatic block template selection mode based on parent is limited to 1 template per location
         //To extend, allow custom block's template to be selected to suppress automatic selection
         //for tpls that stores in main.php (other extensions templates)
         $ext_tpls = $this->extensions->getExtensionTemplates();
         foreach ($ext_tpls as $section) {
             foreach ($section as $s => $tpls) {
                 if ($s != 'storefront') {
                     continue;
                 }
                 foreach ($tpls as $tpl) {
                     if (isset($this->data['block_wrappers'][$tpl]) || strpos($tpl, 'blocks/banner_block/') === false) {
                         continue;
                     }
                     $this->data['block_wrappers'][$tpl] = $tpl;
                 }
             }
         }
         $tpls = glob(DIR_STOREFRONT . 'view/*/template/blocks/banner_block/*.tpl');
         foreach ($tpls as $tpl) {
             $pos = strpos($tpl, 'blocks/banner_block/');
             $tpl = substr($tpl, $pos);
             if (!isset($this->data['block_wrappers'][$tpl])) {
                 $this->data['block_wrappers'][$tpl] = $tpl;
             }
         }
     }
     ksort($this->data['block_wrappers']);
     array_unshift($this->data['block_wrappers'], $this->language->get('text_automatic'));
     if ($this->data['block_wrapper'] && !isset($this->data['block_wrappers'][$this->data['block_wrapper']])) {
         $this->data['block_wrappers'] = array_merge(array($this->data['block_wrapper'] => $this->data['block_wrapper']), $this->data['block_wrappers']);
     }
     $this->data['form']['fields']['block_wrapper'] = $form->getFieldHtml(array('type' => 'selectbox', 'name' => 'block_wrapper', 'options' => $this->data['block_wrappers'], 'value' => $this->data['block_wrapper']));
     $this->data['form']['text']['block_wrapper'] = $this->language->get('entry_block_wrapper');
     $this->data['form']['fields']['block_framed'] = $form->getFieldHtml(array('type' => 'checkbox', 'name' => 'block_framed', 'value' => $this->data['block_framed'], 'style' => 'btn_switch'));
     $this->data['form']['text']['block_framed'] = $this->language->get('entry_block_framed');
     $this->data['form']['fields']['block_description'] = $form->getFieldHtml(array('type' => 'textarea', 'name' => 'block_description', 'value' => $this->data['description'], 'attr' => ' style="height: 50px;"', 'multilingual' => true));
     $this->data['form']['text']['block_description'] = $this->language->get('entry_block_description');
     // groups of banners
     $this->loadModel('extension/banner_manager');
     $result = $this->model_extension_banner_manager->getBannerGroups();
     $groups = array('0' => $this->language->get('text_select'));
     if ($result) {
         foreach ($result as $row) {
             $groups[$row['banner_group_name']] = $row['banner_group_name'];
         }
     }
     $this->data['form']['fields']['banner_group_name'] = $form->getFieldHtml(array('type' => 'selectbox', 'name' => 'banner_group_name', 'options' => $groups, 'value' => $this->data['banner_group_name'], 'style' => 'no-save'));
     $this->data['form']['text']['banner_group_name'] = $this->language->get('entry_banner_group_name');
     $this->data['form']['text']['listed_banners'] = $this->language->get('entry_banners_selected');
     //load only prior saved products
     $this->data['banners'] = array();
     $this->data['form']['fields']['listed_banners'] = $form->getFieldHtml(array('type' => 'multiselectbox', 'name' => 'block_banners[]', 'value' => $ids, 'options' => $options_list, 'style' => 'no-save chosen', 'ajax_url' => $this->html->getSecureURL('listing_grid/banner_manager/banners'), 'placeholder' => $this->language->get('text_select_from_lookup')));
     $this->view->batchAssign($this->language->getASet());
     $this->view->batchAssign($this->data);
     $this->view->assign('form_language_switch', $this->html->getContentLanguageSwitcher());
     $this->view->assign('language_code', $this->session->data['language']);
     $this->view->assign('help_url', $this->gen_help_url('banner_edit'));
     $this->view->assign('rl', $this->html->getSecureURL('common/resource_library', '&object_name=banners&type=image&mode=url'));
     $this->processTemplate('pages/extension/banner_manager_block_form.tpl');
 }
Example #30
0
 /**
  * Method fill data into embedded block with manufacturer or few manufacturers
  */
 public function manufacturers()
 {
     $this->extensions->hk_InitData($this, __FUNCTION__);
     $manufacturer_id = (array) $this->request->get['manufacturer_id'];
     if (!$manufacturer_id) {
         return null;
     } else {
         foreach ($manufacturer_id as &$id) {
             $id = (int) $id;
         }
         unset($id);
     }
     $this->data['targets'] = (array) $this->request->get['target_id'];
     if (!$this->data['targets']) {
         return null;
     }
     $this->loadModel('catalog/manufacturer');
     $manufacturers = $this->model_catalog_manufacturer->getManufacturersData(array('subsql_filter' => ' m.manufacturer_id IN (' . implode(',', $manufacturer_id) . ')'));
     //can not locate manufacturers? get out
     if (!$manufacturers) {
         return null;
     }
     $ids = array();
     foreach ($manufacturers as $result) {
         $ids[] = (int) $result['manufacturer_id'];
     }
     //get thumbnails by one pass
     $resource = new AResource('image');
     $thumbnails = $resource->getMainThumbList('manufacturers', $ids, $this->config->get('config_image_category_width'), $this->config->get('config_image_category_height'));
     foreach ($manufacturers as &$manufacturer) {
         //deal with quotes
         $manufacturer['name'] = htmlentities(html_entity_decode($manufacturer['name'], ENT_QUOTES, 'UTF-8'), ENT_QUOTES, 'UTF-8');
         $manufacturer['thumbnail'] = $thumbnails[$manufacturer['manufacturer_id']];
         $rt = $this->config->get('config_embed_click_action') == 'modal' ? 'r/product/manufacturer' : 'product/manufacturer';
         $manufacturer['details_url'] = $this->html->getURL($rt, '&manufacturer_id=' . $manufacturer['manufacturer_id']);
     }
     $this->data['manufacturers'] = $manufacturers;
     $this->view->setTemplate('embed/js_manufacturers.tpl');
     $this->view->batchAssign($this->language->getASet('product/manufacturer'));
     $this->view->batchAssign($this->data);
     $this->_set_js_http_headers();
     $this->processTemplate();
     //init controller data
     $this->extensions->hk_UpdateData($this, __FUNCTION__);
 }