public function main() { //init controller data $this->extensions->hk_InitData($this, __FUNCTION__); $this->loadLanguage('sale/customer'); $this->loadModel('sale/customer'); $this->load->library('json'); $approved = array(1 => $this->language->get('text_yes'), 0 => $this->language->get('text_no')); $page = $this->request->post['page']; // get the requested page $limit = $this->request->post['rows']; // get how many rows we want to have into the grid $sidx = $this->request->post['sidx']; // get index row - i.e. user click to sort $sord = $this->request->post['sord']; // get the direction $data = array('sort' => $sidx, 'order' => $sord, 'start' => ($page - 1) * $limit, 'limit' => $limit); if (has_value($this->request->get['customer_group'])) { $data['filter']['customer_group_id'] = $this->request->get['customer_group']; } if (has_value($this->request->get['status'])) { $data['filter']['status'] = $this->request->get['status']; } if (has_value($this->request->get['approved'])) { $data['filter']['approved'] = $this->request->get['approved']; } $allowedFields = array('name', 'email'); if (isset($this->request->post['_search']) && $this->request->post['_search'] == 'true') { $searchData = AJson::decode(htmlspecialchars_decode($this->request->post['filters']), true); foreach ($searchData['rules'] as $rule) { if (!in_array($rule['field'], $allowedFields)) { continue; } $data['filter'][$rule['field']] = $rule['data']; } } $total = $this->model_sale_customer->getTotalCustomers($data); if ($total > 0) { $total_pages = ceil($total / $limit); } else { $total_pages = 0; } $response = new stdClass(); $response->page = $page; $response->total = $total_pages; $response->records = $total; $results = $this->model_sale_customer->getCustomers($data); $i = 0; foreach ($results as $result) { $response->rows[$i]['id'] = $result['customer_id']; $response->rows[$i]['cell'] = array($result['name'], '<a href="' . $this->html->getSecureURL('sale/contact', '&email[]=' . $result['email']) . '">' . $result['email'] . '</a>', $result['customer_group'], $this->html->buildCheckbox(array('name' => 'status[' . $result['customer_id'] . ']', 'value' => $result['status'], 'style' => 'btn_switch')), $this->html->buildSelectbox(array('name' => 'approved[' . $result['customer_id'] . ']', 'value' => $result['approved'], 'options' => $approved)), $result['orders_count'] > 0 ? $this->html->buildButton(array('name' => 'view orders', 'text' => $result['orders_count'], 'style' => 'button2', 'href' => $this->html->getSecureURL('sale/order', '&customer_id=' . $result['customer_id']), 'title' => $this->language->get('text_view') . ' ' . $this->language->get('tab_history'), 'target' => '_blank')) : 0); $i++; } //update controller data $this->extensions->hk_UpdateData($this, __FUNCTION__); $this->response->setOutput(AJson::encode($response)); }
private function _html_response() { $this->loadLanguage('catalog/download'); $form_name = isset($this->request->get['form_name']) ? $this->request->get['form_name'] : 'SharedFrm'; $multivalue_hidden_id = isset($this->request->get['multivalue_hidden_id']) ? $this->request->get['multivalue_hidden_id'] : 'popup'; //remember selected rows for response if (isset($this->request->post['selected'])) { $this->session->data['listing_selected'] = AJson::decode(html_entity_decode($this->request->post['selected']), true); } $grid_settings = array('table_id' => 'download_grid_' . $multivalue_hidden_id, 'url' => $this->html->getSecureURL('catalog/download_listing', '&response_type=json&product_id=' . $this->request->get['product_id'] . (isset($this->request->get['shared_only']) ? '&shared_only=1' : '')), 'editurl' => '', 'sortname' => 'name', 'sortorder' => 'asc', 'actions' => array(), 'multiselect_noselectbox' => true); $grid_settings['colNames'] = array($this->language->get('column_image'), $this->language->get('column_name')); $grid_settings['colNames'][] = $this->language->get('column_action'); $grid_settings['colModel'] = array(array('name' => 'image', 'index' => 'image', 'align' => 'center', 'width' => 50, 'sortable' => false, 'search' => false), array('name' => 'name', 'index' => 'name', 'align' => 'left', 'width' => 200), array('name' => 'action', 'index' => 'action', 'align' => 'center', 'width' => 30, 'sortable' => false, 'search' => false)); $grid_settings['search_form'] = true; $grid = $this->dispatch('common/listing_grid', array($grid_settings)); $listing_grid = $grid->dispatchGetOutput(); unset($grid); // add js-scripts for grid rows selecting (redeclare onSelectRow event for grid) $view = new AView($this->registry, 0); $view->batchAssign(array('id' => $multivalue_hidden_id, 'form_name' => $form_name . '_' . $multivalue_hidden_id, 'table_id' => $grid_settings['table_id'], 'listing_grid' => $listing_grid, 'filter_product' => $this->language->get('filter_product'), 'filter_price_max' => $this->language->get('filter_price_max'))); $this->data['response'] = $view->fetch('responses/catalog/download_listing.tpl'); }
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->server['REQUEST_METHOD'] == '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 => $items) { $items = AJson::decode(html_entity_decode($items), true); if ($items) { foreach ($items as $download_id => $info) { $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' => ' :: ')); 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'] = $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'), 'style' => 'button3')); $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' => 'confirm-exit="true"', '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->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) { $rl = new AResource('image'); if (!$this->registry->has('jqgrid_script')) { $locale = $this->session->data['language']; if (!file_exists(DIR_ROOT . '/' . RDIR_TEMPLATE . 'javascript/jqgrid/js/i18n/grid.locale-' . $locale . '.js')) { $locale = 'en'; } $this->document->addScript(RDIR_TEMPLATE . 'javascript/jqgrid/js/i18n/grid.locale-' . $locale . '.js'); $this->document->addScript(RDIR_TEMPLATE . 'javascript/jqgrid/js/jquery.jqGrid.min.js'); $this->document->addScript(RDIR_TEMPLATE . 'javascript/jqgrid/plugins/jquery.grid.fluid.js'); $this->document->addScript(RDIR_TEMPLATE . 'javascript/jqgrid/js/jquery.ba-bbq.min.js'); $this->document->addScript(RDIR_TEMPLATE . 'javascript/jqgrid/js/grid.history.js'); //set flag to not include scripts/css twice $this->registry->set('jqgrid_script', true); } $this->session->data['multivalue_excludes'] = array(); $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'] = $rl->getMainThumb('products', $product_id, $this->config->get('config_image_grid_width'), $this->config->get('config_image_grid_height')); 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']); // exclude downloads from multivalue list. why we need relate recursion? $this->session->data['multivalue_excludes'][] = $download_info['download_id']; } $this->data['order_downloads'][$product_id]['push'] = $form->getFieldHtml(array('id' => 'popup' . $product_id, 'type' => 'multivalue', 'name' => 'popup' . $product_id, 'title' => $this->language->get('text_select_from_list'), 'selected_name' => 'push[' . $order_product_id . ']', 'selected' => "{}", 'content_url' => $this->html->getSecureUrl('catalog/download_listing', '&form_name=orderFrm&multivalue_hidden_id=popup' . $product_id), 'postvars' => '', 'return_to' => '', 'popup_height' => 708, 'text' => array('selected' => $this->language->get('text_count_selected'), 'edit' => $this->language->get('text_save_edit'), 'apply' => $this->language->get('text_apply'), 'save' => $this->language->get('text_add'), 'reset' => $this->language->get('button_reset')))); } } $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__); }
public function transactions() { //init controller data $this->extensions->hk_InitData($this, __FUNCTION__); $this->loadModel('report/customer'); //Prepare filter config $filter_params = array('date_start', 'date_end'); $filter_form = new AFilter(array('method' => 'get', 'filter_params' => $filter_params)); $filter_grid = new AFilter(array('method' => 'post')); $data = array_merge($filter_form->getFilterData(), $filter_grid->getFilterData()); //add filters for custom processing $allowedFields = array('customer'); if (isset($this->request->post['_search']) && $this->request->post['_search'] == 'true') { $searchData = AJson::decode(htmlspecialchars_decode($this->request->post['filters']), true); foreach ($searchData['rules'] as $rule) { if (!in_array($rule['field'], $allowedFields)) { continue; } $data['filter'][$rule['field']] = $rule['data']; } } $total = $this->model_report_customer->getTotalCustomerTransactions($data); $response = new stdClass(); $response->page = $filter_grid->getParam('page'); $response->total = $filter_grid->calcTotalPages($total); $response->records = $total; $results = $this->model_report_customer->getCustomerTransactions($data); $i = 0; foreach ($results as $result) { $response->rows[$i]['id'] = $result['customer_transaction_id']; //mark inactive customers. if ($result['status'] != 1) { $response->userdata->classes[$result['customer_transaction_id']] = 'attention'; } $response->rows[$i]['cell'] = array($result['date_added'], $result['customer'], $this->currency->format($result['debit'], $this->config->get('config_currency')), $this->currency->format($result['credit'], $this->config->get('config_currency')), $result['transaction_type'], $result['created_by']); $i++; } //update controller data $this->extensions->hk_UpdateData($this, __FUNCTION__); $this->load->library('json'); $this->response->setOutput(AJson::encode($response)); }
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); }
public function getListing() { //init controller data $this->extensions->hk_InitData($this, __FUNCTION__); $this->load->library('json'); $form_name = 'BannerBlockFrm'; $multivalue_hidden_id = isset($this->request->get['multivalue_hidden_id']) ? $this->request->get['multivalue_hidden_id'] : 'popup'; $this->loadLanguage('banner_manager/banner_manager'); //remember selected rows for response if (isset($this->request->post['selected'])) { $this->session->data['listing_selected'] = AJson::decode(html_entity_decode($this->request->post['selected']), true); } $grid_settings = array('table_id' => 'banner_grid', 'url' => $this->html->getSecureURL('listing_grid/banner_manager/getBannerListData'), 'editurl' => '', 'update_field' => '', 'sortname' => 'name', 'sortorder' => 'asc', 'columns_search' => true, 'actions' => array(), 'multiselect_noselectbox' => true); $form = new AForm(); $form->setForm(array('form_name' => 'banner_grid_search')); $grid_search_form = array(); $grid_search_form['id'] = 'banner_grid_search'; $grid_search_form['form_open'] = $form->getFieldHtml(array('type' => 'form', 'name' => 'banner_grid_search', 'action' => '')); $grid_search_form['submit'] = $form->getFieldHtml(array('type' => 'button', 'name' => 'submit', 'text' => $this->language->get('button_go'), 'style' => 'button1')); $grid_search_form['reset'] = $form->getFieldHtml(array('type' => 'button', 'name' => 'reset', 'text' => $this->language->get('button_reset'), 'style' => 'button2')); $grid_settings['colNames'] = array('', $this->language->get('column_banner_name'), $this->language->get('column_banner_group'), $this->language->get('column_banner_type'), $this->language->get('column_action')); $grid_settings['colModel'] = array(array('name' => 'banner_icon', 'index' => 'icon', 'width' => 40, 'align' => 'center', 'search' => false), array('name' => 'banner_name', 'index' => 'name', 'width' => 100, 'align' => 'left'), array('name' => 'banner_group', 'index' => 'banner_group_name', 'width' => 80, 'align' => 'left'), array('name' => 'banner_type', 'index' => 'banner_type', 'width' => 60, 'align' => 'center', 'search' => false), array('name' => 'action', 'index' => 'action', 'align' => 'center', 'sortable' => false, 'search' => false)); $grid = $this->dispatch('common/listing_grid', array($grid_settings)); $this->data['listing_grid'] = $grid->dispatchGetOutput(); $this->data['search_form'] = $grid_search_form; $grid = $this->dispatch('common/listing_grid', array($grid_settings)); $listing_grid = $grid->dispatchGetOutput(); unset($grid); // add js-scripts for grid rows selecting (redeclare onSelectRow event for grid) $view = new AView($this->registry, 0); $view->batchAssign(array('id' => $multivalue_hidden_id, 'form_name' => $form_name . '_' . $multivalue_hidden_id, 'table_id' => $grid_settings['table_id'], 'listing_grid' => $listing_grid, 'heading_title' => $this->language->get('text_select_banners'))); $this->data['response'] = $view->fetch('responses/extension/banner_listing.tpl'); //update controller data $this->extensions->hk_UpdateData($this, __FUNCTION__); $this->response->setOutput($this->data['response']); }
public function buildListingGridForSelect() { //init controller data $this->extensions->hk_InitData($this, __FUNCTION__); $this->load->library('json'); $custom_block_id = (int) $this->request->get['custom_block_id']; $form_name = has_value($this->request->get['form_name']) ? $this->request->get['form_name'] : 'BlockFrm'; $lm = new AListingManager($custom_block_id); $this->data['data_sources'] = $lm->getListingDataSources(); $listing_datasource = $this->request->post_or_get('listing_datasource'); $this->loadLanguage($this->data['data_sources'][$listing_datasource]['language']); //remember selected rows for response if (isset($this->request->post['selected'])) { $this->session->data['listing_selected'] = AJson::decode(html_entity_decode($this->request->post['selected']), true); } $grid_settings = array('table_id' => 'product_grid', 'url' => $this->html->getSecureURL('listing_grid/blocks_grid/getCustomListListingGridData', '&custom_block_id=' . $custom_block_id . '&listing_datasource=' . $listing_datasource), 'editurl' => '', 'sortname' => 'name', 'actions' => array(), 'multiselect_noselectbox' => true); $grid_settings['colNames'] = array($this->language->get('column_image'), $this->language->get('column_name')); if (strpos($listing_datasource, 'product') !== FALSE) { $grid_settings['colNames'][] = $this->language->get('column_model'); } $grid_settings['colNames'][] = $this->language->get('column_action'); $grid_settings['colModel'] = array(array('name' => 'image', 'index' => 'image', 'align' => 'center', 'width' => 50, 'sortable' => false, 'search' => false), array('name' => 'name', 'index' => 'name', 'align' => 'left', 'width' => 200)); if (strpos($listing_datasource, 'product') !== FALSE) { $grid_settings['colModel'][] = array('name' => 'model', 'index' => 'model', 'align' => 'center', 'width' => 60, 'sortable' => true); } $grid_settings['colModel'][] = array('name' => 'action', 'index' => 'action', 'align' => 'center', 'width' => 30, 'sortable' => false, 'search' => false); $grid_settings['search_form'] = true; $grid = $this->dispatch('common/listing_grid', array($grid_settings)); $this->data['response'] = $grid->dispatchGetOutput(); $view = new AView($this->registry, 0); $view->batchAssign(array('form_name' => $form_name, 'table_id' => $grid_settings['table_id'])); //add scripts $this->data['response'] .= $view->fetch('responses/design/block_custom_listing_js.tpl'); //update controller data $this->extensions->hk_UpdateData($this, __FUNCTION__); $this->response->setOutput($this->data['response']); }
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 (!$this->registry->has('jqgrid_script')) { $locale = $this->session->data['language']; if (!file_exists(DIR_ROOT . '/' . RDIR_TEMPLATE . 'javascript/jqgrid/js/i18n/grid.locale-' . $locale . '.js')) { $locale = 'en'; } $this->document->addScript(RDIR_TEMPLATE . 'javascript/jqgrid/js/i18n/grid.locale-' . $locale . '.js'); $this->document->addScript(RDIR_TEMPLATE . 'javascript/jqgrid/js/jquery.jqGrid.min.js'); $this->document->addScript(RDIR_TEMPLATE . 'javascript/jqgrid/plugins/jquery.grid.fluid.js'); $this->document->addScript(RDIR_TEMPLATE . 'javascript/jqgrid/js/jquery.ba-bbq.min.js'); $this->document->addScript(RDIR_TEMPLATE . 'javascript/jqgrid/js/grid.history.js'); //set flag to not include scripts/css twice $this->registry->set('jqgrid_script', true); } if (isset($this->request->get['product_id']) && $this->request->server['REQUEST_METHOD'] != 'POST') { $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->server['REQUEST_METHOD'] == 'POST') { $this->load->library('json'); $this->request->post['selected'][0] = AJson::decode(html_entity_decode($this->request->post['selected'][0]), true); $this->request->post['selected'][1] = AJson::decode(html_entity_decode($this->request->post['selected'][1]), true); if ($this->request->post['selected']) { $related = array(); foreach ($this->request->post['selected'][1] as $id => $related_product) { if ($related_product['status']) { $related[] = $id; } } $product_category = array(); foreach ($this->request->post['selected'][0] as $id => $category) { if ($category['status']) { $product_category[] = $id; } } unset($this->request->post['selected']); $this->request->post['product_related'] = $related; $this->request->post['product_category'] = $product_category; } $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') . ' ' . $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' => ' :: ')); $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') . ' ' . $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' => 'confirm-exit="true"')); $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['form']['fields']['product_store'] = $form->getFieldHtml(array('type' => 'checkboxgroup', 'name' => 'product_store[]', 'value' => $this->data['product_store'], 'options' => $this->data['stores'], 'scrollbox' => true)); $this->load->library('json'); $listing_data = array(); if ($this->data['product_related']) { foreach ($this->data['product_related'] as $product_id) { $product_info = $this->model_catalog_product->getProduct($product_id); $listing_data[$product_id] = array('id' => $product_id, 'name' => html_entity_decode($product_info['name'] . ' (' . $product_info['model'] . ')'), 'status' => 1); } } // exclude this product from multivalue list. why we need relate recursion? $this->session->data['multivalue_excludes']['product_id'] = $this->request->get['product_id']; $this->data['form']['fields']['list'] = $form->getFieldHtml(array('id' => 'category_products_list', 'type' => 'multivaluelist', 'name' => 'category_products', 'content_url' => $this->html->getSecureUrl('product/product/related'), 'edit_url' => '', 'multivalue_hidden_id' => 'popup', 'values' => $listing_data, 'return_to' => 'productFrm_popup_item_count', 'text' => array('delete' => $this->language->get('button_delete'), 'delete_confirm' => $this->language->get('text_delete_confirm')))); $this->data['form']['fields']['list_hidden'] = $form->getFieldHtml(array('id' => 'popup', 'type' => 'multivalue', 'name' => 'popup', 'title' => $this->language->get('text_select_from_list'), 'selected' => $listing_data ? AJson::encode($listing_data) : "{}", 'content_url' => $this->html->getSecureUrl('catalog/product_listing', '&form_name=productFrm&multivalue_hidden_id=popup'), 'postvars' => '', 'return_to' => '', 'popup_height' => 708, 'js' => array('apply' => "productFrm_category_products_buildList();", 'cancel' => 'productFrm_category_products_buildList();'), 'text' => array('selected' => $this->language->get('text_count_selected'), 'edit' => $this->language->get('text_save_edit'), 'apply' => $this->language->get('text_apply'), 'save' => $this->language->get('button_save'), 'reset' => $this->language->get('button_reset')))); // CATEGORY $listing_data = array(); if ($this->data['product_category']) { foreach ($this->data['product_category'] as $category_id) { $listing_data[$category_id] = array('id' => $category_id, 'name' => html_entity_decode($this->model_catalog_category->getPath($category_id)), 'status' => 1); } } $this->data['form']['fields']['category_list'] = $form->getFieldHtml(array('id' => 'product_categories_list', 'type' => 'multivaluelist', 'name' => 'product_categories', 'content_url' => $this->html->getSecureUrl('product/product/product_categories'), 'edit_url' => '', 'multivalue_hidden_id' => 'cat_popup', 'values' => $listing_data, 'return_to' => '', 'text' => array('delete' => $this->language->get('button_delete'), 'delete_confirm' => $this->language->get('text_delete_confirm')))); $this->data['form']['fields']['category_list_hidden'] = $form->getFieldHtml(array('id' => 'cat_popup', 'type' => 'multivalue', 'name' => 'cat_popup', 'title' => $this->language->get('text_select_from_list'), 'selected' => $listing_data ? AJson::encode($listing_data) : "{}", 'content_url' => $this->html->getSecureUrl('catalog/category_listing', '&form_name=productFrm&multivalue_hidden_id=cat_popup'), 'postvars' => '', 'return_to' => '', 'js' => array('apply' => "productFrm_product_categories_buildList();", 'cancel' => 'productFrm_product_categories_buildList();'), 'text' => array('selected' => 'Count of selected items: ', 'edit' => $this->language->get('text_save_edit'), 'apply' => $this->language->get('text_apply'), 'save' => $this->language->get('button_save'), 'reset' => $this->language->get('button_reset')))); //end $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__); }
public function main() { //init controller data $this->extensions->hk_InitData($this, __FUNCTION__); $this->loadLanguage('sale/customer'); $this->loadModel('sale/customer_transaction'); $this->load->library('json'); $page = $this->request->post['page']; // get the requested page $limit = $this->request->post['rows']; // get how many rows we want to have into the grid $sidx = $this->request->post['sidx']; // get index row - i.e. user click to sort $sord = $this->request->post['sord']; // get the direction $data = array('sort' => $sidx, 'order' => $sord, 'start' => ($page - 1) * $limit, 'limit' => $limit, 'customer_id' => (int) $this->request->get['customer_id']); if (has_value($this->request->get['user'])) { $data['filter']['user'] = $this->request->get['user']; } if (has_value($this->request->get['credit'])) { $data['filter']['credit'] = $this->request->get['credit']; } if (has_value($this->request->get['debit'])) { $data['filter']['debit'] = $this->request->get['debit']; } if (has_value($this->request->get['transaction_type'])) { $data['filter']['transaction_type'] = $this->request->get['transaction_type']; } if (has_value($this->request->get['date_start'])) { $data['filter']['date_start'] = dateDisplay2ISO($this->request->get['date_start']); } if (has_value($this->request->get['date_end'])) { $data['filter']['date_end'] = dateDisplay2ISO($this->request->get['date_end']); } $allowedFields = array('user', 'credit', 'debit', 'transaction_type', 'date_start', 'date_end'); if (isset($this->request->post['_search']) && $this->request->post['_search'] == 'true') { $searchData = AJson::decode(htmlspecialchars_decode($this->request->post['filters']), true); foreach ($searchData['rules'] as $rule) { if (!in_array($rule['field'], $allowedFields)) { continue; } $data['filter'][$rule['field']] = $rule['data']; } } $total = $this->model_sale_customer_transaction->getTotalCustomerTransactions($data); if ($total > 0) { $total_pages = ceil($total / $limit); } else { $total_pages = 0; } $response = new stdClass(); $response->page = $page; $response->total = $total_pages; $response->records = $total; $results = $this->model_sale_customer_transaction->getCustomerTransactions($data); $i = 0; foreach ($results as $result) { $response->rows[$i]['id'] = $result['customer_transaction_id']; $response->rows[$i]['cell'] = array($result['date_added'], $result['user'], $result['debit'], $result['credit'], $result['transaction_type']); $i++; } //update controller data $this->extensions->hk_UpdateData($this, __FUNCTION__); $this->response->addJSONHeader(); $this->response->setOutput(AJson::encode($response)); }
public function getPublisherId() { // if checkbox unchecked - remove publisher_id $this->loadModel('setting/setting'); $store_id = has_value($this->request->get['store_id']) ? $this->request->get['store_id'] : 0; if ($this->request->get['disable']) { $this->model_setting_setting->editSetting('default_pp_express', array('default_pp_express_billmelater_publisher_id' => '', 'default_pp_express_billmelater_agree' => 0), $store_id); $response = '{}'; } else { $this->loadLanguage('default_pp_express/default_pp_express'); $this->load->library('json'); $ch = curl_init('https://api.financing.paypal.com/finapi/v1/publishers/'); curl_setopt($ch, CURLOPT_PORT, 443); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $timestamp = floor(microtime(true) * 1000); curl_setopt($ch, CURLOPT_HTTPHEADER, $arr = array('Accept: application/json', 'Content-Type: application/json', 'Authorization: FPA c5e5282897456bc5cc6ba33d3a9084d6a6993e5c:' . sha1('1be35fe3f6f296e5b991c3d39d01a3863bffa792' . $timestamp) . ':' . $timestamp)); curl_setopt($ch, CURLOPT_FORBID_REUSE, 1); curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, AJson::encode(array("emailAddress" => $this->request->get['email'], "sellerName" => "AbanteCart", "bnCode" => "DLP3CT4UCNTPE"))); $response = curl_exec($ch); $json = AJson::decode($response, true); if ($json['publisherId']) { $this->model_setting_setting->editSetting('default_pp_express', array('default_pp_express_billmelater_publisher_id' => $json['publisherId'], 'default_pp_express_billmelater_agree' => 1), $store_id); $response = AJson::encode(array('publisherId' => $json['publisherId'])); } } $this->response->setOutput($response); }
public function Main() { //init controller data $this->extensions->hk_InitData($this, __FUNCTION__); $this->load->library('json'); $response_type = $this->request->get['response_type']; $form_name = isset($this->request->get['form_name']) ? $this->request->get['form_name'] : 'productFrm'; $multivalue_hidden_id = isset($this->request->get['multivalue_hidden_id']) ? $this->request->get['multivalue_hidden_id'] : 'popup'; if ($response_type != 'json') { $this->loadLanguage('catalog/product'); //remember selected rows for response if (isset($this->request->post['selected'])) { $this->session->data['listing_selected'] = AJson::decode(html_entity_decode($this->request->post['selected']), true); } $grid_settings = array('table_id' => 'product_grid', 'url' => $this->html->getSecureURL('catalog/product_listing', '&response_type=json'), 'editurl' => '', 'sortname' => 'name', 'sortorder' => 'asc', 'actions' => array(), 'multiselect_noselectbox' => true); $grid_settings['colNames'] = array($this->language->get('column_image'), $this->language->get('column_name')); $grid_settings['colNames'][] = $this->language->get('column_model'); $grid_settings['colNames'][] = $this->language->get('column_action'); $grid_settings['colModel'] = array(array('name' => 'image', 'index' => 'image', 'align' => 'center', 'width' => 50, 'sortable' => false, 'search' => false), array('name' => 'name', 'index' => 'name', 'align' => 'left', 'width' => 200), array('name' => 'model', 'index' => 'model', 'align' => 'center', 'width' => 60, 'sortable' => false), array('name' => 'action', 'index' => 'action', 'align' => 'center', 'width' => 30, 'sortable' => false, 'search' => false)); $form = new AForm(); $form->setForm(array('form_name' => 'product_listing_search')); $grid_search_form = array(); $grid_search_form['id'] = 'product_listing_search'; $grid_search_form['form_open'] = $form->getFieldHtml(array('type' => 'form', 'name' => 'product_grid_search', 'action' => '')); $grid_search_form['submit'] = $form->getFieldHtml(array('type' => 'button', 'name' => 'submit', 'text' => $this->language->get('button_go'), 'style' => 'button1')); $grid_search_form['reset'] = $form->getFieldHtml(array('type' => 'button', 'name' => 'reset', 'text' => $this->language->get('button_reset'), 'style' => 'button2')); $grid_search_form['fields']['keyword'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'keyword', 'value' => '')); $grid_search_form['fields']['match'] = $form->getFieldHtml(array('type' => 'selectbox', 'name' => 'match', 'options' => array('any' => $this->language->get('filter_any_word'), 'all' => $this->language->get('filter_all_words'), 'exact' => $this->language->get('filter_exact_match')))); $grid_search_form['fields']['pfrom'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'pfrom', 'value' => '')); $grid_search_form['fields']['pto'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'pto', 'value' => '')); $this->loadModel('catalog/category'); $categories = array('' => $this->language->get('text_select_category')); $results = $this->model_catalog_category->getCategories(0); foreach ($results as $r) { $categories[$r['category_id']] = $r['name']; } $grid_search_form['fields']['category'] = $form->getFieldHtml(array('type' => 'selectbox', 'name' => 'category', 'options' => $categories, 'style' => 'medium-field')); $grid_settings['search_form'] = true; $grid = $this->dispatch('common/listing_grid', array($grid_settings)); $listing_grid = $grid->dispatchGetOutput(); unset($grid); // add js-scripts for grid rows selecting (redeclare onSelectRow event for grid) $view = new AView($this->registry, 0); $view->batchAssign(array('id' => $multivalue_hidden_id, 'form_name' => $form_name . '_' . $multivalue_hidden_id, 'table_id' => $grid_settings['table_id'], 'search_form' => $grid_search_form, 'listing_grid' => $listing_grid, 'filter_product' => $this->language->get('filter_product'), 'filter_price_max' => $this->language->get('filter_price_max'))); $this->data['response'] = $view->fetch('responses/catalog/product_listing.tpl'); } else { // json-response for jqgrid $this->loadLanguage('catalog/product'); $this->loadModel('catalog/product'); $this->loadModel('tool/image'); //Prepare filter config //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)); $total = $this->model_catalog_product->getTotalProducts(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_product->getProducts(array_merge($filter_form->getFilterData(), $filter_grid->getFilterData())); $i = 0; $resource = new AResource('image'); $response->userdata = (object) array('page' => $page); $data_type = 'product_id'; $list = $this->session->data['listing_selected']; $id_list = array(); foreach ($list as $id => $row) { if ($id == $this->session->data['multivalue_excludes']['product_id']) { continue; } if ($row['status']) { $id_list[] = $id; } } if ($results) { foreach ($results as $result) { if ($result[$data_type] == $this->session->data['multivalue_excludes']['product_id']) { continue; } if (in_array($result[$data_type], $id_list)) { $response->userdata->selId[] = $result[$data_type]; } $thumbnail = $resource->getMainThumb('products', $result[$data_type], 27, 27, true); $response->rows[$i]['id'] = $result[$data_type]; $response->rows[$i]['cell'] = array($thumbnail['thumb_html'], $result['name'], $result['model'], '<a class="btn_action" href="JavaScript:void(0);" onclick="showPopup(\'' . $this->html->getSecureURL('catalog/product/update', '&' . $data_type . '=' . $result[$data_type]) . '\')" title="' . $this->language->get('text_view') . '">' . '<img height="27" src="' . RDIR_TEMPLATE . 'image/icons/icon_grid_view.png" alt="' . $this->language->get('text_edit') . '" /></a>'); $i++; } } $this->data['response'] = $response; } //update controller data $this->extensions->hk_UpdateData($this, __FUNCTION__); if ($response_type == 'json') { $this->data['response'] = AJson::encode($this->data['response']); } $this->response->setOutput($this->data['response']); }
public function post() { $request = $this->rest->getRequestParams(); if (!$this->customer->isLoggedWithToken($request['token'])) { $this->rest->sendResponse(401, array('error' => 'Not logged in or Login attempt failed!')); return; } //Check if confirmation details were reviewed. if (!$this->session->data['confirmed']) { $this->rest->sendResponse(400, array('status' => 0, 'error' => 'Need to review confirmation details first!')); return; } $this->session->data['confirmed'] = FALSE; //Check if order is created and process payment if (!isset($this->session->data['order_id'])) { $this->rest->sendResponse(500, array('status' => 2, 'error' => 'Not order data available!')); return; } $order = new AOrder($this->registry); $order_data = $order->loadOrderData($this->session->data['order_id'], 'any'); //Check if order is present and not processed yet if (!isset($order_data)) { $this->rest->sendResponse(500, array('status' => 3, 'error' => 'No order available. Something went wrong!')); return; } if ($order_data['order_status_id'] > 0) { $this->rest->sendResponse(200, array('status' => 4, 'error' => 'Order was already processed!')); return; } //Dispatch the payment send controller process and capture the result if (!$this->session->data['process_rt']) { $this->rest->sendResponse(500, array('status' => 5, 'error' => 'Something went wrong. Incomplete request!')); return; } //we process only responce type payment extensions $payment_controller = $this->dispatch('responses/extension/' . $this->session->data['process_rt']); $this->load->library('json'); $this->data = AJson::decode($payment_controller->dispatchGetOutput(), TRUE); if ($this->data['error']) { $this->data['status'] = 6; $this->rest->sendResponse(200, $this->data); return; } else { if ($this->data['success']) { $this->data['status'] = 1; //order completed clean up if (isset($this->session->data['order_id'])) { $this->cart->clear(); unset($this->session->data['shipping_method']); unset($this->session->data['shipping_methods']); unset($this->session->data['payment_method']); unset($this->session->data['payment_methods']); unset($this->session->data['guest']); unset($this->session->data['comment']); unset($this->session->data['order_id']); unset($this->session->data['coupon']); } $this->rest->setResponseData($this->data); $this->rest->sendResponse(200); } else { $this->data['status'] = 0; $this->data['error'] = "Unexpected Error"; $this->rest->sendResponse(500, $this->data); } } }
private function _getForm() { if (!$this->registry->has('jqgrid_script')) { $locale = $this->session->data['language']; if (!file_exists(DIR_ROOT . '/' . RDIR_TEMPLATE . 'javascript/jqgrid/js/i18n/grid.locale-' . $locale . '.js')) { $locale = 'en'; } $this->document->addScript(RDIR_TEMPLATE . 'javascript/jqgrid/js/i18n/grid.locale-' . $locale . '.js'); $this->document->addScript(RDIR_TEMPLATE . 'javascript/jqgrid/js/jquery.jqGrid.min.js'); $this->document->addScript(RDIR_TEMPLATE . 'javascript/jqgrid/plugins/jquery.grid.fluid.js'); $this->document->addScript(RDIR_TEMPLATE . 'javascript/jqgrid/js/jquery.ba-bbq.min.js'); $this->document->addScript(RDIR_TEMPLATE . 'javascript/jqgrid/js/grid.history.js'); //set flag to not include scripts/css twice $this->registry->set('jqgrid_script', true); } $this->data['token'] = $this->session->data['token']; $this->data['cancel'] = $this->html->getSecureURL('sale/coupon'); $this->data['error'] = $this->error; $this->view->assign('category_products', $this->html->getSecureURL('product/product/category')); $this->view->assign('products_list', $this->html->getSecureURL('product/product/products')); $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 (isset($this->request->get['coupon_id']) && !$this->request->server['REQUEST_METHOD'] != 'POST') { $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(); } } 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'] = date('Y-m-d', strtotime($coupon_info['date_start'])); } else { $this->data['date_start'] = date('Y-m-d', time()); } 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'] = date('Y-m-d', strtotime($coupon_info['date_end'])); } 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 (isset($this->data['status']) && $this->data['status'] == '') { $this->data['status'] = 1; } //check if coupon is active based on dates and update status $now = time(); if (dateISO2Int($this->data['date_start']) > $now || dateISO2Int($this->data['date_end']) < $now) { $this->data['status'] = 0; } if (!isset($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'][$this->session->data['content_language_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' => ' :: ')); $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' => 'confirm-exit="true"', '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[' . $this->session->data['content_language_id'] . '][name]', 'value' => $this->data['coupon_description'][$this->session->data['content_language_id']]['name'], 'required' => true, 'style' => 'large-field')); $this->data['form']['fields']['description'] = $form->getFieldHtml(array('type' => 'textarea', 'name' => 'coupon_description[' . $this->session->data['content_language_id'] . '][description]', 'value' => $this->data['coupon_description'][$this->session->data['content_language_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' => dateISO2Display($this->data['date_start']), 'default' => dateNowDisplay(), 'dateformat' => format4Datepicker($this->language->get('date_format_short')), 'highlight' => 'future', 'required' => true, 'style' => 'medium-field')); $this->data['form']['fields']['date_end'] = $form->getFieldHtml(array('type' => 'date', 'name' => 'date_end', 'value' => dateISO2Display($this->data['date_end']), 'default' => '', 'dateformat' => format4Datepicker($this->language->get('date_format_short')), 'highlight' => 'pased', 'required' => true, 'style' => 'medium-field')); $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'] = (int) $total; } $this->load->library('json'); $listing_data = array(); if ($this->data['coupon_product']) { $this->loadModel('catalog/product'); foreach ($this->data['coupon_product'] as $product_id) { $product_info = $this->model_catalog_product->getProduct($product_id); $listing_data[$product_id] = array('id' => $product_id, 'name' => html_entity_decode($product_info['name'] . ' (' . $product_info['model'] . ')'), 'status' => 1); } } if ($this->request->server['REQUEST_METHOD'] == 'POST') { $listing_data = AJson::decode(html_entity_decode($this->request->post['selected'][0]), true); } $this->data['form']['fields']['product'] = $form->getFieldHtml(array('id' => 'coupon_products_list', 'type' => 'multivaluelist', 'name' => 'coupon_products', 'content_url' => $this->html->getSecureUrl('listing_grid/coupon/products'), 'edit_url' => '', 'multivalue_hidden_id' => 'popup', 'values' => $listing_data, 'return_to' => 'couponFrm_popup_item_count', 'text' => array('delete' => $this->language->get('button_delete'), 'delete_confirm' => $this->language->get('text_delete_confirm')))); $this->data['form']['fields']['list'] = $form->getFieldHtml(array('id' => 'popup', 'type' => 'multivalue', 'name' => 'popup', 'title' => $this->language->get('text_select_from_list'), 'selected' => $listing_data ? AJson::encode($listing_data) : "{}", 'content_url' => $this->html->getSecureUrl('catalog/product_listing', '&form_name=couponFrm&multivalue_hidden_id=popup'), 'postvars' => '', 'return_to' => '', 'popup_height' => 708, 'js' => array('apply' => "couponFrm_coupon_products_buildList();", 'cancel' => 'couponFrm_coupon_products_buildList();'), 'text' => array('selected' => $this->language->get('text_count_selected'), 'edit' => $this->language->get('text_save_edit'), 'apply' => $this->language->get('text_apply'), 'save' => $this->language->get('button_save'), 'reset' => $this->language->get('button_reset')))); $this->view->assign('help_url', $this->gen_help_url('coupon_edit')); $this->view->batchAssign($this->data); $this->processTemplate('pages/sale/coupon_form.tpl'); }
public function Main() { //init controller data $this->extensions->hk_InitData($this, __FUNCTION__); $this->load->library('json'); $response_type = $this->request->get['response_type']; $form_name = isset($this->request->get['form_name']) ? $this->request->get['form_name'] : 'productFrm'; $multivalue_hidden_id = isset($this->request->get['multivalue_hidden_id']) ? $this->request->get['multivalue_hidden_id'] : 'popup'; if ($response_type != 'json') { $this->loadLanguage('catalog/category'); //remember selected rows for response if (isset($this->request->post['selected'])) { $this->session->data['listing_selected'] = AJson::decode(html_entity_decode($this->request->post['selected']), true); } $grid_settings = array('table_id' => 'category_grid', 'url' => $this->html->getSecureURL('catalog/category_listing', '&response_type=json'), 'editurl' => '', 'sortname' => 'name', 'sortorder' => 'asc', 'actions' => array(), 'multiselect_noselectbox' => true); $grid_settings['colNames'] = array($this->language->get('column_image'), $this->language->get('column_name')); $grid_settings['colNames'][] = $this->language->get('column_action'); $grid_settings['colModel'] = array(array('name' => 'image', 'index' => 'image', 'align' => 'center', 'width' => 50, 'sortable' => false, 'search' => false), array('name' => 'name', 'index' => 'name', 'align' => 'left', 'sortable' => false, 'width' => 200), array('name' => 'action', 'index' => 'action', 'align' => 'center', 'width' => 30, 'sortable' => false, 'search' => false)); $grid_settings['search_form'] = true; $grid = $this->dispatch('common/listing_grid', array($grid_settings)); $this->data['response'] = $grid->dispatchGetOutput(); unset($grid); // add js-scripts for grid rows selecting (redeclare onSelectRow event for grid) $view = new AView($this->registry, 0); $view->batchAssign(array('id' => $multivalue_hidden_id, 'form_name' => $form_name . '_' . $multivalue_hidden_id, 'table_id' => $grid_settings['table_id'])); $this->data['response'] .= $view->fetch('responses/catalog/category_listing.tpl'); } else { // json-response for jqgrid $this->loadLanguage('catalog/category'); $this->loadModel('catalog/category'); $this->loadModel('tool/image'); //Prepare filter config $grid_filter_params = array('name'); $filter = new AFilter(array('method' => 'post', 'grid_filter_params' => $grid_filter_params)); $filter_data = $filter->getFilterData(); //Add custom params if (!$filter_data['subsql_filter']) { // without search $parent_id = isset($this->request->get['parent_id']) ? $this->request->get['parent_id'] : 0; $results = $this->model_catalog_category->getCategories($parent_id); $total = sizeof($results); $results = array_slice($results, $filter_data['start'], $filter_data['limit']); } else { $total = $this->model_catalog_category->getTotalCategories($filter_data); $results = $this->model_catalog_category->getCategoriesData($filter_data); } $response = new stdClass(); $response->page = $filter->getParam('page'); $response->total = $filter->calcTotalPages($total); $response->records = $total; $resource = new AResource('image'); $i = 0; $response->userdata = (object) array('page' => $this->request->post['page']); $data_type = 'category_id'; $list = $this->session->data['listing_selected']; $id_list = array(); foreach ($list as $id => $row) { if ($row['status']) { $id_list[] = $id; } } if ($results) { foreach ($results as $result) { if (in_array($result[$data_type], $id_list)) { $response->userdata->selId[] = $result[$data_type]; } $thumbnail = $resource->getMainThumb('categories', $result[$data_type], 36, 36, true); $response->rows[$i]['id'] = $result[$data_type]; $response->rows[$i]['cell'] = array($thumbnail['thumb_html'], $result['name'], '<a class="btn_action" href="JavaScript:void(0);" onclick="showPopup(\'' . $this->html->getSecureURL('catalog/category/update', '&' . $data_type . '=' . $result[$data_type]) . '\')" title="' . $this->language->get('text_view') . '">' . '<img src="' . RDIR_TEMPLATE . 'image/icons/icon_grid_view.png" alt="' . $this->language->get('text_edit') . '" /></a>'); $i++; } } $this->data['response'] = $response; } //update controller data $this->extensions->hk_UpdateData($this, __FUNCTION__); if ($response_type == 'json') { $this->data['response'] = AJson::encode($this->data['response']); } $this->response->setOutput($this->data['response']); }
/** * @param string $adv_filter_str * @param array $allowedFields * @return string */ public function filter($adv_filter_str, $allowedFields) { $allowedOperations = array('AND', 'OR'); $search_param = array(); if (isset($this->search) && $this->search == 'true') { $this->load->library('json'); $searchData = AJson::decode(htmlspecialchars_decode($this->filters), true); $op = $searchData['groupOp']; if (!in_array($op, $allowedOperations)) { $op = $allowedOperations[0]; } if ($searchData['rules']) { foreach ($searchData['rules'] as $rule) { // $allowedFields can be simple or key based array $field_name = ''; if (is_assoc($allowedFields)) { if (!array_key_exists($rule['field'], $allowedFields)) { continue; } $field_name = $allowedFields[$rule['field']]; } else { if (!in_array($rule['field'], $allowedFields)) { continue; } $field_name = $rule['field']; } //support table name extension in fields if (strpos($field_name, '.')) { $parts = explode('.', $field_name); $str = $parts[0] . '.`' . $parts[1] . '`'; } else { $str = '`' . $field_name . '`'; } switch ($rule['op']) { case 'eq': $str .= " = '" . $this->db->escape($rule['data']) . "' "; break; case 'ne': $str .= " != '" . $this->db->escape($rule['data']) . "' "; break; case 'bw': $str = "LOWER(" . $str . ")"; $rule['data'] = mb_strtolower($rule['data']); $str .= " LIKE '" . $this->db->escape($rule['data']) . "%' "; break; case 'cn': $str = "LOWER(" . $str . ")"; $rule['data'] = mb_strtolower($rule['data']); $str .= " LIKE '%" . $this->db->escape($rule['data']) . "%' "; break; default: $str .= " = '" . $this->db->escape($rule['data']) . "' "; } $search_param[] = $str; } } } if (!empty($search_param)) { $adv_filter_str .= (!empty($adv_filter_str) ? ' AND ' : '') . implode(" {$op} ", $search_param); } return $adv_filter_str; }
private function _validateForm() { if (!$this->user->canModify('catalog/product_files')) { $this->error['warning'] = $this->language->get('error_permission'); } $this->load->library('json'); $this->request->post['selected'] = AJson::decode(html_entity_decode(current($this->request->post['selected'])), true); if (!$this->request->post['selected']) { $this->error['warning'] = $this->language->get('error_selected_downloads'); } if (!$this->error) { return TRUE; } else { return FALSE; } }