OpenCart 🇺🇦

Схема

public mixed confirm ( )

Аргументы

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

Описание

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

Исходный код

$this->load->model('setting/extension');
$this->load->model('account/address');
$this->load->model('payment/amazon_checkout');
$this->load->library('cba');
$this->language->load('checkout/checkout');
$this->language->load('payment/amazon_checkout');

if ($this->config->get('amazon_checkout_mode') == 'sandbox') {
	$amazon_payment_js = 'https://static-eu.payments-amazon.com/cba/js/gb/sandbox/PaymentWidgets.js';
} elseif ($this->config->get('amazon_checkout_mode') == 'live') {
	$amazon_payment_js = 'https://static-eu.payments-amazon.com/cba/js/gb/PaymentWidgets.js';
}

$this->document->addScript($amazon_payment_js);

$this->document->setTitle($this->language->get('heading_title'));

if (!isset($this->session->data['cba']) || !isset($this->session->data['cba']['shipping_method'])) {
	$this->redirect($this->url->link('common/home'));
}

// Validate cart has products and has stock.
if (!empty($this->session->data['vouchers']) || !$this->cart->hasProducts() || (!$this->cart->hasStock() && !$this->config->get('config_stock_checkout'))) {
	$this->redirect($this->url->link('checkout/cart'));
}

$this->data['heading_confirm'] = $this->language->get('heading_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_confirm'] = $this->language->get('text_confirm');

// 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) {
		$this->redirect($this->url->link('checkout/cart'));
	}
}

$total_data = array();
$total = 0;
$taxes = $this->cart->getTaxes();

$old_taxes = $taxes;
$cba_tax = array();

$sort_order = array();

$this->session->data['shipping_method'] = $this->session->data['cba']['shipping_method'];

$results = $this->model_setting_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) {
			$cba_tax[$code] = $tax_difference;
		}

		$old_taxes = $taxes;
	}
}

$sort_order = array();

foreach ($total_data as $key => $value) {
	$sort_order[$key] = $value['sort_order'];

	if (isset($cba_tax[$value['code']])) {
		$total_data[$key]['cba_tax'] = $cba_tax[$value['code']];
	} else {
		$total_data[$key]['cba_tax'] = '';
	}
}

array_multisort($sort_order, SORT_ASC, $total_data);

$data = array();

$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'] = '';
	$data['lastname'] = '';
	$data['email'] = '';
	$data['telephone'] = '';
	$data['fax'] = $this->customer->getFax();
} else {
	$data['customer_id'] = 0;
	$data['customer_group_id'] = $this->config->get('config_customer_group_id');
	$data['firstname'] = '';
	$data['lastname'] = '';
	$data['email'] = '';
	$data['telephone'] = '';
	$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) {
		$data['coupon_id'] = $coupon['coupon_id'];
		$data['cba_free_shipping'] = $coupon['shipping'];
	} else {
		$data['coupon_id'] = 0;
		$data['cba_free_shipping'] = '0';
	}
} else {
	$data['coupon_id'] = 0;
	$data['cba_free_shipping'] = '0';
}

$data['payment_firstname'] = '';
$data['payment_lastname'] = '';
$data['payment_company'] = '';
$data['payment_company_id'] = '';
$data['payment_tax_id'] = '';
$data['payment_address_1'] = '';
$data['payment_address_2'] = '';
$data['payment_city'] = '';
$data['payment_postcode'] = '';
$data['payment_zone'] = '';
$data['payment_zone_id'] = '';
$data['payment_country'] = '';
$data['payment_country_id'] = '';
$data['payment_address_format'] = '';

$data['payment_method'] = $this->language->get('text_cba');
$data['payment_code'] = 'amazon_checkout';

$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'] = $this->session->data['cba']['shipping_method']['title'];

if (isset($this->session->data['cba']['shipping_method']['code'])) {
	$data['shipping_code'] = $this->session->data['cba']['shipping_method']['code'];
} else {
	$data['shipping_code'] = '';
}

$product_data = array();

foreach ($this->cart->getProducts() as $product) {
	$option_data = array();

	foreach ($product['option'] as $option) {
		if (isset($option['type'])) {
			if ($option['type'] != 'file') {
				$value = $option['option_value'];
			} else {
				$value = $this->encryption->decrypt($option['option_value']);
			}
		} else {
			$value = $option['value'];
		}

		$option_data[] = array(
			'product_option_id' => (isset($option['product_option_id']) ? $option['product_option_id'] : ''),
			'product_option_value_id' => $option['product_option_value_id'],
			'option_id' => (isset($option['option_id'])) ? $option['option_id'] : '',
			'option_value_id' => (isset($option['option_value_id'])) ? $option['option_value_id'] : '',
			'name' => $option['name'],
			'value' => $value,
			'type' => (isset($option['type'])) ? $option['type'] : '',
			'prefix' => (isset($option['prefix'])) ? $option['prefix'] : ''
		);
	}


	$product_tax = $this->tax->getTax($product['price'], $product['tax_class_id']);

	if (isset($product['reward'])) {
		$reward = $product['reward'];
	} else {
		$reward = '';
	}

	if (isset($product['subtract'])) {
		$subtract = $product['subtract'];
	} else {
		$subtract = '';
	}

	$product_data[] = array(
		'product_id' => $product['product_id'],
		'name' => $product['name'],
		'model' => $product['model'],
		'option' => $option_data,
		'download' => $product['download'],
		'quantity' => $product['quantity'],
		'subtract' => $subtract,
		'price' => $product['price'],
		'total' => $product['total'],
		'tax' => $product_tax,
		'reward' => $reward,
	);

}

$data['products'] = $product_data;
$data['vouchers'] = array();
$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'] = $this->currency->getCode();
$data['currency_value'] = $this->currency->getValue($this->currency->getCode());
$data['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['cba']['order_id'] = $this->model_checkout_order->addOrder($data);
$this->model_payment_amazon_checkout->addTaxesForTotals($this->session->data['cba']['order_id'], $total_data);

$this->model_payment_amazon_checkout->setOrderShipping($this->session->data['cba']['order_id'], $data['cba_free_shipping']);

$this->data['merchant_id'] = $this->config->get('amazon_checkout_merchant_id');
$this->data['process_order'] = $this->url->link('payment/amazon_checkout/process_order', '', 'SSL');

foreach ($this->cart->getProducts() as $product) {
	$option_data = array();

	foreach ($product['option'] as $option) {

		if (isset($option['type'])) {
			if ($option['type'] != 'file') {
				$value = $option['option_value'];
			} else {
				$filename = $this->encryption->decrypt($option['option_value']);

				$value = utf8_substr($filename, 0, utf8_strrpos($filename, '.'));
			}
		} else {
			$value = $option['value'];
		}

		$option_data[] = array(
			'name' => $option['name'],
			'value' => (utf8_strlen($value) > 20 ? utf8_substr($value, 0, 20) . '..' : $value)
		);
	}

	$this->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']),
	);
}

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

$this->data['totals'] = $total_data;

$this->data['back'] = $this->url->link('payment/amazon_checkout/payment_method', '', 'SSL');
$this->data['text_back'] = $this->language->get('text_back');

if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/payment/amazon_checkout_confirm.tpl')) {
	$this->template = $this->config->get('config_template') . '/template/payment/amazon_checkout_confirm.tpl';
} else {
	$this->template = 'default/template/payment/amazon_checkout_confirm.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(true));