OpenCart 🇺🇦

Схема

public mixed invoice ( )

Аргументы

Аргумент Возможный тип Описание
У метода нет аргументов

Описание

Метод пока еще не документирован.

Исходный код

$this->language->load('sale/order');

$this->data['title'] = $this->language->get('heading_title');

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['direction'] = $this->language->get('direction');
$this->data['language'] = $this->language->get('code');

$this->data['text_invoice'] = $this->language->get('text_invoice');

$this->data['text_order_id'] = $this->language->get('text_order_id');
$this->data['text_invoice_no'] = $this->language->get('text_invoice_no');
$this->data['text_invoice_date'] = $this->language->get('text_invoice_date');
$this->data['text_date_added'] = $this->language->get('text_date_added');
$this->data['text_telephone'] = $this->language->get('text_telephone');
$this->data['text_fax'] = $this->language->get('text_fax');
$this->data['text_to'] = $this->language->get('text_to');
$this->data['text_company_id'] = $this->language->get('text_company_id');
$this->data['text_tax_id'] = $this->language->get('text_tax_id');
$this->data['text_ship_to'] = $this->language->get('text_ship_to');
$this->data['text_payment_method'] = $this->language->get('text_payment_method');
$this->data['text_shipping_method'] = $this->language->get('text_shipping_method');

$this->data['column_product'] = $this->language->get('column_product');
$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_comment'] = $this->language->get('column_comment');

$this->load->model('sale/order');

$this->load->model('setting/setting');

$this->data['orders'] = array();

$orders = array();

if (isset($this->request->post['selected'])) {
	$orders = $this->request->post['selected'];
} elseif (isset($this->request->get['order_id'])) {
	$orders[] = $this->request->get['order_id'];
}

foreach ($orders as $order_id) {
	$order_info = $this->model_sale_order->getOrder($order_id);

	if ($order_info) {
		$store_info = $this->model_setting_setting->getSetting('config', $order_info['store_id']);

		if ($store_info) {
			$store_address = $store_info['config_address'];
			$store_email = $store_info['config_email'];
			$store_telephone = $store_info['config_telephone'];
			$store_fax = $store_info['config_fax'];
		} else {
			$store_address = $this->config->get('config_address');
			$store_email = $this->config->get('config_email');
			$store_telephone = $this->config->get('config_telephone');
			$store_fax = $this->config->get('config_fax');
		}

		if ($order_info['invoice_no']) {
			$invoice_no = $order_info['invoice_prefix'] . $order_info['invoice_no'];
		} else {
			$invoice_no = '';
		}

		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']
		);

		$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))));

		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']
		);

		$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))));

		$product_data = array();

		$products = $this->model_sale_order->getOrderProducts($order_id);

		foreach ($products as $product) {
			$option_data = array();

			$options = $this->model_sale_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' => $value
				);
			}

			$product_data[] = 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'])
			);
		}

		$voucher_data = array();

		$vouchers = $this->model_sale_order->getOrderVouchers($order_id);

		foreach ($vouchers as $voucher) {
			$voucher_data[] = array(
				'description' => $voucher['description'],
				'amount'      => $this->currency->format($voucher['amount'], $order_info['currency_code'], $order_info['currency_value'])
			);
		}

		$total_data = $this->model_sale_order->getOrderTotals($order_id);

		$this->data['orders'][] = array(
			'order_id'	         => $order_id,
			'invoice_no'         => $invoice_no,
			'date_added'         => date($this->language->get('date_format_short'), strtotime($order_info['date_added'])),
			'store_name'         => $order_info['store_name'],
			'store_url'          => rtrim($order_info['store_url'], '/'),
			'store_address'      => nl2br($store_address),
			'store_email'        => $store_email,
			'store_telephone'    => $store_telephone,
			'store_fax'          => $store_fax,
			'email'              => $order_info['email'],
			'telephone'          => $order_info['telephone'],
			'shipping_address'   => $shipping_address,
			'shipping_method'    => $order_info['shipping_method'],
			'payment_address'    => $payment_address,
			'payment_company_id' => $order_info['payment_company_id'],
			'payment_tax_id'     => $order_info['payment_tax_id'],
			'payment_method'     => $order_info['payment_method'],
			'product'            => $product_data,
			'voucher'            => $voucher_data,
			'total'              => $total_data,
			'comment'            => nl2br($order_info['comment'])
		);
	}
}

$this->template = 'sale/order_invoice.tpl';

$this->response->setOutput($this->render());