/** * @param array $data * @return int */ public function getTotalOrderedProducts($data = array()) { $implode = array("o.order_status_id > '0'"); if (!empty($data['filter']['date_start'])) { $date_start = dateDisplay2ISO($data['filter']['date_start'], $this->language->get('date_format_short')); $implode[] = " DATE_FORMAT(o.date_added,'%Y-%m-%d') >= DATE_FORMAT('" . $this->db->escape($date_start) . "','%Y-%m-%d') "; } if (!empty($data['filter']['date_end'])) { $date_end = dateDisplay2ISO($data['filter']['date_end'], $this->language->get('date_format_short')); $implode[] = " DATE_FORMAT(o.date_added,'%Y-%m-%d') <= DATE_FORMAT('" . $this->db->escape($date_end) . "','%Y-%m-%d') "; } $query = $this->db->query("SELECT op.*\n \t FROM " . $this->db->table("order_products") . " op\n \t LEFT JOIN " . $this->db->table("orders") . " o ON (op.order_id = o.order_id)\n \t WHERE " . implode(' AND ', $implode) . "\n \t GROUP BY op.model"); return (int) $query->num_rows; }
/** * @param int $product_special_id * @param array $data */ public function updateProductSpecial($product_special_id, $data) { $fields = array("customer_group_id", "priority", "price", "date_start", "date_end"); if (isset($data['price'])) { $data['price'] = preformatFloat($data['price'], $this->language->get('decimal_point')); } if (!empty($data['date_start'])) { $data['date_start'] = dateDisplay2ISO($data['date_start'], $this->language->get('date_format_short')); } if (!empty($data['date_end'])) { $data['date_end'] = dateDisplay2ISO($data['date_end'], $this->language->get('date_format_short')); } $update = array(); foreach ($fields as $f) { if (isset($data[$f])) { $update[] = $f . " = '" . $this->db->escape($data[$f]) . "'"; } } if (!empty($update)) { $this->db->query("UPDATE `" . $this->db->table("product_specials`") . " SET " . implode(',', $update) . " WHERE product_special_id = '" . (int) $product_special_id . "'"); } $this->cache->remove('product'); }
public function update_field() { //init controller data $this->extensions->hk_InitData($this, __FUNCTION__); if ($this->request->is_POST()) { $this->loadModel('extension/banner_manager'); if (isset($this->request->post['start_date']) && $this->request->post['start_date']) { $this->request->post['start_date'] = dateDisplay2ISO($this->request->post['start_date']); } if (isset($this->request->post['end_date']) && $this->request->post['end_date']) { $this->request->post['end_date'] = dateDisplay2ISO($this->request->post['end_date']); } //request sent from edit form. ID in url foreach ($this->request->post as $field => $value) { if ($field == 'banner_group_name') { if (isset($value[0]) && !in_array($value[0], array('0', 'new'))) { $tmp = array('banner_group_name' => trim($value[0])); } if (isset($value[1])) { $tmp = array('banner_group_name' => trim($value[1])); } $id = (int) $this->request->get['banner_id']; $this->model_extension_banner_manager->editBanner($id, $tmp); } elseif (is_array($value)) { foreach ($value as $id => $val) { $tmp[$field] = (int) $val; $this->model_extension_banner_manager->editBanner($id, $tmp); } } else { if ((int) $this->request->get['banner_id']) { $this->model_extension_banner_manager->editBanner($this->request->get['banner_id'], array($field => $value)); } } } } //update controller data $this->extensions->hk_UpdateData($this, __FUNCTION__); }
/** * @param array $data * @param string $mode * @return array|int */ public function getCouponsReport($data = array(), $mode = 'default') { $filter = isset($data['filter']) ? $data['filter'] : array(); $total_sql = ''; if ($mode == 'total_only') { $total_sql = "COUNT(DISTINCT o.coupon_id) AS total "; } else { //condition if coupon is deleted $total_sql = "\tIF(cd.name IS NULL OR cd.name = '', ot.title, cd.name) as coupon_name,\n\t\t\t\t\t\t\tc.code, \n\t\t\t\t\t\t\tCOUNT(DISTINCT o.order_id), \n\t\t\t\t\t\t\tSUM(o.total) AS total, \n\t\t\t\t\t\t\tSUM(ot.value) AS discount_total, \n\t\t\t\t\t\t\tCOUNT(o.order_id) AS orders "; } $sql = "SELECT {$total_sql} FROM `" . $this->db->table("orders") . "` o \n\t\t\t\t\tLEFT JOIN `" . $this->db->table("coupons") . "` c ON (o.coupon_id = c.coupon_id)"; if ($mode == 'default') { $sql .= "LEFT JOIN `" . $this->db->table("coupon_descriptions") . "` cd\n\t\t\t\t\t\tON (c.coupon_id = cd.coupon_id AND cd.language_id=" . (int) $this->language->getContentLanguageID() . ")"; } $sql .= "LEFT JOIN `" . $this->db->table("order_totals") . "` ot ON (o.order_id = ot.order_id)\n\t\t\t\tWHERE ot.type = 'discount' "; if (isset($filter['date_start'])) { $date_start = dateDisplay2ISO($filter['date_start'], $this->language->get('date_format_short')); } else { $date_start = date('Y-m-d', strtotime('-7 day')); } if (isset($filter['date_end'])) { $date_end = dateDisplay2ISO($filter['date_end'], $this->language->get('date_format_short')); } else { $date_end = date('Y-m-d', time()); } $sql .= " AND (DATE_FORMAT(o.date_added,'%Y-%m-%d') >= DATE_FORMAT('" . $this->db->escape($date_start) . "','%Y-%m-%d') \n\t\t\t\t AND DATE_FORMAT(o.date_added,'%Y-%m-%d') <= DATE_FORMAT('" . $this->db->escape($date_end) . "','%Y-%m-%d') )"; //If for total, we done bulding the query if ($mode == 'total_only') { $query = $this->db->query($sql); return $query->row['total']; } $sql .= " GROUP BY o.coupon_id "; $sort_data = array('coupon_name' => 'cd.name', 'code' => 'c.code', 'orders' => 'COUNT(o.order_id)', 'total' => 'SUM(o.total)', 'discount_total' => 'SUM(ot.value)'); if (isset($data['sort']) && array_key_exists($data['sort'], $sort_data)) { $sql .= " ORDER BY " . $sort_data[$data['sort']]; } else { $sql .= " ORDER BY c.coupon_id"; } $sql .= " " . $this->db->escape($data['order']); if (isset($data['start']) || isset($data['limit'])) { if ($data['start'] < 0) { $data['start'] = 0; } if ($data['limit'] < 1) { $data['limit'] = 20; } $sql .= " LIMIT " . (int) $data['start'] . "," . (int) $data['limit']; } $query = $this->db->query($sql); return $query->rows; }
/** * update only one field * * @return void */ public function update_field() { //init controller data $this->extensions->hk_InitData($this, __FUNCTION__); $this->loadLanguage('sale/order'); $this->loadModel('sale/order'); if (!$this->user->canModify('listing_grid/order')) { $error = new AError(''); return $error->toJSONResponse('NO_PERMISSIONS_402', array('error_text' => sprintf($this->language->get('error_permission_modify'), 'listing_grid/order'), 'reset_value' => true)); } 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); } return null; } if (isset($this->request->get['id'])) { $this->model_sale_order->editOrder($this->request->get['id'], $this->request->post); return null; } //request sent from jGrid. ID is key of array foreach ($this->request->post as $field => $value) { foreach ($value as $k => $v) { $this->model_sale_order->editOrder($k, array($field => $v)); } } //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)); }
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 $resource = new AResource('image'); $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); foreach ($results as $r) { $thumbnail = $resource->getMainThumb('products', $r['product_id'], (int) $this->config->get('config_image_grid_width'), (int) $this->config->get('config_image_grid_height'), true); $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'); }
public function getSaleReportTotal($data = array()) { $sql = "SELECT MIN(date_added) AS date_start, MAX(date_added) AS date_end, COUNT(*) AS orders, SUM(total) AS total FROM `" . $this->db->table("orders") . "` WHERE order_status_id > '0'"; if (isset($data['date_start'])) { $date_start = dateDisplay2ISO($data['date_start'], $this->language->get('date_format_short')); } else { $date_start = date('Y-m-d', strtotime('-7 day')); } if (isset($data['date_end'])) { $date_end = dateDisplay2ISO($data['date_end'], $this->language->get('date_format_short')); } else { $date_end = date('Y-m-d', time()); } $sql .= " AND (DATE(date_added) >= '" . $this->db->escape($date_start) . "' AND DATE(date_added) <= '" . $this->db->escape($date_end) . "')"; if (isset($data['filter_order_status_id']) && $data['filter_order_status_id']) { $sql .= " AND order_status_id = '" . (int) $data['filter_order_status_id'] . "'"; } if (isset($data['filter_group'])) { $group = $data['filter_group']; } else { $group = $data['group']; } $group = !$group ? 'week' : $group; switch ($group) { case 'day': $sql .= " GROUP BY DAY(date_added)"; break; default: case 'week': $sql .= " GROUP BY WEEK(date_added)"; break; case 'month': $sql .= " GROUP BY MONTH(date_added)"; break; case 'year': $sql .= " GROUP BY YEAR(date_added)"; break; } $query = $this->db->query($sql); return $query->num_rows; }
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) { $rl = new AResource('image'); $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']); $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__); }
private function _prepareData($data = array()) { if (isset($data['date_available'])) { $data['date_available'] = dateDisplay2ISO($data['date_available']); } return $data; }
/** * update only one field * * @return void */ public function update_field() { //init controller data $this->extensions->hk_InitData($this, __FUNCTION__); if (!$this->user->canModify('listing_grid/product')) { $error = new AError(''); return $error->toJSONResponse('NO_PERMISSIONS_402', array('error_text' => sprintf($this->language->get('error_permission_modify'), 'listing_grid/product'), 'reset_value' => true)); } $this->loadLanguage('catalog/product'); $this->loadModel('catalog/product'); if (isset($this->request->get['id'])) { //request sent from edit form. ID in url foreach ($this->request->post as $key => $value) { $err = $this->_validateField($key, $value); if (!empty($err)) { $error = new AError(''); return $error->toJSONResponse('VALIDATION_ERROR_406', array('error_text' => $err)); } if ($key == 'date_available') { $value = dateDisplay2ISO($value); } $data = array($key => $value); $this->model_catalog_product->updateProduct($this->request->get['id'], $data); $this->model_catalog_product->updateProductLinks($this->request->get['id'], $data); } return null; } //request sent from jGrid. ID is key of array $fields = array('product_description', 'model', 'price', 'call_to_order', 'quantity', 'status'); foreach ($fields as $f) { if (isset($this->request->post[$f])) { foreach ($this->request->post[$f] as $k => $v) { $err = $this->_validateField($f, $v); if (!empty($err)) { $error = new AError(''); return $error->toJSONResponse('VALIDATION_ERROR_406', array('error_text' => $err)); } $this->model_catalog_product->updateProduct($k, array($f => $v)); } } } //update controller data $this->extensions->hk_UpdateData($this, __FUNCTION__); }
private function _validateForm($field, $value) { $err = false; switch ($field) { case 'coupon_description': foreach ($value as $language_id => $v) { if (isset($v['name'])) { if (mb_strlen($v['name']) < 2 || mb_strlen($v['name']) > 64) { $err = $this->language->get('error_name'); } } if (isset($v['description'])) { if (mb_strlen($v['description']) < 2) { $err = $this->language->get('error_description'); } } } break; case 'code': if (mb_strlen($value) < 2 || mb_strlen($value) > 10) { $err = $this->language->get('error_code'); } break; case 'date_start': case 'date_end': if (!dateDisplay2ISO($value)) { $err = $this->language->get('error_date'); } break; } return $err; }
private function _getForm() { $view = new AView($this->registry, 0); $view->batchAssign($this->language->getASet('catalog/product')); $view->assign('error_warning', $this->error['warning']); $view->assign('success', $this->session->data['success']); if (isset($this->session->data['success'])) { unset($this->session->data['success']); } $this->data = array(); $this->data['error'] = $this->error; $this->data['cancel'] = $this->html->getSecureURL('catalog/product_promotions', '&product_id=' . $this->request->get['product_id']); $this->data['active'] = 'promotions'; $this->data['product_description'] = $this->model_catalog_product->getProductDescriptions($this->request->get['product_id']); $this->data['heading_title'] = $this->language->get('text_edit') . ' ' . $this->language->get('text_product') . ' - ' . $this->data['product_description'][$this->session->data['content_language_id']]['name']; if (isset($this->request->get['product_discount_id']) && $this->request->is_GET()) { $discount_info = $this->model_catalog_product->getProductDiscount($this->request->get['product_discount_id']); if ($discount_info['date_start'] == '0000-00-00') { $discount_info['date_start'] = ''; } if ($discount_info['date_end'] == '0000-00-00') { $discount_info['date_end'] = ''; } } $this->loadModel('sale/customer_group'); $results = $this->model_sale_customer_group->getCustomerGroups(); $this->data['customer_groups'] = array(); foreach ($results as $r) { $this->data['customer_groups'][$r['customer_group_id']] = $r['name']; } $fields = array('customer_group_id', 'quantity', 'priority', 'price', 'date_start', 'date_end'); foreach ($fields as $f) { if (isset($this->request->post[$f])) { $this->data[$f] = $this->request->post[$f]; if (in_array($f, array('date_start', 'date_end'))) { $this->data[$f] = dateDisplay2ISO($this->data[$f], $this->language->get('date_format_short')); } } elseif (isset($discount_info)) { $this->data[$f] = $discount_info[$f]; } else { $this->data[$f] = ''; } } if (!isset($this->request->get['product_discount_id'])) { $this->data['action'] = $this->html->getSecureURL('catalog/product_promotions', '&product_id=' . $this->request->get['product_id']); $this->data['form_title'] = $this->language->get('text_insert') . ' ' . $this->language->get('entry_discount'); $this->data['update'] = ''; $form = new AForm('ST'); } else { $this->data['action'] = $this->html->getSecureURL('catalog/product_promotions', '&product_id=' . $this->request->get['product_id'] . '&product_discount_id=' . $this->request->get['product_discount_id']); $this->data['form_title'] = $this->language->get('text_edit') . ' ' . $this->language->get('entry_discount'); $this->data['update'] = $this->html->getSecureURL('listing_grid/product/update_discount_field', '&id=' . $this->request->get['product_discount_id']); $form = new AForm('HS'); } $this->document->addBreadcrumb(array('href' => $this->data['action'], 'text' => $this->data['form_title'], 'separator' => ' :: ')); $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"')) . $form->getFieldHtml(array('type' => 'hidden', 'name' => 'promotion_type', 'value' => 'discount')); $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']['customer_group'] = $form->getFieldHtml(array('type' => 'selectbox', 'name' => 'customer_group_id', 'value' => $this->data['customer_group_id'], 'options' => $this->data['customer_groups'])); $this->data['form']['fields']['quantity'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'quantity', 'value' => $this->data['quantity'], 'style' => 'small-field')); $this->data['form']['fields']['priority'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'priority', 'value' => $this->data['priority'], 'style' => 'small-field')); $this->data['form']['fields']['price'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'price', 'value' => moneyDisplayFormat($this->data['price']), 'style' => 'tiny-field')); $this->data['js_date_format'] = format4Datepicker($this->language->get('date_format_short')); $this->data['form']['fields']['date_start'] = $form->getFieldHtml(array('type' => 'date', 'name' => 'date_start', 'value' => dateISO2Display($this->data['date_start'], $this->language->get('date_format_short')), 'default' => '', 'dateformat' => format4Datepicker($this->language->get('date_format_short')), 'highlight' => 'future', 'style' => 'small-field')); $this->data['form']['fields']['date_end'] = $form->getFieldHtml(array('type' => 'date', 'name' => 'date_end', 'value' => dateISO2Display($this->data['date_end'], $this->language->get('date_format_short')), 'default' => '', 'dateformat' => format4Datepicker($this->language->get('date_format_short')), 'highlight' => 'future', 'style' => 'small-field')); $view->assign('help_url', $this->gen_help_url('product_discount_edit')); $view->batchAssign($this->data); $this->data['response'] = $view->fetch('responses/catalog/product_promotion_form.tpl'); $this->response->setOutput($this->data['response']); }
public function getCustomerTransactions($data = array(), $mode = 'default') { if ($mode == 'total_only') { $total_sql = 'SELECT COUNT(DISTINCT c.customer_id) as total'; } else { $total_sql = "SELECT \tc.customer_id, \n\t\t\t\t\t\t\t\t\tCONCAT(c.firstname, ' ', c.lastname) AS customer, \n\t\t\t\t\t\t\t\t\tct.date_added,\n\t\t\t\t\t\t\t\t\tc.status, \n\t\t\t\t\t\t\t\t\tct.debit,\n\t\t\t\t\t\t\t\t\tct.credit,\n\t\t\t\t\t\t\t\t\tct.date_added,\n\t\t\t\t\t\t\t\t\tct.transaction_type,\n\t\t\t\t\t\t\t\t\tu.username as created_by\n\t\t\t\t\t\t"; } $sql = $total_sql . " FROM `" . $this->db->table("customer_transactions") . "` ct \n\t\t\t\t\t\t\t\tLEFT JOIN `" . $this->db->table("customers") . "` c ON (ct.customer_id = c.customer_id) \n\t\t\t\t\t\t\t\tLEFT JOIN `" . $this->db->table("users") . "` u ON u.user_id = ct.created_by \n\t\t\t\t\t\t\t"; $filter = isset($data['filter']) ? $data['filter'] : array(); $implode = array(); $where = ''; if (has_value($filter['customer_id'])) { $implode[] = " c.customer_id = " . (int) $filter['customer_id'] . " "; } if (!empty($filter['date_start'])) { $date_start = dateDisplay2ISO($filter['date_start'], $this->language->get('date_format_short')); $implode[] = " DATE_FORMAT(ct.date_added,'%Y-%m-%d') >= DATE_FORMAT('" . $this->db->escape($date_start) . "','%Y-%m-%d') "; } if (!empty($filter['date_end'])) { $date_end = dateDisplay2ISO($filter['date_end'], $this->language->get('date_format_short')); $implode[] = " DATE_FORMAT(ct.date_added,'%Y-%m-%d') <= DATE_FORMAT('" . $this->db->escape($date_end) . "','%Y-%m-%d') "; } //fillter for first and last name if (has_value($filter['customer'])) { $implode[] = "CONCAT(c.firstname, ' ', c.lastname) LIKE '%" . $this->db->escape($filter['customer']) . "%' collate utf8_general_ci"; } if ($implode) { $where .= implode(" AND ", $implode); } if (!empty($data['subsql_filter'])) { //$where .= " " . $data['subsql_filter']; } if ($where) { $sql .= " WHERE " . $where; } //If for total, we done bulding the query if ($mode == 'total_only') { $query = $this->db->query($sql); return $query->row['total']; } $sql .= " GROUP BY c.customer_id "; $sort_data = array('transaction_type' => 'ct.transaction_type', 'debit' => 'ct.debit', 'credit' => 'ct.credit', 'date_added' => 'ct.date_added'); if (isset($data['sort']) && array_key_exists($data['sort'], $sort_data)) { $sql .= " ORDER BY " . $sort_data[$data['sort']]; } else { $sql .= " ORDER BY ct.date_added"; } if (isset($data['order']) && $data['order'] == 'DESC') { $sql .= " DESC"; } else { $sql .= " ASC"; } if (isset($data['start']) || isset($data['limit'])) { if ($data['start'] < 0) { $data['start'] = 0; } if ($data['limit'] < 1) { $data['limit'] = 20; } $sql .= " LIMIT " . (int) $data['start'] . "," . (int) $data['limit']; } $query = $this->db->query($sql); return $query->rows; }
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'); }
private function _prepareData() { if (isset($this->request->post['start_date']) && $this->request->post['start_date']) { $this->request->post['start_date'] = dateDisplay2ISO($this->request->post['start_date']); } if (isset($this->request->post['end_date']) && $this->request->post['end_date']) { $this->request->post['end_date'] = dateDisplay2ISO($this->request->post['end_date']); } if (is_array($this->request->post['banner_group_name']) && isset($this->request->post['banner_group_name'][1])) { $this->request->post['banner_group_name'][1] = trim($this->request->post['banner_group_name'][1]); $this->request->post['banner_group_name'][1] = mb_ereg_replace('/^[0-9A-Za-z\\ \\. _\\-]/', '', $this->request->post['banner_group_name'][1]); } if ($this->request->post['banner_group_name'][1] && $this->request->post['banner_group_name'][0] == 'new') { $this->request->post['banner_group_name'] = $this->request->post['banner_group_name'][1]; } else { $this->request->post['banner_group_name'] = $this->request->post['banner_group_name'][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->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__); }
private function _getForm() { $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->data = array(); $this->data['error'] = $this->error; $this->data['cancel'] = $this->html->getSecureURL('catalog/product_promotions', '&product_id=' . $this->request->get['product_id']); $this->data['active'] = 'promotions'; //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['product_description'] = $this->model_catalog_product->getProductDescriptions($this->request->get['product_id']); $this->data['heading_title'] = $this->language->get('text_edit') . ' ' . $this->language->get('text_product') . ' - ' . $this->data['product_description'][$this->session->data['content_language_id']]['name']; $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->data['heading_title'], 'separator' => ' :: ')); $this->document->addBreadcrumb(array('href' => $this->html->getSecureURL('catalog/product_promotions', '&product_id=' . $this->request->get['product_id']), 'text' => $this->language->get('tab_promotions'), 'separator' => ' :: ')); if (isset($this->request->get['product_discount_id']) && $this->request->server['REQUEST_METHOD'] != 'POST') { $discount_info = $this->model_catalog_product->getProductDiscount($this->request->get['product_discount_id']); if ($discount_info['date_start'] == '0000-00-00') { $discount_info['date_start'] = ''; } if ($discount_info['date_end'] == '0000-00-00') { $discount_info['date_end'] = ''; } } $this->loadModel('sale/customer_group'); $results = $this->model_sale_customer_group->getCustomerGroups(); $this->data['customer_groups'] = array(); foreach ($results as $r) { $this->data['customer_groups'][$r['customer_group_id']] = $r['name']; } $fields = array('customer_group_id', 'quantity', 'priority', 'price', 'date_start', 'date_end'); foreach ($fields as $f) { if (isset($this->request->post[$f])) { $this->data[$f] = $this->request->post[$f]; if (in_array($f, array('date_start', 'date_end'))) { $this->data[$f] = dateDisplay2ISO($this->data[$f], $this->language->get('date_format_short')); } } elseif (isset($discount_info)) { $this->data[$f] = $discount_info[$f]; } else { $this->data[$f] = ''; } } if (!isset($this->request->get['product_discount_id'])) { $this->data['action'] = $this->html->getSecureURL('catalog/product_discount/insert', '&product_id=' . $this->request->get['product_id']); $this->data['form_title'] = $this->language->get('text_insert') . ' ' . $this->language->get('entry_discount'); $this->data['update'] = ''; $form = new AForm('ST'); } else { $this->data['action'] = $this->html->getSecureURL('catalog/product_discount/update', '&product_id=' . $this->request->get['product_id'] . '&product_discount_id=' . $this->request->get['product_discount_id']); $this->data['form_title'] = $this->language->get('text_edit') . ' ' . $this->language->get('entry_discount'); $this->data['update'] = $this->html->getSecureURL('listing_grid/product/update_discount_field', '&id=' . $this->request->get['product_discount_id']); $form = new AForm('HS'); } $this->document->addBreadcrumb(array('href' => $this->data['action'], 'text' => $this->data['form_title'], 'separator' => ' :: ')); $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', 'name' => 'cancel', 'text' => $this->language->get('button_cancel'), 'style' => 'button2')); $this->data['form']['fields']['customer_group'] = $form->getFieldHtml(array('type' => 'selectbox', 'name' => 'customer_group_id', 'value' => $this->data['customer_group_id'], 'options' => $this->data['customer_groups'])); $this->data['form']['fields']['quantity'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'quantity', 'value' => $this->data['quantity'], 'style' => 'small-field')); $this->data['form']['fields']['priority'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'priority', 'value' => $this->data['priority'], 'style' => 'small-field')); $this->data['form']['fields']['price'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'price', 'value' => moneyDisplayFormat($this->data['price']))); $this->data['js_date_format'] = format4Datepicker($this->language->get('date_format_short')); $this->data['form']['fields']['date_start'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'date_start', 'value' => dateISO2Display($this->data['date_start'], $this->language->get('date_format_short')), 'style' => 'date')); $this->data['form']['fields']['date_end'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'date_end', 'value' => dateISO2Display($this->data['date_end'], $this->language->get('date_format_short')), 'style' => 'date')); $this->addChild('pages/catalog/product_summary', 'summary_form', 'pages/catalog/product_summary.tpl'); $this->view->assign('help_url', $this->gen_help_url('product_discount_edit')); $this->view->batchAssign($this->data); $this->processTemplate('pages/catalog/product_discount_form.tpl'); }