protected function getList() { $this->document->addBreadcrumbs(array('text' => Language::getVar('SUMO_ADMIN_CATALOG_DASHBOARD'), 'href' => $this->url->link('catalog/dashboard'))); $this->document->addBreadcrumbs(array('text' => Language::getVar('SUMO_ADMIN_CATALOG_SPECIAL'))); $this->data = array_merge($this->data, array('delete' => $this->url->link('catalog/special/delete', 'token=' . $this->session->data['token'], 'SSL'), 'specials' => array(), 'error' => isset($this->data['error']) ? $this->data['error'] : '')); // Initiate pagination if (isset($this->request->get['page'])) { $page = $this->request->get['page']; } else { $page = 1; } $data = array('start' => ($page - 1) * 25, 'limit' => 25); $special_total = $this->model_catalog_special->getTotalSpecials(); foreach ($this->model_catalog_special->getSpecials($data) as $special) { $this->data['specials'][] = array_merge($special, array('product_special_no' => 'SID.' . str_pad($special['product_special_id'], 5, 0, STR_PAD_LEFT), 'price' => Formatter::currency($special['price']), 'product_price' => Formatter::currency($special['product_price']), 'edit' => $this->url->link('catalog/special/update', 'token=' . $this->session->data['token'] . '&product_special_id=' . $special['product_special_id'], 'SSL'))); } $pagination = new Pagination(); $pagination->total = $special_total; $pagination->page = $page; $pagination->limit = 25; $pagination->text = ''; $pagination->url = $this->url->link('catalog/special', 'token=' . $this->session->data['token'] . '&page={page}', 'SSL'); $this->data['pagination'] = $pagination->renderAdmin(); $this->getForm(); $this->template = 'catalog/special.tpl'; $this->children = array('common/header', 'common/footer'); $this->response->setOutput($this->render()); }
public function updateInvoice($invoiceID, $data) { // Delete invoice-lines and add 'em later again $this->query('DELETE FROM PREFIX_invoice_line WHERE invoice_id = :invoiceID', array('invoiceID' => $invoiceID)); $this->query('DELETE FROM PREFIX_invoice_total WHERE invoice_id = :invoiceID', array('invoiceID' => $invoiceID)); $totalTax = $total = 0; foreach ($data['amount'] as $line => $amount) { // Recalculate tax-amount based on the tax-percentage if ($data['tax_percentage'][$line] > 0) { $data['tax'][$line] = round($data['amount'][$line] * $data['quantity'][$line] * ($data['tax_percentage'][$line] / 100), 4); $totalTax += $data['tax'][$line]; } else { $data['tax'][$line] = 0; } $total += $amount * $data['quantity'][$line]; $this->query('INSERT INTO PREFIX_invoice_line (invoice_id, product_id, product, quantity, amount, tax_percentage, description) VALUES ( :invoiceID, :productID, :product, :quantity, :amount, :taxPercentage, :description)', array('invoiceID' => $invoiceID, 'productID' => $data['product_id'][$line], 'product' => $data['product'][$line], 'quantity' => $data['quantity'][$line], 'amount' => $data['amount'][$line], 'taxPercentage' => $data['tax_percentage'][$line], 'description' => $data['description'][$line])); } foreach ($data['totals'] as $sortOrder => $productTotal) { $labelInject = isset($productTotal['label_inject']) ? $productTotal['label_inject'] : ''; $this->query("INSERT INTO PREFIX_invoice_total\n SET invoice_id = :id,\n sort_order = :sortOrder,\n label = :label,\n label_inject = :labelInject,\n value = :value,\n value_hr = :valueHR", array('id' => $invoiceID, 'sortOrder' => $sortOrder, 'label' => $productTotal['label'], 'labelInject' => $labelInject, 'value' => $productTotal['value'], 'valueHR' => Formatter::currency($productTotal['value']))); } // Totalamount is always the last line. $total = $productTotal['value']; $invoicePrefix = $this->config->get('invoice_prefix'); // Customer country numeric? Change to plain text if (preg_match("/^\\d+\$/", $data['customer_country'])) { $countryData = $this->query("SELECT name FROM PREFIX_country WHERE country_id = :countryID", array('countryID' => $data['customer_country']))->fetch(); $data['customer_country'] = !empty($countryData) ? $countryData['name'] : '-'; } $this->query('UPDATE PREFIX_invoice SET invoice_no = :invoiceNO, customer_id = :customerID, customer_no = :customerNo, customer_name = :customerName, customer_address = :customerAddress, customer_postcode = :customerPostcode, customer_city = :customerCity, customer_country = :customerCountry, customer_email = :customerEmail, payment_amount = :paymentAmount, payment_tax_percentage = :paymentTax, shipping_amount = :shippingAmount, shipping_tax_percentage = :shippingTax, discount = :discount, total_amount = :amount, sent_date = :sentDate, notes = :notes, template = :template, term = :term, auto = :auto, reference = :reference WHERE invoice_id = :invoiceID', array('invoiceNO' => $invoicePrefix . str_pad($invoiceID, 5, 0, STR_PAD_LEFT), 'customerNo' => $customerNo, 'customerID' => $data['customer_id'], 'customerName' => $data['customer_name'], 'customerAddress' => $data['customer_address'], 'customerPostcode' => $data['customer_postcode'], 'customerCity' => $data['customer_city'], 'customerCountry' => $data['customer_country'], 'customerEmail' => $data['customer_email'], 'paymentAmount' => $data['payment_amount'], 'paymentTax' => $data['payment_tax'], 'shippingAmount' => $data['shipping_amount'], 'shippingTax' => $data['shipping_tax'], 'discount' => json_encode($data['discount']), 'amount' => $total, 'sentDate' => Formatter::dateReverse($data['sent_date']), 'notes' => $data['notes'], 'template' => $data['template'], 'term' => $data['term'], 'auto' => $data['auto'], 'reference' => $data['reference'], 'invoiceID' => $invoiceID)); }
public function index() { if (!$this->customer->isLogged()) { $this->session->data['redirect'] = $this->url->link('account/transaction', '', 'SSL'); $this->redirect($this->url->link('account/login', '', 'SSL')); } $this->document->setTitle(Language::getVar('SUMO_ACCOUNT_TRANSACTION_TITLE')); $this->data['breadcrumbs'] = array(); $this->data['breadcrumbs'][] = array('text' => Language::getVar('SUMO_NOUN_HOME'), 'href' => $this->url->link('common/home'), 'separator' => false); $this->data['breadcrumbs'][] = array('text' => Language::getVar('SUMO_ACCOUNT_TITLE'), 'href' => $this->url->link('account/account', '', 'SSL')); $this->data['breadcrumbs'][] = array('text' => Language::getVar('SUMO_ACCOUNT_TRANSACTION_TITLE'), 'href' => $this->url->link('account/transaction', '', 'SSL')); $this->load->model('account/transaction'); //$this->data['column_amount'] = sprintf(Language::getVar('SUMO_ACCOUNT_TRANSACTION_AMOUNT'), $this->config->get('config_currency')); if (isset($this->request->get['page'])) { $page = $this->request->get['page']; } else { $page = 1; } $this->data['transactions'] = array(); $data = array('sort' => 'date_added', 'order' => 'DESC', 'start' => ($page - 1) * 10, 'limit' => 10); $transaction_total = $this->model_account_transaction->getTotalTransactions($data); foreach ($this->model_account_transaction->getTransactions($data) as $result) { $this->data['transactions'][] = array('transaction_id' => str_pad($result['customer_transaction_id'], 9, 0, STR_PAD_LEFT), 'amount' => Formatter::currency($result['amount']), 'description' => $result['description'], 'date_added' => Formatter::date($result['date_added'])); } $pagination = new Pagination(); $pagination->total = $transaction_total; $pagination->page = $page; $pagination->limit = 10; $pagination->url = $this->url->link('account/transaction', 'page={page}', 'SSL'); $this->data['pagination'] = $pagination->render(); $this->data['total'] = $this->currency->format($this->customer->getBalance()); $this->data['settings'] = $this->config->get('details_account_' . $this->config->get('template')); if (!is_array($this->data['settings']) || !count($this->data['settings'])) { $this->data['settings']['left'][] = $this->getChild('app/widgetsimplesidebar/', array('type' => 'accountTree', 'data' => array())); } $this->template = 'account/transaction.tpl'; $this->children = array('common/footer', 'common/header'); $this->response->setOutput($this->render()); }
public function saveOrder($order_id, $data) { $data['store'] = array(); $storeData = $this->model_settings_stores->getStore($data['store_id']); $data['store']['id'] = $data['store_id']; $data['store']['url'] = $storeData['base_' . $storeData['base_default']]; $data['store']['name'] = $storeData['name']; // Existing customer? if (!isset($data['customer']['customer_id']) || empty($data['customer']['customer_id'])) { $customerData = $data['customer']; $customerData['address'][] = $data['customer']['payment_address']; unset($customerData['customer_id']); unset($customerData['payment_address']); unset($customerData['shipping_address']); $this->load->model('sale/customer'); $data['customer']['customer_id'] = $this->model_sale_customer->addCustomer($customerData); } $this->query("UPDATE PREFIX_orders SET order_status = :status WHERE order_id = :id", array('status' => $data['order_status_id'], 'id' => $order_id)); $this->query("DELETE FROM PREFIX_orders_download WHERE order_id = :id", array('id' => $order_id)); $this->query("DELETE FROM PREFIX_orders_data WHERE order_id = :id", array('id' => $order_id)); $this->query("DELETE FROM PREFIX_orders_lines WHERE order_id = :id", array('id' => $order_id)); $this->query("DELETE FROM PREFIX_orders_totals WHERE order_id = :id", array('id' => $order_id)); $this->query("INSERT INTO PREFIX_orders_data\n SET order_id = :id,\n store = :store,\n admin_comment = :comment,\n discount = :discount,\n reward = :reward,\n points = :points,\n customer = :customer,\n shipping = :shipping,\n payment = :payment", array('id' => $order_id, 'store' => json_encode($data['store']), 'comment' => $data['comment'], 'discount' => json_encode($data['discount']), 'customer' => json_encode($data['customer']), 'shipping' => json_encode($data['method']['shipping']), 'payment' => json_encode($data['method']['payment']), 'reward' => '', 'points' => $data['points'])); // Add product lines foreach ($data['lines'] as $productLine) { $this->query("INSERT INTO PREFIX_orders_lines \n SET order_id = :id,\n product_id = :productID,\n name = :name,\n `option` = '',\n download = '',\n model = :model,\n quantity = :quantity,\n price = :price,\n tax_percentage = :taxPercentage", array('id' => $order_id, 'productID' => $productLine['product_id'], 'name' => $productLine['name'], 'model' => $productLine['model'], 'quantity' => $productLine['quantity'], 'price' => $productLine['price'], 'taxPercentage' => $productLine['tax'])); // Product has download? $productDownloads = $this->query("SELECT * \n FROM PREFIX_download d, PREFIX_download_description dd \n WHERE d.download_id = dd.download_id \n AND dd.language_id = :languageID\n AND d.download_id IN (\n SELECT download_id \n FROM PREFIX_product_to_download \n WHERE product_id = :productID)", array('languageID' => $this->config->get('language_id'), 'productID' => $productLine['product_id']))->fetchAll(); foreach ($productDownloads as $productDownload) { // Add order download $this->query("INSERT INTO PREFIX_orders_download SET \n order_id = :orderID,\n name = :name,\n filename = :filename,\n remaining = :remaining", array('orderID' => $productDownload['order_id'], 'name' => $productDownload['mask'], 'filename' => $productDownload['filename'], 'remaining' => $productDownload['remaining'])); } } // Add product totals foreach ($data['totals'] as $sortOrder => $productTotal) { $labelInject = isset($productTotal['label_inject']) ? $productTotal['label_inject'] : ''; $this->query("INSERT INTO PREFIX_orders_totals \n SET order_id = :id,\n sort_order = :sortOrder,\n label = :label,\n label_inject = :labelInject,\n value = :value,\n value_hr = :valueHR", array('id' => $order_id, 'sortOrder' => $sortOrder, 'label' => $productTotal['label'], 'labelInject' => $labelInject, 'value' => $productTotal['value'], 'valueHR' => Formatter::currency($productTotal['value']))); } }
public function index() { $this->data['breadcrumbs'] = array(); $this->data['breadcrumbs'][] = array('text' => Language::getVar('SUMO_NOUN_HOME'), 'href' => $this->url->link('common/home'), 'separator' => false); $this->load->model('catalog/category'); $this->load->model('catalog/manufacturer'); $this->load->model('catalog/product'); $this->load->model('tool/image'); if (isset($this->request->get['path'])) { $path = ''; $parts = explode('_', (string) $this->request->get['path']); $category_id = (int) array_pop($parts); foreach ($parts as $path_id) { if (!$path) { $path = $path_id; } else { $path .= '_' . $path_id; } $category_info = $this->model_catalog_category->getCategory($path_id); if ($category_info) { $this->data['breadcrumbs'][] = array('text' => $category_info['name'], 'href' => $this->url->link('product/category', 'path=' . $path), 'separator' => Language::getVar('SUMO_BREADCRUMBS_SEPARATOR')); } } // Set the last category breadcrumb $category_info = $this->model_catalog_category->getCategory($category_id); if ($category_info) { $url = ''; if (isset($this->request->get['sort'])) { $url .= '&sort=' . $this->request->get['sort']; } if (isset($this->request->get['order'])) { $url .= '&order=' . $this->request->get['order']; } if (isset($this->request->get['page'])) { $url .= '&page=' . $this->request->get['page']; } if (isset($this->request->get['limit'])) { $url .= '&limit=' . $this->request->get['limit']; } $this->data['breadcrumbs'][] = array('text' => $category_info['name'], 'href' => $this->url->link('product/category', 'path=' . $this->request->get['path']), 'separator' => Language::getVar('SUMO_BREADCRUMBS_SEPARATOR')); } } if (isset($this->request->get['manufacturer_id'])) { $this->data['breadcrumbs'][] = array('text' => Language::getVar('SUMO_NOUN_MANUFACTURER_PLURAL'), 'href' => $this->url->link('product/manufacturer'), 'separator' => Language::getVar('SUMO_BREADCRUMBS_SEPARATOR')); $url = ''; if (isset($this->request->get['sort'])) { $url .= '&sort=' . $this->request->get['sort']; } if (isset($this->request->get['order'])) { $url .= '&order=' . $this->request->get['order']; } if (isset($this->request->get['page'])) { $url .= '&page=' . $this->request->get['page']; } if (isset($this->request->get['limit'])) { $url .= '&limit=' . $this->request->get['limit']; } $manufacturer_info = $this->model_catalog_manufacturer->getManufacturer($this->request->get['manufacturer_id']); if ($manufacturer_info) { $this->data['breadcrumbs'][] = array('text' => $manufacturer_info['name'], 'href' => $this->url->link('product/manufacturer/info', 'manufacturer_id=' . $this->request->get['manufacturer_id'] . $url), 'separator' => Language::getVar('SUMO_BREADCRUMBS_SEPARATOR')); } } if (isset($this->request->get['search']) || isset($this->request->get['tag'])) { $url = ''; if (isset($this->request->get['search'])) { $url .= '&search=' . $this->request->get['search']; } if (isset($this->request->get['tag'])) { $url .= '&tag=' . $this->request->get['tag']; } if (isset($this->request->get['description'])) { $url .= '&description=' . $this->request->get['description']; } if (isset($this->request->get['category_id'])) { $url .= '&category_id=' . $this->request->get['category_id']; } if (isset($this->request->get['sub_category'])) { $url .= '&sub_category=' . $this->request->get['sub_category']; } if (isset($this->request->get['sort'])) { $url .= '&sort=' . $this->request->get['sort']; } if (isset($this->request->get['order'])) { $url .= '&order=' . $this->request->get['order']; } if (isset($this->request->get['page'])) { $url .= '&page=' . $this->request->get['page']; } if (isset($this->request->get['limit'])) { $url .= '&limit=' . $this->request->get['limit']; } $this->data['breadcrumbs'][] = array('text' => Language::getVar('SUMO_NOUN_SEARCH_PLURAL'), 'href' => $this->url->link('product/search', $url), 'separator' => Language::getVar('SUMO_BREADCRUMBS_SEPARATOR')); } if (isset($this->request->get['product_id'])) { $product_id = (int) $this->request->get['product_id']; } else { $product_id = 0; } $product_info = $this->model_catalog_product->getProduct($product_id); if ($product_info) { $this->data['product_info'] = $product_info; $url = ''; if (isset($this->request->get['path'])) { $url .= '&path=' . $this->request->get['path']; $path = '&path=' . $this->request->get['path']; } else { $url .= '&path=unknown'; $path = '&path=' . $product_info['category_id']; } if (isset($this->request->get['filter'])) { $url .= '&filter=' . $this->request->get['filter']; } if (isset($this->request->get['manufacturer_id'])) { $url .= '&manufacturer_id=' . $this->request->get['manufacturer_id']; } if (isset($this->request->get['search'])) { $url .= '&search=' . $this->request->get['search']; } if (isset($this->request->get['tag'])) { $url .= '&tag=' . $this->request->get['tag']; } if (isset($this->request->get['description'])) { $url .= '&description=' . $this->request->get['description']; } if (isset($this->request->get['category_id'])) { $url .= '&category_id=' . $this->request->get['category_id']; $path = '&path=' . $this->request->get['category_id']; } if (isset($this->request->get['sub_category'])) { $url .= '&sub_category=' . $this->request->get['sub_category']; } if (isset($this->request->get['sort'])) { $url .= '&sort=' . $this->request->get['sort']; } if (isset($this->request->get['order'])) { $url .= '&order=' . $this->request->get['order']; } if (isset($this->request->get['page'])) { $url .= '&page=' . $this->request->get['page']; } if (isset($this->request->get['limit'])) { $url .= '&limit=' . $this->request->get['limit']; } $this->data['breadcrumbs'][] = array('text' => $product_info['name'], 'href' => $this->url->link('product/product', $url . '&product_id=' . $this->request->get['product_id']), 'separator' => Language::getVar('SUMO_BREADCRUMBS_SEPARATOR')); $this->document->setTitle($product_info['name']); $this->document->setDescription(!empty($product_info['meta_description']) ? $product_info['meta_description'] : substr(htmlentities(strip_tags(html_entity_decode($product_info['description']))), 0, 150)); if (!empty($product_info['meta_keyword'])) { $this->document->setKeywords($product_info['meta_keyword']); } $this->document->addLink($this->url->link('product/product', $path . '&product_id=' . $this->request->get['product_id']), 'canonical'); $this->data['heading_title'] = $product_info['name']; $this->data['product_id'] = $this->request->get['product_id']; $this->data['manufacturer'] = $product_info['manufacturer']; $this->data['manufacturer_link'] = $this->url->link('product/manufacturer/info', 'manufacturer_id=' . $product_info['manufacturer_id']); $this->data['model'] = $product_info['model']; $this->data['points'] = $product_info['points']; if ($product_info['quantity'] <= 0) { $this->data['stock'] = $product_info['stock_status']; } elseif ($this->config->get('stock_display') || $product_info['stock_amount_visible'] == 1) { $this->data['stock'] = $product_info['quantity']; } else { $this->data['stock'] = Language::getVar('SUMO_PRODUCT_IN_STOCK'); } if ($product_info['image']) { $this->data['popup'] = $this->model_tool_image->resize($product_info['image'], $this->config->get('image_popup_width'), $this->config->get('image_popup_height')); } else { $this->data['popup'] = $this->model_tool_image->resize('no_image.jpg', 150, 150); } if ($product_info['image']) { $this->data['thumb'] = $this->model_tool_image->resize($product_info['image'], $this->config->get('image_thumb_width'), $this->config->get('image_thumb_height')); $this->data['additional'] = $this->model_tool_image->resize($product_info['image'], $this->config->get('image_additional_width'), $this->config->get('image_additional_height')); } else { $this->data['thumb'] = $this->model_tool_image->resize('no_image.jpg', 150, 150); $this->data['additional'] = $this->model_tool_image->resize('no_image.jpg', 150, 150); } $this->data['images'] = array(); $results = $this->model_catalog_product->getProductImages($this->request->get['product_id']); foreach ($results as $result) { if (empty($result['image'])) { $result['image'] = 'no_image.jpg'; } $this->data['images'][] = array('popup' => $this->model_tool_image->resize($result['image'], $this->config->get('image_popup_width'), $this->config->get('image_popup_height')), 'thumb' => $this->model_tool_image->resize($result['image'], $this->config->get('image_thumb_width'), $this->config->get('image_thumb_height')), 'additional' => $this->model_tool_image->resize($result['image'], $this->config->get('image_additional_width'), $this->config->get('image_additional_height'))); } $this->data['price'] = $this->data['price_raw'] = false; if ($this->config->get('customer_price') && $this->customer->isLogged() || !$this->config->get('customer_price')) { if ($this->config->get('tax_enabled')) { $this->data['price'] = Formatter::currency($product_info['price'] + $product_info['price'] / 100 * $product_info['tax_percentage']); } else { $this->data['price'] = Formatter::currency($product_info['price']); } $this->data['price_raw'] = $product_info['price']; } if ((double) $product_info['special']) { $this->data['percent_savings'] = round(($product_info['price'] - $product_info['special']) / $product_info['price'] * 100); if ($this->config->get('tax_enabled')) { $this->data['special'] = Formatter::currency($product_info['special'] + $product_info['special'] / 100 * $product_info['tax_percentage']); } else { $this->data['special'] = Formatter::currency($product_info['special']); } $this->data['price_raw'] = $product_info['special']; } $this->data['tax'] = $this->data['tax_raw'] = false; if ($this->config->get('tax_display')) { $price = $product_info['special'] ? $product_info['special'] : $product_info['price']; $this->data['tax'] = Formatter::currency($price); // + ($price / 100 * $product_info['tax_percentage'])); $this->data['tax_raw'] = $price; } $discounts = $this->model_catalog_product->getProductDiscounts($this->request->get['product_id']); $this->data['discounts'] = array(); foreach ($discounts as $discount) { $percent_savings = round(($product_info['price'] - $discount['price']) / $product_info['price'] * 100); if ($this->config->get('tax_enabled')) { $price = Formatter::currency(round($discount['price'] + $discount['price'] / 100 * $product_info['tax_percentage'])); } else { $price = Formatter::currency($discount['price']); } $this->data['discounts'][] = array('quantity' => $discount['quantity'], 'percent_savings' => $percent_savings, 'price' => $price); } $this->data['options'] = $this->model_catalog_product->getProductOptions($this->request->get['product_id']); $this->data['minimum'] = 1; if ($product_info['minimum']) { $this->data['minimum'] = $product_info['minimum']; } $this->data['review_status'] = $this->config->get('review_status'); $this->data['rating'] = !empty($product_info['rating']) ? $product_info['rating'] : 0; $this->data['description'] = html_entity_decode($product_info['description'], ENT_QUOTES, 'UTF-8'); $this->data['attributes'] = $this->model_catalog_product->getProductAttributes($this->request->get['product_id']); $this->model_catalog_product->updateViewed($this->request->get['product_id']); $this->template = 'product/product.tpl'; $this->children = array('common/footer', 'common/header'); $this->response->setOutput($this->render()); } else { return $this->forward('error/not_found'); } }
public function discountcheck() { $json = array(); if ($this->request->server['REQUEST_METHOD'] == 'POST') { if (!empty($this->request->post['type'])) { switch ($this->request->post['type']) { case 'coupon': $this->load->model('checkout/coupon'); $json['coupon'] = $this->model_checkout_coupon->check($this->request->post['code']); if (isset($json['coupon']['discount'])) { if ($json['coupon']['type'] == 'P') { $json['coupon']['display'] = round($json['coupon']['discount']) . '%'; } else { if ($this->config->get('tax_enabled')) { $json['coupon']['display'] = Formatter::currency($json['coupon']['discount'] + $json['coupon']['discount'] / 100 * $json['coupon']['tax_percentage']); } else { $json['coupon']['display'] = Formatter::currency($json['coupon']['discount']); } } $json['coupon']['display'] = Language::getVar('SUMO_CATALOG_COUPON_DISCOUNT', $json['coupon']['display']); } break; case 'voucher': $this->load->model('checkout/voucher'); $json['voucher'] = $this->model_checkout_voucher->check($this->request->post['code']); if (isset($json['voucher']['amount'])) { $json['voucher']['display'] = Language::getVar('SUMO_CATALOG_VOUCHER_DISCOUNT', array($json['voucher']['to_name'], $json['voucher']['from_name'], $json['voucher']['theme'], Formatter::currency($json['voucher']['amount']), htmlentities($json['voucher']['message']))); } break; case 'reward': if (!empty($this->request->post['amount'])) { $json['reward']['display'] = Language::getVar('SUMO_CHECKOUT_REWARD_CALCULATION', array(intval($this->request->post['amount']), Formatter::currency($this->config->get('points_value')), Formatter::currency($this->config->get('points_value') * intval($this->request->post['amount'])))); } break; } } } $this->response->setOutput(json_encode($json)); }
private function getDataProductSales($filters) { $cache = 'report.products.sales.' . json_encode($filters); $data = Cache::find($cache); if (is_array($data) && count($data)) { //return $data; } $sql = "SELECT * FROM PREFIX_orders_lines AS ol LEFT JOIN PREFIX_orders AS o ON o.order_id = ol.order_id"; if (!empty($filters['date_start'])) { $sql .= " AND DATE(order_date) >= '" . Formatter::dateReverse($filters['date_start']) . "'"; } if (!empty($filters['date_end'])) { $sql .= " AND DATE(order_date) <= '" . Formatter::dateReverse($filters['date_end']) . "'"; } if (isset($filters['start']) && !empty($filters['limit'])) { if ($filters['start'] < 1) { $filters['start'] = 0; } } $return = $temp = array(); $products = $this->fetchAll($sql); $i = 0; foreach ($products as $list) { //$list = json_decode($list['data'], true); $check = $this->query("SELECT viewed FROM PREFIX_product WHERE product_id = :id", array('id' => $list['product_id']))->fetch(); if (empty($check['viewed'])) { $check['viewed'] = 0; } $poc = $list['name'] . $list['product_id']; if (!isset($temp[$poc])) { $temp[$poc] = array(0 => $list['name'], 1 => !empty($list['model']) ? $list['model'] : 'P' . $list['product_id'], 2 => $check['viewed'], 3 => 0, 4 => 0); } $temp[$poc][3] += $list['quantity']; $temp[$poc][4] += $list['price'] * $list['quantity']; } $quantity = $total = array(); foreach ($temp as $key => $row) { $quantity[$key] = $row[3]; $total[$key] = $row[4]; } unset($products); array_multisort($quantity, SORT_DESC, $total, SORT_DESC, $temp); unset($quantity); unset($total); if (isset($filters['start']) && !empty($filters['limit'])) { $return = array_slice($temp, $filters['start'], $filters['limit']); } else { return count($temp); } foreach ($return as $key => $list) { $return[$key][4] = Formatter::currency($list[4]); $return[$key][5] = round($list[3] / $list[2] * 100, 2) . '%'; } Cache::set($cache, $return); return $return; }
</td> </tr> <tr> <td class="label">Forma de Pago:</td> <td><?php echo $PAYMENT_TYPE[$sell->paymentType]; ?> </td> </tr> <?php if ($sell->paymentType == PAYMENT_TYPE_CREDIT) { ?> <tr> <td class="label">Anticipo:</td> <td><?php echo Formatter::currency($sell->prepayment); ?> </td> </tr> <?php } ?> <tr> <td class="label">Cliente:</td> <td><?php echo $sell->customer; ?> </td> </tr> <tr> <td class="label">NIT Cliente:</td>
} ?> </select> </td> </tr> <tr> <td class="label">Fecha:</td> <td><?php echo $purchase->date; ?> </td> </tr> <tr> <td class="label">Anticipo:</td> <td><?php echo Formatter::currency($purchase->prepayment); ?> </td> </tr> <tr> <td class="label">Proveedor:</td> <td><?php echo $purchase->provider; ?> </td> </tr> <tr> <td class="label">Observaciones:</td> <td style="width:15em"><?php echo $purchase->gloss; ?>
public function updateStatus($order_id, $status_id, $extra = '', $notify = null) { if ($status_id == 1) { $notify = true; } else { $old = $this->get($order_id); if (!isset($old['status_id']) || isset($old['status_id']) && isset($data['status_id']) && $old['status_id'] != $data['status_id']) { //$this->updateStatus($order_id, !empty($data['status_id']) ? $data['status_id'] : 1, !empty($data['status']['comment']) ? $data['status']['comment'] : !empty($data['comment']) ? $data['comment'] : ''); if ($notify == null) { $notify = $this->config->get('customer_notify_email'); } } else { //$this->updateStatus($order_id, 1, !empty($data['comment']) ? $data['comment'] : ''); if ($notify == null) { $notify = false; } } } $this->query("UPDATE PREFIX_orders\n SET order_status = :status\n WHERE order_id = :id", array('status' => $status_id, 'id' => $order_id)); if ($notify || $this->config->get('admin_notify_email')) { $template = Mailer::getTemplate('update_order_status_' . $status_id); $content = $template['content']; if ($status_id == 1) { $this->load->model('account/order'); $orderInfo = $this->model_account_order->getOrder($order_id); Mailer::setOrder($orderInfo); // Grab order totals foreach ($this->model_account_order->getOrderTotals($order_id) as $total) { if (!empty($total['label_inject'])) { $label = sprintf(Language::getVar($total['label'] . '_INJ'), $total['label_inject']); } else { $label = Language::getVar($total['label']); } $totals[] = array_merge($total, array('label' => $label)); } // Grab order products foreach ($this->model_account_order->getOrderProducts($order_id) as $product) { $price = $product['price'] * (1 + $product['tax_percentage'] / 100); $products[] = array_merge($product, array('price' => Formatter::currency($price), 'total' => Formatter::currency($price * $product['quantity']), 'return' => $this->url->link('account/return/insert', 'order_id=' . $orderInfo['order_id'] . '&product_id=' . $product['product_id'], 'SSL'))); } /** * Parse address info */ // 1. Shipping $shippingAddress = str_replace('{address_1}', '{address_1} {number}{addon}', $orderInfo['customer']['shipping_address']['address_format']); foreach ($orderInfo['customer']['shipping_address'] as $key => $value) { $shippingAddress = str_replace('{' . $key . '}', $value, $shippingAddress); } // 2. Payment $paymentAddress = str_replace('{address_1}', '{address_1} {number}{addon}', $orderInfo['customer']['payment_address']['address_format']); foreach ($orderInfo['customer']['payment_address'] as $key => $value) { $paymentAddress = str_replace('{' . $key . '}', $value, $paymentAddress); } // Remove remaining vars and excessive line breaks $shippingAddress = preg_replace("/\\{([a-z0-9_\\-]+)\\}/", '', $shippingAddress); $shippingAddress = preg_replace("/[\r\n]+/", "\n", $shippingAddress); // Remove remaining vars and excessive line breaks $paymentAddress = preg_replace("/\\{([a-z0-9_\\-]+)\\}/", '', $paymentAddress); $paymentAddress = preg_replace("/[\r\n]+/", "\n", $paymentAddress); // Other data $order_date = Formatter::date(time()); $order_id = str_pad($order_id, 6, 0, STR_PAD_LEFT); $payment_method = $orderInfo['payment']['name']; $shipping_method = $orderInfo['shipping']['name']; $order_view = '<hr /> <div class="row"> <div class="col-sm-6"> <h4>' . Language::getVar('SUMO_NOUN_INVOICE_ADDRESS') . '</h4> <p>' . nl2br($paymentAddress) . '</p> </div> <div class="col-sm-6"> <h4>' . Language::getVar('SUMO_NOUN_SHIPPING_ADDRESS') . '</h4> <p>' . nl2br($shippingAddress) . '</p> </div> </div> <hr> <div class="row"> <div class="col-sm-6"> <dl class="info"> <dt>' . Language::getVar('SUMO_NOUN_ORDER_NO') . ':</dt> <dd>' . $order_id . '</dd> </dl> </div> <div class="col-sm-6"> <dl class="info"> <dt>' . Language::getVar('SUMO_NOUN_ORDER_DATE') . ':</dt> <dd>' . $order_date . '</dd> </dl> </div> </div> <table class="table" style="margin-top: 30px; font-size: 100%;"> <thead> <tr> <th style="width: 65px; font-size: 14px;">' . Language::getVar('SUMO_NOUN_QUANTITY') . '</th> <th>' . Language::getVar('SUMO_NOUN_PRODUCT') . '</th> <th style="width: 75px;">' . Language::getVar('SUMO_NOUN_MODEL') . '</th> <th class="text-right" style="width: 75px;">' . Language::getVar('SUMO_NOUN_PRICE') . '</th> <th class="text-right" style="width: 75px;">' . Language::getVar('SUMO_NOUN_TOTAL') . '</th> <th style="width: 30px;"></th> </tr> </thead> <tbody>'; foreach ($products as $product) { $order_view .= ' <tr> <td>' . $product['quantity'] . '</td> <td>' . $product['name'] . '</td> <td>' . $product['model'] . '</td> <td class="text-right">' . $product['price'] . '</td> <td class="text-right">' . $product['total'] . '</td> </tr>'; } $order_view .= ' </tbody> </table> <hr> <div class="row"> <div class="col-sm-6"> <div class="content"> <dl class="info"> <dt>' . Language::getVar('SUMO_NOUN_PAYMENT_BY') . ':</dt> <dd>' . $payment_method . '</dd> </dl> <dl class="info"> <dt>' . Language::getVar('SUMO_NOUN_SHIPPING_METHOD') . ':</dt> <dd>' . $shipping_method . '</dd> </dl> </div> </div> <div class="col-sm-6"> <div class="content pull-right">'; foreach ($totals as $total) { $order_view .= ' <dl class="info"> <dt>' . $total['label'] . ':</dt> <dd class="text-right" style="min-width: 75px; padding-right: 38px;">' . $total['value_hr'] . '</dd> </dl>'; } $order_view .= ' </div> </div> </div>'; } if (!empty($content)) { if ($notify) { $data = $this->get($order_id); Mailer::setCustomer($data['customer']); Mailer::setOrder(array('order_id' => $order_id)); $template = Mailer::getTemplate('update_order_status_' . $status_id); $content = $template['content'] = str_replace('{hasComments}', '<br />' . $extra, $template['content']); if ($status_id == 1) { $template['content'] = str_replace('{orderView}', $order_view, $template['content']); } Mail::setTo($data['customer']['email']); Mail::setSubject($template['title']); Mail::setHtml($template['content']); Mail::send(); } if ($this->config->get('admin_notify_email')) { $sendTo = array($this->config->get('email')); $extraMails = $this->config->get('extra_notify_email'); if (!empty($extraMails)) { $extraMails = explode(',', $extraMails); foreach ($extraMails as $mail) { if (!empty($mail) && filter_var($mail, \FILTER_VALIDATE_EMAIL)) { $sendTo[] = $mail; } } } $data = $this->get($order_id); Mailer::setCustomer($data['customer']); Mailer::setOrder(array('order_id' => $order_id)); $template = Mailer::getTemplate('update_order_status_' . $status_id); $template['content'] = str_replace('{hasComments}', '<br />' . $extra, $template['content']); if ($status_id == 1) { $template['content'] = str_replace('{orderView}', $order_view, $template['content']); } foreach ($sendTo as $to) { Mail::setTo($to); Mail::setSubject($template['title']); Mail::setHtml($template['content']); Mail::send(); } } } } // Fallback if ($status_id != 1) { $template = Mailer::getTemplate('update_order_status_' . $status_id); $content = $template['content']; $content = str_replace('{hasComments}', '<br />' . $extra, $content); $content = str_replace('{orderView}', '', $content); } else { $content = $extra; } $this->query("INSERT INTO PREFIX_orders_history\n SET order_id = :id,\n status_id = :status,\n notify = :notify,\n comment = :comment,\n history_date = :date", array('id' => $order_id, 'status' => $status_id, 'notify' => $notify, 'comment' => !empty($content) ? $content : '', 'date' => date('Y-m-d H:i:s'))); Cache::removeAll(); return true; }
private function getList() { $this->document->addBreadcrumbs(array('text' => Language::getVar('SUMO_ADMIN_SALES_DASHBOARD'), 'href' => $this->url->link('sale/dashboard'))); $this->document->addBreadcrumbs(array('text' => Language::getVar('SUMO_ADMIN_SALES_INVOICES'))); // Find invoices $allowedFilters = array('concept', 'sent', 'partially_paid', 'paid', 'credit', 'expired'); if (isset($this->request->get['filter']) && in_array($this->request->get['filter'], $allowedFilters)) { $status = mb_strtoupper($this->request->get['filter']); } else { $status = array('CONCEPT', 'SENT', 'PARTIALLY_PAID', 'PAID', 'CREDIT'); } $limit = 20; $page_total_ex = $page_total_in = 0; $page = isset($this->request->get['page']) ? $this->request->get['page'] : 1; $filter = array('status' => $status, 'limit' => $limit, 'start' => ($page - 1) * $limit); foreach ($this->model_sale_invoice->getInvoices($filter) as $invoice) { // Customer is corporate or private? if (!empty($invoice['customer_company_name'])) { $customer = $invoice['customer_company_name']; } else { $customer = $invoice['customer_name']; } // Sent to the view $this->data['invoices'][] = array('invoice_id' => $invoice['invoice_id'], 'invoice_no' => $invoice['invoice_no'], 'customer' => $customer, 'date' => Formatter::date($invoice['invoice_date']), 'amount' => Formatter::currency($invoice['total_amount']), 'status' => $invoice['status'], 'send' => $this->url->link('sale/invoice/send', 'token=' . $this->session->data['token'] . '&invoice_id=' . $invoice['invoice_id'], 'SSL'), 'view' => $this->url->link('sale/invoice/view', 'token=' . $this->session->data['token'] . '&invoice_id=' . $invoice['invoice_id'], 'SSL'), 'download' => $this->url->link('sale/invoice/download', 'token=' . $this->session->data['token'] . '&invoice_id=' . $invoice['invoice_id'], 'SSL'), 'update' => $this->url->link('sale/invoice/update', 'token=' . $this->session->data['token'] . '&invoice_id=' . $invoice['invoice_id'], 'SSL')); $page_total_ex += $invoice['amount'] - $invoice['tax']; $page_total_in += $invoice['amount']; } // In need of pagination? $invoiceTotal = $this->model_sale_invoice->getTotalInvoices($filter); if ($invoiceTotal > $limit) { $pagination = new Pagination(); $pagination->total = $product_total; $pagination->limit = $limit; $pagination->page = $page; $pagination->url = $this->url->link('sale/invoice', 'token=' . $this->session->data['token'] . '&page={page}' . (!is_array($status) ? '&status=' . $status : '')); $this->data['pagination'] = $pagination->renderAdmin(); } else { $this->data['pagination'] = false; } $this->data = array_merge($this->data, array('page_total_ex' => Formatter::currency($page_total_ex), 'page_total_in' => Formatter::currency($page_total_in), 'status' => !is_array($status) ? Language::getVar('SUMO_NOUN_' . mb_strtoupper($status)) : Language::getVar('SUMO_NOUN_DEFAULT'), 'delete' => $this->url->link('sale/invoice/delete', 'token=' . $this->session->data['token'], 'SSL'), 'insert' => $this->url->link('sale/invoice/insert', 'token=' . $this->session->data['token'], 'SSL'), 'filter' => $this->url->link('sale/invoice', 'token=' . $this->session->data['token'] . '&filter=', 'SSL'), 'overview' => $this->url->link('sale/invoice', 'token=' . $this->session->data['token'], 'SSL'))); $this->template = 'sale/invoice_list.tpl'; $this->children = array('common/header', 'common/footer'); $this->response->setOutput($this->render()); }
protected function getForm() { $this->setParent('catalog/product/insert'); $this->data['token'] = $this->session->data['token']; if (isset($this->error['warning'])) { $this->data['error_warning'] = $this->error['warning']; } else { $this->data['error_warning'] = ''; } if (isset($this->error['name'])) { $this->data['error_name'] = $this->error['name']; } else { $this->data['error_name'] = array(); } if (isset($this->error['meta_description'])) { $this->data['error_meta_description'] = $this->error['meta_description']; } else { $this->data['error_meta_description'] = array(); } if (isset($this->error['description'])) { $this->data['error_description'] = $this->error['description']; } else { $this->data['error_description'] = array(); } if (isset($this->error['model'])) { $this->data['error_model'] = $this->error['model']; } else { $this->data['error_model'] = ''; } if (isset($this->error['date_available'])) { $this->data['error_date_available'] = $this->error['date_available']; } else { $this->data['error_date_available'] = ''; } if (!isset($this->request->get['product_id'])) { $this->data['action'] = $this->url->link('catalog/product/insert', 'token=' . $this->session->data['token'], 'SSL'); $this->data['id'] = 'XX'; } else { $this->data['action'] = $this->url->link('catalog/product/update', 'token=' . $this->session->data['token'] . '&product_id=' . $this->request->get['product_id'], 'SSL'); $this->data['id'] = $this->request->get['product_id']; } $this->data['cancel'] = $this->url->link('catalog/product', 'token=' . $this->session->data['token'] . '&' . $this->getFilterURL(), 'SSL'); 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']); } $this->data['token'] = $this->session->data['token']; $this->load->model('localisation/language'); $this->data['languages'] = $this->model_localisation_language->getLanguages(); if (isset($this->request->post['product_description'])) { $this->data['product_description'] = $this->request->post['product_description']; } elseif (isset($this->request->get['product_id'])) { $this->data['product_description'] = $this->model_catalog_product->getProductDescriptions($this->request->get['product_id']); } else { foreach ($this->data['languages'] as $language) { $this->data['product_description'][$language['language_id']] = array('title' => '', 'keyword' => '', 'meta_description' => '', 'meta_keyword' => ''); } } if (isset($this->request->post['model'])) { $this->data['model'] = $this->request->post['model_2']; } elseif (!empty($product_info)) { $this->data['model'] = $product_info['model_2']; } else { $this->data['model'] = ''; } $extra_info_types = array('sku', 'upc', 'ean', 'jan', 'isbn', 'mpn'); $this->data['extra_info'] = array(); foreach ($extra_info_types as $type) { if (isset($this->request->post[$type])) { $this->data['extra_info'][] = array('type' => $type, 'value' => $this->request->post[$type], 'visible' => $this->request->post[$type . '_visible']); } else { if (!empty($product_info[$type])) { $this->data['extra_info'][] = array('type' => $type, 'value' => $product_info[$type], 'visible' => $product_info[$type . '_visible']); } } } if (isset($this->request->post['location'])) { $this->data['location'] = $this->request->post['location']; } elseif (!empty($product_info)) { $this->data['location'] = $product_info['location']; } else { $this->data['location'] = ''; } $this->load->model('settings/stores'); $stores = array(); /*$stores[] = array( 'url' => HTTP_CATALOG, 'name' => $this->config->get('config_name'), 'store_id' => 0 );*/ foreach ($this->model_settings_stores->getStores() as $list) { $stores[$list['store_id']] = $list; } $this->data['stores'] = $stores; if (isset($this->request->post['product_store'])) { $this->data['product_store'] = $this->request->post['product_store']; } elseif (isset($this->request->get['product_id'])) { $this->data['product_store'] = $this->model_catalog_product->getProductStores($this->request->get['product_id']); } else { $this->data['product_store'] = 0; } if (isset($this->request->post['image'])) { $this->data['image'] = $this->request->post['image']; } elseif (!empty($product_info)) { $this->data['image'] = $product_info['image']; } else { $this->data['image'] = ''; } $this->load->model('tool/image'); if (isset($this->request->post['image']) && file_exists(DIR_IMAGE . $this->request->post['image'])) { $this->data['thumb'] = $this->model_tool_image->resize($this->request->post['image'], 150, 150); } elseif (!empty($product_info) && $product_info['image'] && file_exists(DIR_IMAGE . $product_info['image'])) { $this->data['thumb'] = $this->model_tool_image->resize($product_info['image'], 150, 150); } else { $this->data['thumb'] = $this->model_tool_image->resize('no_image.jpg', 150, 150); } $this->data['thumb_extra'] = $this->model_tool_image->resize('no_image.jpg', 125, 125); if (isset($this->request->post['shipping'])) { $this->data['shipping'] = $this->request->post['shipping']; } elseif (!empty($product_info)) { $this->data['shipping'] = $product_info['shipping']; } else { $this->data['shipping'] = 1; } if (isset($this->request->post['model_supplier'])) { $this->data['model_supplier'] = $this->request->post['model_supplier']; } elseif (!empty($product_info)) { $this->data['model_supplier'] = $product_info['model_supplier']; } else { $this->data['model_supplier'] = ''; } if (isset($this->request->post['product_price'])) { $this->data['price'] = $this->request->post['product_price']; } elseif (!empty($product_info)) { $this->data['price'] = $product_info['price']; } else { $this->data['price'] = '0.0000'; } // Get tax rates $this->load->model('settings/general'); $tax_percentages = $this->model_settings_general->getSetting('tax_percentage'); if (is_array($tax_percentages)) { foreach ($tax_percentages as $tp) { if (is_array($tp)) { // Extra tax percentages foreach ($tp as $tpExtra) { $this->data['tax_percentages'][] = $tpExtra; } } else { // Default tax percentage $this->data['tax_percentages'][] = $tp; $this->data['tax_percentage'] = $tp; } } } else { $this->data['tax_percentages'] = array(); } if (isset($this->request->post['tax_percentage'])) { $this->data['tax_percentage'] = $this->request->post['tax_percentage']; } elseif (!empty($product_info)) { $this->data['tax_percentage'] = $product_info['tax_percentage']; } elseif (!isset($this->data['tax_percentage'])) { $this->data['tax_percentage'] = 0; } if (isset($this->request->post['date_available'])) { $this->data['date_available'] = $this->request->post['date_available']; } elseif (!empty($product_info) && $product_info['date_available'] != '0000-00-00') { $this->data['date_available'] = Formatter::date($product_info['date_available']); } else { $this->data['date_available'] = Formatter::date(time() - 86400); } if (isset($this->request->post['product_quantity'])) { $this->data['quantity'] = $this->request->post['product_quantity']; } elseif (!empty($product_info)) { $this->data['quantity'] = $product_info['quantity']; } else { $this->data['quantity'] = 1; } $this->data['stock_linked_products'] = $this->model_catalog_product->getLinkedProducts(); $this->data['stock_product_name'] = ''; if (isset($this->request->post['stock_id'])) { $this->data['stock_id'] = $this->request->post['stock_id']; $this->data['stock_product'] = $this->request->post['stock_product']; $this->data['stock_product_name'] = $this->request->post['stock_product_name']; } elseif (!empty($product_info)) { $this->data['stock_id'] = $product_info['stock_id']; if ($product_info['stock_id'] != $this->data['id']) { $this->data['stock_product'] = true; $stock_product_data = $this->model_catalog_product->getProduct($product_info['stock_id']); $this->data['stock_product_name'] = $stock_product_data['name']; } else { $this->data['stock_product'] = false; } } else { $this->data['stock_id'] = 0; $this->data['stock_product'] = false; } $this->load->model('localisation/stock_status'); $this->data['stock_statuses'] = $this->model_localisation_stock_status->getStockStatuses(); if (isset($this->request->post['stock_status_id'])) { $this->data['stock_status_id'] = $this->request->post['stock_status_id']; } elseif (!empty($product_info)) { $this->data['stock_status_id'] = $product_info['stock_status_id']; } else { $this->data['stock_status_id'] = $this->config->get('stock_status_id'); } if (isset($this->request->post['stock_visible'])) { $this->data['stock_visible'] = $this->request->post['stock_visible']; } elseif (!empty($product_info)) { $this->data['stock_visible'] = $product_info['stock_visible']; } else { $this->data['stock_visible'] = 2; } if (isset($this->request->post['minimum'])) { $this->data['minimum'] = $this->request->post['minimum']; } elseif (!empty($product_info)) { $this->data['minimum'] = $product_info['minimum']; } else { $this->data['minimum'] = 1; } if (isset($this->request->post['subtract'])) { $this->data['subtract'] = $this->request->post['subtract']; } elseif (!empty($product_info)) { $this->data['subtract'] = $product_info['subtract']; } else { $this->data['subtract'] = 1; } if (isset($this->request->post['sort_order'])) { $this->data['sort_order'] = $this->request->post['sort_order']; } elseif (!empty($product_info)) { $this->data['sort_order'] = $product_info['sort_order']; } else { $this->data['sort_order'] = 1; } if (isset($this->request->post['status'])) { $this->data['status'] = $this->request->post['status']; } elseif (!empty($product_info)) { $this->data['status'] = $product_info['status']; } else { $this->data['status'] = 1; } if (isset($this->request->post['product_weight'])) { $this->data['weight'] = $this->request->post['product_weight']; } elseif (!empty($product_info)) { $this->data['weight'] = $product_info['weight']; } else { $this->data['weight'] = ''; } $this->load->model('localisation/weight_class'); $this->data['weight_classes'] = $this->model_localisation_weight_class->getWeightClasses(); if (isset($this->request->post['weight_class_id'])) { $this->data['weight_class_id'] = $this->request->post['weight_class_id']; } elseif (!empty($product_info)) { $this->data['weight_class_id'] = $product_info['weight_class_id']; } else { $this->data['weight_class_id'] = $this->config->get('config_weight_class_id'); } if (isset($this->request->post['length'])) { $this->data['length'] = $this->request->post['length']; } elseif (!empty($product_info)) { $this->data['length'] = $product_info['length']; } else { $this->data['length'] = ''; } if (isset($this->request->post['width'])) { $this->data['width'] = $this->request->post['width']; } elseif (!empty($product_info)) { $this->data['width'] = $product_info['width']; } else { $this->data['width'] = ''; } if (isset($this->request->post['height'])) { $this->data['height'] = $this->request->post['height']; } elseif (!empty($product_info)) { $this->data['height'] = $product_info['height']; } else { $this->data['height'] = ''; } if (isset($this->request->post['cost_price'])) { $this->data['cost_price'] = $this->request->post['cost_price']; } elseif (!empty($product_info)) { $this->data['cost_price'] = $product_info['cost_price']; } else { $this->data['cost_price'] = '0.0000'; } $this->load->model('localisation/length_class'); $this->data['length_classes'] = $this->model_localisation_length_class->getLengthClasses(); if (isset($this->request->post['length_class_id'])) { $this->data['length_class_id'] = $this->request->post['length_class_id']; } elseif (!empty($product_info)) { $this->data['length_class_id'] = $product_info['length_class_id']; } else { $this->data['length_class_id'] = $this->config->get('config_length_class_id'); } $this->load->model('catalog/manufacturer'); $this->data['manufacturers'] = array(); $this->data['manufacturers'][0] = array('manufacturer_id' => 0, 'name' => Language::getVar('SUMO_NOUN_NONE')); foreach ($this->model_catalog_manufacturer->getManufacturers() as $man) { $this->data['manufacturers'][] = $man; } if (isset($this->request->post['manufacturer_id'])) { $this->data['manufacturer_id'] = $this->request->post['manufacturer_id']; } elseif (!empty($product_info)) { $this->data['manufacturer_id'] = $product_info['manufacturer_id']; } else { $this->data['manufacturer_id'] = 0; } if (isset($this->request->post['manufacturer'])) { $this->data['manufacturer'] = $this->request->post['manufacturer']; } elseif (!empty($product_info)) { $manufacturer_info = $this->model_catalog_manufacturer->getManufacturer($product_info['manufacturer_id']); if ($manufacturer_info) { $this->data['manufacturer'] = $manufacturer_info['name']; } else { $this->data['manufacturer'] = ''; } } else { $this->data['manufacturer'] = ''; } // Categories $this->load->model('catalog/category'); if (isset($this->request->post['product_category'])) { $category = $this->request->post['product_category']; } elseif (isset($this->request->get['product_id'])) { $category = $this->model_catalog_product->getProductCategories($this->request->get['product_id']); } else { $category = array(); } $this->data['product_category'] = $category; $categories = $this->model_catalog_category->getCategories(); $tmp_cats = array(); foreach ($categories as $store => $storeCats) { foreach ($storeCats as $category_info) { if (!isset($category_info['name'])) { foreach ($category_info as $cat) { $tmp_cats2[$cat['category_id']] = $cat['name']; $this->data['product_categories'][] = array('store_id' => $store, 'category_id' => $cat['category_id'], 'name' => $tmp_cats2[$cat['parent_id']] . ' > ' . $cat['name'], 'store_name' => $stores[$store]['name'], 'selected' => in_array($cat['category_id'], $category) ? true : false); } continue; } $this->data['product_categories'][] = array('store_id' => $store, 'category_id' => $category_info['category_id'], 'name' => $category_info['name'], 'store_name' => $stores[$store]['name'], 'selected' => in_array($category_info['category_id'], $category) ? true : false); $tmp_cats[$category_info['category_id']] = $category_info['name']; $tmp_cats2[$category_info['category_id']] = $category_info['name']; } } // Attributes $this->load->model('catalog/attribute'); $posted = false; if (isset($this->request->post['attribute'])) { $posted = true; $product_attributes = $this->request->post['attribute']; } elseif (isset($this->request->get['product_id'])) { $product_attributes = $this->model_catalog_product->getProductAttributes($this->request->get['product_id']); } else { $product_attributes = array(); } $this->data['attribute_sets'] = array(); foreach ($this->model_catalog_attribute->getAttributeGroups() as $group) { $attributes = $this->model_catalog_attribute->getAttributes(array('filter_attribute_group_id' => $group['attribute_group_id'])); // Check certain attributes? foreach ($attributes as $key => $attribute) { if (in_array($attribute['attribute_id'], $product_attributes)) { $attributes[$key]['checked'] = true; } else { $attributes[$key]['checked'] = false; } } $this->data['attribute_sets'][] = array('name' => $group['name'], 'attributes' => $attributes); } // Options if (isset($this->request->post['product_option'])) { $product_options = $this->request->post['product_option']; } elseif (isset($this->request->get['product_id'])) { $product_options = $this->model_catalog_product->getProductOptions($this->request->get['product_id']); } else { $product_options = array(); } // Set option prices foreach ($product_options as $i => $option) { if (isset($option['product_option_value'])) { foreach ($option['product_option_value'] as $j => $option_value) { $product_options[$i]['product_option_value'][$j]['price'] = round(floatval($product_options[$i]['product_option_value'][$j]['price']) * (1 + $product_info['tax_percentage'] / 100), 4); } } } $this->data['product_options'] = $product_options; $this->load->model('sale/customer_group'); $this->load->model('sale/volume'); //$this->data['volumes'] = $this->model_sale_volume->getVolumes(); $this->data['customer_groups'] = $this->model_sale_customer_group->getCustomerGroups(); if (isset($this->request->post['product_discount'])) { $product_discounts = $this->request->post['product_discount']; } elseif (isset($this->request->get['product_id'])) { $product_discounts = $this->model_catalog_product->getProductDiscounts($this->request->get['product_id']); } else { $product_discounts = array(); } foreach ($product_discounts as $i => $discount) { $product_discounts[$i]['price_in'] = Formatter::currency($discount['price'] + $discount['price'] / 100 * $this->data['tax_percentage']); } $this->data['product_discounts'] = $product_discounts; if (isset($this->request->post['product_special'])) { $product_specials = $this->request->post['product_special']; } elseif (isset($this->request->get['product_id'])) { $product_specials = $this->model_catalog_product->getProductSpecials($this->request->get['product_id']); } else { $product_specials = array(); } foreach ($product_specials as $i => $special) { $product_specials[$i]['price_in'] = Formatter::currency($special['price'] + $special['price'] / 100 * $this->data['tax_percentage']); } $this->data['product_specials'] = $product_specials; // Images if (isset($this->request->post['product_image'])) { $product_images = $this->request->post['product_image']; } elseif (isset($this->request->get['product_id'])) { $product_images = $this->model_catalog_product->getProductImages($this->request->get['product_id']); } else { $product_images = array(); } $this->data['product_images'] = array(); foreach ($product_images as $product_image) { if ($product_image['image'] && file_exists(DIR_IMAGE . $product_image['image'])) { $image = $product_image['image']; } else { $image = 'no_image.jpg'; } $this->data['product_images'][] = array('image' => $image, 'thumb' => $this->model_tool_image->resize($image, 125, 125), 'sort_order' => $product_image['sort_order']); } $this->data['no_image'] = $this->model_tool_image->resize('no_image.jpg', 125, 125); // Downloads $this->load->model('catalog/download'); if (isset($this->request->post['product_download'])) { $product_downloads = $this->request->post['product_download']; } elseif (isset($this->request->get['product_id'])) { $product_downloads = $this->model_catalog_product->getProductDownloads($this->request->get['product_id']); } else { $product_downloads = array(); } $this->data['product_downloads'] = array(); foreach ($product_downloads as $download_id) { $this->data['product_downloads'][] = $this->model_catalog_download->getDownload($download_id); } if (isset($this->request->post['product_related'])) { $products = $this->request->post['product_related']; } elseif (isset($this->request->get['product_id'])) { $products = $this->model_catalog_product->getProductRelated($this->request->get['product_id']); } else { $products = array(); } $this->data['product_related'] = array(); foreach ($products as $id) { if (isset($this->request->get['product_id'])) { if ($this->request->get['product_id'] == $id) { continue; } } $related_product = $this->model_catalog_product->getProduct($id); $related_product['image'] = $this->model_tool_image->resize($related_product['image'], 50, 50); $this->data['product_related'][] = $related_product; } if (isset($this->request->post['product_points'])) { $this->data['points'] = $this->request->post['product_points']; } elseif (!empty($product_info)) { $this->data['points'] = $product_info['points']; } else { $this->data['points'] = ''; } if (isset($this->request->post['product_reward'])) { $this->data['product_reward'] = $this->request->post['product_reward']; } elseif (isset($this->request->get['product_id'])) { $this->data['product_reward'] = $this->model_catalog_product->getProductRewards($this->request->get['product_id']); } else { $this->data['product_reward'] = array(); } if (!empty($this->error)) { $this->data['error'] = implode('<br />', $this->error); } else { $this->data['error'] = ''; } $this->data['tax_settings'] = $this->url->link('settings/store/general', 'token=' . $this->session->data['token'], 'SSL'); $this->document->addStyle('view/css/pages/product.css'); $this->document->addStyle('view/css/pages/uploader.css'); $this->document->addScript('view/js/pages/product_form.js'); $this->document->addScript('view/js/pages/uploader.js'); $this->document->addScript('view/js/jquery/jquery.ajaxupload.js'); $this->document->addScript('view/js/jquery/jquery.autocomplete.js'); $this->template = 'catalog/product_form.tpl'; $this->children = array('common/header', 'common/footer'); $this->response->setOutput($this->render()); }
public function transaction() { $this->load->model('sale/customer'); if ($this->request->server['REQUEST_METHOD'] == 'POST' && $this->user->hasPermission('modify', 'sale/customer')) { $this->model_sale_customer->addTransaction($this->request->get['customer_id'], $this->request->post['description'], $this->request->post['amount']); $return = array('success' => Language::getVar('SUMO_SUCCESS_TRANSACTION_ADDED')); $this->response->setOutput(json_encode($return)); } if ($this->request->server['REQUEST_METHOD'] == 'POST' && !$this->user->hasPermission('modify', 'sale/customer')) { $return = array('error' => Language::getVar('SUMO_ERROR_NO_PERMISSION')); $this->response->setOutput(json_encode($return)); } $this->data['transactions'] = array(); $results = $this->model_sale_customer->getTransactions($this->request->get['customer_id']); foreach ($results as $result) { $this->data['transactions'][] = array_merge($result, array('amount' => Formatter::currency($result['amount']), 'date_added' => Formatter::date($result['date_added']))); } $this->data['transaction_balance'] = $this->currency->format($this->model_sale_customer->getTransactionTotal($this->request->get['customer_id']), $this->config->get('currency')); }
public function index() { $this->document->setTitle(Language::getVar('SUMO_ADMIN_NOUN_DASHBOARD')); $this->document->addStyle('view/css/pages/dashboard.css'); $this->document->addScript('view/js/pages/dashboard.js'); $this->document->addScript('view/js/jquery/jquery.flot.js'); $this->document->addScript('view/js/jquery/jquery.flot.pie.js'); $this->document->addScript('view/js/jquery/jquery.flot.resize.js'); $this->data['token'] = $this->session->data['token']; $this->load->model('sale/orders'); $this->data['total_sale'] = Formatter::currency($this->model_sale_orders->getTotalSales()); $this->data['total_sale_year'] = Formatter::currency($this->model_sale_orders->getTotalSalesByYear(date('Y'))); $this->data['total_order'] = $this->model_sale_orders->getOrdersTotal(); $this->load->model('sale/customer'); $this->data['total_customer'] = $this->model_sale_customer->getTotalCustomers(); $this->data['total_customer_approval'] = $this->model_sale_customer->getTotalCustomersAwaitingApproval(); $this->load->model('catalog/review'); $this->data['total_review'] = $this->model_catalog_review->getTotalReviews(); $this->data['total_review_approval'] = $this->model_catalog_review->getTotalReviewsAwaitingApproval(); $this->data['orders'] = array(); $data = array('sort' => 'o.date_added', 'order' => 'DESC', 'start' => 0, 'limit' => 10); $results = $this->model_sale_orders->getOrders($data); foreach ($results as $result) { if (!empty($result['middlename'])) { $name = $result['customer']['firstname'] . ' ' . $result['customer']['middlename'] . ' ' . $result['customer']['lastname']; } else { $name = $result['customer']['firstname'] . ' ' . $result['customer']['lastname']; } $this->data['orders'][] = array('order_id' => $result['order_id'], 'customer' => $name, 'status' => $result['status'], 'date_added' => Formatter::date($result['order_date']), 'total' => Formatter::currency($result['total']), 'info' => $this->url->link('sale/orders/info', 'token=' . $this->session->data['token'] . '&order_id=' . $result['order_id'], 'SSL')); } // Get last ten customers $data = array('sort' => 'date_added', 'order' => 'DESC', 'start' => 0, 'limit' => 10); $results = $this->model_sale_customer->getCustomers($data); foreach ($results as $result) { if (!empty($result['middlename'])) { $name = $result['firstname'] . ' ' . $result['middlename'] . ' ' . $result['lastname']; } else { $name = $result['firstname'] . ' ' . $result['lastname']; } // Get address if ($result['address_id'] > 0) { $addressInfo = $this->model_sale_customer->getAddress($result['address_id']); $result['city'] = $addressInfo['city']; } else { $result['city'] = '—'; } $this->data['visitors'][] = array('customer_id' => $result['customer_id'], 'customer' => $name, 'city' => $result['city'], 'info' => $this->url->link('sale/customer/edit', 'token=' . $this->session->data['token'] . '&customer_id=' . $result['customer_id'], 'SSL')); } // Get countries for customers /* $this->load->model('sale/customer'); $countries = $this->model_sale_customer->getCustomersPerCountry(); $colors = array("#93e529", "#ffffff", "#f97f32", "#40a5c3"); foreach ($countries as $i => $country) { $this->data['countries'][] = array( 'label' => $country['country_name'], 'data' => $country['customers'], 'color' => $colors[$i] ); } */ $this->load->model('user/user'); $this->data = array_merge($this->data, array('todo' => $this->model_user_user->getTodos(), 'uri_orders' => $this->url->link('sale/orders', 'token=' . $this->session->data['token']), 'uri_customers' => $this->url->link('sale/customers', 'token=' . $this->session->data['token']))); /* $this->data['visitors'] = array(); $this->load->model('report/online'); $results = Database::fetchAll("SELECT customer_id FROM PREFIX_customer ORDER BY date_added DESC LIMIT 0,5"); foreach ($results as $list) { if ($list['customer_id'] >= 1) { $tmp = Database::query("SELECT city, firstname, lastname FROM PREFIX_address WHERE customer_id = :id LIMIT 1", array('id' => $list['customer_id']))->fetch(); $list['city'] = $tmp['city']; $list['customer'] = $tmp['firstname'] . ' ' . $tmp['lastname']; } else { $list['city'] = ''; $list['customer'] = Language::getVar('SUMO_NOUN_GUEST'); } $this->data['visitors'][] = $list; } if ($this->config->get('currency_auto')) { $this->load->model('localisation/currency'); $this->model_localisation_currency->updateCurrencies(); } */ $this->assembleCharts(); $this->template = 'common/home.tpl'; $this->children = array('common/header', 'common/footer'); $this->response->setOutput($this->render()); }
public function info() { if (!$this->customer->isLogged()) { $this->session->data['redirect'] = $this->url->link('account/order/info', 'order_id=' . $orderID, 'SSL'); $this->redirect($this->url->link('account/login', '', 'SSL')); } $orderID = 0; if (isset($this->request->get['order_id'])) { $orderID = $this->request->get['order_id']; } $this->load->model('account/order'); $orderInfo = $this->model_account_order->getOrder($orderID); if ($orderInfo) { $this->document->setTitle(Language::getVar('SUMO_NOUN_ORDER')); $this->data['breadcrumbs'] = array(); $this->data['breadcrumbs'][] = array('text' => Language::getVar('SUMO_NOUN_HOME'), 'href' => $this->url->link('common/home'), 'separator' => false); $this->data['breadcrumbs'][] = array('text' => Language::getVar('SUMO_ACCOUNT_TITLE'), 'href' => $this->url->link('account/account', '', 'SSL')); $url = ''; if (isset($this->request->get['page'])) { $url .= '&page=' . $this->request->get['page']; } $this->data['breadcrumbs'][] = array('text' => Language::getVar('SUMO_ACCOUNT_ORDER_TITLE'), 'href' => $this->url->link('account/order', $url, 'SSL')); $this->data['breadcrumbs'][] = array('text' => Language::getVar('SUMO_NOUN_ORDER'), 'href' => $this->url->link('account/order/info', 'order_id=' . $this->request->get['order_id'] . $url, 'SSL')); // ** NOTICE ** // This data is also fetched in model/checkout/order.php :: updateStatus // to create the order 'table'. If anything is changed here, // check there as well to be consistent. // Grab order totals foreach ($this->model_account_order->getOrderTotals($orderID) as $total) { if (!empty($total['label_inject'])) { $label = sprintf(Language::getVar($total['label'] . '_INJ'), $total['label_inject']); } else { $label = Language::getVar($total['label']); } $this->data['totals'][] = array_merge($total, array('label' => $label)); } // Grab order products foreach ($this->model_account_order->getOrderProducts($orderID) as $product) { $price = $product['price'] * (1 + $product['tax_percentage'] / 100); $this->data['products'][] = array_merge($product, array('price' => Formatter::currency($price), 'total' => Formatter::currency($price * $product['quantity']), 'return' => $this->url->link('account/return/insert', 'order_id=' . $orderInfo['order_id'] . '&product_id=' . $product['product_id'], 'SSL'))); } // Grab history foreach ($this->model_account_order->getOrderHistories($orderID) as $history) { $this->data['histories'][] = array_merge($history, array('date_added' => Formatter::date($history['history_date']))); } /** * Parse address info */ // 1. Shipping $shippingAddress = str_replace('{address_1}', '{address_1} {number}{addon}', $orderInfo['customer']['shipping_address']['address_format']); foreach ($orderInfo['customer']['shipping_address'] as $key => $value) { $shippingAddress = str_replace('{' . $key . '}', $value, $shippingAddress); } // Remove remaining vars and excessive line breaks $shippingAddress = preg_replace("/\\{([a-z0-9_\\-]+)\\}/", '', $shippingAddress); $shippingAddress = preg_replace("/[\r\n]+/", "\n", $shippingAddress); // 2. Payment $paymentAddress = str_replace('{address_1}', '{address_1} {number}{addon}', $orderInfo['customer']['payment_address']['address_format']); foreach ($orderInfo['customer']['payment_address'] as $key => $value) { $paymentAddress = str_replace('{' . $key . '}', $value, $paymentAddress); } // Remove remaining vars and excessive line breaks $paymentAddress = preg_replace("/\\{([a-z0-9_\\-]+)\\}/", '', $paymentAddress); $paymentAddress = preg_replace("/[\r\n]+/", "\n", $paymentAddress); $this->data = array_merge($this->data, array('order_date' => Formatter::date($orderInfo['order_date']), 'invoice_no' => isset($orderInfo['invoice_no']) ? $orderInfo['invoice_no'] : '—', 'order_id' => str_pad($orderInfo['order_id'], 6, 0, STR_PAD_LEFT), 'payment_method' => $orderInfo['payment']['name'], 'payment_address' => $paymentAddress, 'shipping_method' => $orderInfo['shipping']['name'], 'shipping_address' => $shippingAddress, 'continue' => $this->url->link('account/order', '', 'SSL'))); $this->data['settings'] = $this->config->get('details_account_' . $this->config->get('template')); if (!is_array($this->data['settings']) || !count($this->data['settings'])) { $this->data['settings']['left'][] = $this->getChild('app/widgetsimplesidebar/', array('type' => 'accountTree', 'data' => array())); } $this->template = 'account/order/view.tpl'; $this->children = array('common/footer', 'common/header'); $this->response->setOutput($this->render()); } else { $this->document->setTitle(Language::getVar('SUMO_NOUN_ORDER')); $this->data['breadcrumbs'] = array(); $this->data['breadcrumbs'][] = array('text' => Language::getVar('SUMO_NOUN_HOME'), 'href' => $this->url->link('common/home'), 'separator' => false); $this->data['breadcrumbs'][] = array('text' => Language::getVar('SUMO_ACCOUNT_TITLE'), 'href' => $this->url->link('account/account', '', 'SSL')); $this->data['breadcrumbs'][] = array('text' => Language::getVar('SUMO_ACCOUNT_ORDER_TITLE'), 'href' => $this->url->link('account/order', '', 'SSL')); $this->data['breadcrumbs'][] = array('text' => Language::getVar('SUMO_NOUN_ORDER'), 'href' => $this->url->link('account/order/info', 'order_id=' . $orderID, 'SSL')); $this->data['continue'] = $this->url->link('account/order', '', 'SSL'); $this->data['settings'] = $this->config->get('details_account_' . $this->config->get('template')); if (!is_array($this->data['settings']) || !count($this->data['settings'])) { $this->data['settings']['left'][] = $this->getChild('app/widgetsimplesidebar/', array('type' => 'accountTree', 'data' => array())); } $this->template = 'account/order/view.tpl'; $this->children = array('common/footer', 'common/header'); $this->response->setOutput($this->render()); } }