<?php
    //<editor-fold desc="Initial vars">
        $temp_data = array();
        $more_oc_2 = version_compare(VERSION, '2.0.0.0', '>=');
        $more_oc_3 =  version_compare(VERSION, '3.0.0.0', '>=');
        $temp_data['more_oc_2'] = $more_oc_2;

        if(version_compare(VERSION, '1.5.6.4', '<='))
        {
            $vars_to_fix = array('shipping', 'payment');
            foreach ($vars_to_fix as $key => $var) {
                if(!array_key_exists('guest', $this->session->data))
                {
                    $this->session->data['guest'] = array(
                        $var => array()
                    );
                }
                if(array_key_exists('guest', $this->session->data) && (!array_key_exists($var, $this->session->data['guest'])))
                {
                    $this->session->data['guest'][$var] = array();
                }
            }
        }
        $this->load->model('extension/module/perfect_one_checkout');
        $logged = $this->customer->isLogged();
        $customer_id = $logged ? $this->customer->getAddressId() : '';

        $this->language_id = $this->config->get('config_language_id');
    //</editor-fold>

    //<editor-fold desc="Load another vars and functionalities">
        $temp_data['poc_phone_mask'] = $this->config->get('poc_phone_mask_'.$this->language_id);
		$temp_data['poc_post_code_mask'] = $this->config->get('poc_post_code_mask_'.$this->language_id);
		$temp_data['poc_same_address'] = $this->session->data['poc']['same_address'] = isset($this->session->data['poc']['same_address']) ? $this->session->data['poc']['same_address'] : $this->config->get('poc_billing_same_address_checked');

		$poc_modals_in_forms = $this->config->get('poc_modals_in_forms');
        $temp_data['poc_modals_in_forms'] = $poc_modals_in_forms;

        $poc_order_comment_required = $this->config->get('poc_order_comment_required');
        $temp_data['poc_order_comment_required'] = $poc_order_comment_required;

        $poc_google_api_address_autocomplete = $this->config->get('poc_google_api_address_autocomplete');
        $temp_data['poc_google_api_address_autocomplete'] = $poc_google_api_address_autocomplete;

		$this->load->model('localisation/country');
		$countries = $this->model_localisation_country->getCountries();
		$this->countries = $this->model_extension_module_perfect_one_checkout->format_to_select($countries, 'country');

		$this->customer_groups = $this->model_extension_module_perfect_one_checkout->get_customer_groups();
		$temp_data['layout_vars'] = $this->model_extension_module_perfect_one_checkout->get_layout_vars();

		$temp_data['poc_cart_weight'] = $this->config->get('config_cart_weight') ? $this->weight->format($this->cart->getWeight(), $this->config->get('config_weight_class_id'), $this->language->get('decimal_point'), $this->language->get('thousand_point')) : '';
        $temp_data['poc_custom_code'] = htmlspecialchars_decode($this->config->get('poc_custom_code'));
        $temp_data['poc_custom_code'] .= array_key_exists('poc_custom_code', $this->session->data) ? $this->session->data['poc_custom_code'] : '';
        unset($this->session->data['poc_custom_code']);

        $poc_layout_identification_panel_cols = $this->config->get('poc_layout_identification_panel_cols');
        $poc_layout_addresses_panel_cols = $this->config->get('poc_layout_addresses_panel_cols');
        $poc_layout_shipping_panel_cols = $this->config->get('poc_layout_shipping_panel_cols');
        $poc_layout_payment_panel_cols = $this->config->get('poc_layout_payment_panel_cols');
        $poc_layout_cart_panel_cols = $this->config->get('poc_layout_cart_panel_cols');
        $poc_layout_confirm_panel_cols = $this->config->get('poc_layout_confirm_panel_cols');

        $temp_data['poc_styles'] = '<style type="text/css">'.$this->model_extension_module_perfect_one_checkout->get_styles().'</style>';

        $vars_to_load = array('poc_steps_status','poc_guest_buy','poc_layout_identification_panel_status','poc_layout_cart_panel_status','poc_layout_identification_panel_cols','poc_layout_addresses_panel_cols','poc_layout_shipping_panel_cols','poc_layout_payment_panel_cols','poc_layout_cart_panel_cols','poc_layout_confirm_panel_cols','poc_hide_uncompleted_panels',);

		foreach ($vars_to_load as $key => $config_key) {
			$temp_data[$config_key] = $this->config->get($config_key);
		}

		$this->default_customer_group_id = $this->config->get('config_customer_group_id');

		$temp_data['poc_confirm_buttons_targets'] = $this->config->get('poc_confirm_buttons_targets');
		$temp_data['poc_popup_form_validations'] = $this->config->get('poc_popup_form_validations') && !$this->config->get('poc_modals_in_forms');

        $temp_data['comment'] = array_key_exists('comment', $this->session->data) ? $this->session->data['comment'] : '';
    //</editor-fold>

    //<editor-fold desc="Geo IP location">
        $exist_shipping_address = array_key_exists('shipping_address', $this->session->data) && !empty($this->session->data['shipping_address']);

        $get_default_country_zone = $this->config->get('poc_address_geo_ip_localization') && !array_key_exists('poc_first_access', $this->session->data) && !$logged;

        if($exist_shipping_address && !array_key_exists('poc_first_access', $this->session->data) && !$logged) {
            $shipping_country_id = array_key_exists('country_id', $this->session->data['shipping_address']) && !empty($this->session->data['shipping_address']['country_id']) ? $this->session->data['shipping_address']['country_id'] : '';
            $shipping_zone_id = array_key_exists('zone_id', $this->session->data['shipping_address']) && !empty($this->session->data['shipping_address']['zone_id']) ? $this->session->data['shipping_address']['zone_id'] : '';
            $this->session->data['shipping_address']['country_id'] = $shipping_country_id;
            $this->session->data['shipping_address']['zone_id'] = $shipping_zone_id;
            $this->session->data['payment_address']['country_id'] = $shipping_country_id;
            $this->session->data['payment_address']['zone_id'] = $shipping_zone_id;
            $this->session->data['guest']['country_id'] = $shipping_country_id;
            $this->session->data['guest']['zone_id'] = $shipping_zone_id;
            $country_id = empty($shipping_country_id) ? $this->config->get('config_country_id') : $shipping_country_id;
        }else if($get_default_country_zone) {
            $ipaddress = '';

            if (getenv('HTTP_CLIENT_IP'))
                $ipaddress = getenv('HTTP_CLIENT_IP');
            else if(getenv('HTTP_X_FORWARDED_FOR'))
                $ipaddress = getenv('HTTP_X_FORWARDED_FOR');
            else if(getenv('HTTP_X_FORWARDED'))
                $ipaddress = getenv('HTTP_X_FORWARDED');
            else if(getenv('HTTP_FORWARDED_FOR'))
                $ipaddress = getenv('HTTP_FORWARDED_FOR');
            else if(getenv('HTTP_FORWARDED'))
               $ipaddress = getenv('HTTP_FORWARDED');
            else if(getenv('REMOTE_ADDR'))
                $ipaddress = getenv('REMOTE_ADDR');
            else
                $ipaddress = 'UNKNOWN';

            $geo_location = file_get_contents('http://www.geoplugin.net/php.gp?ip='.$ipaddress);
            $geo_location = unserialize($geo_location);

            if(array_key_exists('geoplugin_countryCode', $geo_location)) {
                $country_id = $this->model_extension_module_perfect_one_checkout->_get_country_id($geo_location['geoplugin_countryName'], $geo_location['geoplugin_countryCode']);
            }
            if(!empty($country_id) && array_key_exists('geoplugin_regionCode', $geo_location)) {
                $zone_id = $this->model_extension_module_perfect_one_checkout->_get_zone_id($country_id, $geo_location['geoplugin_regionName'], $geo_location['geoplugin_regionCode']);
            } else {
                $zone_id = '';
            }

            if(empty($country_id)) {
                $country_id = $this->config->get('config_country_id');
            }
            if(empty($zone_id) && !empty($country_id)) {
                $zone_id = $this->model_extension_module_perfect_one_checkout->_get_first_zone_id($country_id);
            }
            if(!empty($country_id)) {
                $this->session->data['payment_address']['country_id'] = $country_id;
                $this->session->data['payment_address']['zone_id'] = $zone_id;
                $this->session->data['shipping_address']['country_id'] = isset($shipping_country_id) && !empty($shipping_country_id) ? $shipping_country_id : $country_id;
                $this->session->data['shipping_address']['zone_id'] = isset($shipping_zone_id) && !empty($shipping_zone_id) ? $shipping_zone_id : $zone_id;
                $this->session->data['guest']['country_id'] = isset($shipping_country_id) && !empty($shipping_country_id) ? $shipping_country_id : $country_id;
                $this->session->data['guest']['zone_id'] = isset($shipping_zone_id) && !empty($shipping_zone_id) ? $shipping_zone_id : $zone_id;
            }
        } else {
            $country_id = $this->config->get('config_country_id');
        }

        $this->default_country_id = $country_id;
        $this->default_zone_id = isset($zone_id) ? $zone_id : '';

        $country_query = $this->db->query('SELECT * FROM '.DB_PREFIX.'country WHERE country_id = '.$this->default_country_id);
        $iso_code_2 = !empty($country_query->row['iso_code_2']) ? $country_query->row['iso_code_2'] : '';
        $this->session->data['payment_address']['iso_code_2'] = $iso_code_2;
        $this->session->data['shipping_address']['iso_code_2'] = $iso_code_2;
        $this->session->data['guest']['iso_code_2'] = $iso_code_2;
    //</editor-fold>

    //<editor-fold desc="Get countries and zones">
        $this->load->model('localisation/zone');
		$zones = $this->model_localisation_zone->getZonesByCountryId($this->default_country_id);

		if($get_default_country_zone) {
		    $this->session->data['poc_first_access'] = true;
		    if(!empty($zones) && empty($this->default_zone_id)) {
		        $default_zone_id = $zones[0]['zone_id'];
		        $this->session->data['payment_address']['zone_id'] = $default_zone_id;
                $this->session->data['shipping_address']['zone_id'] = $default_zone_id;
                $this->session->data['guest']['zone_id'] = $default_zone_id;
            }
        }
		$this->zones = $this->model_extension_module_perfect_one_checkout->format_to_select($zones, 'zone');

		//Billing countries and zones
			if(!empty($this->session->data['guest']['country_id']) || !empty($this->session->data['payment_address']['country_id']))
			{
				$zones = $this->model_localisation_zone->getZonesByCountryId(!empty($this->session->data['guest']['country_id']) ? $this->session->data['guest']['country_id'] : $this->session->data['payment_address']['country_id']);

				$zones_billing = $this->model_extension_module_perfect_one_checkout->format_to_select($zones, 'zone');
				if(empty($zones_billing))
					$zones_billing = array(
						0 => $this->session->data['poc']['lang']['addresses_none_state']
					);
			}
			else
				$zones_billing = $this->zones;

			$this->zones_billing = $zones_billing;
			$this->countries_billing = $this->countries;
		//END

        if(!$this->customer->isLogged())
        {
            if(empty($temp_data['poc_same_address']))
                $shipping_address = !empty($this->session->data['shipping_address']) ? $this->session->data['shipping_address'] : array();
            else
                $shipping_address = !empty($this->session->data['guest']) ? $this->session->data['guest'] : array();
        }
        else
            $shipping_address = !empty($this->session->data['shipping_address']) ? $this->session->data['shipping_address'] : array();

        if(!empty($shipping_address['country_id']))
        {
            $zones = $this->model_localisation_zone->getZonesByCountryId($shipping_address['country_id']);
            $zones_delivery = $this->model_extension_module_perfect_one_checkout->format_to_select($zones, 'zone');

            if(empty($zones_delivery))
            {
                $zones_delivery = array(
                    0 => $this->session->data['poc']['lang']['addresses_none_state']
                );
            }
        }
        else
            $zones_delivery = $this->zones;

        if(!$logged && !isset($this->request->data['shipping_address']))
            $this->session->data['shipping_address'] = $shipping_address;

        if(!$more_oc_2 && !empty($shipping_address['address_id']))
            $this->session->data['shipping_address_id'] = $shipping_address['address_id'];

        $this->zones_delivery = $zones_delivery;
        $this->countries_delivery = $this->countries;
    //</editor-fold>

    //<editor-fold desc="Load languages">
        $lang = $this->config->get('poc_lang');

		$final_lang = array();

		foreach ($lang['lang'] as $lang_name => $langs) {
			$final_lang[$lang_name] = $langs[$this->language_id];
		}

		$this->session->data['poc']['lang'] = $final_lang;

		$array_lang = array(
			'identification_title',
			'identification_icon',
			'identification_button_login',
			'identification_button_register',
			'identification_button_guest',
			'identification_welcome',
			'identification_forgotten_password',
			'identification_modal_login_heading',
			'identification_modal_login_email',
			'identification_modal_login_error_email',
			'identification_modal_login_password',
			'identification_modal_login_error_password',
			'identification_error_login',
			'identification_error_attemps',
			'identification_button_accept',
			'identification_button_cancel',

			'identification_modal_register_heading',
			'identification_modal_register_button_accept',
			'identification_modal_register_button_cancel',

			'sign_in_main_title',
			'sign_in_success_title',
			'sign_in_google_icon',
            'sign_in_google_text',

			'sign_in_facebook_icon',
            'sign_in_facebook_text',

			'sign_in_paypal_icon',
            'sign_in_paypal_text',

			'sign_in_linkedin_icon',
            'sign_in_linkedin_text',

			'addresses_title',
			'addresses_icon',
			'addresses_button_billing_address',
			'addresses_button_billing_address_icon',
			'addresses_button_delivery_address',
			'addresses_button_delivery_address_icon',
			'addresses_button_delivery_billing_address',
			'addresses_button_delivery_billing_address_icon',
			'addresses_same_address',
			'addresses_button_add_new_address_text',
			'addresses_billing_address_selector_title',
			'addresses_delivery_address_selector_title',
			'addresses_none_state',
			'addresses_not_addresses',

			'addresses_modal_billing_address_title',
			'addresses_modal_billing_address_button_accept',
			'addresses_modal_billing_address_button_cancel',

			'addresses_modal_delivery_address_title',
			'addresses_modal_delivery_address_button_accept',
			'addresses_modal_delivery_address_button_cancel',

			'addresses_modal_delivery_billing_address_title',

			'shipping_title',
			'shipping_icon',

			'payment_title',
			'payment_icon',

			'cart_title',
			'cart_icon',
			'cart_thead_image',
			'cart_thead_name',
			'cart_thead_quantity',
			'cart_thead_price',
			'cart_thead_total',
			'cart_insert_coupon',
			'cart_coupon_icon',
			'cart_insert_gift',
			'cart_gift_icon',
			'cart_insert_reward',
			'cart_reward_icon',
			'cart_out_stock_error',
			'cart_minimum_error',
			'cart_coupon_success',
            'cart_gift_success',
            'cart_reward_success',

			'confirm_title',
			'confirm_icon',
			'confirm_icon_help',
			'confirm_comments',
			'confirm_comments_error',
			'confirm_checkbox_terms',
			'confirm_checkbox_terms_error',
			'confirm_button',
			'confirm_error',
			'confirm_error_billing',
            'confirm_error_shipping',
            'confirm_error_shipping_method',
            'confirm_error_payment_method',
            'confirm_error_panel_confirm',
            'confirm_error_register',
			'confirm_error_show_errors',
            'confirm_register_button',

			'steps_identification_title',
			'steps_identification_subtitle',
			'steps_identification_icon',
			'steps_addresses_title',
			'steps_addresses_subtitle',
			'steps_addresses_icon',
			'steps_shipping_title',
			'steps_shipping_subtitle',
			'steps_shipping_icon',
			'steps_payment_title',
			'steps_payment_subtitle',
			'steps_payment_icon',
			'steps_confirm_title',
			'steps_confirm_subtitle',
			'steps_confirm_icon',
		);

		foreach ($array_lang as $key => $value) {
			$temp_data[$value] = !empty($this->session->data['poc']['lang'][$value]) ? $this->session->data['poc']['lang'][$value] : '';
		}

		//Devman Extensions - info@devmanextensions.com - 11/12/17 9:22 - HTML Compatibility in heading panel
            foreach ($temp_data as $key => $value) {
                if(in_array($key, array('identification_title', 'addresses_title', 'shipping_title', 'payment_title', 'cart_title', 'confirm_title')))
                    $temp_data[$key] = html_entity_decode($value);
            }
        //END
    //</editor-fold>

    //<editor-fold desc="Sign-In socials">
        $temp_data['some_sign_in'] = false;
		if($this->config->get('poc_sign_in_google_status') && $this->config->get('poc_sign_in_google_client_id'))
        {
            $temp_data['some_sign_in'] = true;
            $temp_data['poc_sign_in_google'] = true;
            $temp_data['poc_sign_in_google_client_id'] = $this->config->get('poc_sign_in_google_client_id');

            if(!empty($temp_data['sign_in_google_icon']))
                $temp_data['sign_in_google_icon'] = $this->config->get('poc_design_icons') == 'typicons' ? '<span class="typcn typcn-'.$temp_data['sign_in_google_icon'].'"></span>' : '<i class="fa fa-'.$temp_data['sign_in_google_icon'].'"></i>';

            $this->document->addScript('https://apis.google.com/js/api:client.js');
            $this->document->addScript('catalog/view/theme/perfect_one_checkout/js/sign_in_google.js');
        }

        if($this->config->get('poc_sign_in_facebook_status') && $this->config->get('poc_sign_in_facebook_app_id') && $this->config->get('poc_sign_in_facebook_app_secret'))
        {
            $temp_data['some_sign_in'] = true;
            $temp_data['poc_sign_in_facebook'] = true;
            $temp_data['poc_sign_in_facebook_link'] = $this->model_extension_module_perfect_one_checkout->sign_in_facebook_get_link();
            if(!empty($temp_data['sign_in_facebook_icon']))
                $temp_data['sign_in_facebook_icon'] = $this->config->get('poc_design_icons') == 'typicons' ? '<span class="typcn typcn-'.$temp_data['sign_in_facebook_icon'].'"></span>' : '<i class="fa fa-'.$temp_data['sign_in_facebook_icon'].'"></i>';
        }

        if($this->config->get('poc_sign_in_paypal_status') && $this->config->get('poc_sign_in_paypal_app_id') && $this->config->get('poc_sign_in_paypal_secret_id') && $this->config->get('poc_sign_in_paypal_locale'))
        {
            $temp_data['some_sign_in'] = true;
            $temp_data['poc_sign_in_paypal'] = true;
            $temp_data['poc_sign_in_paypal_js_code'] = $this->model_extension_module_perfect_one_checkout->sign_in_paypal_get_code();
            if(!empty($temp_data['sign_in_paypal_icon']))
                $temp_data['sign_in_paypal_icon'] = '<i class="fa fa-'.$temp_data['sign_in_paypal_icon'].'"></i>';
        }

        if($this->config->get('poc_sign_in_linkedin_status') && $this->config->get('poc_sign_in_linkedin_client_id') && $this->config->get('poc_sign_in_linkedin_secret_id'))
        {
            $temp_data['some_sign_in'] = true;
            $temp_data['poc_sign_in_linkedin'] = true;
            $temp_data['poc_sign_in_linkedin_link'] = $this->model_extension_module_perfect_one_checkout->sign_in_linkedin_get_link();
            if(!empty($temp_data['sign_in_linkedin_icon']))
                $temp_data['sign_in_linkedin_icon'] = $this->config->get('poc_design_icons') == 'typicons' ? '<span class="typcn typcn-'.$temp_data['sign_in_linkedin_icon'].'"></span>' : '<i class="fa fa-'.$temp_data['sign_in_linkedin_icon'].'"></i>';
        }
    //</editor-fold>

    //<editor-fold desc="Put link in text confirm_checkbox_terms">
        $term_text = $temp_data['confirm_checkbox_terms'];
		if (strpos($term_text, '[link]') !== false && strpos($term_text, '[/link]') !== false)
		{
			$this->load->model('catalog/information');
			$information_info = $this->model_catalog_information->getInformation($this->config->get('config_checkout_id'));

			if ($information_info) {
				$term_text = str_replace('[link]', '<a href="javascript:{}" data-remodal-target="modal_terms">', $term_text);
				$term_text = str_replace('[/link]', '</a>', $term_text);
				$temp_data['confirm_checkbox_terms'] = $term_text;

				$temp_data['terms'] = $information_info;

				if(array_key_exists('description', $temp_data['terms']))
					$temp_data['terms']['description'] = htmlspecialchars_decode($temp_data['terms']['description']);
				else
					$temp_data['terms']['description'] = '';
			}
		}

		$temp_data['poc_terms_accepted'] = isset($this->session->data['poc']['terms_accepted']) ? $this->session->data['poc']['terms_accepted'] : false;
    //</editor-fold>

    //<editor-fold desc="Forgotten password">
        $forgotten_text = $temp_data['identification_forgotten_password'];
        if (strpos($forgotten_text, '[link]') !== false && strpos($forgotten_text, '[/link]') !== false) {

            $forgotten_text = str_replace('[link]', '<a href="'.$this->url->link('account/forgotten', false, true).'" class="poc_forgotten_password_link">', $forgotten_text);
            $forgotten_text = str_replace('[/link]', '</a>', $forgotten_text);

            $temp_data['identification_forgotten_password'] = $forgotten_text;
        }
    //</editor-fold>

    //<editor-fold desc="User status loged vs no loged">
        $temp_data['poc_is_logged'] = $logged;
		if($temp_data['poc_is_logged'])
			$temp_data['poc_welcome_text'] = html_entity_decode(sprintf($temp_data['identification_welcome'],$this->customer->getFirstName(),$this->customer->getLastName()));

        $this->session->data['poc']['guest'] = $this->config->get('poc_guest_buy') && !$logged;
		$temp_data['guest'] = $this->session->data['poc']['guest'];
        $temp_data['show_guest_forms'] = $this->config->get('poc_guest_buy');

        $this->session->data['poc']['register'] = (!$this->config->get('poc_guest_buy') && !$logged) || (array_key_exists('poc', $this->session->data) && array_key_exists('register', $this->session->data['poc']) && !empty($this->session->data['poc']['register']));
        $temp_data['register'] = $this->session->data['poc']['register'];

        if($temp_data['register'])
            $this->session->data['poc']['guest'] = $temp_data['guest'] = false;
    //</editor-fold>

    //<editor-fold desc="Register form">
        if(!$logged)
        {
            $form_register = $this->model_extension_module_perfect_one_checkout->generate_form($this->config->get('poc_billing_address'), 'register', 'payment_address');
            $temp_data['form_register'] = $form_register;
        }
    //</editor-fold>

    //<editor-fold desc="If logged, load his addresses">
        if($logged)
		{
			$this->load->model('account/address');
			$addresses = $this->model_account_address->getAddresses();
            if(!empty($addresses)) {
                $temp = array_values($addresses);
                $first_address = $temp[0];

                $default_delivery_address_id = isset($this->session->data['poc']['shipping_address']) ? $this->session->data['poc']['shipping_address'] : $this->customer->getAddressId();
                $default_billing_address_id = isset($this->session->data['poc']['payment_address']) ? $this->session->data['poc']['payment_address'] : $this->customer->getAddressId();
                $temp_data['default_billing_address_id'] = $default_billing_address_id;
                $temp_data['default_delivery_address_id'] = $default_delivery_address_id;

                $this->session->data['shipping_address'] = !empty($default_delivery_address_id) && array_key_exists($default_delivery_address_id, $addresses) ? $addresses[$default_delivery_address_id] : $first_address;
                $this->session->data['payment_address'] = !empty($default_billing_address_id) && array_key_exists($default_billing_address_id, $addresses) ? $addresses[$default_billing_address_id] : $first_address;

                if (!array_key_exists('shipping_address_id', $this->session->data) && !empty($default_delivery_address_id))
                    $this->session->data['shipping_address_id'] = $default_delivery_address_id;

                if (!array_key_exists('payment_address_id', $this->session->data) && !empty($default_billing_address_id))
                    $this->session->data['payment_address_id'] = $default_billing_address_id;

                $temp_data['addresses'] = $this->model_extension_module_perfect_one_checkout->format_addresses($addresses);

                $shipping_address = $this->session->data['shipping_address'];
            }
		} elseif(!$logged && !empty($this->session->data['shipping_address']))
			$shipping_address = $this->session->data['shipping_address'];
    //</editor-fold>

    //<editor-fold desc="Create or edit order">
        $this->load->model('extension/module/perfect_one_checkout');
        $this->model_extension_module_perfect_one_checkout->add_edit_order();
    //</editor-fold>

    //<editor-fold desc="Load shipping methods">
        $temp_data['shipping_methods'] = array_key_exists('shipping_no_shipping_methods', $this->session->data['poc']['lang']) ? $this->session->data['poc']['lang']['shipping_no_shipping_methods'] : '';

		if(!empty($shipping_address))
		{
			if($more_oc_2)
				$temp_data['shipping_methods'] = $this->load->controller('extension/module/perfect_one_checkout/ajax_get_shipping_methods', array('return' => true));
			else
				$temp_data['shipping_methods'] = $this->getChild('extension/module/perfect_one_checkout/ajax_get_shipping_methods', array('return' => true));

			$temp_data['shipping_method_choosed'] = !empty($this->session->data['shipping_method']);
		}
    //</editor-fold>

    //<editor-fold desc="Load payment methods">
        $temp_data['payment_methods'] = array_key_exists('payment_no_payment_methods', $this->session->data['poc']['lang']) ? $this->session->data['poc']['lang']['payment_no_payment_methods'] : '';

		if(isset($this->session->data['payment_address']))
		{
			if($more_oc_2)
				$temp_data['payment_methods'] = $this->load->controller('extension/module/perfect_one_checkout/ajax_get_payment_methods', array('return' => true));
			else
				$temp_data['payment_methods'] = $this->getChild('extension/module/perfect_one_checkout/ajax_get_payment_methods', array('return' => true));

			$temp_data['payment_method_choosed'] = !empty($this->session->data['payment_method']);

			if(!$more_oc_2 && !empty($this->session->data['payment_address']['address_id']))
				$this->session->data['payment_address_id'] = $this->session->data['payment_address']['address_id'];

			if(!$logged && !isset($this->session->data['guest']))
			{
				$this->session->data['guest'] = $this->session->data['payment_address'];
				if (!isset($this->session->data['guest']['customer_group_id']))
					$this->session->data['guest']['customer_group_id'] = $this->config->get('config_customer_group_id');
			}
		}
    //</editor-fold>

    //<editor-fold desc="If payment method was selected, load payment info (with confirm form)">
        $temp_data['payment_info'] = '';
		if(!empty($this->session->data['payment_method']['code']))
		{
			if($more_oc_2)
				$temp_data['payment_info'] = $this->load->controller('extension/module/perfect_one_checkout/ajax_get_payment_info', array('return' => true));
			else
			{
				require_once(DIR_APPLICATION.'controller/extension/module/perfect_one_checkout.php');
				$pocController = new ControllerExtensionModulePerfectOneCheckout($this->registry);
				$temp_data['payment_info'] = $pocController->ajax_get_payment_info(array('return' => true));
			}
		}
    //</editor-fold>

    //<editor-fold desc="Load guest delivery form or add new address in case loged">
        $form_billing_address = $this->model_extension_module_perfect_one_checkout->generate_form($this->config->get('poc_billing_address'), $logged ? 'logged' : 'guest', 'payment_address');
		$temp_data['form_billing_address'] = $form_billing_address;

		$id_2 = $this->model_extension_module_perfect_one_checkout->_generate_random_string(5);
		$explode_id_form = explode('id="', $form_billing_address);
		$form_billing_address_to_modal = $explode_id_form[0].(array_key_exists(1, $explode_id_form) ? 'id="'.$id_2.$explode_id_form[1] : '');
		$temp_data['form_billing_address_modal'] = $form_billing_address_to_modal;
    //</editor-fold>

    //<editor-fold desc="Load guest delivery form">
        if(!$logged)
		{
			$form_delivery_address = $this->model_extension_module_perfect_one_checkout->generate_form($this->config->get('poc_delivery_address'), $logged ? 'logged' : 'guest', 'shipping_address');

			$temp_data['form_delivery_address'] = $form_delivery_address;
		}
    //</editor-fold>

    //<editor-fold desc="Check agree confirm order">
        if ($this->config->get('config_checkout_id')) {
			$this->load->model('catalog/information');

			$information_info = $this->model_catalog_information->getInformation($this->config->get('config_checkout_id'));

			if ($information_info) {
				$temp_data['text_agree'] = sprintf($this->language->get('text_agree'), $this->url->link('information/information/agree', 'information_id=' . $this->config->get('config_checkout_id'), true), $information_info['title'], $information_info['title']);
			}
		}
    //</editor-fold>

    //<editor-fold desc="Privacy policy">
        if($this->config->get('config_account_id'))
		{
			$this->load->model('catalog/information');
			$temp_data['privacy_policy'] = $this->model_catalog_information->getInformation($this->config->get('config_account_id'));

			if(array_key_exists('description', $temp_data['privacy_policy']))
				$temp_data['privacy_policy']['description'] = htmlspecialchars_decode($temp_data['privacy_policy']['description']);
			else
				$temp_data['privacy_policy']['description'] = '';
		}
    //</editor-fold>

    //<editor-fold desc="Load cart information">
        if($more_oc_2)
		{
			$this->session->data['poc_cart_view'] = (version_compare(VERSION, '2.1.0.2', '<=') ? 'default/template/' : '').'checkout/perfect_one_checkout/cart_info'.(!$more_oc_3 ? '.tpl':'');
			$cart_info = $this->load->controller('common/cart');
		}
		else
		{
			$this->session->data['poc_cart_view'] = 'default/template/checkout/perfect_one_checkout/cart_info.tpl';
			$cart_info = $this->getChild('module/cart');
		}

		$temp_data['cart_info'] = $cart_info;
    //</editor-fold>

    //<editor-fold desc="Coupon and Gift URLs">
        if(version_compare(VERSION, '1.5.6.4', '<='))
			$url_coupon = 'index.php?route=extension/module/perfect_one_checkout/_oc15x_coupon';
		elseif(version_compare(VERSION, '2', '>=') && version_compare(VERSION, '2.1', '<'))
			$url_coupon = 'index.php?route=checkout/coupon/coupon';
		elseif(version_compare(VERSION, '2.1', '>=') && version_compare(VERSION, '2.3.0.1', '<'))
			$url_coupon = 'index.php?route=total/coupon/coupon';
		elseif(version_compare(VERSION, '2.3.0.1', '>='))
			$url_coupon = 'index.php?route=extension/total/coupon/coupon';

		$temp_data['url_coupon'] = $url_coupon;

		if(version_compare(VERSION, '1.5.6.4', '<='))
			$url_voucher = 'index.php?route=extension/module/perfect_one_checkout/_oc15x_voucher';
		elseif(version_compare(VERSION, '2', '>=') && version_compare(VERSION, '2.1', '<'))
			$url_voucher = 'index.php?route=checkout/voucher/voucher';
		elseif(version_compare(VERSION, '2.1', '>=') && version_compare(VERSION, '2.3.0.1', '<'))
			$url_voucher = 'index.php?route=total/voucher/voucher';
		elseif(version_compare(VERSION, '2.3.0.1', '>='))
			$url_voucher = 'index.php?route=extension/total/voucher/voucher';

		$temp_data['url_voucher'] = $url_voucher;

		if(version_compare(VERSION, '1.5.6.4', '<='))
			$url_reward = 'index.php?route=extension/module/perfect_one_checkout/_oc15x_reward';
		elseif(version_compare(VERSION, '2', '>=') && version_compare(VERSION, '2.1', '<'))
			$url_reward = 'index.php?route=checkout/reward/reward';
		elseif(version_compare(VERSION, '2.1', '>=') && version_compare(VERSION, '2.3.0.1', '<'))
			$url_reward = 'index.php?route=total/reward/reward';
		elseif(version_compare(VERSION, '2.3.0.1', '>='))
			$url_reward = 'index.php?route=extension/total/reward/reward';

		$temp_data['url_reward'] = $url_reward;
    //</editor-fold>

    //<editor-fold desc="icons html code">
        $poc_icon_html = $this->config->get('poc_design_icons') == 'typicons' ? '<span class="typcn typcn-classIcon"></span>' : '<i class="fa fa-classIcon"></i>';
		$temp_data['poc_icon_html'] = $poc_icon_html;

		$icon_add_address_class = 'plus addaddress';
		$temp_data['poc_icon_add_address'] = str_replace('classIcon', $icon_add_address_class, $poc_icon_html);

		$icon_warning_class = $this->config->get('poc_design_icons') == 'typicons' ? 'warning' : 'warning';
		$temp_data['poc_icon_warning'] = str_replace('classIcon', $icon_warning_class, $poc_icon_html);

		$icon_error_class = $this->config->get('poc_design_icons') == 'typicons' ? 'warning' : 'exclamation-circle';
		$temp_data['poc_icon_error'] = str_replace('classIcon', $icon_error_class, $poc_icon_html);

		$icon_user_class = $this->config->get('poc_design_icons') == 'typicons' ? 'user' : 'user';
		$temp_data['poc_icon_user'] = str_replace('classIcon', $icon_user_class, $poc_icon_html);

		$icon_password_class = $this->config->get('poc_design_icons') == 'typicons' ? 'key' : 'key';
		$temp_data['poc_icon_password'] = str_replace('classIcon', $icon_password_class, $poc_icon_html);
    //</editor-fold>

    //<editor-fold desc="Calc separators">
        $total_separators = 0;

		$panels = array('identification','addresses','shipping','payment','cart','confirm');

		$open_row_identification = true;

		foreach ($panels as $key => $pan_name) {
			if(!in_array($pan_name, array('identification', 'cart')) || (in_array($pan_name, array('identification', 'cart')) && $this->config->get('poc_layout_'.$pan_name.'_panel_status')))
			{
				$total_separators += $this->config->get('poc_layout_'.$pan_name.'_panel_cols');
				if($total_separators == 12)
				{
					$temp_data['close_row_'.$pan_name] = true;

					if(!empty($panels[$key+1]))
						$temp_data['open_row_'.$panels[$key+1]] = true;

					$total_separators = 0;
				}
			}
		}
    //</editor-fold>


	$this->language->load('checkout/checkout');

	foreach ($temp_data as $key => $value) {
		if($more_oc_2)
			$data[$key] = $value;
		else
			$this->data[$key] = $value;
	}
?>