public function resize($filename, $width, $height) { if (!file_exists(DIR_IMAGE . $filename) || !is_file(DIR_IMAGE . $filename)) { return; } $info = pathinfo($filename); $extension = $info['extension']; $old_image = $filename; $new_image = 'cache/' . utf8_substr($filename, 0, utf8_strrpos($filename, '.')) . '-' . $width . 'x' . $height . '.' . $extension; if (!file_exists(DIR_IMAGE . $new_image) || filemtime(DIR_IMAGE . $old_image) > filemtime(DIR_IMAGE . $new_image)) { $path = ''; $directories = explode('/', dirname(str_replace('../', '', $new_image))); foreach ($directories as $directory) { $path = $path . '/' . $directory; if (!file_exists(DIR_IMAGE . $path)) { @mkdir(DIR_IMAGE . $path, 0777); } } $image = new Image(DIR_IMAGE . $old_image); $image->resize($width, $height); $image->save(DIR_IMAGE . $new_image); } if (isset($this->request->server['HTTPS']) && ($this->request->server['HTTPS'] == 'on' || $this->request->server['HTTPS'] == '1')) { return HTTPS_CATALOG . 'image/' . $new_image; } else { return HTTP_CATALOG . 'image/' . $new_image; } }
public function cart() { $this->load->model('tool/image'); $this->data['products'] = array(); foreach ($this->cart->getProducts() as $product) { if ($product['image']) { $image = $this->model_tool_image->resize($product['image'], $this->config->get('image_cart_width'), $this->config->get('image_cart_height')); } else { $image = ''; } $option_data = array(); foreach ($product['option'] as $option) { if ($option['type'] != 'file') { $value = $option['option_value']; } else { $filename = $this->encryption->decrypt($option['option_value']); $value = utf8_substr($filename, 0, utf8_strrpos($filename, '.')); } $option_data[] = array('name' => $option['name'], 'value' => utf8_strlen($value) > 20 ? utf8_substr($value, 0, 20) . '..' : $value, 'type' => $option['type']); } $this->data['products'][] = array('product_id' => $product['product_id'], 'key' => $product['key'], 'thumb' => $image, 'name' => $product['name'], 'model' => $product['model'], 'option' => $option_data, 'quantity' => $product['quantity'], 'price' => $product['price'], 'total' => $product['total'], 'tax' => $product['tax_percentage'], 'href' => $this->url->link('product/product', 'product_id=' . $product['product_id'])); } // Gift Voucher if (!empty($this->session->data['vouchers'])) { foreach ($this->session->data['vouchers'] as $key => $voucher) { $this->data['products'][] = array('key' => $key, 'name' => $voucher['description'], 'price' => $voucher['amount'], 'amount' => 1, 'total' => $voucher['amount']); } } $this->template = 'cart.tpl'; $this->response->setOutput($this->render()); }
public function resize($filename, $width, $height) { if (!is_file(DIR_IMAGE . $filename)) { return; } $extension = pathinfo($filename, PATHINFO_EXTENSION); $old_image = $filename; $new_image = 'cache/' . utf8_substr($filename, 0, utf8_strrpos($filename, '.')) . '-' . $width . 'x' . $height . '.' . $extension; if (!is_file(DIR_IMAGE . $new_image) || filectime(DIR_IMAGE . $old_image) > filectime(DIR_IMAGE . $new_image)) { $path = ''; $directories = explode('/', dirname(str_replace('../', '', $new_image))); foreach ($directories as $directory) { $path = $path . '/' . $directory; if (!is_dir(DIR_IMAGE . $path)) { @mkdir(DIR_IMAGE . $path, 0777); } } list($width_orig, $height_orig) = getimagesize(DIR_IMAGE . $old_image); if ($width_orig != $width || $height_orig != $height) { $image = new Image(DIR_IMAGE . $old_image); $image->resize($width, $height); $image->save(DIR_IMAGE . $new_image); } else { copy(DIR_IMAGE . $old_image, DIR_IMAGE . $new_image); } } if ($this->request->server['HTTPS']) { return $this->config->get('config_ssl') . 'image/' . $new_image; } else { return $this->config->get('config_url') . 'image/' . $new_image; } }
public function resize($filename, $width, $height) { if (!is_file(DIR_IMAGE . $filename) || substr(str_replace('\\', '/', realpath(DIR_IMAGE . $filename)), 0, strlen(DIR_IMAGE)) != DIR_IMAGE) { return; } $extension = pathinfo($filename, PATHINFO_EXTENSION); $image_old = $filename; $image_new = 'cache/' . utf8_substr($filename, 0, utf8_strrpos($filename, '.')) . '-' . $width . 'x' . $height . '.' . $extension; if (!is_file(DIR_IMAGE . $image_new) || filectime(DIR_IMAGE . $image_old) > filectime(DIR_IMAGE . $image_new)) { list($width_orig, $height_orig, $image_type) = getimagesize(DIR_IMAGE . $image_old); if (!in_array($image_type, array(IMAGETYPE_PNG, IMAGETYPE_JPEG, IMAGETYPE_GIF))) { return DIR_IMAGE . $image_old; } $path = ''; $directories = explode('/', dirname($image_new)); foreach ($directories as $directory) { $path = $path . '/' . $directory; if (!is_dir(DIR_IMAGE . $path)) { @mkdir(DIR_IMAGE . $path, 0777); } } if ($width_orig != $width || $height_orig != $height) { $image = new Image(DIR_IMAGE . $image_old); $image->resize($width, $height); $image->save(DIR_IMAGE . $image_new); } else { copy(DIR_IMAGE . $image_old, DIR_IMAGE . $image_new); } } if ($this->request->server['HTTPS']) { return HTTPS_CATALOG . 'image/' . $image_new; } else { return HTTP_CATALOG . 'image/' . $image_new; } }
public function resize($filename, $width, $height) { if (!is_file(DIR_IMAGE . $filename) || substr(str_replace('\\', '/', realpath(DIR_IMAGE . $filename)), 0, strlen(DIR_IMAGE)) != DIR_IMAGE) { return; } $extension = pathinfo($filename, PATHINFO_EXTENSION); $old_image = $filename; $new_image = 'cache/' . utf8_substr($filename, 0, utf8_strrpos($filename, '.')) . '-' . (int) $width . 'x' . (int) $height . '.' . $extension; if (!is_file(DIR_IMAGE . $new_image) || filectime(DIR_IMAGE . $old_image) > filectime(DIR_IMAGE . $new_image)) { $path = ''; $directories = explode('/', dirname($new_image)); foreach ($directories as $directory) { $path = $path . '/' . $directory; if (!is_dir(DIR_IMAGE . $path)) { @mkdir(DIR_IMAGE . $path, 0777); } } list($width_orig, $height_orig) = getimagesize(DIR_IMAGE . $old_image); if ($width_orig != $width || $height_orig != $height) { $image = new Image(DIR_IMAGE . $old_image); $image->resize($width, $height); $image->save(DIR_IMAGE . $new_image); } else { copy(DIR_IMAGE . $old_image, DIR_IMAGE . $new_image); } } $new_image = str_replace(' ', '%20', $new_image); if (isset($this->request->server['HTTPS']) && ($this->request->server['HTTPS'] == 'on' || $this->request->server['HTTPS'] == '1') || $this->request->server['HTTPS'] == '443') { return $this->config->get('config_ssl') . 'image/' . $new_image; } elseif (isset($this->request->server['HTTP_X_FORWARDED_PROTO']) && $this->request->server['HTTP_X_FORWARDED_PROTO'] == 'https') { return $this->config->get('config_ssl') . 'image/' . $new_image; } else { return $this->config->get('config_url') . 'image/' . $new_image; } }
/** * * @param filename string * @param width * @param height * @param type char [default, w, h] * default = scale with white space, * w = fill according to width, * h = fill according to height * */ public function resize($filename, $width, $height, $type = "") { if (!file_exists(DIR_IMAGE . $filename) || !is_file(DIR_IMAGE . $filename)) { return; } $info = pathinfo($filename); $extension = $info['extension']; $old_image = $filename; $new_image = 'cache/' . utf8_substr($filename, 0, utf8_strrpos($filename, '.')) . '-' . $width . 'x' . $height . $type . '.' . $extension; if (!file_exists(DIR_IMAGE . $new_image) || filemtime(DIR_IMAGE . $old_image) > filemtime(DIR_IMAGE . $new_image)) { $path = ''; $directories = explode('/', dirname(str_replace('../', '', $new_image))); foreach ($directories as $directory) { $path = $path . '/' . $directory; if (!file_exists(DIR_IMAGE . $path)) { @mkdir(DIR_IMAGE . $path, 0777); } } list($width_orig, $height_orig) = getimagesize(DIR_IMAGE . $old_image); if ($width_orig != $width || $height_orig != $height) { $image = new Image(DIR_IMAGE . $old_image); $image->resize($width, $height, $type); $image->save(DIR_IMAGE . $new_image); } else { copy(DIR_IMAGE . $old_image, DIR_IMAGE . $new_image); } } if (isset($this->request->server['HTTPS']) && ($this->request->server['HTTPS'] == 'on' || $this->request->server['HTTPS'] == '1')) { return (defined('HTTPS_STATIC_CDN') ? HTTPS_STATIC_CDN : $this->config->get('config_ssl')) . 'image/' . $new_image; } else { return (defined('HTTP_STATIC_CDN') ? HTTP_STATIC_CDN : $this->config->get('config_url')) . 'image/' . $new_image; } }
function utf8_strrpos($string, $needle, $offset = NULL) { if (is_null($offset)) { $data = explode($needle, $string); if (count($data) > 1) { array_pop($data); $string = join($needle, $data); return utf8_strlen($string); } return false; } else { if (!is_int($offset)) { trigger_error('utf8_strrpos expects parameter 3 to be long', E_USER_WARNING); return false; } $string = utf8_substr($string, $offset); if (false !== ($position = utf8_strrpos($string, $needle))) { return $position + $offset; } return false; } }
/** * * @param filename string * @param width * @param height * @param type char [default, w, h] * default = scale with white space, * w = fill according to width, * h = fill according to height * */ public function resize($filename, $width, $height, $type = "") { if (!file_exists(DIR_IMAGE . $filename) || !is_file(DIR_IMAGE . $filename)) { return; } $info = pathinfo($filename); $extension = $info['extension']; $old_image = $filename; $new_image = 'cache/' . utf8_substr($filename, 0, utf8_strrpos($filename, '.')) . '-' . $width . 'x' . $height . $type . '.' . $extension; if (!file_exists(DIR_IMAGE . $new_image) || filemtime(DIR_IMAGE . $old_image) > filemtime(DIR_IMAGE . $new_image)) { $path = ''; $directories = explode('/', dirname(str_replace('../', '', $new_image))); foreach ($directories as $directory) { $path = $path . '/' . $directory; if (!file_exists(DIR_IMAGE . $path)) { @mkdir(DIR_IMAGE . $path, 0777); } } list($width_orig, $height_orig) = getimagesize(DIR_IMAGE . $old_image); if ($width_orig != $width || $height_orig != $height) { $image = new Image(DIR_IMAGE . $old_image); $image->resize($width, $height, $type); $image->save(DIR_IMAGE . $new_image); } else { copy(DIR_IMAGE . $old_image, DIR_IMAGE . $new_image); } } return $this->getImageUrl($new_image); }
/** * Unicode: Returns the position of the last occurrence of needle in haystack * * @param string haystack * @param string needle * @param int offset * @return integer or false on failure */ function zula_strrpos($haystack, $needle, $offset = null) { if (UNICODE_MBSTRING === true) { return $offset === null ? mb_strrpos($haystack, $needle) : mb_strrpos($haystack, $needle, $offset); } else { return $offset === null ? utf8_strrpos($haystack, $needle) : utf8_strrpos($haystack, $needle, $offset); } }
protected function index() { $this->language->load('payment/mvd_pp_standard'); $this->data['button_confirm'] = $this->language->get('button_confirm'); //$this->data['action'] = 'https://www.paypal.com/cgi-bin/webscr'; $this->data['action'] = 'https://www.sandbox.paypal.com/cgi-bin/webscr'; $this->load->model('checkout/order'); $order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']); if ($order_info) { $this->load->model('checkout/order'); $mybankinfo = $this->model_checkout_order->PaymentGateway(); $this->data['business'] = $mybankinfo['paypal_email']; $this->data['item_name'] = html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8'); $this->data['products'] = array(); foreach ($this->cart->getProducts() as $product) { $option_data = array(); foreach ($product['option'] as $option) { if ($option['type'] != 'file') { $value = $option['option_value']; } else { $filename = $this->encryption->decrypt($option['option_value']); $value = utf8_substr($filename, 0, utf8_strrpos($filename, '.')); } $option_data[] = array('name' => $option['name'], 'value' => utf8_strlen($value) > 20 ? utf8_substr($value, 0, 20) . '..' : $value); } $this->data['products'][] = array('name' => $product['name'], 'model' => $product['model'], 'price' => $this->currency->format($product['price'], $order_info['currency_code'], false, false), 'quantity' => $product['quantity'], 'option' => $option_data, 'weight' => $product['weight']); } $this->data['discount_amount_cart'] = 0; $total = $this->currency->format($order_info['total'] - $this->cart->getSubTotal(), $order_info['currency_code'], false, false); if ($total > 0) { $this->data['products'][] = array('name' => $this->language->get('text_total'), 'model' => '', 'price' => $total, 'quantity' => 1, 'option' => array(), 'weight' => 0); } else { $this->data['discount_amount_cart'] -= $total; } $this->data['currency_code'] = $order_info['currency_code']; $this->data['first_name'] = html_entity_decode($order_info['payment_firstname'], ENT_QUOTES, 'UTF-8'); $this->data['last_name'] = html_entity_decode($order_info['payment_lastname'], ENT_QUOTES, 'UTF-8'); $this->data['address1'] = html_entity_decode($order_info['payment_address_1'], ENT_QUOTES, 'UTF-8'); $this->data['address2'] = html_entity_decode($order_info['payment_address_2'], ENT_QUOTES, 'UTF-8'); $this->data['city'] = html_entity_decode($order_info['payment_city'], ENT_QUOTES, 'UTF-8'); $this->data['zip'] = html_entity_decode($order_info['payment_postcode'], ENT_QUOTES, 'UTF-8'); $this->data['country'] = $order_info['payment_iso_code_2']; $this->data['email'] = $order_info['email']; $this->data['invoice'] = $this->session->data['order_id'] . ' - ' . html_entity_decode($order_info['payment_firstname'], ENT_QUOTES, 'UTF-8') . ' ' . html_entity_decode($order_info['payment_lastname'], ENT_QUOTES, 'UTF-8'); $this->data['lc'] = $this->session->data['language']; $this->data['return'] = $this->url->link('checkout/success'); $this->data['notify_url'] = $this->url->link('payment/mvd_pp_standard/callback', '', 'SSL'); $this->data['cancel_return'] = $this->url->link('checkout/checkout', '', 'SSL'); $this->data['paymentaction'] = 'sale'; $this->data['custom'] = $this->session->data['order_id']; if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/payment/mvd_pp_standard.tpl')) { $this->template = $this->config->get('config_template') . '/template/payment/mvd_pp_standard.tpl'; } else { $this->template = 'default/template/payment/mvd_pp_standard.tpl'; } $this->render(); } }
public function getTableData() { $colMap = array('customer_name' => 'firstname', 'date_created' => 'o.date_added'); $sorts = array('order_id', 'customer_name', 'date_created', 'total_amount'); $filters = array_merge($sorts, array('products')); list($sortCol, $sortDir) = $this->MsLoader->MsHelper->getSortParams($sorts, $colMap); $filterParams = $this->MsLoader->MsHelper->getFilterParams($filters, $colMap); $seller_id = $this->customer->getId(); $this->load->model('account/order'); $orders = $this->MsLoader->MsOrderData->getOrders(array('seller_id' => $seller_id, 'order_status' => $this->config->get('msconf_credit_order_statuses')), array('order_by' => $sortCol, 'order_way' => $sortDir, 'offset' => $this->request->get['iDisplayStart'], 'limit' => $this->request->get['iDisplayLength'], 'filters' => $filterParams), array('total_amount' => 1, 'products' => 1)); $total_orders = isset($orders[0]) ? $orders[0]['total_rows'] : 0; $columns = array(); foreach ($orders as $order) { $order_products = $this->MsLoader->MsOrderData->getOrderProducts(array('order_id' => $order['order_id'], 'seller_id' => $seller_id)); if ($this->config->get('msconf_hide_customer_email')) { $customer_name = "{$order['firstname']} {$order['lastname']}"; } else { $customer_name = "{$order['firstname']} {$order['lastname']} ({$order['email']})"; } $products = ""; foreach ($order_products as $p) { $products .= "<p style='text-align:left'>"; $products .= "<span class='name'>" . ($p['quantity'] > 1 ? "{$p['quantity']} x " : "") . "<a href='" . $this->url->link('product/product', 'product_id=' . $p['product_id'], 'SSL') . "'>{$p['name']}</a></span>"; $options = $this->model_account_order->getOrderOptions($order['order_id'], $p['order_product_id']); foreach ($options as $option) { if ($option['type'] != 'file') { $value = $option['value']; } else { $value = utf8_substr($option['value'], 0, utf8_strrpos($option['value'], '.')); } $option['value'] = utf8_strlen($value) > 20 ? utf8_substr($value, 0, 20) . '..' : $value; $products .= "<br />"; $products .= "<small> - {$option['name']} : {$option['value']} </small>"; } $products .= "<span class='total'>" . $this->currency->format($p['seller_net_amt'], $this->config->get('config_currency')) . "</span>"; $products .= "</p>"; } $this->load->model('localisation/order_status'); $order_statuses = $this->model_localisation_order_status->getOrderStatuses(); $order_status_id = $this->model_localisation_order_status->getSuborderStatusId($order['order_id'], $this->customer->getId()); $order_status_name = ''; foreach ($order_statuses as $order_status) { if ($order_status['order_status_id'] == $order_status_id) { $order_status_name = $order_status['name']; } } $columns[] = array_merge($order, array('order_id' => $order['order_id'], 'customer_name' => $customer_name, 'products' => $products, 'suborder_status' => $order_status_name, 'date_created' => date($this->language->get('date_format_short'), strtotime($order['date_added'])), 'total_amount' => $this->currency->format($order['total_amount'], $this->config->get('config_currency')), 'view_order' => '<a href="' . $this->url->link('seller/account-order/viewOrder', 'order_id=' . $order['order_id']) . '" class="ms-button ms-button-view"></a>')); } $this->response->setOutput(json_encode(array('iTotalRecords' => $total_orders, 'iTotalDisplayRecords' => $total_orders, 'aaData' => $columns))); }
/** * Returns information about a file path * * @author Lars Knickrehm <*****@*****.**> * @category Library * @copyright Copyright © 2009 Lars Knickrehm * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License * @link http://php.net/manual/function.pathinfo.php * @package UTF-8 * @param string $path The path being checked. * @return array The following associative array elements are returned: dirname, basename, extension (if any), and filename. * @since Version 0.5.0 * @version 0.5.0 */ function utf8_pathinfo($path) { $return['dirname'] = dirname($path); $return['basename'] = utf8_basename($path); $position = utf8_strrpos($return['basename'], '.'); if ($position !== false) { $return['extension'] = utf8_substr($return['basename'], $position + 1); $return['filename'] = $return['basename']; $return['filename'] = utf8_substr($return['filename'], 0, $position); } else { $return['filename'] = $return['basename']; } return $return; }
public function resizeme($filename, $width, $height, $type = true, $copy = true) { if (!class_exists('PhpThumbFactory')) { require_once DIR_SYSTEM . 'library/image/ThumbLib.php'; } $ok = false; if (!file_exists(DIR_IMAGE . $filename) || !is_file(DIR_IMAGE . $filename)) { return $ok; } $info = pathinfo($filename); $extension = $info['extension']; $old_image = $filename; $new_image = 'cache/' . utf8_substr($filename, 0, utf8_strrpos($filename, '.')) . '-' . $width . 'x' . $height . '.' . $extension; if (!file_exists(DIR_IMAGE . $new_image) || filemtime(DIR_IMAGE . $old_image) > filemtime(DIR_IMAGE . $new_image)) { $path = ''; $directories = explode('/', dirname(str_replace('../', '', $new_image))); foreach ($directories as $directory) { $path = $path . '/' . $directory; if (!file_exists(DIR_IMAGE . $path)) { @mkdir(DIR_IMAGE . $path, 0777); } } list($width_orig, $height_orig) = getimagesize(DIR_IMAGE . $old_image); if ($width_orig != $width || $height_orig != $height || !$copy) { //********* code ************* $thumb = PhpThumbFactory::create(DIR_IMAGE . $old_image, array('resizeUp' => true)); if ($type) { $ok = $thumb->adaptiveResize($width, $height)->save(DIR_IMAGE . $new_image); } else { //$ok = $thumb->resize($width, $height)->save(DIR_IMAGE . $new_image); // opencart standart $image = new Image(DIR_IMAGE . $old_image); $image->resize($width, $height); $image->save(DIR_IMAGE . $new_image); $ok = true; } //********* code ************* } else { $ok = copy(DIR_IMAGE . $old_image, DIR_IMAGE . $new_image); } if ($ok) { return $this->getHttpImage() . $new_image; } else { return ''; } } else { return $this->getHttpImage() . $new_image; } }
/** * Returns filename component of path * * @author Lars Knickrehm <*****@*****.**> * @category Library * @copyright Copyright © 2009 Lars Knickrehm * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License * @link http://php.net/manual/function.basename.php * @package UTF-8 * @param string $path A path. Both slash (/) and backslash (\) are used as directory separator character. * @param string $suffix If the filename ends in suffix this will also be cut off. * @return string Base name of the given path * @since Version 0.5.0 * @version 0.5.0 */ function utf8_basename($path, $suffix = '') { // Change backslash (\) to slash (/) $path = utf8_trim(strtr($path, array('\\' => '/')), '/'); // Get basename $i = utf8_strrpos($path, '/'); if ($i !== false) { $path = utf8_substr($path, $i + 1); } // Handle suffix if ($suffix !== '') { $position = utf8_strrpos($path, $suffix); if ($position !== false) { $path = utf8_substr($path, 0, $position); } } return $path; }
/** * * @param filename string * @param width * @param height * @param type char [default, w, h] * default = scale with white space, * w = fill according to width, * h = fill according to height * */ public function resize($filename, $width, $height, $type = "h") { if (!file_exists(DIR_IMAGE . $filename) || !is_file(DIR_IMAGE . $filename)) { return; } if (!$width) { $width = 1; } if (!$height) { $height = 1; } $info = pathinfo($filename); $extension = $info['extension']; $old_image = $filename; $new_image = 'cache/' . utf8_substr($filename, 0, utf8_strrpos($filename, '.')) . '-' . $width . 'x' . $height . $type . '.' . $extension; if (!file_exists(DIR_IMAGE . $new_image) || filemtime(DIR_IMAGE . $old_image) > filemtime(DIR_IMAGE . $new_image)) { $path = ''; $directories = explode('/', dirname(str_replace('../', '', $new_image))); foreach ($directories as $directory) { $path = $path . '/' . $directory; if (!file_exists(DIR_IMAGE . $path)) { @mkdir(DIR_IMAGE . $path, 0777); } } list($width_orig, $height_orig) = getimagesize(DIR_IMAGE . $old_image); if ($width_orig != $width || $height_orig != $height) { $image = new Image(DIR_IMAGE . $old_image); $image->resize($width, $height, $type); if ($width >= 500 || $height >= 500) { $quality = 90; } else { $quality = 75; } $image->save(DIR_IMAGE . $new_image, $quality); } else { copy(DIR_IMAGE . $old_image, DIR_IMAGE . $new_image); } } // Prevent cache-anti-refresh which could show old images return $this->url->link('image/' . $new_image, filemtime(DIR_IMAGE . $new_image)); }
public function resize($filename, $width, $height) { if (!file_exists(DIR_IMAGE . $filename) || !is_file(DIR_IMAGE . $filename)) { return; } $info = pathinfo($filename); $extension = $info['extension']; $old_image = $filename; $new_image = 'cache/' . utf8_substr($filename, 0, utf8_strrpos($filename, '.')) . '-' . $width . 'x' . $height . '.' . $extension; if (!file_exists(DIR_IMAGE . $new_image) || filemtime(DIR_IMAGE . $old_image) > filemtime(DIR_IMAGE . $new_image)) { $path = ''; $directories = explode('/', dirname(str_replace('../', '', $new_image))); foreach ($directories as $directory) { $path = $path . '/' . $directory; if (!file_exists(DIR_IMAGE . $path)) { @mkdir(DIR_IMAGE . $path, 0777); } } list($width_orig, $height_orig) = getimagesize(DIR_IMAGE . $old_image); if ($width_orig != $width || $height_orig != $height) { $image = new Image(DIR_IMAGE . $old_image); $image->resize($width, $height); // tokoonline $watermark_path = str_replace("\\", '/', DIR_IMAGE) . 'watermark.png'; if ($width > 100 || $height > 100 and strpos($old_image, 'banner') === false and file_exists($watermark_path)) { $image->watermark($watermark_path, 'center'); } $image->save(DIR_IMAGE . $new_image); } else { copy(DIR_IMAGE . $old_image, DIR_IMAGE . $new_image); } } if (isset($this->request->server['HTTPS']) && ($this->request->server['HTTPS'] == 'on' || $this->request->server['HTTPS'] == '1')) { return HTTPS_IMAGE . $new_image; } else { return HTTP_IMAGE . $new_image; } }
/** * UTF-8 aware alternative to strrpos * Find position of last occurrence of a char in a string * Note: This will get alot slower if offset is used * Note: requires utf8_substr and utf8_strlen to be loaded * @param string haystack * @param string needle (you should validate this with utf8_is_valid) * @param integer (optional) offset (from left) * @return mixed integer position or FALSE on failure * @see http://www.php.net/strrpos * @see utf8_substr * @see utf8_strlen * @package utf8 * @subpackage strings */ function utf8_strrpos($str, $needle, $offset = NULL) { if (is_null($offset)) { $ar = explode($needle, $str); if (count($ar) > 1) { // Pop off the end of the string where the last match was made array_pop($ar); $str = join($needle, $ar); return utf8_strlen($str); } return FALSE; } else { if (!is_int($offset)) { trigger_error('utf8_strrpos expects parameter 3 to be long', E_USER_WARNING); return FALSE; } $str = utf8_substr($str, $offset); if (FALSE !== ($pos = utf8_strrpos($str, $needle))) { return $pos + $offset; } return FALSE; } }
public function resize($filename, $width, $height) { if (!is_file(DIR_IMAGE . $filename) || substr(str_replace('\\', '/', realpath(DIR_IMAGE . $filename)), 0, strlen(DIR_IMAGE)) != str_replace('\\', '/', DIR_IMAGE)) { return; } $extension = pathinfo($filename, PATHINFO_EXTENSION); $image_old = $filename; $image_new = 'cache/' . utf8_substr($filename, 0, utf8_strrpos($filename, '.')) . '-' . (int) $width . 'x' . (int) $height . '.' . $extension; if (!is_file(DIR_IMAGE . $image_new) || filectime(DIR_IMAGE . $image_old) > filectime(DIR_IMAGE . $image_new)) { list($width_orig, $height_orig, $image_type) = getimagesize(DIR_IMAGE . $image_old); if (!in_array($image_type, array(IMAGETYPE_PNG, IMAGETYPE_JPEG, IMAGETYPE_GIF))) { return DIR_IMAGE . $image_old; } $path = ''; $directories = explode('/', dirname($image_new)); foreach ($directories as $directory) { $path = $path . '/' . $directory; if (!is_dir(DIR_IMAGE . $path)) { @mkdir(DIR_IMAGE . $path, 0777); } } if ($width_orig != $width || $height_orig != $height) { $image = new Image(DIR_IMAGE . $image_old); $image->resize($width, $height); $image->save(DIR_IMAGE . $image_new); } else { copy(DIR_IMAGE . $image_old, DIR_IMAGE . $image_new); } } $image_new = str_replace(' ', '%20', $image_new); // fix bug when attach image on email (gmail.com). it is automatic changing space " " to + if ($this->request->server['HTTPS']) { return $this->config->get('config_ssl') . 'image/' . $image_new; } else { return $this->config->get('config_url') . 'image/' . $image_new; } }
public function expressConfirm() { $this->language->load('payment/pp_express'); $this->language->load('checkout/cart'); $this->load->model('tool/image'); // Coupon if (isset($this->request->post['coupon']) && $this->validateCoupon()) { $this->session->data['coupon'] = $this->request->post['coupon']; $this->session->data['success'] = $this->language->get('text_coupon'); $this->redirect($this->url->link('payment/pp_express/expressConfirm', '', 'SSL')); } // Voucher if (isset($this->request->post['voucher']) && $this->validateVoucher()) { $this->session->data['voucher'] = $this->request->post['voucher']; $this->session->data['success'] = $this->language->get('text_voucher'); $this->redirect($this->url->link('payment/pp_express/expressConfirm', '', 'SSL')); } // Reward if (isset($this->request->post['reward']) && $this->validateReward()) { $this->session->data['reward'] = abs($this->request->post['reward']); $this->session->data['success'] = $this->language->get('text_reward'); $this->redirect($this->url->link('payment/pp_express/expressConfirm', '', 'SSL')); } $this->document->setTitle($this->language->get('express_text_title')); $points = $this->customer->getRewardPoints(); $points_total = 0; foreach ($this->cart->getProducts() as $product) { if ($product['points']) { $points_total += $product['points']; } } $this->data['text_title'] = $this->language->get('express_text_title'); $this->data['text_next'] = $this->language->get('text_next'); $this->data['text_next_choice'] = $this->language->get('text_next_choice'); $this->data['text_use_voucher'] = $this->language->get('text_use_voucher'); $this->data['text_use_coupon'] = $this->language->get('text_use_coupon'); $this->data['text_use_reward'] = sprintf($this->language->get('text_use_reward'), $points); $this->data['button_coupon'] = $this->language->get('button_coupon'); $this->data['button_voucher'] = $this->language->get('button_voucher'); $this->data['button_reward'] = $this->language->get('button_reward'); $this->data['button_shipping'] = $this->language->get('express_button_shipping'); $this->data['entry_coupon'] = $this->language->get('express_entry_coupon'); $this->data['entry_voucher'] = $this->language->get('entry_voucher'); $this->data['entry_reward'] = sprintf($this->language->get('entry_reward'), $points_total); $this->data['button_confirm'] = $this->language->get('express_button_confirm'); $this->data['column_name'] = $this->language->get('column_name'); $this->data['column_model'] = $this->language->get('column_model'); $this->data['column_quantity'] = $this->language->get('column_quantity'); $this->data['column_price'] = $this->language->get('column_price'); $this->data['column_total'] = $this->language->get('column_total'); $this->data['text_until_cancelled'] = $this->language->get('text_until_cancelled'); $this->data['text_trial'] = $this->language->get('text_trial'); $this->data['text_recurring'] = $this->language->get('text_recurring'); $this->data['text_length'] = $this->language->get('text_length'); $this->data['text_recurring_item'] = $this->language->get('text_recurring_item'); $this->data['text_payment_profile'] = $this->language->get('text_payment_profile'); if (isset($this->request->post['next'])) { $this->data['next'] = $this->request->post['next']; } else { $this->data['next'] = ''; } $this->data['coupon_status'] = $this->config->get('coupon_status'); if (isset($this->request->post['coupon'])) { $this->data['coupon'] = $this->request->post['coupon']; } elseif (isset($this->session->data['coupon'])) { $this->data['coupon'] = $this->session->data['coupon']; } else { $this->data['coupon'] = ''; } $this->data['voucher_status'] = $this->config->get('voucher_status'); if (isset($this->request->post['voucher'])) { $this->data['voucher'] = $this->request->post['voucher']; } elseif (isset($this->session->data['voucher'])) { $this->data['voucher'] = $this->session->data['voucher']; } else { $this->data['voucher'] = ''; } $this->data['reward_status'] = $points && $points_total && $this->config->get('reward_status'); if (isset($this->request->post['reward'])) { $this->data['reward'] = $this->request->post['reward']; } elseif (isset($this->session->data['reward'])) { $this->data['reward'] = $this->session->data['reward']; } else { $this->data['reward'] = ''; } $this->data['action'] = $this->url->link('payment/pp_express/expressConfirm', '', 'SSL'); $products = $this->cart->getProducts(); foreach ($products as $product) { $product_total = 0; foreach ($products as $product_2) { if ($product_2['product_id'] == $product['product_id']) { $product_total += $product_2['quantity']; } } if ($product['minimum'] > $product_total) { $this->data['error_warning'] = sprintf($this->language->get('error_minimum'), $product['name'], $product['minimum']); } if ($product['image']) { $image = $this->model_tool_image->resize($product['image'], $this->config->get('config_image_cart_width'), $this->config->get('config_image_cart_height')); } else { $image = ''; } $option_data = array(); foreach ($product['option'] as $option) { if ($option['type'] != 'file') { $value = $option['option_value']; } else { $filename = $this->encryption->decrypt($option['option_value']); $value = utf8_substr($filename, 0, utf8_strrpos($filename, '.')); } $option_data[] = array('name' => $option['name'], 'value' => utf8_strlen($value) > 20 ? utf8_substr($value, 0, 20) . '..' : $value); } // Display prices if ($this->config->get('config_customer_price') && $this->customer->isLogged() || !$this->config->get('config_customer_price')) { $price = $this->currency->format($this->tax->calculate($product['price'], $product['tax_class_id'], $this->config->get('config_tax'))); } else { $price = false; } // Display prices if ($this->config->get('config_customer_price') && $this->customer->isLogged() || !$this->config->get('config_customer_price')) { $total = $this->currency->format($this->tax->calculate($product['price'], $product['tax_class_id'], $this->config->get('config_tax')) * $product['quantity']); } else { $total = false; } $profile_description = ''; if ($product['recurring']) { $frequencies = array('day' => $this->language->get('text_day'), 'week' => $this->language->get('text_week'), 'semi_month' => $this->language->get('text_semi_month'), 'month' => $this->language->get('text_month'), 'year' => $this->language->get('text_year')); if ($product['recurring_trial']) { $recurring_price = $this->currency->format($this->tax->calculate($product['recurring_trial_price'] * $product['quantity'], $product['tax_class_id'], $this->config->get('config_tax'))); $profile_description = sprintf($this->language->get('text_trial_description'), $recurring_price, $product['recurring_trial_cycle'], $frequencies[$product['recurring_trial_frequency']], $product['recurring_trial_duration']) . ' '; } $recurring_price = $this->currency->format($this->tax->calculate($product['recurring_price'] * $product['quantity'], $product['tax_class_id'], $this->config->get('config_tax'))); if ($product['recurring_duration']) { $profile_description .= sprintf($this->language->get('text_payment_description'), $recurring_price, $product['recurring_cycle'], $frequencies[$product['recurring_frequency']], $product['recurring_duration']); } else { $profile_description .= sprintf($this->language->get('text_payment_until_canceled_description'), $recurring_price, $product['recurring_cycle'], $frequencies[$product['recurring_frequency']], $product['recurring_duration']); } } $this->data['products'][] = array('key' => $product['key'], 'thumb' => $image, 'name' => $product['name'], 'model' => $product['model'], 'option' => $option_data, 'quantity' => $product['quantity'], 'stock' => $product['stock'] ? true : !(!$this->config->get('config_stock_checkout') || $this->config->get('config_stock_warning')), 'reward' => $product['reward'] ? sprintf($this->language->get('text_points'), $product['reward']) : '', 'price' => $price, 'total' => $total, 'href' => $this->url->link('product/product', 'product_id=' . $product['product_id']), 'remove' => $this->url->link('checkout/cart', 'remove=' . $product['key']), 'recurring' => $product['recurring'], 'profile_name' => $product['profile_name'], 'profile_description' => $profile_description); } $this->data['vouchers'] = array(); if ($this->cart->hasShipping()) { $this->data['has_shipping'] = true; /** * Shipping services */ if ($this->customer->isLogged()) { $this->load->model('account/address'); $shipping_address = $this->model_account_address->getAddress($this->session->data['shipping_address_id']); } elseif (isset($this->session->data['guest'])) { $shipping_address = $this->session->data['guest']['shipping']; } if (!empty($shipping_address)) { // Shipping Methods $quote_data = array(); $this->load->model('setting/extension'); $results = $this->model_setting_extension->getExtensions('shipping'); if (!empty($results)) { foreach ($results as $result) { if ($this->config->get($result['code'] . '_status')) { $this->load->model('shipping/' . $result['code']); $quote = $this->{'model_shipping_' . $result['code']}->getQuote($shipping_address); if ($quote) { $quote_data[$result['code']] = array('title' => $quote['title'], 'quote' => $quote['quote'], 'sort_order' => $quote['sort_order'], 'error' => $quote['error']); } } } if (!empty($quote_data)) { $sort_order = array(); foreach ($quote_data as $key => $value) { $sort_order[$key] = $value['sort_order']; } array_multisort($sort_order, SORT_ASC, $quote_data); $this->session->data['shipping_methods'] = $quote_data; $this->data['shipping_methods'] = $quote_data; if (!isset($this->session->data['shipping_method'])) { //default the shipping to the very first option. $key1 = key($quote_data); $key2 = key($quote_data[$key1]['quote']); $this->session->data['shipping_method'] = $quote_data[$key1]['quote'][$key2]; } $this->data['code'] = $this->session->data['shipping_method']['code']; $this->data['action_shipping'] = $this->url->link('payment/pp_express/shipping', '', 'SSL'); } else { unset($this->session->data['shipping_methods']); unset($this->session->data['shipping_method']); $this->data['error_no_shipping'] = $this->language->get('error_no_shipping'); } } else { unset($this->session->data['shipping_methods']); unset($this->session->data['shipping_method']); $this->data['error_no_shipping'] = $this->language->get('error_no_shipping'); } } } else { $this->data['has_shipping'] = false; } /** * Product totals */ $this->load->model('setting/extension'); $total_data = array(); $total = 0; $taxes = $this->cart->getTaxes(); // Display prices if ($this->config->get('config_customer_price') && $this->customer->isLogged() || !$this->config->get('config_customer_price')) { $sort_order = array(); $results = $this->model_setting_extension->getExtensions('total'); foreach ($results as $key => $value) { $sort_order[$key] = $this->config->get($value['code'] . '_sort_order'); } array_multisort($sort_order, SORT_ASC, $results); foreach ($results as $result) { if ($this->config->get($result['code'] . '_status')) { $this->load->model('total/' . $result['code']); $this->{'model_total_' . $result['code']}->getTotal($total_data, $total, $taxes); } $sort_order = array(); foreach ($total_data as $key => $value) { $sort_order[$key] = $value['sort_order']; } array_multisort($sort_order, SORT_ASC, $total_data); } } $this->data['totals'] = $total_data; /** * Payment methods */ if ($this->customer->isLogged() && isset($this->session->data['payment_address_id'])) { $this->load->model('account/address'); $payment_address = $this->model_account_address->getAddress($this->session->data['payment_address_id']); } elseif (isset($this->session->data['guest'])) { $payment_address = $this->session->data['guest']['payment']; } $method_data = array(); $this->load->model('setting/extension'); $results = $this->model_setting_extension->getExtensions('payment'); foreach ($results as $result) { if ($this->config->get($result['code'] . '_status')) { $this->load->model('payment/' . $result['code']); $method = $this->{'model_payment_' . $result['code']}->getMethod($payment_address, $total); if ($method) { $method_data[$result['code']] = $method; } } } $sort_order = array(); foreach ($method_data as $key => $value) { $sort_order[$key] = $value['sort_order']; } array_multisort($sort_order, SORT_ASC, $method_data); $this->session->data['payment_methods'] = $method_data; $this->session->data['payment_method'] = $this->session->data['payment_methods']['pp_express']; $this->data['action_confirm'] = $this->url->link('payment/pp_express/expressComplete', '', 'SSL'); $this->data['error_warning'] = ''; $this->data['attention'] = ''; $this->data['success'] = ''; if (isset($this->session->data['error_warning'])) { $this->data['error_warning'] = $this->session->data['error_warning']; unset($this->session->data['error_warning']); } if (isset($this->session->data['success'])) { $this->data['success'] = $this->session->data['success']; unset($this->session->data['success']); } if (isset($this->session->data['attention'])) { $this->data['attention'] = $this->session->data['attention']; unset($this->session->data['attention']); } $this->children = array('common/column_left', 'common/column_right', 'common/content_top', 'common/content_bottom', 'common/footer', 'common/header'); if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/payment/pp_express_confirm.tpl')) { $this->template = $this->config->get('config_template') . '/template/payment/pp_express_confirm.tpl'; } else { $this->template = 'default/template/payment/pp_express_confirm.tpl'; } $this->response->setOutput($this->render()); }
/** * UTF-8 aware alternative to strrpos * Finds position of last occurrence of a string * * @param string $str String being examined. * @param string $search String being searched for. * @param integer $offset Offset from the left of the string. * * @return mixed Number of characters before the last match or false on failure * * @see http://www.php.net/strrpos * @since 11.1 */ public static function strrpos($str, $search, $offset = 0) { return utf8_strrpos($str, $search, $offset); }
public function confirm() { $this->load->model('catalog/product'); $this->load->model('checkout/order'); $this->load->model('account/order'); $this->load->model('tool/image'); $this->language->load('error/not_found'); $this->language->load('order/confirm'); if (isset($this->request->get['order_id'])) { $order_id = (int) $this->encryption->decrypt($this->request->get['order_id']); } else { $order_id = 0; } if (isset($this->request->server['HTTPS']) && ($this->request->server['HTTPS'] == 'on' || $this->request->server['HTTPS'] == '1')) { $this->data['base'] = HTTPS_SERVER; } else { $this->data['base'] = HTTP_SERVER; } $this->data['breadcrumbs'] = array(); $this->data['breadcrumbs'][] = array('text' => $this->language->get('text_home'), 'href' => $this->url->link('common/home'), 'separator' => false); $array_allow_status_id = array(5); $order_info = $this->model_checkout_order->getOrder($order_id); //var_dump($order_info); if ($order_info && in_array($order_info['order_status_id'], $array_allow_status_id)) { //Text $this->data['heading_title'] = sprintf($this->language->get('heading_title'), $order_info['order_id']); $this->data['title'] = $this->language->get('title'); $this->data['title_welcome'] = $this->language->get('title_welcome'); $this->data['text_customer_info'] = $this->language->get('text_customer_info'); $this->data['text_booking_info'] = $this->language->get('text_booking_info'); $this->data['text_customer'] = $this->language->get('text_customer'); $this->data['text_telephone'] = $this->language->get('text_telephone'); $this->data['text_email'] = $this->language->get('text_email'); $this->data['text_address'] = $this->language->get('text_address'); $this->data['text_represent'] = $this->language->get('text_represent'); $this->data['text_website'] = $this->language->get('text_website'); $this->data['text_booking_date'] = $this->language->get('text_booking_date'); $this->data['text_payment_method'] = $this->language->get('text_payment_method'); $this->data['text_website_company'] = $this->language->get('text_website_company'); $this->data['text_duration'] = $this->language->get('text_duration'); $this->data['text_start_time'] = $this->language->get('text_start_time'); $this->data['text_meeting'] = $this->language->get('text_meeting'); $this->data['text_included'] = $this->language->get('text_included'); $this->data['text_notincluded'] = $this->language->get('text_notincluded'); $this->data['text_terms'] = $this->language->get('text_terms'); $this->data['text_notice'] = $this->language->get('text_notice'); $this->data['text_print'] = $this->language->get('text_print'); $this->data['text_pdf'] = $this->language->get('text_pdf'); $this->data['text_home'] = $this->language->get('text_home'); //data $this->data['header'] = html_entity_decode($this->config->get('header_site'), ENT_QUOTES, 'UTF-8'); $this->data['footer'] = html_entity_decode($this->config->get('footer_site'), ENT_QUOTES, 'UTF-8'); $this->data['notice'] = html_entity_decode($this->config->get('notice_site'), ENT_QUOTES, 'UTF-8'); $this->data['customer'] = array('customer_id' => $order_info['customer_id'], 'customer_name' => $order_info['lastname'] . ' ' . $order_info['firstname'], 'telephone' => $order_info['telephone'], 'email' => $order_info['email'], 'address' => $order_info['payment_address_1'] . ' - ' . $order_info['payment_zone'] . ' - ' . $order_info['payment_country']); $this->data['payment_method'] = $order_info['payment_method']; $this->data['date_added'] = date($this->language->get('date_format_short'), strtotime($order_info['date_added'])); $this->data['comment'] = $order_info['comment']; $this->data['products'] = array(); $products = $this->model_account_order->getOrderProducts($order_id); foreach ($products as $product) { $option_data = array(); $options = $this->model_account_order->getOrderOptions($order_id, $product['order_product_id']); foreach ($options as $option) { if ($option['type'] != 'file') { $value = $option['value']; } else { $value = utf8_substr($option['value'], 0, utf8_strrpos($option['value'], '.')); } $option_data[] = array('name' => $option['name'], 'value' => utf8_strlen($value) > 20 ? utf8_substr($value, 0, 20) . '..' : $value, 'type' => $option['type']); } $result = $this->model_catalog_product->getProduct($product['product_id']); if (isset($result['custom_link'])) { $custom_link = '&path=' . $result['custom_link']; } $this->data['products'][] = array('name' => $product['name'], 'model' => $product['model'], 'option' => $option_data, 'quantity' => $product['quantity'], 'duration' => $product['duration'], 'start_time' => $product['start_time'], 'meeting' => $product['meeting'] ? $product['meeting'] : '28/13 Bùi Viện, P.Phạm Ngũ Lão, Q.1, Tp.HCM', 'included' => preg_replace('/(<[^>]+) style=".*?"/i', '$1', strip_tags(html_entity_decode($product['included'], ENT_QUOTES, 'UTF-8'), '<li><a><b><strong><i><u>')), 'notincluded' => preg_replace('/(<[^>]+) style=".*?"/i', '$1', strip_tags(html_entity_decode($product['notincluded'], ENT_QUOTES, 'UTF-8'), '<li><a><b><strong><i><u>')), 'terms' => preg_replace('/(<[^>]+) style=".*?"/i', '$1', strip_tags(html_entity_decode($product['terms'], ENT_QUOTES, 'UTF-8'), '<li><a><b><strong><i><u>')), 'href' => $this->url->link('product/product', $custom_link . '&product_id=' . $product['product_id']), 'price' => $this->currency->format($product['price'] + ($this->config->get('config_tax') ? $product['tax'] : 0), $order_info['currency_code'], $order_info['currency_value']), 'total' => $this->currency->format($product['total'] + ($this->config->get('config_tax') ? $product['tax'] * $product['quantity'] : 0), $order_info['currency_code'], $order_info['currency_value'])); } $this->data['thumb_vf'] = $this->model_tool_image->resize('data/dulichvietvui.png', 170, 170); if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/order/confirm.tpl')) { $this->template = $this->config->get('config_template') . '/template/order/confirm.tpl'; } else { $this->template = 'default/template/product/confirm.tpl'; } $this->response->setOutput($this->render()); } else { $this->data['breadcrumbs'][] = array('text' => $this->language->get('text_error'), 'href' => $this->url->link('error/not_found'), 'separator' => $this->language->get('text_separator')); $this->document->setTitle($this->language->get('text_error')); $this->data['heading_title'] = $this->language->get('text_error'); $this->data['text_error'] = $this->language->get('text_error'); $this->data['button_continue'] = $this->language->get('button_continue'); $this->data['continue'] = $this->url->link('common/home'); $this->response->addHeader($this->request->server['SERVER_PROTOCOL'] . '/1.1 404 Not Found'); if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/error/not_found.tpl')) { $this->template = $this->config->get('config_template') . '/template/error/not_found.tpl'; } else { $this->template = 'default/template/error/not_found.tpl'; } $this->children = array('common/column_left', 'common/column_right', 'common/content_top', 'common/content_bottom', 'common/footer', 'common/header'); $this->response->setOutput($this->render()); } }
/** * Unicode (UTF-8) analogue of standard @link http://php.net/strrpos strrpos PHP function. * Find the position of the last occurrence of a case-sensitive UTF-8 encoded string. * Returns the numeric position (offset in amount of UTF-8 characters) * of the last occurrence of needle in the haystack string. * * @param string $haystack The UTF-8 encoded string being searched in. * @param integer $needle The UTF-8 encoded string being searched for. * @param integer $offset [optional] - The optional offset parameter allows you to specify which character in haystack to start searching. * The position returned is still relative to the beginning of haystack. * @return integer|boolean Returns the position as an integer. If needle is not found, the function will return boolean FALSE. */ public function ustrrpos($haystack, $needle, $offset = 0) { switch ($this->utfAction) { case 0: return strrpos($haystack, $needle, $offset); case 1: return mb_strrpos($haystack, $needle, $offset); } return utf8_strrpos($haystack, $needle, $offset); }
public function index() { $redirect = ''; if ($this->cart->hasShipping()) { // Validate if shipping address has been set. $this->load->model('account/address'); if ($this->customer->isLogged() && isset($this->session->data['shipping_address_id'])) { $shipping_address = $this->model_account_address->getAddress($this->session->data['shipping_address_id']); } elseif (isset($this->session->data['guest'])) { $shipping_address = $this->session->data['guest']['shipping']; } if (empty($shipping_address)) { $redirect = $this->url->link('checkout/checkout', '', 'SSL'); } // Validate if shipping method has been set. if (!isset($this->session->data['shipping_method'])) { $redirect = $this->url->link('checkout/checkout', '', 'SSL'); } } else { unset($this->session->data['shipping_method']); unset($this->session->data['shipping_methods']); } // Validate if payment address has been set. $this->load->model('account/address'); if ($this->customer->isLogged() && isset($this->session->data['payment_address_id'])) { $payment_address = $this->model_account_address->getAddress($this->session->data['payment_address_id']); } elseif (isset($this->session->data['guest'])) { $payment_address = $this->session->data['guest']['payment']; } if (empty($payment_address)) { $redirect = $this->url->link('checkout/checkout', '', 'SSL'); } // Validate if payment method has been set. /*if (!isset($this->session->data['payment_method'])) { $redirect = $this->url->link('checkout/checkout', '', 'SSL'); }*/ // Validate cart has products and has stock. if (!$this->cart->hasProducts() && empty($this->session->data['vouchers']) || !$this->cart->hasStock() && !$this->config->get('config_stock_checkout')) { $redirect = $this->url->link('checkout/cart'); } // Validate minimum quantity requirments. $products = $this->cart->getProducts(); foreach ($products as $product) { $product_total = 0; foreach ($products as $product_2) { if ($product_2['product_id'] == $product['product_id']) { $product_total += $product_2['quantity']; } } if ($product['minimum'] > $product_total) { $redirect = $this->url->link('checkout/cart'); break; } } if (!$redirect) { $total_data = array(); $total = 0; $taxes = $this->cart->getTaxes(); $this->load->model('setting/extension'); $sort_order = array(); $results = $this->model_setting_extension->getExtensions('total'); foreach ($results as $key => $value) { $sort_order[$key] = $this->config->get($value['code'] . '_sort_order'); } array_multisort($sort_order, SORT_ASC, $results); foreach ($results as $result) { if ($this->config->get($result['code'] . '_status')) { $this->load->model('total/' . $result['code']); $this->{'model_total_' . $result['code']}->getTotal($total_data, $total, $taxes); } } $sort_order = array(); foreach ($total_data as $key => $value) { $sort_order[$key] = $value['sort_order']; } array_multisort($sort_order, SORT_ASC, $total_data); $this->language->load('checkout/checkout'); $data = array(); $this->data['button_continue'] = $this->language->get('button_continue'); $data['invoice_prefix'] = $this->config->get('config_invoice_prefix'); $data['store_id'] = $this->config->get('config_store_id'); $data['store_name'] = $this->config->get('config_name'); if ($data['store_id']) { $data['store_url'] = $this->config->get('config_url'); } else { $data['store_url'] = HTTP_SERVER; } if ($this->customer->isLogged()) { $data['customer_id'] = $this->customer->getId(); $data['customer_group_id'] = $this->customer->getCustomerGroupId(); $data['firstname'] = $this->customer->getFirstName(); $data['lastname'] = $this->customer->getLastName(); $data['email'] = $this->customer->getEmail(); $data['telephone'] = $this->customer->getTelephone(); $data['fax'] = $this->customer->getFax(); $this->load->model('account/address'); $payment_address = $this->model_account_address->getAddress($this->session->data['payment_address_id']); } elseif (isset($this->session->data['guest'])) { $data['customer_id'] = 0; $data['customer_group_id'] = $this->session->data['guest']['customer_group_id']; $data['firstname'] = $this->session->data['guest']['firstname']; $data['lastname'] = $this->session->data['guest']['lastname']; $data['email'] = $this->session->data['guest']['email']; $data['telephone'] = $this->session->data['guest']['telephone']; $data['fax'] = $this->session->data['guest']['fax']; $payment_address = $this->session->data['guest']['payment']; } $data['payment_firstname'] = $payment_address['firstname']; $data['payment_lastname'] = $payment_address['lastname']; $data['payment_company'] = $payment_address['company']; $data['payment_company_id'] = $payment_address['company_id']; $data['payment_tax_id'] = $payment_address['tax_id']; $data['payment_address_1'] = $payment_address['address_1']; $data['payment_address_2'] = $payment_address['address_2']; $data['payment_city'] = $payment_address['city']; $data['payment_postcode'] = $payment_address['postcode']; $data['payment_zone'] = $payment_address['zone']; $data['payment_zone_id'] = $payment_address['zone_id']; $data['payment_country'] = $payment_address['country']; $data['payment_country_id'] = $payment_address['country_id']; $data['payment_address_format'] = $payment_address['address_format']; if (isset($this->session->data['payment_method']['title'])) { $data['payment_method'] = $this->session->data['payment_method']['title']; } else { $data['payment_method'] = ''; } if (isset($this->session->data['payment_method']['code'])) { $data['payment_code'] = $this->session->data['payment_method']['code']; } else { $data['payment_code'] = ''; } if ($this->cart->hasShipping()) { if ($this->customer->isLogged()) { $this->load->model('account/address'); $shipping_address = $this->model_account_address->getAddress($this->session->data['shipping_address_id']); } elseif (isset($this->session->data['guest'])) { $shipping_address = $this->session->data['guest']['shipping']; } $data['shipping_firstname'] = $shipping_address['firstname']; $data['shipping_lastname'] = $shipping_address['lastname']; $data['shipping_company'] = $shipping_address['company']; $data['shipping_address_1'] = $shipping_address['address_1']; $data['shipping_address_2'] = $shipping_address['address_2']; $data['shipping_city'] = $shipping_address['city']; $data['shipping_postcode'] = $shipping_address['postcode']; $data['shipping_zone'] = $shipping_address['zone']; $data['shipping_zone_id'] = $shipping_address['zone_id']; $data['shipping_country'] = $shipping_address['country']; $data['shipping_country_id'] = $shipping_address['country_id']; $data['shipping_address_format'] = $shipping_address['address_format']; if (isset($this->session->data['shipping_method']['title'])) { $data['shipping_method'] = $this->session->data['shipping_method']['title']; } else { $data['shipping_method'] = ''; } if (isset($this->session->data['shipping_method']['code'])) { $data['shipping_code'] = $this->session->data['shipping_method']['code']; } else { $data['shipping_code'] = ''; } } else { $data['shipping_firstname'] = ''; $data['shipping_lastname'] = ''; $data['shipping_company'] = ''; $data['shipping_address_1'] = ''; $data['shipping_address_2'] = ''; $data['shipping_city'] = ''; $data['shipping_postcode'] = ''; $data['shipping_zone'] = ''; $data['shipping_zone_id'] = ''; $data['shipping_country'] = ''; $data['shipping_country_id'] = ''; $data['shipping_address_format'] = ''; $data['shipping_method'] = ''; $data['shipping_code'] = ''; } $product_data = array(); foreach ($this->cart->getProducts() as $product) { $option_data = array(); foreach ($product['option'] as $option) { if ($option['type'] != 'file') { if ((double) $option['price']) { $option['option_value'] .= ' ('; if (isset($option['special']) && $option['special'] !== false) { $option['option_value'] .= $option['special_prefix'] . $this->currency->format($this->tax->calculate($option['special'], $product['tax_class_id'], $this->config->get('config_tax'))); } else { $option['option_value'] .= $option['price_prefix'] . $this->currency->format($this->tax->calculate($option['price'], $product['tax_class_id'], $this->config->get('config_tax'))); } $option['option_value'] .= ')'; } $value = $option['option_value']; } else { $value = $this->encryption->decrypt($option['option_value']); } $option_data[] = array('price' => (double) $option['price'] ? $option['price_prefix'] . $this->currency->format($this->tax->calculate($option['price'], $product['tax_class_id'], $this->config->get('config_tax'))) : false, 'special' => isset($option['special']) && $option['special'] !== false ? $option['special_prefix'] . $this->currency->format($this->tax->calculate($option['special'], $product['tax_class_id'], $this->config->get('config_tax'))) : false, 'product_option_id' => $option['product_option_id'], 'product_option_value_id' => $option['product_option_value_id'], 'option_id' => $option['option_id'], 'option_value_id' => $option['option_value_id'], 'name' => $option['name'], 'value' => $value, 'type' => $option['type']); } $product_data[] = array('product_id' => $product['product_id'], 'name' => $product['name'], 'model' => $product['model'], 'option' => $option_data, 'download' => $product['download'], 'quantity' => $product['quantity'], 'subtract' => $product['subtract'], 'price' => $product['price'], 'total' => $product['total'], 'tax' => $this->tax->getTax($product['price'], $product['tax_class_id']), 'reward' => $product['reward']); } // Gift Voucher $voucher_data = array(); if (!empty($this->session->data['vouchers'])) { foreach ($this->session->data['vouchers'] as $voucher) { $voucher_data[] = array('description' => $voucher['description'], 'code' => substr(md5(mt_rand()), 0, 10), 'to_name' => $voucher['to_name'], 'to_email' => $voucher['to_email'], 'from_name' => $voucher['from_name'], 'from_email' => $voucher['from_email'], 'voucher_theme_id' => $voucher['voucher_theme_id'], 'message' => $voucher['message'], 'amount' => $voucher['amount']); } } $data['products'] = $product_data; $data['vouchers'] = $voucher_data; $data['totals'] = $total_data; $data['comment'] = ''; $data['total'] = $total; if (isset($this->request->cookie['tracking'])) { $this->load->model('affiliate/affiliate'); $affiliate_info = $this->model_affiliate_affiliate->getAffiliateByCode($this->request->cookie['tracking']); $subtotal = $this->cart->getSubTotal(); if ($affiliate_info) { $data['affiliate_id'] = $affiliate_info['affiliate_id']; $data['commission'] = $subtotal / 100 * $affiliate_info['commission']; } else { $data['affiliate_id'] = 0; $data['commission'] = 0; } } else { $data['affiliate_id'] = 0; $data['commission'] = 0; } $data['language_id'] = $this->config->get('config_language_id'); $data['currency_id'] = $this->currency->getId(); $data['currency_code'] = $this->currency->getCode(); $data['currency_value'] = $this->currency->getValue($this->currency->getCode()); $data['ip'] = $this->request->server['REMOTE_ADDR']; if (!empty($this->request->server['HTTP_X_FORWARDED_FOR'])) { $data['forwarded_ip'] = $this->request->server['HTTP_X_FORWARDED_FOR']; } elseif (!empty($this->request->server['HTTP_CLIENT_IP'])) { $data['forwarded_ip'] = $this->request->server['HTTP_CLIENT_IP']; } else { $data['forwarded_ip'] = ''; } if (isset($this->request->server['HTTP_USER_AGENT'])) { $data['user_agent'] = $this->request->server['HTTP_USER_AGENT']; } else { $data['user_agent'] = ''; } if (isset($this->request->server['HTTP_ACCEPT_LANGUAGE'])) { $data['accept_language'] = $this->request->server['HTTP_ACCEPT_LANGUAGE']; } else { $data['accept_language'] = ''; } $this->load->model('checkout/order'); $this->session->data['order_id'] = $this->model_checkout_order->addOrder($data); $this->data['column_name'] = $this->language->get('column_name'); $this->data['column_model'] = $this->language->get('column_model'); $this->data['column_quantity'] = $this->language->get('column_quantity'); $this->data['column_price'] = $this->language->get('column_price'); $this->data['column_total'] = $this->language->get('column_total'); $this->data['text_recurring_item'] = $this->language->get('text_recurring_item'); $this->data['text_payment_profile'] = $this->language->get('text_payment_profile'); $this->data['products'] = array(); foreach ($this->cart->getProducts() as $product) { $option_data = array(); foreach ($product['option'] as $option) { if ($option['type'] != 'file') { $value = $option['option_value']; } else { $filename = $this->encryption->decrypt($option['option_value']); $value = utf8_substr($filename, 0, utf8_strrpos($filename, '.')); } $option_data[] = array('price' => (double) $option['price'] ? $option['price_prefix'] . $this->currency->format($this->tax->calculate($option['price'], $product['tax_class_id'], $this->config->get('config_tax'))) : false, 'special' => isset($option['special']) && $option['special'] !== false ? $option['special_prefix'] . $this->currency->format($this->tax->calculate($option['special'], $product['tax_class_id'], $this->config->get('config_tax'))) : false, 'name' => $option['name'], 'value' => utf8_strlen($value) > 20 ? utf8_substr($value, 0, 20) . '..' : $value); } $profile_description = ''; if ($product['recurring']) { $frequencies = array('day' => $this->language->get('text_day'), 'week' => $this->language->get('text_week'), 'semi_month' => $this->language->get('text_semi_month'), 'month' => $this->language->get('text_month'), 'year' => $this->language->get('text_year')); if ($product['recurring_trial']) { $recurring_price = $this->currency->format($this->tax->calculate($product['recurring_trial_price'] * $product['quantity'], $product['tax_class_id'], $this->config->get('config_tax'))); $profile_description = sprintf($this->language->get('text_trial_description'), $recurring_price, $product['recurring_trial_cycle'], $frequencies[$product['recurring_trial_frequency']], $product['recurring_trial_duration']) . ' '; } $recurring_price = $this->currency->format($this->tax->calculate($product['recurring_price'] * $product['quantity'], $product['tax_class_id'], $this->config->get('config_tax'))); if ($product['recurring_duration']) { $profile_description .= sprintf($this->language->get('text_payment_description'), $recurring_price, $product['recurring_cycle'], $frequencies[$product['recurring_frequency']], $product['recurring_duration']); } else { $profile_description .= sprintf($this->language->get('text_payment_until_canceled_description'), $recurring_price, $product['recurring_cycle'], $frequencies[$product['recurring_frequency']], $product['recurring_duration']); } } $this->data['products'][] = array('key' => $product['key'], 'product_id' => $product['product_id'], 'name' => $product['name'], 'model' => $product['model'], 'option' => $option_data, 'quantity' => $product['quantity'], 'subtract' => $product['subtract'], 'price' => $this->currency->format($this->tax->calculate($product['price'], $product['tax_class_id'], $this->config->get('config_tax'))), 'total' => $this->currency->format($this->tax->calculate($product['price'], $product['tax_class_id'], $this->config->get('config_tax')) * $product['quantity']), 'href' => $this->url->link('product/product', 'product_id=' . $product['product_id']), 'recurring' => $product['recurring'], 'profile_name' => $product['profile_name'], 'profile_description' => $profile_description); } // Gift Voucher $this->data['vouchers'] = array(); if (!empty($this->session->data['vouchers'])) { foreach ($this->session->data['vouchers'] as $voucher) { $this->data['vouchers'][] = array('description' => $voucher['description'], 'amount' => $this->currency->format($voucher['amount'])); } } $this->data['totals'] = $total_data; //$this->data['payment'] = $this->getChild('payment/' . $this->session->data['payment_method']['code']); } else { //$this->data['redirect'] = $redirect; } if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/checkout/confirm.tpl')) { $this->template = $this->config->get('config_template') . '/template/checkout/confirm.tpl'; } else { $this->template = 'default/template/checkout/confirm.tpl'; } $this->response->setOutput($this->render()); }
protected function index() { //以下是为了获取购物车信息从cart.php的controller里面拿到的东西 $this->data['productss'] = array(); $productss = $this->cart->getProducts(); foreach ($productss as $product) { $product_total = 0; foreach ($productss as $product_2) { if ($product_2['product_id'] == $product['product_id']) { $product_total += $product_2['quantity']; } } if ($product['minimum'] > $product_total) { $this->data['error_warning'] = sprintf($this->language->get('error_minimum'), $product['name'], $product['minimum']); } if ($product['image']) { //$image = $this->model_tool_image->resize($product['image'], $this->config->get('config_image_cart_width'), $this->config->get('config_image_cart_height')); } else { $image = ''; } $option_data = array(); foreach ($product['option'] as $option) { if ($option['type'] != 'file') { $value = $option['option_value']; } else { $filename = $this->encryption->decrypt($option['option_value']); $value = utf8_substr($filename, 0, utf8_strrpos($filename, '.')); } $option_data[] = array( 'name' => $option['name'], 'value' => (utf8_strlen($value) > 20 ? utf8_substr($value, 0, 20) . '..' : $value) ); } // Display prices if (($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) { $price = $this->currency->format($this->tax->calculate($product['price'], $product['tax_class_id'], $this->config->get('config_tax'))); } else { $price = false; } // Display prices if (($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) { $total = $this->currency->format($this->tax->calculate($product['price'], $product['tax_class_id'], $this->config->get('config_tax')) * $product['quantity']); } else { $total = false; } $this->data['productss'][] = array( 'key' => $product['key'], //'thumb' => $image, 'name' => $product['name'], 'model' => $product['model'], //'option' => $option_data, 'quantity' => $product['quantity'], //'stock' => $product['stock'] ? true : !(!$this->config->get('config_stock_checkout') || $this->config->get('config_stock_warning')), //'reward' => ($product['reward'] ? sprintf($this->language->get('text_points'), $product['reward']) : ''), 'price' => $price, 'total' => $total, //'href' => $this->url->link('product/product', 'product_id=' . $product['product_id']), //'remove' => $this->url->link('checkout/cart', 'remove=' . $product['key']), 'meals' => isset($product['meals']) ? $product['meals'] : '' ); } //购物车信息获取在这里结束 //以下是为了获取总金额 $this->load->model('setting/extension'); $total_data = array(); $total = 0; $taxes = $this->cart->getTaxes(); // Display prices if (($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) { $sort_order = array(); $results = $this->model_setting_extension->getExtensions('total'); foreach ($results as $key => $value) { $sort_order[$key] = $this->config->get($value['code'] . '_sort_order'); } array_multisort($sort_order, SORT_ASC, $results); foreach ($results as $result) { if ($this->config->get($result['code'] . '_status')) { $this->load->model('total/' . $result['code']); $this->{'model_total_' . $result['code']}->getTotal($total_data, $total, $taxes); } $sort_order = array(); foreach ($total_data as $key => $value) { $sort_order[$key] = $value['sort_order']; } array_multisort($sort_order, SORT_ASC, $total_data); } } $this->data['totals'] = $total_data; //总金额获取在这里结束 $this->data['title'] = $this->document->getTitle(); if (isset($this->request->server['HTTPS']) && (($this->request->server['HTTPS'] == 'on') || ($this->request->server['HTTPS'] == '1'))) { $server = $this->config->get('config_ssl'); } else { $server = $this->config->get('config_url'); } $this->data['action'] = $this->url->link('product/search'); $this->data['telephone'] = $this->config->get('config_telephone'); $this->data['base'] = $server; $this->data['description'] = $this->document->getDescription(); $this->data['keywords'] = $this->document->getKeywords(); $this->data['links'] = $this->document->getLinks(); $this->data['styles'] = $this->document->getStyles(); $this->data['scripts'] = $this->document->getScripts(); $this->data['lang'] = $this->language->get('code'); $this->data['direction'] = $this->language->get('direction'); $this->data['google_analytics'] = html_entity_decode($this->config->get('config_google_analytics'), ENT_QUOTES, 'UTF-8'); $this->data['name'] = $this->config->get('config_name'); if ($this->config->get('config_icon') && file_exists(DIR_IMAGE . $this->config->get('config_icon'))) { $this->data['icon'] = $server . 'image/' . $this->config->get('config_icon'); } else { $this->data['icon'] = ''; } if ($this->config->get('config_logo') && file_exists(DIR_IMAGE . $this->config->get('config_logo'))) { $this->data['logo'] = $server . 'image/' . $this->config->get('config_logo'); } else { $this->data['logo'] = ''; } $this->language->load('common/header'); $this->data['text_home'] = $this->language->get('text_home'); $this->data['text_wishlist'] = sprintf($this->language->get('text_wishlist'), (isset($this->session->data['wishlist']) ? count($this->session->data['wishlist']) : 0)); $this->data['text_shopping_cart'] = $this->language->get('text_shopping_cart'); $this->data['text_search'] = $this->language->get('text_search'); $this->data['text_welcome'] = sprintf($this->language->get('text_welcome'), $this->url->link('account/login', '', 'SSL'), $this->url->link('account/register', '', 'SSL')); $this->data['text_logged'] = sprintf($this->language->get('text_logged'), $this->url->link('account/account', '', 'SSL'), $this->customer->getFirstName(), $this->url->link('account/logout', '', 'SSL')); $this->data['text_account'] = $this->language->get('text_account'); $this->data['text_checkout'] = $this->language->get('text_checkout'); $this->data['home'] = $this->url->link('common/home'); $this->data['wishlist'] = $this->url->link('account/wishlist', '', 'SSL'); $this->data['logged'] = $this->customer->isLogged(); $this->data['account'] = $this->url->link('account/account', '', 'SSL'); $this->data['shopping_cart'] = $this->url->link('checkout/cart'); $this->data['checkout'] = $this->url->link('checkout/checkout', '', 'SSL'); // Daniel's robot detector $status = true; if (isset($this->request->server['HTTP_USER_AGENT'])) { $robots = explode("\n", trim($this->config->get('config_robots'))); foreach ($robots as $robot) { if (trim($robot) && strpos($this->request->server['HTTP_USER_AGENT'], trim($robot)) !== false) { $status = false; break; } } } // A dirty hack to try to set a cookie for the multi-store feature $this->load->model('setting/store'); $this->data['stores'] = array(); if ($this->config->get('config_shared') && $status) { $this->data['stores'][] = $server . 'catalog/view/javascript/crossdomain.php?session_id=' . $this->session->getId(); $stores = $this->model_setting_store->getStores(); foreach ($stores as $store) { $this->data['stores'][] = $store['url'] . 'catalog/view/javascript/crossdomain.php?session_id=' . $this->session->getId(); } } //lihf settings $this->load->model('setting/setting'); $this->data['setting'] = $this->model_setting_setting->getSetting('config'); //print_r($this->data['settings']);exit; // Search if (isset($this->request->get['search'])) { $this->data['search'] = $this->request->get['search']; } else { $this->data['search'] = ''; } // Menu $this->load->model('catalog/category'); $this->load->model('catalog/product'); $this->data['categories'] = array(); $categories = $this->model_catalog_category->getCategories(0); foreach ($categories as $category) { if ($category['top']) { // Level 2 $children_data = array(); $children = $this->model_catalog_category->getCategories($category['category_id']); foreach ($children as $child) { $data = array( 'filter_category_id' => $child['category_id'], 'filter_sub_category' => true ); $product_total = $this->model_catalog_product->getTotalProducts($data); $children_data[] = array( 'category_id' => $child['category_id'], 'name' => $child['name'] . ($this->config->get('config_product_count') ? ' (' . $product_total . ')' : ''), 'href' => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id']), 'des' => strip_tags(html_entity_decode($child['description'], ENT_QUOTES, 'UTF-8')), ); } // Level 1 $this->data['categories'][] = array( 'category_id' => $category['category_id'], 'name' => $category['name'], 'children' => $children_data, 'column' => $category['column'] ? $category['column'] : 1, 'href' => $this->url->link('product/category', 'path=' . $category['category_id']) ); } } if (isset($this->session->data['isEmporter'])) { $this->data['isEmporter'] = $this->session->data['isEmporter']; }else{ $this->data['isEmporter'] = false; } //echo "<pre>";print_r($this->data['categories']);echo "</pre>";die; $this->language->load('module/cart'); $this->children = array( 'module/language', //'module/currency', 'module/cart' ); if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/common/header.tpl')) { $this->template = $this->config->get('config_template') . '/template/common/header.tpl'; } else { $this->template = 'default/template/common/header.tpl'; } //$this->render(); //这之下是为了判断当前的catalog的id //下面这一行是为了获取当前的页面的父目录以及子目录的ID //echo $this->request->get['path']; if (isset($this->request->get['path'])) { $this->data['path_number'] = explode('_', (string)$this->request->get['path']); } $this->render(); }
public function resize($filename, $width, $height, $type = "") { if (!file_exists(DIR_IMAGE . $filename) || !is_file(DIR_IMAGE . $filename)) { return; } $info = pathinfo($filename); $extension = $info['extension']; $old_image = $filename; $new_image = 'cache/' . utf8_substr($filename, 0, utf8_strrpos($filename, '.')) . '-' . $width . 'x' . $height . $type . '.' . $extension; if (!file_exists(DIR_IMAGE . $new_image) || filemtime(DIR_IMAGE . $old_image) > filemtime(DIR_IMAGE . $new_image)) { $path = ''; $directories = explode('/', dirname(str_replace('../', '', $new_image))); foreach ($directories as $directory) { $path = $path . '/' . $directory; if (!file_exists(DIR_IMAGE . $path)) { @mkdir(DIR_IMAGE . $path, 0777); } } list($width_orig, $height_orig) = getimagesize(DIR_IMAGE . $old_image); require_once DIR_SYSTEM . 'nitro/config.php'; require_once DIR_SYSTEM . 'nitro/core/core.php'; $nitroPersistence = getNitroPersistence(); if (!empty($nitroPersistence['Nitro']['Enabled']) && $nitroPersistence['Nitro']['Enabled'] == 'yes' && !empty($nitroPersistence['Nitro']['ImageCache']['OverrideCompression']) && $nitroPersistence['Nitro']['ImageCache']['OverrideCompression'] == 'yes') { } if ($width_orig != $width || $height_orig != $height) { $image = new Image(DIR_IMAGE . $old_image); $image->resize($width, $height, $type); $image->save(DIR_IMAGE . $new_image); if (!empty($nitroPersistence['Nitro']['Enabled']) && $nitroPersistence['Nitro']['Enabled'] == 'yes' && !empty($nitroPersistence['Nitro']['PageCache']['Enabled']) && $nitroPersistence['Nitro']['PageCache']['Enabled'] == 'yes' && !empty($nitroPersistence['Nitro']['SmushIt']['OnDemand']) && $nitroPersistence['Nitro']['SmushIt']['OnDemand'] == 'yes' && !(function_exists('areWeInIgnoredUrl') && areWeInIgnoredUrl())) { include_once dirname(DIR_SYSTEM) . DIRECTORY_SEPARATOR . 'assets' . DIRECTORY_SEPARATOR . 'smushit.php'; try { $file = new SmushIt(DIR_IMAGE . $new_image, SmushIt::LOCAL_ORIGIN); // And finaly, replace original file by the compressed version // Sometimes, Smush.it convert files. We don't want that to happen. $src = pathinfo($file->source, PATHINFO_EXTENSION); $dst = pathinfo($file->destination, PATHINFO_EXTENSION); if ($src == $dst and copy($file->destination, DIR_IMAGE . $new_image)) { // Success ! //echo 'Smushed File: '.$source.'<br>'; } } catch (Exception $e) { set_time_limit(30); } } } else { copy(DIR_IMAGE . $old_image, DIR_IMAGE . $new_image); if (!empty($nitroPersistence['Nitro']['Enabled']) && $nitroPersistence['Nitro']['Enabled'] == 'yes' && !empty($nitroPersistence['Nitro']['PageCache']['Enabled']) && $nitroPersistence['Nitro']['PageCache']['Enabled'] == 'yes' && !empty($nitroPersistence['Nitro']['SmushIt']['OnDemand']) && $nitroPersistence['Nitro']['SmushIt']['OnDemand'] == 'yes' && !(function_exists('areWeInIgnoredUrl') && areWeInIgnoredUrl())) { include_once dirname(DIR_SYSTEM) . DIRECTORY_SEPARATOR . 'assets' . DIRECTORY_SEPARATOR . 'smushit.php'; try { $file = new SmushIt(DIR_IMAGE . $new_image, SmushIt::LOCAL_ORIGIN); // And finaly, replace original file by the compressed version // Sometimes, Smush.it convert files. We don't want that to happen. $src = pathinfo($file->source, PATHINFO_EXTENSION); $dst = pathinfo($file->destination, PATHINFO_EXTENSION); if ($src == $dst and copy($file->destination, DIR_IMAGE . $new_image)) { // Success ! //echo 'Smushed File: '.$source.'<br>'; } } catch (Exception $e) { set_time_limit(30); } } } } return $this->getImageUrl($new_image); }
public function infoSMS() { $this->data['active'] = 'order'; $this->load->model('catalog/product'); $this->language->load('account/order'); $this->language->load('account/account'); if (isset($this->request->get['M'])) { $key = giaima($this->request->get['M'], "vietfuntravel"); $order_id = $key; } else { $order_id = 0; } $this->load->model('account/order'); $order_info = $this->model_account_order->getOrderSMS($order_id); if ($order_info) { $this->data['order_info'] = $order_info; $this->document->setTitle($this->language->get('text_order')); $this->data['breadcrumbs'] = array(); $this->data['breadcrumbs'][] = array('text' => $this->language->get('text_home'), 'href' => $this->url->link('common/home'), 'separator' => false); $this->data['breadcrumbs'][] = array('text' => $this->language->get('text_account'), 'href' => $this->url->link('account/account', '', 'SSL'), 'separator' => $this->language->get('text_separator')); $url = ''; if (isset($this->request->get['page'])) { $url .= '&page=' . $this->request->get['page']; } $this->data['breadcrumbs'][] = array('text' => $this->language->get('heading_title'), 'href' => $this->url->link('account/order', $url, 'SSL'), 'separator' => $this->language->get('text_separator')); $this->data['breadcrumbs'][] = array('text' => $this->language->get('text_order'), 'href' => $this->url->link('account/order/info', 'order_id=' . $key . $url, 'SSL'), 'separator' => $this->language->get('text_separator')); $this->data['heading_title'] = $this->language->get('text_order'); $this->data['text_order_detail'] = $this->language->get('text_order_detail'); $this->data['text_invoice_no'] = $this->language->get('text_invoice_no'); $this->data['text_order_id'] = $this->language->get('text_order_id'); $this->data['text_date_added'] = $this->language->get('text_date_added'); $this->data['text_shipping_method'] = $this->language->get('text_shipping_method'); $this->data['text_shipping_address'] = $this->language->get('text_shipping_address'); $this->data['text_payment_method'] = $this->language->get('text_payment_method'); $this->data['text_payment_address'] = $this->language->get('text_payment_address'); $this->data['text_history'] = $this->language->get('text_history'); $this->data['text_comment'] = $this->language->get('text_comment'); $this->data['text_invoice'] = $this->language->get('text_invoice'); $this->data['text_confirm'] = $this->language->get('text_confirm'); $this->data['text_info_order'] = $this->language->get('text_info_order'); $this->data['text_info_customer'] = $this->language->get('text_info_customer'); $this->data['entry_name_customer'] = $this->language->get('entry_name_customer'); $this->data['entry_email'] = $this->language->get('entry_email'); $this->data['entry_telephone'] = $this->language->get('entry_telephone'); $this->data['column_name'] = $this->language->get('column_name'); $this->data['column_model'] = $this->language->get('column_model'); $this->data['column_quantity'] = $this->language->get('column_quantity'); $this->data['column_price'] = $this->language->get('column_price'); $this->data['column_total'] = $this->language->get('column_total'); $this->data['column_action'] = $this->language->get('column_action'); $this->data['column_date_added'] = $this->language->get('column_date_added'); $this->data['column_status'] = $this->language->get('column_status'); $this->data['column_comment'] = $this->language->get('column_comment'); $this->data['button_return'] = $this->language->get('button_return'); $this->data['button_continue'] = $this->language->get('button_continue'); $this->data['text_my_account'] = $this->language->get('text_my_account'); $this->data['text_my_orders'] = $this->language->get('text_my_orders'); $this->data['text_my_newsletter'] = $this->language->get('text_my_newsletter'); $this->data['text_edit'] = $this->language->get('text_edit'); $this->data['text_password'] = $this->language->get('text_password'); $this->data['text_address'] = $this->language->get('text_address'); $this->data['text_order'] = $this->language->get('text_order'); $this->data['text_newsletter'] = $this->language->get('text_newsletter'); $this->data['edit'] = $this->url->link('account/account', '', 'SSL'); $this->data['password'] = $this->url->link('account/password', '', 'SSL'); $this->data['order'] = $this->url->link('account/order', '', 'SSL'); $this->data['return'] = $this->url->link('account/return', '', 'SSL'); $this->data['newsletter'] = $this->url->link('account/newsletter', '', 'SSL'); if ($order_info['invoice_no']) { $this->data['invoice_no'] = $order_info['invoice_prefix'] . $order_info['invoice_no']; } else { $this->data['invoice_no'] = ''; } $this->data['order_id'] = $key; $this->data['date_added'] = date($this->language->get('date_format_short'), strtotime($order_info['date_added'])); if ($order_info['payment_address_format']) { $format = $order_info['payment_address_format']; } else { $format = '{firstname} {lastname}' . "\n" . '{company}' . "\n" . '{address_1}' . "\n" . '{address_2}' . "\n" . '{city} {postcode}' . "\n" . '{zone}' . "\n" . '{country}'; } $find = array('{firstname}', '{lastname}', '{company}', '{address_1}', '{address_2}', '{city}', '{postcode}', '{zone}', '{zone_code}', '{country}'); $replace = array('firstname' => $order_info['payment_firstname'], 'lastname' => $order_info['payment_lastname'], 'company' => $order_info['payment_company'], 'address_1' => $order_info['payment_address_1'], 'address_2' => $order_info['payment_address_2'], 'city' => $order_info['payment_city'], 'postcode' => $order_info['payment_postcode'], 'zone' => $order_info['payment_zone'], 'zone_code' => $order_info['payment_zone_code'], 'country' => $order_info['payment_country']); $this->data['payment_address'] = str_replace(array("\r\n", "\r", "\n"), '<br />', preg_replace(array("/\\s\\s+/", "/\r\r+/", "/\n\n+/"), '<br />', trim(str_replace($find, $replace, $format)))); $this->data['payment_method'] = $order_info['payment_method']; if ($order_info['shipping_address_format']) { $format = $order_info['shipping_address_format']; } else { $format = '{firstname} {lastname}' . "\n" . '{company}' . "\n" . '{address_1}' . "\n" . '{address_2}' . "\n" . '{city} {postcode}' . "\n" . '{zone}' . "\n" . '{country}'; } $find = array('{firstname}', '{lastname}', '{company}', '{address_1}', '{address_2}', '{city}', '{postcode}', '{zone}', '{zone_code}', '{country}'); $replace = array('firstname' => $order_info['shipping_firstname'], 'lastname' => $order_info['shipping_lastname'], 'company' => $order_info['shipping_company'], 'address_1' => $order_info['shipping_address_1'], 'address_2' => $order_info['shipping_address_2'], 'city' => $order_info['shipping_city'], 'postcode' => $order_info['shipping_postcode'], 'zone' => $order_info['shipping_zone'], 'zone_code' => $order_info['shipping_zone_code'], 'country' => $order_info['shipping_country']); $this->data['shipping_address'] = str_replace(array("\r\n", "\r", "\n"), '<br />', preg_replace(array("/\\s\\s+/", "/\r\r+/", "/\n\n+/"), '<br />', trim(str_replace($find, $replace, $format)))); $this->data['shipping_method'] = $order_info['shipping_method']; // $this->data['name_customer'] = $order_info['lastname'] . ' ' . $order_info['firstname']; $this->data['link_invoice'] = '/order/view/invoice' . '?order_id=' . $this->encryption->encrypt($order_info['order_id']); $this->data['link_confirm'] = '/order/view/confirm' . '?order_id=' . $this->encryption->encrypt($order_info['order_id']); //var_dump($order_info); $this->data['products'] = array(); $products = $this->model_account_order->getOrderProducts($key); foreach ($products as $product) { $option_data = array(); $options = $this->model_account_order->getOrderOptions($key, $product['order_product_id']); foreach ($options as $option) { if ($option['type'] != 'file') { $value = $option['value']; } else { $value = utf8_substr($option['value'], 0, utf8_strrpos($option['value'], '.')); } $option_data[] = array('name' => $option['name'], 'value' => utf8_strlen($value) > 20 ? utf8_substr($value, 0, 20) . '..' : $value); } $result = $this->model_catalog_product->getProduct($product['product_id']); if (isset($result['custom_link'])) { $custom_link = '&path=' . $result['custom_link']; } $this->data['products'][] = array('name' => $product['name'], 'model' => $product['model'], 'option' => $option_data, 'quantity' => $product['quantity'], 'href' => $this->url->link('product/product', $custom_link . '&product_id=' . $product['product_id']), 'price' => $this->currency->format($product['price'] + ($this->config->get('config_tax') ? $product['tax'] : 0), $order_info['currency_code'], $order_info['currency_value']), 'total' => $this->currency->format($product['total'] + ($this->config->get('config_tax') ? $product['tax'] * $product['quantity'] : 0), $order_info['currency_code'], $order_info['currency_value']), 'return' => $this->url->link('account/return/insert', 'order_id=' . $order_info['order_id'] . '&product_id=' . $product['product_id'], 'SSL')); } // Voucher $this->data['vouchers'] = array(); $vouchers = $this->model_account_order->getOrderVouchers($key); foreach ($vouchers as $voucher) { $this->data['vouchers'][] = array('description' => $voucher['description'], 'amount' => $this->currency->format($voucher['amount'], $order_info['currency_code'], $order_info['currency_value'])); } $this->data['totals'] = $this->model_account_order->getOrderTotals($key); $this->data['comment'] = $order_info['comment']; $this->data['histories'] = array(); $results = $this->model_account_order->getOrderHistories($key); foreach ($results as $result) { $this->data['histories'][] = array('date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])), 'status' => $result['status'], 'comment' => html_entity_decode($result['comment'], ENT_QUOTES, 'UTF-8')); } $this->data['continue'] = $this->url->link('account/order', '', 'SSL'); if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/account/order_info.tpl')) { $this->template = $this->config->get('config_template') . '/template/account/order_info.tpl'; } else { $this->template = 'default/template/account/order_info.tpl'; } $this->children = array('common/content_top', 'common/content_bottom', 'common/footer', 'common/header'); $this->response->setOutput($this->render()); } else { $this->document->setTitle($this->language->get('text_order')); $this->data['heading_title'] = $this->language->get('text_order'); $this->data['text_error'] = $this->language->get('text_error'); $this->data['button_continue'] = $this->language->get('button_continue'); $this->data['breadcrumbs'] = array(); $this->data['breadcrumbs'][] = array('text' => $this->language->get('text_home'), 'href' => $this->url->link('common/home'), 'separator' => false); $this->data['breadcrumbs'][] = array('text' => $this->language->get('text_account'), 'href' => $this->url->link('account/account', '', 'SSL'), 'separator' => $this->language->get('text_separator')); $this->data['breadcrumbs'][] = array('text' => $this->language->get('heading_title'), 'href' => $this->url->link('account/order', '', 'SSL'), 'separator' => $this->language->get('text_separator')); $this->data['breadcrumbs'][] = array('text' => $this->language->get('text_order'), 'href' => $this->url->link('account/order/info', 'order_id=' . $order_id, 'SSL'), 'separator' => $this->language->get('text_separator')); $this->data['continue'] = $this->url->link('account/order', '', 'SSL'); $this->response->addHeader($this->request->server['SERVER_PROTOCOL'] . '/1.1 404 Not Found'); if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/error/not_found.tpl')) { $this->template = $this->config->get('config_template') . '/template/error/not_found.tpl'; } else { $this->template = 'default/template/error/not_found.tpl'; } $this->children = array('common/column_left', 'common/column_right', 'common/content_top', 'common/content_bottom', 'common/footer', 'common/header'); $this->response->setOutput($this->render()); } }
public function addOrderHistory($order_id, $order_status_id, $comment = '', $notify = false) { $this->event->trigger('pre.order.history.add', $order_id); $order_info = $this->getOrder($order_id); if ($order_info) { // Fraud Detection $this->load->model('account/customer'); $customer_info = $this->model_account_customer->getCustomer($order_info['customer_id']); if ($customer_info && $customer_info['safe']) { $safe = true; } else { $safe = false; } if ($this->config->get('config_fraud_detection')) { $this->load->model('checkout/fraud'); $risk_score = $this->model_checkout_fraud->getFraudScore($order_info); if (!$safe && $risk_score > $this->config->get('config_fraud_score')) { $order_status_id = $this->config->get('config_fraud_status_id'); } } // Ban IP if (!$safe) { $status = false; if ($order_info['customer_id']) { $results = $this->model_account_customer->getIps($order_info['customer_id']); foreach ($results as $result) { if ($this->model_account_customer->isBanIp($result['ip'])) { $status = true; break; } } } else { $status = $this->model_account_customer->isBanIp($order_info['ip']); } if ($status) { $order_status_id = $this->config->get('config_order_status_id'); } } $this->db->query("UPDATE `" . DB_PREFIX . "order` SET order_status_id = '" . (int) $order_status_id . "', date_modified = NOW() WHERE order_id = '" . (int) $order_id . "'"); $this->db->query("INSERT INTO " . DB_PREFIX . "order_history SET order_id = '" . (int) $order_id . "', order_status_id = '" . (int) $order_status_id . "', notify = '" . (int) $notify . "', comment = '" . $this->db->escape($comment) . "', date_added = NOW()"); // If current order status is not processing or complete but new status is processing or complete then commence completing the order if (!in_array($order_info['order_status_id'], array_merge($this->config->get('config_processing_status'), $this->config->get('config_complete_status'))) && in_array($order_status_id, array_merge($this->config->get('config_processing_status'), $this->config->get('config_complete_status')))) { // Stock subtraction $order_product_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_product WHERE order_id = '" . (int) $order_id . "'"); foreach ($order_product_query->rows as $order_product) { $this->db->query("UPDATE " . DB_PREFIX . "product SET quantity = (quantity - " . (int) $order_product['quantity'] . ") WHERE product_id = '" . (int) $order_product['product_id'] . "' AND subtract = '1'"); $order_option_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_option WHERE order_id = '" . (int) $order_id . "' AND order_product_id = '" . (int) $order_product['order_product_id'] . "'"); foreach ($order_option_query->rows as $option) { $this->db->query("UPDATE " . DB_PREFIX . "product_option_value SET quantity = (quantity - " . (int) $order_product['quantity'] . ") WHERE product_option_value_id = '" . (int) $option['product_option_value_id'] . "' AND subtract = '1'"); } } // Redeem coupon, vouchers and reward points $order_total_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "order_total` WHERE order_id = '" . (int) $order_id . "' ORDER BY sort_order ASC"); foreach ($order_total_query->rows as $order_total) { $this->load->model('total/' . $order_total['code']); if (method_exists($this->{'model_total_' . $order_total['code']}, 'confirm')) { $this->{'model_total_' . $order_total['code']}->confirm($order_info, $order_total); } } // Add commission if sale is linked to affiliate referral. if ($order_info['affiliate_id'] && $this->config->get('config_affiliate_auto')) { $this->load->model('affiliate/affiliate'); $this->model_affiliate_affiliate->addTransaction($order_info['affiliate_id'], $order_info['commission'], $order_id); } } // If old order status is the processing or complete status but new status is not then commence restock, and remove coupon, voucher and reward history if (in_array($order_info['order_status_id'], array_merge($this->config->get('config_processing_status'), $this->config->get('config_complete_status'))) && !in_array($order_status_id, array_merge($this->config->get('config_processing_status'), $this->config->get('config_complete_status')))) { // Restock $product_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_product WHERE order_id = '" . (int) $order_id . "'"); foreach ($product_query->rows as $product) { $this->db->query("UPDATE `" . DB_PREFIX . "product` SET quantity = (quantity + " . (int) $product['quantity'] . ") WHERE product_id = '" . (int) $product['product_id'] . "' AND subtract = '1'"); $option_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_option WHERE order_id = '" . (int) $order_id . "' AND order_product_id = '" . (int) $product['order_product_id'] . "'"); foreach ($option_query->rows as $option) { $this->db->query("UPDATE " . DB_PREFIX . "product_option_value SET quantity = (quantity + " . (int) $product['quantity'] . ") WHERE product_option_value_id = '" . (int) $option['product_option_value_id'] . "' AND subtract = '1'"); } } // Remove coupon, vouchers and reward points history $this->load->model('account/order'); $order_total_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "order_total` WHERE order_id = '" . (int) $order_id . "' ORDER BY sort_order ASC"); foreach ($order_total_query->rows as $order_total) { $this->load->model('total/' . $order_total['code']); if (method_exists($this->{'model_total_' . $order_total['code']}, 'unconfirm')) { $this->{'model_total_' . $order_total['code']}->unconfirm($order_id); } } // Remove commission if sale is linked to affiliate referral. if ($order_info['affiliate_id']) { $this->load->model('affiliate/affiliate'); $this->model_affiliate_affiliate->deleteTransaction($order_id); } } $this->cache->delete('product'); // If order status is 0 then becomes greater than 0 send main html email if (!$order_info['order_status_id'] && $order_status_id) { // Check for any downloadable products $download_status = false; $order_product_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_product WHERE order_id = '" . (int) $order_id . "'"); foreach ($order_product_query->rows as $order_product) { // Check if there are any linked downloads $product_download_query = $this->db->query("SELECT COUNT(*) AS total FROM `" . DB_PREFIX . "product_to_download` WHERE product_id = '" . (int) $order_product['product_id'] . "'"); if ($product_download_query->row['total']) { $download_status = true; } } // Load the language for any mails that might be required to be sent out $language = new Language($order_info['language_directory']); $language->load('default'); $language->load('mail/order'); $order_status_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_status WHERE order_status_id = '" . (int) $order_status_id . "' AND language_id = '" . (int) $order_info['language_id'] . "'"); if ($order_status_query->num_rows) { $order_status = $order_status_query->row['name']; } else { $order_status = ''; } $subject = sprintf($language->get('text_new_subject'), $order_info['store_name'], $order_id); // HTML Mail $data = array(); $data['title'] = sprintf($language->get('text_new_subject'), html_entity_decode($order_info['store_name'], ENT_QUOTES, 'UTF-8'), $order_id); $data['text_greeting'] = sprintf($language->get('text_new_greeting'), html_entity_decode($order_info['store_name'], ENT_QUOTES, 'UTF-8')); $data['text_link'] = $language->get('text_new_link'); $data['text_download'] = $language->get('text_new_download'); $data['text_order_detail'] = $language->get('text_new_order_detail'); $data['text_instruction'] = $language->get('text_new_instruction'); $data['text_order_id'] = $language->get('text_new_order_id'); $data['text_date_added'] = $language->get('text_new_date_added'); $data['text_payment_method'] = $language->get('text_new_payment_method'); $data['text_shipping_method'] = $language->get('text_new_shipping_method'); $data['text_email'] = $language->get('text_new_email'); $data['text_telephone'] = $language->get('text_new_telephone'); $data['text_ip'] = $language->get('text_new_ip'); $data['text_order_status'] = $language->get('text_new_order_status'); $data['text_payment_address'] = $language->get('text_new_payment_address'); $data['text_shipping_address'] = $language->get('text_new_shipping_address'); $data['text_product'] = $language->get('text_new_product'); $data['text_model'] = $language->get('text_new_model'); $data['text_quantity'] = $language->get('text_new_quantity'); $data['text_price'] = $language->get('text_new_price'); $data['text_total'] = $language->get('text_new_total'); $data['text_footer'] = $language->get('text_new_footer'); $data['logo'] = $this->config->get('config_url') . 'image/' . $this->config->get('config_logo'); $data['store_name'] = $order_info['store_name']; $data['store_url'] = $order_info['store_url']; $data['customer_id'] = $order_info['customer_id']; $data['link'] = $order_info['store_url'] . 'index.php?route=account/order/info&order_id=' . $order_id; if ($download_status) { $data['download'] = $order_info['store_url'] . 'index.php?route=account/download'; } else { $data['download'] = ''; } $data['order_id'] = $order_id; $data['date_added'] = date($language->get('date_format_short'), strtotime($order_info['date_added'])); $data['payment_method'] = $order_info['payment_method']; $data['shipping_method'] = $order_info['shipping_method']; $data['email'] = $order_info['email']; $data['telephone'] = $order_info['telephone']; $data['ip'] = $order_info['ip']; $data['order_status'] = $order_status; if ($comment && $notify) { $data['comment'] = nl2br($comment); } else { $data['comment'] = ''; } if ($order_info['payment_address_format']) { $format = $order_info['payment_address_format']; } else { $format = '{firstname} {lastname}' . "\n" . '{company}' . "\n" . '{address_1}' . "\n" . '{address_2}' . "\n" . '{city} {postcode}' . "\n" . '{zone}' . "\n" . '{country}'; } $find = array('{firstname}', '{lastname}', '{company}', '{address_1}', '{address_2}', '{city}', '{postcode}', '{zone}', '{zone_code}', '{country}'); $replace = array('firstname' => $order_info['payment_firstname'], 'lastname' => $order_info['payment_lastname'], 'company' => $order_info['payment_company'], 'address_1' => $order_info['payment_address_1'], 'address_2' => $order_info['payment_address_2'], 'city' => $order_info['payment_city'], 'postcode' => $order_info['payment_postcode'], 'zone' => $order_info['payment_zone'], 'zone_code' => $order_info['payment_zone_code'], 'country' => $order_info['payment_country']); $data['payment_address'] = str_replace(array("\r\n", "\r", "\n"), '<br />', preg_replace(array("/\\s\\s+/", "/\r\r+/", "/\n\n+/"), '<br />', trim(str_replace($find, $replace, $format)))); if ($order_info['shipping_address_format']) { $format = $order_info['shipping_address_format']; } else { $format = '{firstname} {lastname}' . "\n" . '{company}' . "\n" . '{address_1}' . "\n" . '{address_2}' . "\n" . '{city} {postcode}' . "\n" . '{zone}' . "\n" . '{country}'; } $find = array('{firstname}', '{lastname}', '{company}', '{address_1}', '{address_2}', '{city}', '{postcode}', '{zone}', '{zone_code}', '{country}'); $replace = array('firstname' => $order_info['shipping_firstname'], 'lastname' => $order_info['shipping_lastname'], 'company' => $order_info['shipping_company'], 'address_1' => $order_info['shipping_address_1'], 'address_2' => $order_info['shipping_address_2'], 'city' => $order_info['shipping_city'], 'postcode' => $order_info['shipping_postcode'], 'zone' => $order_info['shipping_zone'], 'zone_code' => $order_info['shipping_zone_code'], 'country' => $order_info['shipping_country']); $data['shipping_address'] = str_replace(array("\r\n", "\r", "\n"), '<br />', preg_replace(array("/\\s\\s+/", "/\r\r+/", "/\n\n+/"), '<br />', trim(str_replace($find, $replace, $format)))); $this->load->model('tool/upload'); // Products $data['products'] = array(); foreach ($order_product_query->rows as $product) { $option_data = array(); $order_option_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_option WHERE order_id = '" . (int) $order_id . "' AND order_product_id = '" . (int) $product['order_product_id'] . "'"); foreach ($order_option_query->rows as $option) { if ($option['type'] != 'file') { $value = $option['value']; } else { $upload_info = $this->model_tool_upload->getUploadByCode($option['value']); if ($upload_info) { $value = $upload_info['name']; } else { $value = ''; } } $option_data[] = array('name' => $option['name'], 'value' => utf8_strlen($value) > 20 ? utf8_substr($value, 0, 20) . '..' : $value); } $data['products'][] = array('name' => $product['name'], 'model' => $product['model'], 'option' => $option_data, 'quantity' => $product['quantity'], 'price' => $this->currency->format($product['price'] + ($this->config->get('config_tax') ? $product['tax'] : 0), $order_info['currency_code'], $order_info['currency_value']), 'total' => $this->currency->format($product['total'] + ($this->config->get('config_tax') ? $product['tax'] * $product['quantity'] : 0), $order_info['currency_code'], $order_info['currency_value'])); } // Vouchers $data['vouchers'] = array(); $order_voucher_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_voucher WHERE order_id = '" . (int) $order_id . "'"); foreach ($order_voucher_query->rows as $voucher) { $data['vouchers'][] = array('description' => $voucher['description'], 'amount' => $this->currency->format($voucher['amount'], $order_info['currency_code'], $order_info['currency_value'])); } // Order Totals $order_total_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "order_total` WHERE order_id = '" . (int) $order_id . "' ORDER BY sort_order ASC"); foreach ($order_total_query->rows as $total) { $data['totals'][] = array('title' => $total['title'], 'text' => $this->currency->format($total['value'], $order_info['currency_code'], $order_info['currency_value'])); } if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/mail/order.tpl')) { $html = $this->load->view($this->config->get('config_template') . '/template/mail/order.tpl', $data); } else { $html = $this->load->view('default/template/mail/order.tpl', $data); } // Can not send confirmation emails for CBA orders as email is unknown $this->load->model('payment/amazon_checkout'); if (!$this->model_payment_amazon_checkout->isAmazonOrder($order_info['order_id'])) { // Text Mail $text = sprintf($language->get('text_new_greeting'), html_entity_decode($order_info['store_name'], ENT_QUOTES, 'UTF-8')) . "\n\n"; $text .= $language->get('text_new_order_id') . ' ' . $order_id . "\n"; $text .= $language->get('text_new_date_added') . ' ' . date($language->get('date_format_short'), strtotime($order_info['date_added'])) . "\n"; $text .= $language->get('text_new_order_status') . ' ' . $order_status . "\n\n"; if ($comment && $notify) { $text .= $language->get('text_new_instruction') . "\n\n"; $text .= $comment . "\n\n"; } // Products $text .= $language->get('text_new_products') . "\n"; foreach ($order_product_query->rows as $product) { $text .= $product['quantity'] . 'x ' . $product['name'] . ' (' . $product['model'] . ') ' . html_entity_decode($this->currency->format($product['total'] + ($this->config->get('config_tax') ? $product['tax'] * $product['quantity'] : 0), $order_info['currency_code'], $order_info['currency_value']), ENT_NOQUOTES, 'UTF-8') . "\n"; $order_option_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_option WHERE order_id = '" . (int) $order_id . "' AND order_product_id = '" . $product['order_product_id'] . "'"); foreach ($order_option_query->rows as $option) { if ($option['type'] != 'file') { $value = $option['value']; } else { $upload_info = $this->model_tool_upload->getUploadByCode($option['value']); if ($upload_info) { $value = $upload_info['name']; } else { $value = ''; } } $text .= chr(9) . '-' . $option['name'] . ' ' . (utf8_strlen($value) > 20 ? utf8_substr($value, 0, 20) . '..' : $value) . "\n"; } } foreach ($order_voucher_query->rows as $voucher) { $text .= '1x ' . $voucher['description'] . ' ' . $this->currency->format($voucher['amount'], $order_info['currency_code'], $order_info['currency_value']); } $text .= "\n"; $text .= $language->get('text_new_order_total') . "\n"; foreach ($order_total_query->rows as $total) { $text .= $total['title'] . ': ' . html_entity_decode($this->currency->format($total['value'], $order_info['currency_code'], $order_info['currency_value']), ENT_NOQUOTES, 'UTF-8') . "\n"; } $text .= "\n"; if ($order_info['customer_id']) { $text .= $language->get('text_new_link') . "\n"; $text .= $order_info['store_url'] . 'index.php?route=account/order/info&order_id=' . $order_id . "\n\n"; } if ($download_status) { $text .= $language->get('text_new_download') . "\n"; $text .= $order_info['store_url'] . 'index.php?route=account/download' . "\n\n"; } // Comment if ($order_info['comment']) { $text .= $language->get('text_new_comment') . "\n\n"; $text .= $order_info['comment'] . "\n\n"; } $text .= $language->get('text_new_footer') . "\n\n"; $mail = new Mail($this->config->get('config_mail')); $mail->setTo($order_info['email']); $mail->setFrom($this->config->get('config_email')); $mail->setSender($order_info['store_name']); $mail->setSubject($subject); $mail->setHtml($html); $mail->setText($text); $mail->send(); } // Admin Alert Mail if ($this->config->get('config_order_mail')) { $subject = sprintf($language->get('text_new_subject'), html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8'), $order_id); // HTML Mail $data['text_greeting'] = $language->get('text_new_received'); if ($comment) { if ($order_info['comment']) { $data['comment'] = nl2br($comment) . '<br/><br/>' . $order_info['comment']; } else { $data['comment'] = nl2br($comment); } } else { if ($order_info['comment']) { $data['comment'] = $order_info['comment']; } else { $data['comment'] = ''; } } $data['text_download'] = ''; $data['text_footer'] = ''; $data['text_link'] = ''; $data['link'] = ''; $data['download'] = ''; if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/mail/order.tpl')) { $html = $this->load->view($this->config->get('config_template') . '/template/mail/order.tpl', $data); } else { $html = $this->load->view('default/template/mail/order.tpl', $data); } // Text $text = $language->get('text_new_received') . "\n\n"; $text .= $language->get('text_new_order_id') . ' ' . $order_id . "\n"; $text .= $language->get('text_new_date_added') . ' ' . date($language->get('date_format_short'), strtotime($order_info['date_added'])) . "\n"; $text .= $language->get('text_new_order_status') . ' ' . $order_status . "\n\n"; $text .= $language->get('text_new_products') . "\n"; foreach ($order_product_query->rows as $product) { $text .= $product['quantity'] . 'x ' . $product['name'] . ' (' . $product['model'] . ') ' . html_entity_decode($this->currency->format($product['total'] + ($this->config->get('config_tax') ? $product['tax'] * $product['quantity'] : 0), $order_info['currency_code'], $order_info['currency_value']), ENT_NOQUOTES, 'UTF-8') . "\n"; $order_option_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_option WHERE order_id = '" . (int) $order_id . "' AND order_product_id = '" . $product['order_product_id'] . "'"); foreach ($order_option_query->rows as $option) { if ($option['type'] != 'file') { $value = $option['value']; } else { $value = utf8_substr($option['value'], 0, utf8_strrpos($option['value'], '.')); } $text .= chr(9) . '-' . $option['name'] . ' ' . (utf8_strlen($value) > 20 ? utf8_substr($value, 0, 20) . '..' : $value) . "\n"; } } foreach ($order_voucher_query->rows as $voucher) { $text .= '1x ' . $voucher['description'] . ' ' . $this->currency->format($voucher['amount'], $order_info['currency_code'], $order_info['currency_value']); } $text .= "\n"; $text .= $language->get('text_new_order_total') . "\n"; foreach ($order_total_query->rows as $total) { $text .= $total['title'] . ': ' . html_entity_decode($this->currency->format($total['value'], $order_info['currency_code'], $order_info['currency_value']), ENT_NOQUOTES, 'UTF-8') . "\n"; } $text .= "\n"; if ($order_info['comment']) { $text .= $language->get('text_new_comment') . "\n\n"; $text .= $order_info['comment'] . "\n\n"; } $mail = new Mail($this->config->get('config_mail')); $mail->setTo($this->config->get('config_email')); $mail->setFrom($this->config->get('config_email')); $mail->setReplyTo($order_info['email']); $mail->setSender($order_info['store_name']); $mail->setSubject($subject); $mail->setHtml($html); $mail->setText(html_entity_decode($text, ENT_QUOTES, 'UTF-8')); $mail->send(); // Send to additional alert emails $emails = explode(',', $this->config->get('config_mail_alert')); foreach ($emails as $email) { if ($email && preg_match('/^[^\\@]+@.*.[a-z]{2,15}$/i', $email)) { $mail->setTo($email); $mail->send(); } } } } // If order status is not 0 then send update text email if ($order_info['order_status_id'] && $order_status_id) { $language = new Language($order_info['language_directory']); $language->load('default'); $language->load('mail/order'); $subject = sprintf($language->get('text_update_subject'), html_entity_decode($order_info['store_name'], ENT_QUOTES, 'UTF-8'), $order_id); $message = $language->get('text_update_order') . ' ' . $order_id . "\n"; $message .= $language->get('text_update_date_added') . ' ' . date($language->get('date_format_short'), strtotime($order_info['date_added'])) . "\n\n"; $order_status_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_status WHERE order_status_id = '" . (int) $order_status_id . "' AND language_id = '" . (int) $order_info['language_id'] . "'"); if ($order_status_query->num_rows) { $message .= $language->get('text_update_order_status') . "\n\n"; $message .= $order_status_query->row['name'] . "\n\n"; } if ($order_info['customer_id']) { $message .= $language->get('text_update_link') . "\n"; $message .= $order_info['store_url'] . 'index.php?route=account/order/info&order_id=' . $order_id . "\n\n"; } if ($notify && $comment) { $message .= $language->get('text_update_comment') . "\n\n"; $message .= strip_tags($comment) . "\n\n"; } $message .= $language->get('text_update_footer'); $mail = new Mail($this->config->get('config_mail')); $mail->setTo($order_info['email']); $mail->setFrom($this->config->get('config_email')); $mail->setSender($order_info['store_name']); $mail->setSubject($subject); $mail->setText(html_entity_decode($message, ENT_QUOTES, 'UTF-8')); $mail->send(); } // If order status in the complete range create any vouchers that where in the order need to be made available. if (in_array($order_info['order_status_id'], $this->config->get('config_complete_status'))) { // Send out any gift voucher mails $this->load->model('checkout/voucher'); $this->model_checkout_voucher->confirm($order_id); } } $this->event->trigger('post.order.history.add', $order_id); }
public function confirm() { $this->load->language('payment/amazon_login_pay'); $this->load->language('checkout/checkout'); $this->document->setTitle($this->language->get('heading_title')); $this->load->model('extension/extension'); $this->load->model('payment/amazon_login_pay'); // capital L in Amazon cookie name is required, do not alter for coding standards if (!$this->customer->isLogged() || !isset($this->request->cookie['amazon_Login_state_cache'])) { $this->session->data['lpa']['error'] = $this->language->get('error_login'); $this->response->redirect($this->url->link('payment/amazon_login_pay/loginFailure', '', 'SSL')); } if ($this->config->get('amazon_login_pay_minimum_total') > 0 && $this->config->get('amazon_login_pay_minimum_total') > $this->cart->getTotal()) { $this->failure(sprintf($this->language->get('error_minimum'), $this->currency->format($this->config->get('amazon_login_pay_minimum_total')))); } $data['amazon_login_pay_merchant_id'] = $this->config->get('amazon_login_pay_merchant_id'); $data['amazon_login_pay_client_id'] = $this->config->get('amazon_login_pay_client_id'); if ($this->config->get('amazon_login_pay_test') == 'sandbox') { $data['amazon_login_pay_test'] = true; } $amazon_payment_js = $this->model_payment_amazon_login_pay->getWidgetJs(); $this->document->addScript($amazon_payment_js); if (isset($this->session->data['lpa']['AmazonOrderReferenceId'])) { $data['AmazonOrderReferenceId'] = $this->session->data['lpa']['AmazonOrderReferenceId']; } else { $this->failure($this->language->get('error_process_order')); } if (!empty($this->session->data['vouchers']) || !$this->cart->hasProducts() || !$this->cart->hasStock() && !$this->config->get('config_stock_checkout')) { $this->response->redirect($this->url->link('checkout/cart')); } $data['heading_confirm'] = $this->language->get('heading_confirm'); $data['column_name'] = $this->language->get('column_name'); $data['column_model'] = $this->language->get('column_model'); $data['column_quantity'] = $this->language->get('column_quantity'); $data['column_price'] = $this->language->get('column_price'); $data['column_total'] = $this->language->get('column_total'); $data['text_confirm'] = $this->language->get('text_confirm'); $products = $this->cart->getProducts(); foreach ($products as $product) { $product_total = 0; foreach ($products as $product_2) { if ($product_2['product_id'] == $product['product_id']) { $product_total += $product_2['quantity']; } } if ($product['minimum'] > $product_total) { $this->response->redirect($this->url->link('checkout/cart')); } } $total_data = array(); $total = 0; $taxes = $this->cart->getTaxes(); $old_taxes = $taxes; $lpa_tax = array(); $sort_order = array(); if (isset($this->session->data['lpa']['shipping_method'])) { $this->session->data['shipping_method'] = $this->session->data['lpa']['shipping_method']; } else { $this->response->redirect($this->url->link('payment/amazon_login_pay/address', '', 'SSL')); } $results = $this->model_extension_extension->getExtensions('total'); foreach ($results as $key => $value) { if (isset($value['code'])) { $code = $value['code']; } else { $code = $value['key']; } $sort_order[$key] = $this->config->get($code . '_sort_order'); } array_multisort($sort_order, SORT_ASC, $results); foreach ($results as $result) { if (isset($result['code'])) { $code = $result['code']; } else { $code = $result['key']; } if ($this->config->get($code . '_status')) { $this->load->model('total/' . $code); $this->{'model_total_' . $code}->getTotal($total_data, $total, $taxes); if (!empty($total_data[count($total_data) - 1]) && !isset($total_data[count($total_data) - 1]['code'])) { $total_data[count($total_data) - 1]['code'] = $code; } $tax_difference = 0; foreach ($taxes as $tax_id => $value) { if (isset($old_taxes[$tax_id])) { $tax_difference += $value - $old_taxes[$tax_id]; } else { $tax_difference += $value; } } if ($tax_difference != 0) { $lpa_tax[$code] = $tax_difference; } $old_taxes = $taxes; } } $sort_order = array(); foreach ($total_data as $key => $value) { $sort_order[$key] = $value['sort_order']; if (isset($lpa_tax[$value['code']])) { $total_data[$key]['lpa_tax'] = $lpa_tax[$value['code']]; } else { $total_data[$key]['lpa_tax'] = ''; } } array_multisort($sort_order, SORT_ASC, $total_data); $order_data = array(); $order_data['invoice_prefix'] = $this->config->get('config_invoice_prefix'); $order_data['store_id'] = $this->config->get('config_store_id'); $order_data['store_name'] = $this->config->get('config_name'); if ($order_data['store_id']) { $order_data['store_url'] = $this->config->get('config_url'); } else { $order_data['store_url'] = HTTP_SERVER; } $address = $this->session->data['lpa']['address']; $order_data['customer_id'] = $this->customer->getId(); $order_data['customer_group_id'] = $this->customer->getGroupId(); $order_data['firstname'] = $this->customer->getFirstName(); $order_data['lastname'] = $this->customer->getLastName(); $order_data['email'] = $this->customer->getEmail(); $order_data['telephone'] = $address['telephone']; $order_data['fax'] = ''; if (isset($this->session->data['coupon'])) { $this->load->model('checkout/coupon'); $coupon = $this->model_checkout_coupon->getCoupon($this->session->data['coupon']); if ($coupon) { $order_data['coupon_id'] = $coupon['coupon_id']; $order_data['lpa_free_shipping'] = $coupon['shipping']; } else { $order_data['coupon_id'] = 0; $order_data['lpa_free_shipping'] = '0'; } } else { $order_data['coupon_id'] = 0; $order_data['lpa_free_shipping'] = '0'; } $order_data['payment_firstname'] = $this->customer->getFirstName(); $order_data['payment_lastname'] = $this->customer->getLastName(); $order_data['payment_company'] = $address['company']; $order_data['payment_company_id'] = $address['company_id']; $order_data['payment_tax_id'] = $address['tax_id']; $order_data['payment_address_1'] = $address['address_1']; $order_data['payment_address_2'] = $address['address_2']; $order_data['payment_city'] = $address['city']; $order_data['payment_postcode'] = $address['postcode']; $order_data['payment_zone'] = $address['zone']; $order_data['payment_zone_id'] = $address['zone_id']; $order_data['payment_country'] = $address['country']; $order_data['payment_country_id'] = $address['country_id']; $order_data['payment_address_format'] = $address['address_format']; $order_data['payment_method'] = $this->language->get('text_lpa'); $order_data['payment_code'] = 'amazon_login_pay'; $order_data['shipping_firstname'] = $address['firstname']; $order_data['shipping_lastname'] = $address['lastname']; $order_data['shipping_company'] = $address['company']; $order_data['shipping_address_1'] = $address['address_1']; $order_data['shipping_address_2'] = $address['address_2']; $order_data['shipping_city'] = $address['city']; $order_data['shipping_postcode'] = $address['postcode']; $order_data['shipping_zone'] = $address['zone']; $order_data['shipping_zone_id'] = $address['zone_id']; $order_data['shipping_country'] = $address['country']; $order_data['shipping_country_id'] = $address['country_id']; $order_data['shipping_address_format'] = $address['address_format']; $order_data['shipping_method'] = $this->session->data['lpa']['shipping_method']['title']; if (isset($this->session->data['lpa']['shipping_method']['code'])) { $order_data['shipping_code'] = $this->session->data['lpa']['shipping_method']['code']; } else { $order_data['shipping_code'] = ''; } $product_data = array(); foreach ($this->cart->getProducts() as $product) { $option_data = array(); foreach ($product['option'] as $option) { if ($option['type'] != 'file') { $value = $option['value']; } else { $value = $this->encryption->decrypt($option['value']); } $option_data[] = array('product_option_id' => $option['product_option_id'], 'product_option_value_id' => $option['product_option_value_id'], 'option_id' => $option['option_id'], 'option_value_id' => $option['option_value_id'], 'name' => $option['name'], 'value' => $value, 'type' => $option['type']); } $product_data[] = array('product_id' => $product['product_id'], 'name' => $product['name'], 'model' => $product['model'], 'option' => $option_data, 'download' => $product['download'], 'quantity' => $product['quantity'], 'subtract' => $product['subtract'], 'price' => $product['price'], 'total' => $product['total'], 'tax' => $this->tax->getTax($product['price'], $product['tax_class_id']), 'reward' => $product['reward']); } $order_data['products'] = $product_data; $order_data['vouchers'] = array(); $order_data['totals'] = $total_data; $order_data['comment'] = ''; $order_data['total'] = $total; if (isset($this->request->cookie['tracking'])) { $order_data['tracking'] = $this->request->cookie['tracking']; $subtotal = $this->cart->getSubTotal(); $this->load->model('affiliate/affiliate'); $affiliate_info = $this->model_affiliate_affiliate->getAffiliateByCode($this->request->cookie['tracking']); if ($affiliate_info) { $order_data['affiliate_id'] = $affiliate_info['affiliate_id']; $order_data['commission'] = $subtotal / 100 * $affiliate_info['commission']; } else { $order_data['affiliate_id'] = 0; $order_data['commission'] = 0; } $this->load->model('checkout/marketing'); $marketing_info = $this->model_checkout_marketing->getMarketingByCode($this->request->cookie['tracking']); if ($marketing_info) { $order_data['marketing_id'] = $marketing_info['marketing_id']; } else { $order_data['marketing_id'] = 0; } } else { $order_data['affiliate_id'] = 0; $order_data['commission'] = 0; $order_data['marketing_id'] = 0; $order_data['tracking'] = ''; } $order_data['language_id'] = $this->config->get('config_language_id'); $order_data['currency_id'] = $this->currency->getId(); $order_data['currency_code'] = $this->currency->getCode(); $order_data['currency'] = $this->currency->getCode(); $order_data['currency_value'] = $this->currency->getValue($this->currency->getCode()); $order_data['value'] = $this->currency->getValue($this->currency->getCode()); $order_data['ip'] = $this->request->server['REMOTE_ADDR']; if (!empty($this->request->server['HTTP_X_FORWARDED_FOR'])) { $order_data['forwarded_ip'] = $this->request->server['HTTP_X_FORWARDED_FOR']; } elseif (!empty($this->request->server['HTTP_CLIENT_IP'])) { $order_data['forwarded_ip'] = $this->request->server['HTTP_CLIENT_IP']; } else { $order_data['forwarded_ip'] = ''; } if (isset($this->request->server['HTTP_USER_AGENT'])) { $order_data['user_agent'] = $this->request->server['HTTP_USER_AGENT']; } else { $order_data['user_agent'] = ''; } if (isset($this->request->server['HTTP_ACCEPT_LANGUAGE'])) { $order_data['accept_language'] = $this->request->server['HTTP_ACCEPT_LANGUAGE']; } else { $order_data['accept_language'] = ''; } $this->load->model('checkout/order'); $this->session->data['order_id'] = $this->model_checkout_order->addOrder($order_data); $this->model_payment_amazon_login_pay->addTaxesForTotals($this->session->data['order_id'], $total_data); $this->session->data['lpa']['amazon_login_pay_order_id'] = $this->model_payment_amazon_login_pay->setOrderShipping($this->session->data['order_id'], $order_data['lpa_free_shipping']); $data['merchant_id'] = $this->config->get('amazon_login_pay_merchant_id'); $data['process_order'] = $this->url->link('payment/amazon_login_pay/processorder', '', 'SSL'); foreach ($this->cart->getProducts() as $product) { $option_data = array(); foreach ($product['option'] as $option) { if ($option['type'] != 'file') { $value = $option['value']; } else { $filename = $this->encryption->decrypt($option['value']); $value = utf8_substr($filename, 0, utf8_strrpos($filename, '.')); } $option_data[] = array('name' => $option['name'], 'value' => utf8_strlen($value) > 20 ? utf8_substr($value, 0, 20) . '..' : $value); } $data['products'][] = array('product_id' => $product['product_id'], 'name' => $product['name'], 'model' => $product['model'], 'option' => $option_data, 'quantity' => $product['quantity'], 'price' => $this->currency->format($this->tax->calculate($product['price'], $product['tax_class_id'], $this->config->get('config_tax'))), 'total' => $this->currency->format($this->tax->calculate($product['price'], $product['tax_class_id'], $this->config->get('config_tax')) * $product['quantity'])); } $data['vouchers'] = array(); $data['totals'] = array(); foreach ($total_data as $total) { $data['totals'][] = array('title' => $total['title'], 'text' => $this->currency->format($total['value'])); } $data['back'] = $this->url->link('payment/amazon_login_pay/paymentMethod', '', 'SSL'); $data['text_back'] = $this->language->get('text_back'); $data['column_left'] = $this->load->controller('common/column_left'); $data['column_right'] = $this->load->controller('common/column_right'); $data['content_top'] = $this->load->controller('common/content_top'); $data['content_bottom'] = $this->load->controller('common/content_bottom'); $data['footer'] = $this->load->controller('common/footer'); $data['header'] = $this->load->controller('common/header'); if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/payment/amazon_login_pay_confirm.tpl')) { $this->response->setOutput($this->load->view($this->config->get('config_template') . '/template/payment/amazon_login_pay_confirm.tpl', $data)); } else { $this->response->setOutput($this->load->view('default/template/payment/amazon_login_pay_confirm.tpl', $data)); } }
public function hold_cart_select() { $this->load->model('pos/pos'); $row = $this->model_pos_pos->hold_cart_select($_POST['cart_holder_id']); $this->session->data['cart'] = unserialize($row['cart']); $json['products'] = array(); $this->load->library('customer'); $this->customer = new Customer($this->registry); $this->load->library('tax'); // $this->tax = new Tax($this->registry); $this->load->library('pos_cart'); // $this->cart = new Pos_cart($this->registry); foreach ($this->cart->getProducts() as $product) { $option_data = array(); foreach ($product['option'] as $option) { if ($option['type'] != 'file') { $value = $option['option_value']; } else { $filename = $this->encryption->decrypt($option['option_value']); $value = utf8_substr($filename, 0, utf8_strrpos($filename, '.')); } $option_data[] = array('name' => $option['name'], 'value' => utf8_strlen($value) > 20 ? utf8_substr($value, 0, 20) . '..' : $value, 'type' => $option['type']); } // Display prices if ($this->config->get('config_customer_price') && $this->customer->isLogged() || !$this->config->get('config_customer_price')) { $price = $this->currency->format($product['price']); } else { $price = false; } // Display prices if ($this->config->get('config_customer_price') && $this->customer->isLogged() || !$this->config->get('config_customer_price')) { $total = $this->currency->format($this->tax->calculate($product['price'], $product['tax_class_id'], $this->config->get('config_tax')) * $product['quantity']); } else { $total = false; } //tax $a = $product['price'] * $product['quantity']; $b = $this->tax->calculate($product['price'], $product['tax_class_id'], $this->config->get('config_tax')) * $product['quantity']; $tax = $this->currency->format($b - $a); $json['products'][] = array('key' => $product['key'], 'name' => $product['name'], 'model' => $product['model'], 'option' => $option_data, 'quantity' => $product['quantity'], 'price' => $price, 'total' => $total, 'tax' => $tax, 'href' => $this->url->link('product/product', 'product_id=' . $product['product_id'])); } //foreach product in cart generate html // Totals $this->load->model('pos/extension'); $total_data = array(); $total = 0; $taxes = $this->cart->getTaxes(); // Display prices $sort_order = array(); $results = $this->model_pos_extension->getExtensions('total'); foreach ($results as $key => $value) { $sort_order[$key] = $this->config->get($value['code'] . '_sort_order'); } array_multisort($sort_order, SORT_ASC, $results); foreach ($results as $result) { if ($this->config->get($result['code'] . '_status')) { $this->load->model('pos/' . $result['code']); $this->{'model_pos_' . $result['code']}->getTotal($total_data, $total, $taxes); } $sort_order = array(); foreach ($total_data as $key => $value) { $sort_order[$key] = $value['sort_order']; } array_multisort($sort_order, SORT_ASC, $total_data); } $json['total_data'] = $total_data; $json['total'] = $this->currency->format($total); $json['success'] = 'Success: cart restored from hold list.'; echo json_encode($json); }
public function index() { $this->language->load('checkout/cart'); if (!isset($this->session->data['vouchers'])) { $this->session->data['vouchers'] = array(); } // Update if (!empty($this->request->post['quantity'])) { foreach ($this->request->post['quantity'] as $key => $value) { $this->cart->update($key, $value); } unset($this->session->data['shipping_method']); unset($this->session->data['shipping_methods']); unset($this->session->data['payment_method']); unset($this->session->data['payment_methods']); unset($this->session->data['reward']); $this->redirect($this->url->link('checkout/cart')); } // Remove if (isset($this->request->get['remove'])) { $this->cart->remove($this->request->get['remove']); unset($this->session->data['vouchers'][$this->request->get['remove']]); $this->session->data['success'] = $this->language->get('text_remove'); unset($this->session->data['shipping_method']); unset($this->session->data['shipping_methods']); unset($this->session->data['payment_method']); unset($this->session->data['payment_methods']); unset($this->session->data['reward']); $this->redirect($this->url->link('checkout/cart')); } // Coupon if (isset($this->request->post['coupon']) && $this->validateCoupon()) { $this->session->data['coupon'] = $this->request->post['coupon']; $this->session->data['success'] = $this->language->get('text_coupon'); $this->redirect($this->url->link('checkout/cart')); } // Voucher if (isset($this->request->post['voucher']) && $this->validateVoucher()) { $this->session->data['voucher'] = $this->request->post['voucher']; $this->session->data['success'] = $this->language->get('text_voucher'); $this->redirect($this->url->link('checkout/cart')); } // Reward if (isset($this->request->post['reward']) && $this->validateReward()) { $this->session->data['reward'] = abs($this->request->post['reward']); $this->session->data['success'] = $this->language->get('text_reward'); $this->redirect($this->url->link('checkout/cart')); } // Shipping if (isset($this->request->post['shipping_method']) && $this->validateShipping()) { $shipping = explode('.', $this->request->post['shipping_method']); $this->session->data['shipping_method'] = $this->session->data['shipping_methods'][$shipping[0]]['quote'][$shipping[1]]; $this->session->data['success'] = $this->language->get('text_shipping'); $this->redirect($this->url->link('checkout/cart')); } $this->document->setTitle($this->language->get('heading_title')); $this->document->addScript('catalog/view/javascript/jquery/colorbox/jquery.colorbox-min.js'); $this->document->addStyle('catalog/view/javascript/jquery/colorbox/colorbox.css'); $this->data['breadcrumbs'] = array(); $this->data['breadcrumbs'][] = array('href' => $this->url->link('common/home'), 'text' => $this->language->get('text_home'), 'separator' => false); $this->data['breadcrumbs'][] = array('href' => $this->url->link('checkout/cart'), 'text' => $this->language->get('heading_title'), 'separator' => $this->language->get('text_separator')); if ($this->cart->hasProducts() || !empty($this->session->data['vouchers'])) { $points = $this->customer->getRewardPoints(); $points_total = 0; foreach ($this->cart->getProducts() as $product) { if ($product['points']) { $points_total += $product['points']; } } $this->data['heading_title'] = $this->language->get('heading_title'); $this->data['text_next'] = $this->language->get('text_next'); $this->data['text_next_choice'] = $this->language->get('text_next_choice'); $this->data['text_use_coupon'] = $this->language->get('text_use_coupon'); $this->data['text_use_voucher'] = $this->language->get('text_use_voucher'); $this->data['text_use_reward'] = sprintf($this->language->get('text_use_reward'), $points); $this->data['text_shipping_estimate'] = $this->language->get('text_shipping_estimate'); $this->data['text_shipping_detail'] = $this->language->get('text_shipping_detail'); $this->data['text_shipping_method'] = $this->language->get('text_shipping_method'); $this->data['text_select'] = $this->language->get('text_select'); $this->data['text_none'] = $this->language->get('text_none'); $this->data['column_image'] = $this->language->get('column_image'); $this->data['column_name'] = $this->language->get('column_name'); $this->data['column_model'] = $this->language->get('column_model'); $this->data['column_quantity'] = $this->language->get('column_quantity'); $this->data['column_price'] = $this->language->get('column_price'); $this->data['column_total'] = $this->language->get('column_total'); $this->data['entry_coupon'] = $this->language->get('entry_coupon'); $this->data['entry_voucher'] = $this->language->get('entry_voucher'); $this->data['entry_reward'] = sprintf($this->language->get('entry_reward'), $points_total); $this->data['entry_country'] = $this->language->get('entry_country'); $this->data['entry_zone'] = $this->language->get('entry_zone'); $this->data['entry_postcode'] = $this->language->get('entry_postcode'); $this->data['button_update'] = $this->language->get('button_update'); $this->data['button_remove'] = $this->language->get('button_remove'); $this->data['button_coupon'] = $this->language->get('button_coupon'); $this->data['button_voucher'] = $this->language->get('button_voucher'); $this->data['button_reward'] = $this->language->get('button_reward'); $this->data['button_quote'] = $this->language->get('button_quote'); $this->data['button_shipping'] = $this->language->get('button_shipping'); $this->data['button_shopping'] = $this->language->get('button_shopping'); $this->data['button_checkout'] = $this->language->get('button_checkout'); if (isset($this->error['warning'])) { $this->data['error_warning'] = $this->error['warning']; } elseif (!$this->cart->hasStock() && (!$this->config->get('config_stock_checkout') || $this->config->get('config_stock_warning'))) { $this->data['error_warning'] = $this->language->get('error_stock'); } else { $this->data['error_warning'] = ''; } if ($this->config->get('config_customer_price') && !$this->customer->isLogged()) { $this->data['attention'] = sprintf($this->language->get('text_login'), $this->url->link('account/login'), $this->url->link('account/register')); } else { $this->data['attention'] = ''; } if (isset($this->session->data['success'])) { $this->data['success'] = $this->session->data['success']; unset($this->session->data['success']); } else { $this->data['success'] = ''; } $this->data['action'] = $this->url->link('checkout/cart'); if ($this->config->get('config_cart_weight')) { $this->data['weight'] = $this->weight->format($this->cart->getWeight(), $this->config->get('config_weight_class_id'), $this->language->get('decimal_point'), $this->language->get('thousand_point')); } else { $this->data['weight'] = ''; } $this->load->model('tool/image'); $this->data['products'] = array(); $products = $this->cart->getProducts(); foreach ($products as $product) { $product_total = 0; foreach ($products as $product_2) { if ($product_2['product_id'] == $product['product_id']) { $product_total += $product_2['quantity']; } } if ($product['minimum'] > $product_total) { $this->data['error_warning'] = sprintf($this->language->get('error_minimum'), $product['name'], $product['minimum']); } if ($product['image']) { $image = $this->model_tool_image->resize($product['image'], $this->config->get('config_image_cart_width'), $this->config->get('config_image_cart_height')); } else { $image = ''; } $option_data = array(); foreach ($product['option'] as $option) { if ($option['type'] != 'file') { $value = $option['option_value']; } else { $filename = $this->encryption->decrypt($option['option_value']); $value = utf8_substr($filename, 0, utf8_strrpos($filename, '.')); } $option_data[] = array('name' => $option['name'], 'value' => utf8_strlen($value) > 20 ? utf8_substr($value, 0, 20) . '..' : $value); } // Display prices if ($this->config->get('config_customer_price') && $this->customer->isLogged() || !$this->config->get('config_customer_price')) { $price = $this->currency->format($this->tax->calculate($product['price'], $product['tax_class_id'], $this->config->get('config_tax'))); } else { $price = false; } // Display prices if ($this->config->get('config_customer_price') && $this->customer->isLogged() || !$this->config->get('config_customer_price')) { $total = $this->currency->format($this->tax->calculate($product['price'], $product['tax_class_id'], $this->config->get('config_tax')) * $product['quantity']); } else { $total = false; } // New link to Category $bu_href_prod = str_replace('product/product', 'product/category', $this->url->link('product/product', 'product_id=' . $product['product_id'])); $bu_href_prod = str_replace('product_id=' . $product['product_id'], '', $bu_href_prod); $this->data['products'][] = array('key' => $product['key'], 'thumb' => $image, 'name' => $product['name'], 'model' => $product['model'], 'option' => $option_data, 'quantity' => $product['quantity'], 'stock' => $product['stock'] ? true : !(!$this->config->get('config_stock_checkout') || $this->config->get('config_stock_warning')), 'reward' => $product['reward'] ? sprintf($this->language->get('text_points'), $product['reward']) : '', 'price' => $price, 'total' => $total, 'href' => $bu_href_prod, 'remove' => $this->url->link('checkout/cart', 'remove=' . $product['key'])); } // Gift Voucher $this->data['vouchers'] = array(); if (!empty($this->session->data['vouchers'])) { foreach ($this->session->data['vouchers'] as $key => $voucher) { $this->data['vouchers'][] = array('key' => $key, 'description' => $voucher['description'], 'amount' => $this->currency->format($voucher['amount']), 'remove' => $this->url->link('checkout/cart', 'remove=' . $key)); } } if (isset($this->request->post['next'])) { $this->data['next'] = $this->request->post['next']; } else { $this->data['next'] = ''; } $this->data['coupon_status'] = $this->config->get('coupon_status'); if (isset($this->request->post['coupon'])) { $this->data['coupon'] = $this->request->post['coupon']; } elseif (isset($this->session->data['coupon'])) { $this->data['coupon'] = $this->session->data['coupon']; } else { $this->data['coupon'] = ''; } $this->data['voucher_status'] = $this->config->get('voucher_status'); if (isset($this->request->post['voucher'])) { $this->data['voucher'] = $this->request->post['voucher']; } elseif (isset($this->session->data['voucher'])) { $this->data['voucher'] = $this->session->data['voucher']; } else { $this->data['voucher'] = ''; } $this->data['reward_status'] = $points && $points_total && $this->config->get('reward_status'); if (isset($this->request->post['reward'])) { $this->data['reward'] = $this->request->post['reward']; } elseif (isset($this->session->data['reward'])) { $this->data['reward'] = $this->session->data['reward']; } else { $this->data['reward'] = ''; } $this->data['shipping_status'] = $this->config->get('shipping_status') && $this->config->get('shipping_estimator') && $this->cart->hasShipping(); if (isset($this->request->post['country_id'])) { $this->data['country_id'] = $this->request->post['country_id']; } elseif (isset($this->session->data['shipping_country_id'])) { $this->data['country_id'] = $this->session->data['shipping_country_id']; } else { $this->data['country_id'] = $this->config->get('config_country_id'); } $this->load->model('localisation/country'); $this->data['countries'] = $this->model_localisation_country->getCountries(); if (isset($this->request->post['zone_id'])) { $this->data['zone_id'] = $this->request->post['zone_id']; } elseif (isset($this->session->data['shipping_zone_id'])) { $this->data['zone_id'] = $this->session->data['shipping_zone_id']; } else { $this->data['zone_id'] = ''; } if (isset($this->request->post['postcode'])) { $this->data['postcode'] = $this->request->post['postcode']; } elseif (isset($this->session->data['shipping_postcode'])) { $this->data['postcode'] = $this->session->data['shipping_postcode']; } else { $this->data['postcode'] = ''; } if (isset($this->request->post['shipping_method'])) { $this->data['shipping_method'] = $this->request->post['shipping_method']; } elseif (isset($this->session->data['shipping_method'])) { $this->data['shipping_method'] = $this->session->data['shipping_method']['code']; } else { $this->data['shipping_method'] = ''; } // Totals $this->load->model('setting/extension'); $total_data = array(); $total = 0; $taxes = $this->cart->getTaxes(); // Display prices if ($this->config->get('config_customer_price') && $this->customer->isLogged() || !$this->config->get('config_customer_price')) { $sort_order = array(); $results = $this->model_setting_extension->getExtensions('total'); foreach ($results as $key => $value) { $sort_order[$key] = $this->config->get($value['code'] . '_sort_order'); } array_multisort($sort_order, SORT_ASC, $results); foreach ($results as $result) { if ($this->config->get($result['code'] . '_status')) { $this->load->model('total/' . $result['code']); $this->{'model_total_' . $result['code']}->getTotal($total_data, $total, $taxes); } $sort_order = array(); foreach ($total_data as $key => $value) { $sort_order[$key] = $value['sort_order']; } array_multisort($sort_order, SORT_ASC, $total_data); } } $this->data['totals'] = $total_data; $this->data['continue'] = $this->url->link('common/home'); $this->data['checkout'] = $this->url->link('checkout/checkout', '', 'SSL'); if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/checkout/cart.tpl')) { $this->template = $this->config->get('config_template') . '/template/checkout/cart.tpl'; } else { $this->template = 'default/template/checkout/cart.tpl'; } $this->children = array('common/column_left', 'common/column_right', 'common/content_bottom', 'common/content_top', 'common/footer', 'common/header'); $this->response->setOutput($this->render()); } else { $this->data['heading_title'] = $this->language->get('heading_title'); $this->data['text_error'] = $this->language->get('text_empty'); $this->data['button_continue'] = $this->language->get('button_continue'); $this->data['continue'] = $this->url->link('common/home'); unset($this->session->data['success']); if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/error/not_found.tpl')) { $this->template = $this->config->get('config_template') . '/template/error/not_found.tpl'; } else { $this->template = 'default/template/error/not_found.tpl'; } $this->children = array('common/column_left', 'common/column_right', 'common/content_top', 'common/content_bottom', 'common/footer', 'common/header'); $this->response->setOutput($this->render()); } }