OpenCart 🇺🇦

Схема

public mixed 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());