/** * Get order details (summary & line items) * * @param string $order_id * @return array */ public function getOrderDetails($order_id) { $order_summary = $this->getSummary($order_id); $hide_prices = $GLOBALS['session']->has('hide_prices') ? $GLOBALS['session']->get('hide_prices') : false; $GLOBALS['session']->set('hide_prices', false); // Format prices etc for order emails... $order_summary['subtotal'] = Tax::getInstance()->priceFormat($order_summary['subtotal'], true); $order_summary['total'] = Tax::getInstance()->priceFormat($order_summary['total'], true); $order_summary['discount'] = Tax::getInstance()->priceFormat($order_summary['discount'], true); $order_summary['shipping'] = Tax::getInstance()->priceFormat($order_summary['shipping'], true); // Get taxes $order_taxes = $GLOBALS['db']->select('CubeCart_order_tax', array('tax_id', 'amount'), array('cart_order_id' => $order_id)); // Put in items $vars = array(); foreach ($this->_order_inventory as $item) { if ($item['product_id'] > 0) { $product = array_merge($GLOBALS['catalogue']->getProductData($item['product_id']), $item); $product['item_price'] = Tax::getInstance()->priceFormat($product['price']); $product['price'] = Tax::getInstance()->priceFormat($product['price'] * $product['quantity']); if (!empty($product['product_options'])) { $product['product_options'] = implode(' ', unserialize($item['product_options'])); } $vars['products'][] = $product; } else { $item['price'] = Tax::getInstance()->priceFormat($item['price']); $vars['products'][] = $item; } } // Put tax in if ($order_taxes) { foreach ($order_taxes as $order_tax) { $tax_data = Tax::getInstance()->fetchTaxDetails($order_tax['tax_id']); $tax['tax_name'] = $tax_data['name']; //$tax['tax_percent'] = sprintf('%.3F',$tax_data['tax_percent']); $tax['tax_percent'] = floatval($tax_data['tax_percent']); // get rid of zeroes $tax['tax_amount'] = Tax::getInstance()->priceFormat($order_tax['amount']); $vars['taxes'][] = $tax; } } $billing = array('first_name' => $order_summary['first_name'], 'last_name' => $order_summary['last_name'], 'company_name' => $order_summary['company_name'], 'line1' => $order_summary['line1'], 'line2' => $order_summary['line2'], 'town' => $order_summary['town'], 'state' => getStateFormat($order_summary['state']), 'postcode' => $order_summary['postcode'], 'country' => getCountryFormat($order_summary['country']), 'phone' => $order_summary['phone'], 'email' => $order_summary['email']); $shipping = array('first_name' => $order_summary['first_name_d'], 'last_name' => $order_summary['last_name_d'], 'company_name' => $order_summary['company_name_d'], 'line1' => $order_summary['line1_d'], 'line2' => $order_summary['line2_d'], 'town' => $order_summary['town_d'], 'state' => getStateFormat($order_summary['state_d']), 'postcode' => $order_summary['postcode_d'], 'country' => getCountryFormat($order_summary['country_d'])); // Format data $order_summary['order_date'] = formatTime($order_summary['order_date'], false, true); $order_summary['ship_date'] = (int) str_replace('-', '', $order_summary['ship_date']) > 0 ? formatDispatchDate($order_summary['ship_date']) : ""; $order_summary['gateway'] = str_replace('_', ' ', $order_summary['gateway']); $values['order_summary'] = $order_summary; $values['billing'] = $billing; $values['shipping'] = $shipping; $values['taxes'] = $vars['taxes']; $values['products'] = $vars['products']; foreach ($GLOBALS['hooks']->load('class.order.get_order_details') as $hook) { include $hook; } $GLOBALS['session']->set('hide_prices', $hide_prices); $this->_email_details = $values; return $this->_email_details; }
if (($tax_classes = $GLOBALS['db']->select('CubeCart_tax_class')) !== false) { $GLOBALS['smarty']->assign('TAX_CLASSES', $tax_classes); foreach ($tax_classes as $class) { $tax_class[$class['id']] = $class['tax_name']; } } ## Get Tax Details if (($tax_details = $GLOBALS['db']->select('CubeCart_tax_details')) !== false) { foreach ($tax_details as $tax_detail) { if ($tax_detail['status']) { $tax_detail['enabled'] = 'selected="selected"'; } else { $tax_detail['disabled'] = 'selected="selected"'; } $tax_detail_array[$tax_detail['id']] = $tax_detail['name']; $smarty_data['tax_details'][] = $tax_detail; } $GLOBALS['smarty']->assign('TAX_DETAILS', $smarty_data['tax_details']); } ## Get Tax Rules if (($tax_rules = $GLOBALS['db']->select('CubeCart_tax_rates')) !== false) { foreach ($tax_rules as $rule) { $rule['country'] = getCountryFormat($rule['country_id']); $rule['state'] = $rule['county_id'] != 0 ? getStateFormat($rule['county_id']) : $lang['common']['regions_all']; $rule['class'] = $tax_class[$rule['type_id']]; $rule['detail'] = $tax_detail_array[$rule['details_id']]; $smarty_data['tax_rules'][] = $rule; } $GLOBALS['smarty']->assign('TAX_RULES', $smarty_data['tax_rules']); } $page_content = $GLOBALS['smarty']->fetch('templates/settings.tax.php');
$summary['country'] = getCountryFormat($summary['country']); $summary['country_d'] = getCountryFormat($summary['country_d']); $summary['order_date'] = formatTime($summary['order_date'], false, true); $summary['ship_date'] = (int) str_replace('-', '', $summary['ship_date']) > 0 ? formatDispatchDate($summary['ship_date']) : ''; if (($notes = $GLOBALS['db']->select('CubeCart_order_notes', false, array('cart_order_id' => $summary['cart_order_id']))) !== false) { foreach ($notes as $key => $note) { $summary['notes'][] = $note['content'] . '<br />'; } } $smarty_data['list_orders'][] = $summary; unset($summary, $address); } $GLOBALS['smarty']->assign('ORDER_LIST', $smarty_data['list_orders']); $store_logo = $GLOBALS['gui']->getLogo(true, 'invoices'); $GLOBALS['smarty']->assign('STORE_LOGO', $store_logo); $GLOBALS['smarty']->assign('STORE', array('name' => $GLOBALS['config']->get('config', 'store_name'), 'address' => $GLOBALS['config']->get('config', 'store_address'), 'county' => getStateFormat($GLOBALS['config']->get('config', 'store_zone')), 'country' => getCountryFormat($GLOBALS['config']->get('config', 'store_country')), 'postcode' => $GLOBALS['config']->get('config', 'store_postcode'))); foreach ($GLOBALS['hooks']->load('admin.order.index.print') as $hook) { include $hook; } // Parse $template = $GLOBALS['smarty']->fetch('templates/orders.print.php'); $print_hash = md5(implode('{@}', $summaries[0])); $cleanup = '<?php unlink(__FILE__); ?>'; $filename = 'print.' . $print_hash . '.php'; if (file_put_contents(CC_FILES_DIR . $filename, $template . $cleanup)) { httpredir($GLOBALS['storeURL'] . '/files/' . $filename); } else { $GLOBALS['main']->setACPWarning($lang['orders']['error_print_generate']); httpredir(currentPage(array('print'))); } } else {
// Get list of Customer Groups if (($groups = $GLOBALS['db']->select('CubeCart_customer_group', false, false, array('group_name' => 'ASC'))) !== false) { foreach ($GLOBALS['hooks']->load('admin.customer.group_list') as $hook) { include $hook; } $GLOBALS['smarty']->assign('CUSTOMER_GROUPS', $groups); } $GLOBALS['smarty']->assign('DISPLAY_LIST', true); } if (!isset($_GET['address_id'])) { // avoid states double content by address edit if (($countries = $GLOBALS['db']->select('CubeCart_geo_country', array('id', 'numcode', 'name'))) !== false) { $store_country = $GLOBALS['config']->get('config', 'store_country'); foreach ($countries as $country) { $smarty_data['countries'][] = array('selected' => $country['numcode'] == $store_country ? 'selected="selected"' : '', 'id' => $country['numcode'], 'name' => $country['name']); } $GLOBALS['smarty']->assign('COUNTRIES', $smarty_data['countries']); if (($counties = $GLOBALS['db']->select('CubeCart_geo_zone')) !== false) { $id = $country_format = 0; foreach ($counties as $state) { if ($id != $state['country_id']) { $id = $state['country_id']; $country_format = getCountryFormat($state['country_id'], 'id', 'numcode'); } $jsonArray[$country_format][] = array('id' => $state['id'], 'name' => $state['name']); } $GLOBALS['smarty']->assign('JSON_STATE', json_encode($jsonArray)); } } } $page_content = $GLOBALS['smarty']->fetch('templates/customers.index.php');
/** * Format address array * * @param array * @return array */ public function formatAddress($address = array(), $user_defined = true, $estimate = false) { if (!$user_defined && !is_array($address)) { if ($GLOBALS['config']->get('config', 'disable_estimates') == '1') { $address = array('postcode' => '', 'country' => '', 'state' => ''); } else { $address = array('postcode' => $GLOBALS['config']->get('config', 'store_postcode'), 'country' => $GLOBALS['config']->get('config', 'store_country'), 'state' => $GLOBALS['config']->get('config', 'store_zone')); } } $state_field = is_numeric($address['state']) ? 'id' : 'name'; $address['state_id'] = getStateFormat($address['state'], $state_field, 'id'); $address['country_id'] = $address['country']; $address['country'] = getCountryFormat($address['country_id']); $address['state_abbrev'] = getStateFormat($address['state'], $state_field, 'abbrev'); $address['country_iso'] = getCountryFormat($address['country_id'], 'numcode', 'iso'); $address['country_iso3'] = getCountryFormat($address['country_id'], 'numcode', 'iso3'); $address['state'] = getStateFormat($address['state_id']); $address['user_defined'] = $user_defined; $address['estimate'] = $estimate; return $address; }
/** * Have cookied been accepted or not * * Depreciated but left for backward compatibility * * @param string $token * @return bool */ public function cookiesBlocked() { // Check cookies exists for verified and if so return value if (isset($_COOKIE['accept_cookies'])) { return false; } elseif (!$GLOBALS['config']->get('config', 'cookie_dialogue')) { return false; } $eu_countries = array('AT', 'BE', 'BG', 'CY', 'CZ', 'DE', 'DK', 'EE', 'ES', 'FI', 'FR', 'GB', 'GR', 'HU', 'IE', 'IT', 'LT', 'LU', 'LV', 'MT', 'NL', 'PL', 'PT', 'RO', 'SE', 'SI', 'SK'); $store_country_iso = getCountryFormat($GLOBALS['config']->get('config', 'store_country'), 'numcode', 'iso'); if (in_array($store_country_iso, $eu_countries)) { return true; } return false; }
/** * Admin search function * * @param string $type * @param string $search_string * @return data/false */ public static function search($type, $search_string) { $data = false; if (!empty($type) && !empty($search_string)) { switch (strtolower($type)) { case 'user': if (($results = $GLOBALS['db']->select('CubeCart_customer', false, array('~' . $search_string => array('last_name', 'first_name', 'email')), false, false, false, false)) !== false) { foreach ($results as $result) { $data[] = array('value' => $result['customer_id'], 'display' => $result['first_name'] . ' ' . $result['last_name'], 'info' => $result['email'], 'data' => $result); } } break; case 'address': if (($results = $GLOBALS['db']->select('CubeCart_addressbook', false, array('customer_id' => (int) $search_string), false, false, false, false)) !== false) { foreach ($results as $result) { $result['state'] = getStateFormat($result['state']); $result['country'] = getCountryFormat($result['country']); $data[] = $result; } } break; case 'product': // Limited to a maximum of 15 results, in order to prevent it going mental if (($results = $GLOBALS['db']->select('CubeCart_inventory', false, array('~' . $search_string => array('name', 'product_code')), false, 15, false, false)) !== false) { foreach ($results as $result) { $lower_price = Tax::getInstance()->salePrice($result['price'], $result['sale_price'], false); if ($lower_price && $lower_price < $result['price']) { $result['price'] = $lower_price; } $data[] = array('value' => $result['product_id'], 'display' => $result['name'], 'info' => Tax::getInstance()->priceFormat($result['price']), 'data' => $result); } } break; case 'newsletter': $newsletter = Newsletter::getInstance(); $status = $newsletter->sendNewsletter($_GET['q'], $_GET['page']); if (is_array($status)) { $data = $status; } else { $data = $status ? array('complete' => 'true', 'percent' => 100) : array('error' => 'true'); } break; case 'files': if ($_GET['dir'] == '/') { $dir = false; } elseif ($_GET['dir'] == '/') { $dir = false; } else { $dir = $_GET['dir']; } $filemanager = new FileManager($_GET['group'], $dir); // Directories if (($dirs = $filemanager->findDirectories()) !== false) { foreach ($dirs[$filemanager->formatPath($dir)] as $parent => $folder) { $path = !empty($dir) ? '/' : ''; $json[] = array('type' => 'directory', 'path' => urldecode($dir . basename($folder) . '/'), 'name' => basename($folder)); } } if (($files = $filemanager->listFiles()) !== false) { $catalogue = new Catalogue(); foreach ($files as $result) { if ($filemanager->getMode() == FileManager::FM_FILETYPE_IMG) { $fetch = $catalogue->imagePath($result['file_id'], 'medium'); $path = $name = $fetch; } else { $path = $result['filepath']; $name = $result['filename']; } $json[] = array('type' => 'file', 'path' => dirname($path) . '/', 'file' => basename($result['filename']), 'name' => basename($name), 'id' => $result['file_id'], 'description' => $result['description'], 'mime' => $result['mimetype']); } } $data = isset($json) && is_array($json) ? $json : false; break; default: return false; break; } if (!$data) { $data = array(); } return json_encode($data); } return false; }
/** * Receipt */ private function _receipt() { if (isset($_GET['cart_order_id']) && $GLOBALS['user']->is()) { $customer_id = $GLOBALS['user']->getId(); if (!$customer_id) { $customer_id = $GLOBALS['session']->get('ghost_customer_id'); } $where = array('cart_order_id' => $_GET['cart_order_id'], 'customer_id' => $customer_id); if (($summaries = $GLOBALS['db']->select('CubeCart_order_summary', false, $where)) !== false) { $summary = $summaries[0]; if (($products = $GLOBALS['db']->select('CubeCart_order_inventory', false, array('cart_order_id' => $_GET['cart_order_id']))) !== false) { foreach ($products as $item) { $item['price_total'] = $GLOBALS['tax']->priceFormat(sprintf('%.2F', $item['price'] * $item['quantity']), true); $item['price'] = $GLOBALS['tax']->priceFormat($item['price'], true); if (!empty($item['product_options'])) { $options = ($array = unserialize($item['product_options'])) ? $array : explode("\n", $item['product_options']); foreach ($options as $option) { $value = trim($option); if (empty($value)) { continue; } $item['options'][] = $option; } } $summary['items'][] = $item; } } // Price Formatting $format = array('discount', 'shipping', 'subtotal', 'total_tax', 'total'); foreach ($format as $field) { if (isset($summary[$field])) { $summary[$field] = $GLOBALS['tax']->priceFormat($summary[$field]); } } // Taxes if (($taxes = $GLOBALS['db']->select('CubeCart_order_tax', false, array('cart_order_id' => $summary['cart_order_id']))) !== false) { $GLOBALS['tax']->loadTaxes($summary['country']); foreach ($taxes as $vat) { $detail = $GLOBALS['tax']->fetchTaxDetails($vat['tax_id']); $summary['taxes'][] = array('name' => $detail['name'], 'value' => $GLOBALS['tax']->priceFormat($vat['amount'], true)); } } else { $summary['taxes'][] = array('name' => $GLOBALS['language']->basket['total_tax'], 'value' => $GLOBALS['tax']->priceFormat($summary['total_tax'])); } // Delivery Address $summary['state'] = getStateFormat($summary['state']); $summary['country'] = getCountryFormat($summary['country']); $summary['state_d'] = is_numeric($summary['state_d']) ? getStateFormat($summary['state_d']) : $summary['state_d']; $summary['country_d'] = getCountryFormat($summary['country_d']); $summary['order_status'] = $GLOBALS['language']->order_state['name_' . $summary['status']]; $summary['vat_number'] = $GLOBALS['config']->get('config', 'tax_number'); $summary['order_date'] = formatTime($summary['order_date'], '%d %B %Y', true); $var[] = $summary; $GLOBALS['smarty']->assign('LIST_ORDERS', $var); $GLOBALS['smarty']->assign('PAGE_TITLE', sprintf($GLOBALS['language']->orders['title_invoice_x'], $summary['cart_order_id'])); $GLOBALS['smarty']->assign('STORE', array('address' => $GLOBALS['config']->get('config', 'store_address'), 'county' => getStateFormat($GLOBALS['config']->get('config', 'store_zone')), 'country' => getCountryFormat($GLOBALS['config']->get('config', 'store_country')), 'postcode' => $GLOBALS['config']->get('config', 'store_postcode'))); $GLOBALS['smarty']->assign('STORE_LOGO', $GLOBALS['gui']->getLogo(true, 'invoices')); foreach ($GLOBALS['hooks']->load('class.cubecart.print.receipt') as $hook) { include $hook; } $GLOBALS['smarty']->display('templates/print.receipt.php'); } $GLOBALS['debug']->supress(); exit; } else { httpredir('?_a=login'); } }
/** * Format address array * * @param array * @return array */ public function formatAddress($address = array(), $user_defined = true, $estimate = false) { if (!$user_defined && !is_array($address)) { if ($GLOBALS['config']->get('config', 'disable_estimates') == '1') { $address = array('postcode' => '', 'country' => '', 'state' => ''); } else { $address = array('postcode' => $GLOBALS['config']->get('config', 'store_postcode'), 'country' => $GLOBALS['config']->get('config', 'store_country'), 'state' => $GLOBALS['config']->get('config', 'store_zone')); } } $state_field = is_numeric($address['state']) ? 'id' : 'name'; // Check state $country_id = getCountryFormat($address['country'], 'numcode', 'id'); if ($user_defined && !CC_IN_ADMIN && $_GET['_a'] !== 'addressbook' && (empty($address['state']) && !empty($address['country']) || $GLOBALS['db']->select('CubeCart_geo_zone', false, array($state_field => $address['state'])) == false && $GLOBALS['db']->select('CubeCart_geo_zone', false, array('country_id' => $country_id)))) { $address_description = empty($address['description']) ? '' : ' ("' . $address['description'] . '")'; $GLOBALS['gui']->setError(sprintf($GLOBALS['language']->address['check_state'], $address_description)); httpredir("?_a=addressbook&action=edit&address_id=" . $address['address_id']); return false; } $address['state_id'] = getStateFormat($address['state'], $state_field, 'id'); $address['country_id'] = $address['country']; $address['country'] = getCountryFormat($address['country_id']); $address['state_abbrev'] = getStateFormat($address['state'], $state_field, 'abbrev'); $address['country_iso'] = getCountryFormat($address['country_id'], 'numcode', 'iso'); $address['country_iso3'] = getCountryFormat($address['country_id'], 'numcode', 'iso3'); $address['state'] = getStateFormat($address['state_id']); $address['user_defined'] = $user_defined; $address['estimate'] = $estimate; return $address; }
$order_summary['status'] = $lang['order_state']['name_' . (int) $order_summary['status']]; foreach ($order_summary as $field => $value) { if (in_array($field, array('subtotal', 'discount', 'shipping', 'total_tax', 'total'))) { if (!isset($tally[$field])) { $tally[$field] = 0; } $tally[$field] += $value; } } ##MY ADDITION $order_summary['ship_date'] = sprintf('"=""%s"""', $order_summary['ship_date']); $order_summary['ship_tracking'] = sprintf('"=""%s"""', $order_summary['ship_tracking']); ## END MY ADDITION $order_summary['country'] = is_numeric($order_summary['country']) ? getCountryFormat($order_summary['country']) : $order_summary['country']; $order_summary['state'] = is_numeric($order_summary['state']) ? getStateFormat($order_summary['state']) : $order_summary['state']; $order_summary['country_d'] = is_numeric($order_summary['country_d']) ? getCountryFormat($order_summary['country_d']) : $order_summary['country_d']; $order_summary['state_d'] = is_numeric($order_summary['state_d']) ? getStateFormat($order_summary['state_d']) : $order_summary['state_d']; $order_summary['date'] = formatTime($order_summary['order_date'], false, true); ## Run line of external report data if (isset($external_report) && is_object($external_report)) { $external_report->report_order_data($order_summary); } unset($order_summary['order_date'], $values); foreach ($order_summary as $field => $value) { if ($i == 0) { $headers[] = $field; } $values[] = is_numeric($value) || !strpos($value, ',') ? $value : sprintf('"%s"', addslashes($value)); } if ($i == 0 && $add_headers) { $data[] = implode(',', $headers);