<?xml version="1.0" encoding="utf-8"?>
<modification>
	<name>DearSoft Product Option Image</name>
	<version>3.0</version>
	<author>DearSoft</author>
	<link>https://www.deaersoft.bd/</link>
	<code>again-product-option-image</code>

	<file path="admin/controller/catalog/option.php">

		<!-- autocomplete() -->
		<operation error="skip">
			<search><![CDATA['limit'       => 5]]></search>
			<add position="replace"><![CDATA['limit'       => 15]]></add>
		</operation>
	</file>

	<file path="admin/controller/catalog/product.php">

		<!-- getForm() -->
		<operation error="skip">
			<search index="0"><![CDATA[$this->load->model('catalog/option');]]></search>
			<add position="after"><![CDATA[
			//BOF Related Options
			$this->load->model('tool/image');
			//EOF Related Options
			]]></add>
		</operation>

		<!-- getForm() -->
		<operation error="skip">
			<search index="0"><![CDATA[foreach ($product_option['product_option_value'] as $product_option_value) {]]></search>
			<add position="after"><![CDATA[
			//BOF Related Options
			if (is_file(DIR_IMAGE . $product_option_value['option_image'])) {
				$product_option_value_image = $product_option_value['option_image'];
				$product_option_value_thumb = $product_option_value['option_image'];
			} else {
				$product_option_value_image = '';
				$product_option_value_thumb = 'no_image.png';
			}
			//EOF Related Options
			]]></add>
		</operation>

		<!-- getForm() -->
		<operation error="skip">
			<search><![CDATA['weight_prefix'           => $product_option_value['weight_prefix']]]></search>
			<add position="before"><![CDATA[
			//BOF Related Options
			'master_option_value'		=> $product_option_value['master_option_value'],
			'option_image'			=> $product_option_value_image,
			'option_thumb'			=> $this->model_tool_image->resize($product_option_value_thumb, 100, 100),
			//EOF Related Options
			]]></add>
		</operation>

		<!-- getForm() -->
		<operation error="skip">
			<search index="0"><![CDATA['required'             => $product_option['required']]]></search>
			<add position="before"><![CDATA[
			//BOF Related Options
			'master_option'			=> $product_option['master_option'],
			'master_option_data'		=> $master_option_data,
			//EOF Related Options
			]]></add>
		</operation>

		<!-- getForm(), getList() -->
		<operation error="skip">
			<search><![CDATA[if (isset($this->error['warning'])) {]]></search>
			<add position="before"><![CDATA[
			//BOF Related Options
			$this->load->language('catalog/related_options');
			//$data['entry_master_option']       = $this->language->get('entry_master_option');
			//$data['entry_master_option_value'] = $this->language->get('entry_master_option_value');
			//EOF Related Options
			]]></add>
		</operation>

		<!-- getForm() -->
		<operation error="skip">
			<search><![CDATA[if (isset($product_option['product_option_value'])) {]]></search>
			<add position="before"><![CDATA[
			//BOF Related Options
				$master_option_data = array();
				if (isset($product_option['master_option_data'])) {
					$master_option_data = $product_option['master_option_data'];
				} else {
					if (!empty($product_option['master_option'])) {
						foreach ($product_options as $product_option1) {
							if ($product_option1['option_id'] == $product_option['master_option']) {
								foreach ($product_option1['product_option_value'] as $key_option => $val_option) {
									$option_name = $this->model_catalog_option->getOptionValue($val_option['option_value_id']);
									$product_option1['product_option_value'][$key_option]['name'] = $option_name['name'];
								}
								$master_option_data = $product_option1;
							}
						}
					}
				}

			if ($product_option['type'] == 'select' || $product_option['type'] == 'radio' || $product_option['type'] == 'checkbox' || $product_option['type'] == 'image') {
			//EOF Related Options
			]]></add>
		</operation>

		<!-- getForm() -->
		<operation error="skip">
			<search><![CDATA[$data['option_values'] = array();]]></search>
			<add position="before"><![CDATA[
			//BOF Related Options
			 else {
				$data['product_options'][] = array(
					'product_option_id' => $product_option['product_option_id'],
					'option_id'         => $product_option['option_id'],
					'name'              => $product_option['name'],
					'type'              => $product_option['type'],
					'value'             => $product_option['value'],
					//BOF Related Options
					'master_option'			=> $product_option['master_option'],
					'master_option_data'		=> $master_option_data,
					'master_option_value'		=> isset($product_option['master_option_value']) ? $product_option['master_option_value'] : 0,
					//EOF Related Options
					'required'          => $product_option['required']
				);
			}
		}
		//EOF Related Options
			]]></add>
		</operation>

		<!-- getForm() -->
		<operation error="skip">
			<search><![CDATA[$this->response->setOutput($this->load->view('catalog/product_form', $data));]]></search>
			<add position="before"><![CDATA[
			//BOF Related Options
			//usort($data['product_options'], function($a, $b) {
			//	return $a['product_option_id'] - $b['product_option_id'];
			//});
			//EOF Related Options
			]]></add>
		</operation>

		<!-- getForm() -->
		<operation error="skip">
			<search><![CDATA[$this->load->model('design/layout');]]></search>
			<add position="before"><![CDATA[
			//BOF Related Options
			$data['product_id'] = isset($this->request->get['product_id']) ? $this->request->get['product_id'] : 0;
			//EOF Related Options
			]]></add>
		</operation>

		<!-- autocomplete() -->
		<operation error="skip">
			<search index="1"><![CDATA['required'             => $product_option['required']]]></search>
			<add position="before"><![CDATA[
			//BOF Related Options
			'master_option'			=> $product_option['master_option'],
			'master_option_data'		=> isset($product_option['master_option_data'])  ? $product_option['master_option_data']  : array(),
			'master_option_value'		=> isset($product_option['master_option_value']) ? $product_option['master_option_value'] : 0,
			//EOF Related Options
			]]></add>
		</operation>

		<operation error="skip">
			<search><![CDATA[public function autocomplete() {]]></search>
			<add position="before"><![CDATA[
			//BOF Related Options
	public function updaterelations() {

		$this->load->language('catalog/product');
		$this->load->language('catalog/related_options');

		$json = array();
		
		if (!$this->user->hasPermission('modify', 'catalog/product')) {
			$json['error'] = $this->language->get('error_permission');
		}

		$options = $this->request->post;

		if (($product_id = $this->request->post['product_id'] * 1) > 0 && !$json) {
			$this->load->model('catalog/product');
			$this->model_catalog_product->editProductOptions($product_id, $options);

			$data['row'] = preg_replace ("/[^0-9]/", "", $options['active']);
			$data['user_token'] = $this->session->data['user_token'];

			$data['text_form'] = !isset($this->request->get['product_id']) ? $this->language->get('text_add') : $this->language->get('text_edit');
			//$data['text_enabled'] = $this->language->get('text_enabled');
			//$data['text_disabled'] = $this->language->get('text_disabled');
			//$data['text_none'] = $this->language->get('text_none');
			//$data['text_yes'] = $this->language->get('text_yes');
			//$data['text_no'] = $this->language->get('text_no');
			//$data['text_plus'] = $this->language->get('text_plus');
			//$data['text_minus'] = $this->language->get('text_minus');
			//$data['text_default'] = $this->language->get('text_default');
			//$data['text_option'] = $this->language->get('text_option');
			//$data['text_option_value'] = $this->language->get('text_option_value');
			//$data['text_select'] = $this->language->get('text_select');
			//$data['text_percent'] = $this->language->get('text_percent');
			//$data['text_amount'] = $this->language->get('text_amount');
			//$data['text_select_all'] = $this->language->get('text_select_all');
			//$data['text_unselect_all'] = $this->language->get('text_unselect_all');

			//$data['entry_location'] = $this->language->get('entry_location');
			//$data['entry_minimum'] = $this->language->get('entry_minimum');
			//$data['entry_shipping'] = $this->language->get('entry_shipping');
			//$data['entry_date_available'] = $this->language->get('entry_date_available');
			//$data['entry_quantity'] = $this->language->get('entry_quantity');
			//$data['entry_stock_status'] = $this->language->get('entry_stock_status');
			//$data['entry_price'] = $this->language->get('entry_price');
			//$data['entry_tax_class'] = $this->language->get('entry_tax_class');
			//$data['entry_points'] = $this->language->get('entry_points');
			//$data['entry_option_points'] = $this->language->get('entry_option_points');
			//$data['entry_subtract'] = $this->language->get('entry_subtract');
			//$data['entry_weight_class'] = $this->language->get('entry_weight_class');
			//$data['entry_weight'] = $this->language->get('entry_weight');
			//$data['entry_dimension'] = $this->language->get('entry_dimension');
			//$data['entry_length_class'] = $this->language->get('entry_length_class');
			//$data['entry_length'] = $this->language->get('entry_length');
			//$data['entry_width'] = $this->language->get('entry_width');
			//$data['entry_height'] = $this->language->get('entry_height');
			//$data['entry_image'] = $this->language->get('entry_image');
			//$data['entry_additional_image'] = $this->language->get('entry_additional_image');
			//$data['entry_store'] = $this->language->get('entry_store');
			//$data['entry_download'] = $this->language->get('entry_download');
			//$data['entry_text'] = $this->language->get('entry_text');
			//$data['entry_option'] = $this->language->get('entry_option');
			//$data['entry_option_value'] = $this->language->get('entry_option_value');
			//$data['entry_required'] = $this->language->get('entry_required');
			//$data['entry_sort_order'] = $this->language->get('entry_sort_order');
			//$data['entry_status'] = $this->language->get('entry_status');
			//$data['entry_date_start'] = $this->language->get('entry_date_start');
			//$data['entry_date_end'] = $this->language->get('entry_date_end');
			//$data['entry_priority'] = $this->language->get('entry_priority');
			//$data['entry_customer_group'] = $this->language->get('entry_customer_group');
			//$data['entry_reward'] = $this->language->get('entry_reward');
			//$data['entry_layout'] = $this->language->get('entry_layout');
			//$data['entry_recurring'] = $this->language->get('entry_recurring');

			//$data['button_view'] = $this->language->get('button_view');
			//$data['button_save'] = $this->language->get('button_save');
			//$data['button_cancel'] = $this->language->get('button_cancel');
			//$data['button_option_add'] = $this->language->get('button_option_add');
			//$data['button_option_value_add'] = $this->language->get('button_option_value_add');
			//$data['button_remove'] = $this->language->get('button_remove');

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

			//BOF Related Options
			//$data['entry_master_option'] = $this->language->get('entry_master_option');
			//$data['entry_master_option_value'] = $this->language->get('entry_master_option_value');
			//EOF Related Options

			// Options
			$this->load->model('catalog/option');

			//BOF Related Options
			$this->load->model('tool/image');
			$data['placeholder'] = $this->model_tool_image->resize('no_image.png', 100, 100);
			//EOF Related Options

			$product_options = $this->model_catalog_product->getProductOptions($product_id);

			$data['product_options'] = array();

			foreach ($product_options as $product_option) {
				$product_option_value_data = array();

				//BOF Related Options
				$master_option_data = array();
				if (isset($product_option['master_option_data'])) {
					$master_option_data = $product_option['master_option_data'];
				} else {
					if (!empty($product_option['master_option'])) {
						foreach ($product_options as $product_option1) {
							if ($product_option1['option_id'] == $product_option['master_option']) {
								foreach ($product_option1['product_option_value'] as $key_option => $val_option) {
									$option_name = $this->model_catalog_option->getOptionValue($val_option['option_value_id']);
									$product_option1['product_option_value'][$key_option]['name'] = $option_name['name'];
								}
								$master_option_data = $product_option1;
							}
						}
					}
				}

				if ($product_option['type'] == 'select' || $product_option['type'] == 'radio' || $product_option['type'] == 'checkbox' || $product_option['type'] == 'image') {
					//EOF Related Options
					if (isset($product_option['product_option_value'])) {
						foreach ($product_option['product_option_value'] as $product_option_value) {

							//BOF Related Options
							if (is_file(DIR_IMAGE . $product_option_value['option_image'])) {
								$product_option_value_image = $product_option_value['option_image'];
								$product_option_value_thumb = $product_option_value['option_image'];
							} else {
								$product_option_value_image = '';
								$product_option_value_thumb = 'no_image.png';
							}
							//EOF Related Options

							$product_option_value_data[] = array(
								'product_option_value_id' => $product_option_value['product_option_value_id'],
								'option_value_id'         => $product_option_value['option_value_id'],
								'quantity'                => $product_option_value['quantity'],
								'subtract'                => $product_option_value['subtract'],
								'price'                   => $product_option_value['price'],
								'price_prefix'            => $product_option_value['price_prefix'],
								'points'                  => $product_option_value['points'],
								'points_prefix'           => $product_option_value['points_prefix'],
								'weight'                  => $product_option_value['weight'],
								//BOF Related Options
								'master_option_value'     => $product_option_value['master_option_value'],
								'option_image'            => $product_option_value_image,
								'option_thumb'            => $this->model_tool_image->resize($product_option_value_thumb, 100, 100),
								//EOF Related Options
								'weight_prefix'           => $product_option_value['weight_prefix']
							);
						}
					}

					$data['product_options'][] = array(
						'product_option_id'    => $product_option['product_option_id'],
						'product_option_value' => $product_option_value_data,
						'option_id'            => $product_option['option_id'],
						'name'                 => $product_option['name'],
						'type'                 => $product_option['type'],
						'value'                => isset($product_option['value']) ? $product_option['value'] : '',
						//BOF Related Options
						'master_option'        => $product_option['master_option'],
						'master_option_data'   => $master_option_data,
						//EOF Related Options
						'required'             => $product_option['required']
					);
				} else {
					$data['product_options'][] = array(
						'product_option_id' => $product_option['product_option_id'],
						'option_id'         => $product_option['option_id'],
						'name'              => $product_option['name'],
						'type'              => $product_option['type'],
						'value'      => $product_option['value'],
						//BOF Related Options
						'master_option'			=> $product_option['master_option'],
						'master_option_data'		=> $master_option_data,
						'master_option_value'		=> isset($product_option['master_option_value']) ? $product_option['master_option_value'] : 0,
						//EOF Related Options
						'required'          => $product_option['required']
					);
				}
			}
			//EOF Related Options
			$data['option_values'] = array();

			foreach ($data['product_options'] as $product_option) {
				if ($product_option['type'] == 'select' || $product_option['type'] == 'radio' || $product_option['type'] == 'checkbox' || $product_option['type'] == 'image') {
					if (!isset($data['option_values'][$product_option['option_id']])) {
						$data['option_values'][$product_option['option_id']] = $this->model_catalog_option->getOptionValues($product_option['option_id']);
					}
				}
			}

			//BOF Related Options
			//usort($data['product_options'], function($a, $b) {
			//	return $a['product_option_id'] - $b['product_option_id'];
			//});
			//EOF Related Options

			$html = $this->load->view('extension/module/product_option', $data);

			// "Minimizing" server response size
			$html = preg_replace('/[\t ]{2,}/', ' ', $html);
			
			$json['html'] = $html;
		} else {
			if (!$json) {
				$json['error'] = $this->language->get('error_save_product');
			}
		}

		$this->response->addHeader('Content-Type: application/json');
		$this->response->setOutput(json_encode($json, JSON_UNESCAPED_UNICODE));
	}
	//EOF Related Options
			]]></add>
		</operation>
	</file>

	<file path="admin/model/catalog/product.php">

		<!-- getProductOptions() [Sort product options by oc_option.sort_order and oc_product_option.product_option_id] -->
		<operation error="skip">
			<search><![CDATA[od.language_id = '" . (int)$this->config->get('config_language_id') . "'"]]></search>
			<add position="replace"><![CDATA[od.language_id = '" . (int)$this->config->get('config_language_id') . "' ORDER BY o.sort_order ASC, po.product_option_id ASC"]]></add>
		</operation>

		<!-- getProductOptions() -->
		<operation error="skip">
			<search><![CDATA[$product_option_value_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_option_value pov LEFT JOIN " . DB_PREFIX . "option_value ov ON(pov.option_value_id = ov.option_value_id) WHERE pov.product_option_id = '" . (int)$product_option['product_option_id'] . "' ORDER BY ov.sort_order ASC");]]></search>
			<add position="replace"><![CDATA[
			//BOF Related Options
			$product_option_value_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_option_value pov LEFT JOIN " . DB_PREFIX . "option_value ov ON(pov.option_value_id = ov.option_value_id) WHERE pov.product_option_id = '" . (int)$product_option['product_option_id'] . "' ORDER BY pov.product_option_value_id ASC");
			//EOF Related Options
			]]></add>
		</operation>

		<!-- addProduct(), editProduct() -->
		<operation error="skip">
			<search><![CDATA[$product_option_id = $this->db->getLastId();]]></search>
			<add position="after"><![CDATA[
			//BOF Related Options
			$this->db->query("UPDATE " . DB_PREFIX . "product_option SET master_option = '" . (int)$product_option['master_option'] . "' WHERE product_option_id = '" . $product_option_id . "'");
			//EOF Related Options
			]]></add>
		</operation>

		<!-- addProduct(), editProduct()  -->
		<operation error="skip">
			<search><![CDATA[value = '" . $this->db->escape($product_option['value']) . "', required = '" . (int)$product_option['required'] . "'");]]></search>
			<add position="after"><![CDATA[
			//BOF Related Options
			$product_option_id = $this->db->getLastId();

			$this->db->query("UPDATE " . DB_PREFIX . "product_option SET master_option = '" . (int)$product_option['master_option'] . "', master_option_value = '" . (int)$product_option['master_option_value'] . "' WHERE product_option_id = '" . $this->db->getLastId() . "'");
			//EOF Related Options
			]]></add>
		</operation>

		<!-- addProduct() [Like editProduct() + product copying fix] -->
		<operation error="skip">
			<search index="0"><![CDATA["', weight_prefix = '" . $this->db->escape($product_option_value['weight_prefix']) . "'");]]></search>
			<add position="after"><![CDATA[
			//BOF Related Options
			$product_option_value_id = $this->db->getLastId();

			if ((int)$product_option['master_option']) {
				$this->db->query("UPDATE " . DB_PREFIX . "product_option_value SET master_option_value = '" . (int)$product_option_value['master_option_value'] . "' WHERE product_option_value_id = '" . $product_option_value_id . "'");
			}

			if ($product_option_value['option_image'] != "") {
				$this->db->query("UPDATE " . DB_PREFIX . "product_option_value SET option_image = '" . $this->db->escape($product_option_value['option_image']) . "' WHERE product_option_value_id = '" . $product_option_value_id . "'");
			}

			// If copying products
			if ($product_option_value['product_option_value_id']) {
				$old_id = $product_option_value['product_option_value_id'];
				$matching_table[$old_id]['new_id'] = $product_option_value_id;
			}
			//EOF Related Options
			]]></add>
		</operation>

		<!-- editProduct() -->
		<operation error="skip">
			<search index="1"><![CDATA["', weight_prefix = '" . $this->db->escape($product_option_value['weight_prefix']) . "'");]]></search>
			<add position="after"><![CDATA[
			//BOF Related Options
			$product_option_value_id = $this->db->getLastId();

			if ((int)$product_option['master_option']) {
				$this->db->query("UPDATE " . DB_PREFIX . "product_option_value SET master_option_value = '" . (int)$product_option_value['master_option_value'] . "' WHERE product_option_value_id = '" . $product_option_value_id . "'");
			}

			if ($product_option_value['option_image'] != "") {
				$this->db->query("UPDATE " . DB_PREFIX . "product_option_value SET option_image = '" . $this->db->escape($product_option_value['option_image']) . "' WHERE product_option_value_id = '" . $product_option_value_id . "'");
			}
			//EOF Related Options
			]]></add>
		</operation>

		<!-- addProduct() -->
		<operation error="skip">
			<search index="0"><![CDATA[if (isset($data['product_recurring'])) {]]></search>
			<add position="before"><![CDATA[
			//BOF Related Options
			//The solution to the problem of copying products:
			//value of the "master_option_value" field must be updated by writing new identifiers
			if (isset($matching_table)) {

				//Update oc_product_option table
				$query = $this->db->query("SELECT product_option_id, master_option_value FROM " . DB_PREFIX . "product_option WHERE product_id = '" . (int)$product_id . "' AND master_option_value != '0' ORDER BY product_option_id ASC");

				if ($query->num_rows) {
					foreach ($query->rows as $result) {
						$old_id = $result['master_option_value'];
						$new_id = $matching_table[$old_id]['new_id'];

						$this->db->query("UPDATE " . DB_PREFIX . "product_option SET master_option_value = '" . (int)$new_id . "' WHERE product_option_id = '" . (int)$result['product_option_id'] . "'");
					}
				}

				//Update oc_product_option_value table
				$query = $this->db->query("SELECT product_option_value_id, master_option_value FROM " . DB_PREFIX . "product_option_value WHERE product_id = '" . (int)$product_id . "' AND master_option_value != '0' ORDER BY product_option_value_id ASC");

				if ($query->num_rows) {
					foreach ($query->rows as $result) {
						$old_id = $result['master_option_value'];
						$new_id = $matching_table[$old_id]['new_id'];

						$this->db->query("UPDATE " . DB_PREFIX . "product_option_value SET master_option_value = '" . (int)$new_id . "' WHERE product_option_value_id = '" . (int)$result['product_option_value_id'] . "'");
					}
				}

			}
			//EOF Related Options
			]]></add>
		</operation>

		<!-- getProductOptions() -->
		<operation error="skip">
			<search><![CDATA[=> $product_option['required']]]></search>
			<add position="before"><![CDATA[
			//BOF Related Options
			'master_option'             => $product_option['master_option'],
			'master_option_value'       => $product_option['master_option_value'],
			'master_option_data'        => $this->getProductOption($product_id, $product_option['master_option']),
			//EOF Related Options
			]]></add>
		</operation>

		<!-- getProductOptions() -->
		<operation error="skip">
			<search><![CDATA['weight_prefix'           => $product_option_value['weight_prefix']]]></search>
			<add position="before"><![CDATA[
			//BOF Related Options
			'master_option_value'             => $product_option_value['master_option_value'],
			'option_image'                           => $product_option_value['option_image'],
			//EOF Related Options
			]]></add>
		</operation>

		<operation error="skip">
			<search><![CDATA[public function getProductImages($product_id)]]></search>
			<add position="before" offset="1"><![CDATA[
			//BOF Related Options
	public function getProductOption($product_id, $option_id) {
		$product_option_data = array();

		$product_option_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_option po LEFT JOIN `" . DB_PREFIX . "option` o ON (po.option_id = o.option_id) LEFT JOIN " . DB_PREFIX . "option_description od ON (o.option_id = od.option_id) WHERE po.product_id = '" . (int)$product_id . "' AND od.language_id = '" . (int)$this->config->get('config_language_id') . "' AND po.option_id = '" . (int)$option_id . "' ORDER BY o.sort_order");

		$product_option = $product_option_query->row;
		if ($product_option) {
			if ($product_option['type'] == 'select' || $product_option['type'] == 'radio' || $product_option['type'] == 'checkbox' || $product_option['type'] == 'image') {
				$product_option_value_data = array();

				$product_option_value_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_option_value pov LEFT JOIN " . DB_PREFIX . "option_value ov ON (pov.option_value_id = ov.option_value_id) LEFT JOIN " . DB_PREFIX . "option_value_description ovd ON (ov.option_value_id = ovd.option_value_id) WHERE pov.product_option_id = '" . (int)$product_option['product_option_id'] . "' AND ovd.language_id = '" . (int)$this->config->get('config_language_id') . "' ORDER BY ov.sort_order");

				foreach ($product_option_value_query->rows as $product_option_value) {
					$parent_name = '';
					if ($product_option_value['master_option_value'] > 0) {
						$master_value_query = $this->db->query("SELECT ovd.name FROM " . DB_PREFIX . "option_value_description ovd LEFT JOIN " . DB_PREFIX . "product_option_value pov ON (ovd.option_value_id = pov.option_value_id) WHERE pov.product_option_value_id = '" . (int)$product_option_value['master_option_value'] . "' AND language_id = '" . (int)$this->config->get('config_language_id') . "'");
						$parent_name = ' ('.$master_value_query->row['name'].')';
					}
					$product_option_value_data[] = array(
						'product_option_value_id' => $product_option_value['product_option_value_id'],
						'option_value_id'         => $product_option_value['option_value_id'],
						'name'                    => $product_option_value['name'] . $parent_name,
						'image'                   => $product_option_value['image'],
						'quantity'                => $product_option_value['quantity'],
						'subtract'                => $product_option_value['subtract'],
						'price'                   => $product_option_value['price'],
						'price_prefix'            => $product_option_value['price_prefix'],
						'points'                  => $product_option_value['points'],
						'points_prefix'           => $product_option_value['points_prefix'],
						'weight'                  => $product_option_value['weight'],
						'weight_prefix'           => $product_option_value['weight_prefix']
					);
				}

				$product_option_data = array(
					'product_option_id'    => $product_option['product_option_id'],
					'option_id'            => $product_option['option_id'],
					'name'                 => $product_option['name'],
					'type'                 => $product_option['type'],
					'product_option_value' => $product_option_value_data,
					'required'             => $product_option['required']
				);
			} else {
				$product_option_data = array(
					'product_option_id' => $product_option['product_option_id'],
					'option_id'         => $product_option['option_id'],
					'name'              => $product_option['name'],
					'type'              => $product_option['type'],
					'option_value'      => $product_option['value'],
					'required'          => $product_option['required']
				);
			}
		}

		return $product_option_data;
	}
 			//EOF Related Options

			//BOF Related Options
	public function editProductOptions($product_id, $data) {

		$this->db->query("DELETE FROM " . DB_PREFIX . "product_option WHERE product_id = '" . (int)$product_id . "'");
		$this->db->query("DELETE FROM " . DB_PREFIX . "product_option_value WHERE product_id = '" . (int)$product_id . "'");

		if (isset($data['product_option'])) {
			foreach ($data['product_option'] as $product_option) {
				if ($product_option['type'] == 'select' || $product_option['type'] == 'radio' || $product_option['type'] == 'checkbox' || $product_option['type'] == 'image') {
					if (isset($product_option['product_option_value'])) {
						$this->db->query("INSERT INTO " . DB_PREFIX . "product_option SET product_option_id = '" . (int)$product_option['product_option_id'] . "', product_id = '" . (int)$product_id . "', option_id = '" . (int)$product_option['option_id'] . "', required = '" . (int)$product_option['required'] . "'");

						$product_option_id = $this->db->getLastId();

						//BOF Related Options
						$this->db->query("UPDATE " . DB_PREFIX . "product_option SET master_option = '" . (int)$product_option['master_option'] . "' WHERE product_option_id = '" . $product_option_id . "'");
						//EOF Related Options

						foreach ($product_option['product_option_value'] as $product_option_value) {
							$this->db->query("INSERT INTO " . DB_PREFIX . "product_option_value SET product_option_value_id = '" . (int)$product_option_value['product_option_value_id'] . "', product_option_id = '" . (int)$product_option_id . "', product_id = '" . (int)$product_id . "', option_id = '" . (int)$product_option['option_id'] . "', option_value_id = '" . (int)$product_option_value['option_value_id'] . "', quantity = '" . (int)$product_option_value['quantity'] . "', subtract = '" . (int)$product_option_value['subtract'] . "', price = '" . (float)$product_option_value['price'] . "', price_prefix = '" . $this->db->escape($product_option_value['price_prefix']) . "', points = '" . (int)$product_option_value['points'] . "', points_prefix = '" . $this->db->escape($product_option_value['points_prefix']) . "', weight = '" . (float)$product_option_value['weight'] . "', weight_prefix = '" . $this->db->escape($product_option_value['weight_prefix']) . "'");

							//BOF Related Options
							$product_option_value_id = $this->db->getLastId();

							if ((int)$product_option['master_option']) {
								$this->db->query("UPDATE " . DB_PREFIX . "product_option_value SET master_option_value = '" . (int)$product_option_value['master_option_value'] . "' WHERE product_option_value_id = '" . $product_option_value_id . "'");
							}

							if ($product_option_value['option_image'] != "") {
								$this->db->query("UPDATE " . DB_PREFIX . "product_option_value SET option_image = '" . $this->db->escape($product_option_value['option_image']) . "' WHERE product_option_value_id = '" . $product_option_value_id . "'");
							}
							//EOF Related Options
						}
					}
				} else {
					$this->db->query("INSERT INTO " . DB_PREFIX . "product_option SET product_option_id = '" . (int)$product_option['product_option_id'] . "', product_id = '" . (int)$product_id . "', option_id = '" . (int)$product_option['option_id'] . "', value = '" . $this->db->escape($product_option['value']) . "', required = '" . (int)$product_option['required'] . "'");

					//BOF Related Options
					$product_option_id = $this->db->getLastId();
					$this->db->query("UPDATE " . DB_PREFIX . "product_option SET master_option = '" . (int)$product_option['master_option'] . "', master_option_value = '" . (int)$product_option['master_option_value'] . "' WHERE product_option_id = '" . $this->db->getLastId() . "'");
					//EOF Related Options
				}
			}
		}
	}
			//EOF Related Options
			]]></add>
		</operation>
	</file>
	
	<file path="admin/view/template/catalog/product_form.twig">
		<operation error="skip">
			<search><![CDATA[{% if product_option.type == 'text' %}]]></search>
			<add position="before"><![CDATA[
			<!--BOF Related Options-->
                    <div class="form-group">
                        <label class="col-sm-2 control-label"> {{ entry_master_option }}</label>
                        <div class="col-sm-10">
                            <select name="product_option[{{ option_row }}][master_option]" class="form-control">
                                <option value="0">{{ text_no }}</option>
                                {% for product_option1 in product_options %}
                                    {% if product_option1.type != 'select' and product_option1.type != 'radio' and product_option1.type != 'checkbox' and product_option1.type != 'image' %}
                                    {% else %}
                                    {% if product_option1.option_id != product_option.option_id %}
                                        {% if product_option1.option_id  == product_option.master_option %}
                                            <option value="{{ product_option1.option_id }}" selected="selected">{{ product_option1.name }}</option>
                                        {% else %}
                                            <option value="{{ product_option1.option_id }}">{{ product_option1.name }}</option>
                                        {% endif %}
                                    {% endif %}
                                    {% endif %}
                                {% endfor %}
                            </select>
                        </div>
                    </div>
			<!--EOF Related Options-->
			]]>
			</add>
		</operation>
		<operation error="skip">
			<search><![CDATA[{% if product_option.type == 'text' %}]]></search>
			<add position="after"><![CDATA[
			<!--BOF Related Options-->
                        <div class="form-group">
                            <label class="col-sm-2 control-label">{{ entry_master_option_value }}</label>
                            <div class="col-sm-10 col-master-{{ option_row }}" data-col="{{ option_row }}" data-row="0">
                                {% if product_option.master_option %}
                                <select name="product_option[{{ option_row }}][master_option_value]" value="{{ product_option.value }}" class="form-control">
                                    <option value="0">{{ text_no }}</option>
                                    {% for master_option_value in product_option.master_option_data.product_option_value %}
                                      {% if master_option_value.product_option_value_id == product_option.master_option_value %}
                                          <option value="{{ master_option_value.product_option_value_id }}" selected="selected">{{ master_option_value.name }}</option>
                                      {% else %}
                                          <option value="{{ master_option_value.product_option_value_id }}">{{ master_option_value.name }}</option>
                                      {% endif %}
                                    {% endfor %}
                                </select>
                                {% else %}
                                - <input type="hidden" name="product_option[{{ option_row }}][master_option_value]" value="0">
                                {% endif %}
                            </div>
                        </div>
			<!--EOF Related Options-->
			]]>
			</add>
		</operation>
		<operation error="skip">
			<search><![CDATA[{% if product_option.type == 'textarea' %}]]></search>
			<add position="after"><![CDATA[
			<!--BOF Related Options-->
                        <div class="form-group">
                            <label class="col-sm-2 control-label">{{ entry_master_option_value }}</label>
                            <div class="col-sm-10 col-master-{{ option_row }}" data-col="{{ option_row }}" data-row="0">
                                {% if product_option.master_option %}
                                <select name="product_option[{{ option_row }}][master_option_value]" value="{{ product_option.option_value }}" class="form-control">
                                    <option value="0">{{ text_no }}</option>
                                    {% for master_option_value in product_option.master_option_data.product_option_value %}
                                    {% if master_option_value.product_option_value_id == product_option.master_option_value %}
                                    <option value="{{ master_option_value.product_option_value_id }}" selected="selected">{{ master_option_value.name }}</option>
                                    {% else %}
                                    <option value="{{ master_option_value.product_option_value_id }}">{{ master_option_value.name }}</option>
                                    {% endif %}
                                    {% endfor %}
                                </select>
                                {% else %}
                                - <input type="hidden" name="product_option[{{ option_row }}][master_option_value]" value="0">
                                {% endif %}
                            </div>
                        </div>
			<!--EOF Related Options-->
			]]>
			</add>
		</operation>
		<operation error="skip">
			<search><![CDATA[{% if product_option.type == 'file' %}]]></search>
			<add position="after"><![CDATA[
			<!--BOF Related Options-->
                        <div class="form-group">
                            <label class="col-sm-2 control-label">{{ entry_master_option_value }}</label>
                            <div class="col-sm-10 col-master-{{ option_row }}" data-col="{{ option_row }}" data-row="0">
                                {% if product_option.master_option %}
                                    <select name="product_option[{{ option_row }}][master_option_value]" value="{{ product_option.option_value }}" class="form-control">
                                        <option value="0">{{ text_no }}</option>
                                        {% for master_option_value in product_option.master_option_data.product_option_value %}
                                            {% if master_option_value.product_option_value_id == product_option.master_option_value %}
                                                <option value="{{ master_option_value.product_option_value_id }}" selected="selected">{{ master_option_value.name }}</option>
                                            {% else %}
                                                <option value="{{ master_option_value.product_option_value_id }}">{{ master_option_value.name }}</option>
                                            {% endif %}
                                        {% endfor %}
                                    </select>
                                {% else %}
                                    - <input type="hidden" name="product_option[{{ option_row }}][master_option_value]" value="0">
                                {% endif %}
                            </div>
                        </div>
			<!--EOF Related Options-->
			]]>
			</add>
		</operation>
		<operation error="skip">
			<search><![CDATA[{% if product_option.type == 'date' %}]]></search>
			<add position="after"><![CDATA[
			<!--BOF Related Options-->
                      <div class="form-group">
                          <label class="col-sm-2 control-label">{{ entry_master_option_value }}</label>
                          <div class="col-sm-10 col-master-{{ option_row }}" data-col="{{ option_row }}" data-row="0">
                              {% if product_option.master_option %}
                              <select name="product_option[{{ option_row }}][master_option_value]" value="{{ product_option.option_value }}" class="form-control">
                                  <option value="0">{{ text_no }}</option>
                                  {% for master_option_value in product_option.master_option_data.product_option_value %}
                                  {% if master_option_value.product_option_value_id == product_option.master_option_value %}
                                  <option value="{{ master_option_value.product_option_value_id }}" selected="selected">{{ master_option_value.name }}</option>
                                  {% else %}
                                  <option value="{{ master_option_value.product_option_value_id }}">{{ master_option_value.name }}</option>
                                  {% endif %}
                                  {% endfor %}
                              </select>
                              {% else %}
                              - <input type="hidden" name="product_option[{{ option_row }}][master_option_value]" value="0">
                              {% endif %}
                          </div>
                      </div>
			<!--EOF Related Options-->
			]]>
			</add>
		</operation>
		<operation error="skip">
			<search><![CDATA[{% if product_option.type == 'time' %}]]></search>
			<add position="after"><![CDATA[
			<!--BOF Related Options-->
                      <div class="form-group">
                          <label class="col-sm-2 control-label">{{ entry_master_option_value }}</label>
                          <div class="col-sm-10 col-master-{{ option_row }}" data-col="{{ option_row }}" data-row="0">
                              {% if product_option.master_option %}
                              <select name="product_option[{{ option_row }}][master_option_value]" value="{{ product_option.option_value }}" class="form-control">
                                  <option value="0">{{ text_no }}</option>
                                  {% for master_option_value in product_option.master_option_data.product_option_value %}
                                  {% if master_option_value.product_option_value_id == product_option.master_option_value %}
                                  <option value="{{ master_option_value.product_option_value_id }}" selected="selected">{{ master_option_value.name }}</option>
                                  {% else %}
                                  <option value="{{ master_option_value.product_option_value_id }}">{{ master_option_value.name }}</option>
                                  {% endif %}
                                  {% endfor %}
                              </select>
                              {% else %}
                              - <input type="hidden" name="product_option[{{ option_row }}][master_option_value]" value="0">
                              {% endif %}
                          </div>
                      </div>
			<!--EOF Related Options-->
			]]>
			</add>
		</operation>
		<operation error="skip">
			<search><![CDATA[{% if product_option.type == 'datetime' %}]]></search>
			<add position="after"><![CDATA[
			<!--BOF Related Options-->
                      <div class="form-group">
                          <label class="col-sm-2 control-label">{{ entry_master_option_value }}</label>
                          <div class="col-sm-10 col-master-{{ option_row }}" data-col="{{ option_row }}" data-row="0">
                              {% if product_option.master_option %}
                              <select name="product_option[{{ option_row }}][master_option_value]" value="{{ product_option.option_value }}" class="form-control">
                                  <option value="0">{{ text_no }}</option>
                                  {% for master_option_value in product_option.master_option_data.product_option_value %}
                                  {% if master_option_value.product_option_value_id == product_option.master_option_value %}
                                  <option value="{{ master_option_value.product_option_value_id }}" selected="selected">{{ master_option_value.name }}</option>
                                  {% else %}
                                  <option value="{{ master_option_value.product_option_value_id }}">{{ master_option_value.name }}</option>
                                  {% endif %}
                                  {% endfor %}
                              </select>
                              {% else %}
                              - <input type="hidden" name="product_option[{{ option_row }}][master_option_value]" value="0">
                              {% endif %}
                          </div>
                      </div>
			<!--EOF Related Options-->
			]]>
			</add>
		</operation>
		<operation error="skip">
			<search index="0"><![CDATA[<td class="text-right">{{ entry_weight }}</td>]]></search>
			<add position="after"><![CDATA[
			<!--BOF Related Options-->
                              <td class="text-center">{{ entry_image }}</td>
                              <td class="text-left">{{ entry_master_option_value }}</td>
			<!--EOF Related Options-->
			]]>
			</add>
		</operation>
		<operation error="skip">
			<search index="0"><![CDATA[<td colspan="6"></td>]]></search>
			<add position="replace"><![CDATA[<td colspan="8"></td>]]></add>
		</operation>
		<operation error="skip">
			<search><![CDATA[html += '        <td colspan="6"></td>';]]></search>
			<add position="replace"><![CDATA[html += '        <td colspan="8"></td>';]]></add>
		</operation>
		<operation error="skip">
			<!-- Regular expression for compatibility with Opencart versions <=3.0.3.1 and >=3.0.3.2 -->
			<search regex="true"><![CDATA[~(<input type="text" name="product_option\[{{ option_row }}]\[product_option_value]\[{{ option_value_row }}]\[weight]" value="{{ product_option_value\.weight }}" placeholder="{{ entry_weight }}" class="form-control" ?\/><\/td>)~]]></search>
			<add position="after"><![CDATA[
			$1
			<!--BOF Related Options-->
                          <td class="text-center">
                              <a href="" id="product-option-image-thumb{{ option_value_row }}" data-toggle="image" class="img-thumbnail"><img src="{{ product_option_value.option_thumb }}" alt="" title="" data-placeholder="{{ placeholder }}" /></a>
                              <input type="hidden" name="product_option[{{ option_row }}][product_option_value][{{ option_value_row }}][option_image]" value="{{ product_option_value.option_image }}" id="product-option-image-input{{ option_value_row }}" />
                          </td>
                          <td class="text-left col-master-{{ option_row }}" data-col="{{ option_row }}" data-row="{{ option_value_row }}">
                              {% if product_option.master_option %}
                                <select name="product_option[{{ option_row }}][product_option_value][{{ option_value_row }}][master_option_value]" class="form-control">
                                    <option value="0">{{ text_no }}</option>
                                    {% for master_option_value in product_option.master_option_data.product_option_value %}
                                    {% if master_option_value.product_option_value_id == product_option_value.master_option_value %}
                                    <option value="{{ master_option_value.product_option_value_id }}" selected="selected">{{ master_option_value.name }}</option>
                                    {% else %}
                                    <option value="{{ master_option_value.product_option_value_id }}">{{ master_option_value.name }}</option>
                                    {% endif %}
                                    {% endfor %}
                                </select>
                              {% else %}
                          <center>-</center>
                          <input type="hidden" name="product_option[{{ option_row }}][product_option_value][{{ option_value_row }}][master_option_value]" value="0">
                          {% endif %}
                          </td>

			<!--EOF Related Options-->
			]]>
			</add>
		</operation>
		<operation error="skip">
			<search><![CDATA[<select id="option-values{{ option_row }}" style="display: none;">]]></search>
			<add position="before"><![CDATA[
			<!--BOF Related Options-->
                        {% if product_option.master_option %}
                        <select id="master-option-values{{ option_row }}" style="display: none;" class="form-control">
                            {% for master_option_value in product_option.master_option_data.product_option_value %}
                            <option value="{{ master_option_value.product_option_value_id }}">{{ master_option_value.name }}</option>
                            {% endfor %}
                        </select>
                        {% endif %}
			<!--EOF Related Options-->
			]]>
			</add>
		</operation>
		<operation error="skip">
			<search><![CDATA[if (item['type'] == 'text') {]]></search>
			<add position="before"><![CDATA[
			<!--BOF Related Options-->
                html += '	  <div class="form-group">';
                html += '         <label class="col-sm-2 control-label">{{ entry_master_option }}</label>';
                html += '       <div class="col-sm-10"><select name="product_option[' + option_row + '][master_option]" class="form-control">';
                html += '	    <option value="0">{{ text_no }}</option>';
                
                $('input[name$="[option_id]"]').each(function() {
                var name = $(this).attr('name').split('][');
                var num = name[0].split('[');
                num = num[1];
                html += '<option value="'+ $(this).val() +'">'+ $('input[name="product_option[' + num + '][name]"]').val() +'</option>';
                });
                html += ' </select></div>';
                html += ' </div>';

                if (item['type'] != 'select' && item['type'] != 'radio' && item['type'] != 'checkbox' && item['type'] != 'image') {
                html += '	<div class="form-group">';
                html += '	  <label class="col-sm-2 control-label" for="input-value' + option_row + '">{{ entry_master_option_value }}</label>';
                html += '	  <div class="col-sm-10 col-master-' + option_row +'" data-col="' + option_row +'" data-row="0">- <input type="hidden" name="product_option[' + option_row + '][master_option_value]" value="0"></div>';
                html += '	</div>';
                }
			<!--EOF Related Options-->
			]]>
			</add>
		</operation>
		<operation error="skip">
			<search><![CDATA[html += '        <td class="text-right">{{ entry_weight }}</td>';]]></search>
			<add position="after"><![CDATA[
			<!--BOF Related Options-->
                        html += '        <td class="text-center">{{ entry_image }}</td>';
                        html += '        <td class="text-left">{{ entry_master_option_value }}</td>';
			<!--EOF Related Options-->
			]]>
			</add>
		</operation>
		<operation error="skip">
			<!-- Regular expression for compatibility with Opencart versions <=3.0.3.1 and >=3.0.3.2 -->
			<search regex="true"><![CDATA[~(html  ?= '<div class="tab-pane" id="tab-option' \+ option_row \+ '">';)~]]></search>
			<add position="before"><![CDATA[
				if (item['type'] == 'select' || item['type'] == 'radio' || item['type'] == 'checkbox' || item['type'] == 'image') {
					$('select[name$="[master_option]"]').append('<option value="'+ item['value'] +'">'+ item['label'] +'</option>');
				}
			$1
			]]></add>
		</operation>
		<operation error="skip">
			<search><![CDATA[html += '  <input type="text" name="product_option[' + option_row + '][product_option_value][' + option_value_row + '][weight]" value="" placeholder="{{ entry_weight }}" class="form-control" /></td>';]]></search>
			<add position="after"><![CDATA[
			<!--BOF Related Options-->
		html += '  <td class="text-center">';
		html += '    <a href="" id="product-option-image-thumb' + option_value_row + '" data-toggle="image" class="img-thumbnail"><img src="{{ placeholder }}" alt="" title="" data-placeholder="{{ placeholder }}" /></a>';
		html += '      <input type="hidden" name="product_option[' + option_row + '][product_option_value][' + option_value_row + '][option_image]" value="" id="product-option-image-input' + option_value_row + '" />';
		html += '  </td>';

	if ($('#master-option-values' + option_row).length > 0) {
		html += '    <td class="text-left col-master-' + option_row +'" data-col="' + option_row +'" data-row="' + option_value_row +'"><select name="product_option[' + option_row + '][product_option_value][' + option_value_row + '][master_option_value]" class="form-control">';
		html += '        <option value="0">{{ text_no }}</option>';
		html += $('#master-option-values' + option_row).html();
		html += '    </select></td>';
	} else {
		html += '<td class="text-left col-master-' + option_row +'" data-col="' + option_row +'" data-row="' + option_value_row +'"><center>-</center><input type="hidden" name="product_option[' + option_row + '][product_option_value][' + option_value_row + '][master_option_value]" value="0"></td>';
	}
			<!--EOF Related Options-->
			]]></add>
		</operation>
		<operation error="skip">
			<search><![CDATA[<li><a href="#tab-option{{ option_row }}" data-toggle="tab"><i class="fa fa-minus-circle" onclick="$('a[href=\'#tab-option{{ option_row }}\']').parent().remove(); $('#tab-option{{ option_row }}').remove(); $('#option a:first').tab('show');"></i> {{ product_option.name }}</a></li>]]></search>
			<add position="replace" trim="true"><![CDATA[
				<li><a href="#tab-option{{ option_row }}" data-toggle="tab"><i class="fa fa-minus-circle" onclick="master_option_del({{option_row }}); $('a[href=\'#tab-option{{ option_row }}\']').parent().remove(); $('#tab-option{{ option_row }}').remove(); $('#option a:first').tab('show');"></i> {{ product_option.name }}</a></li>
			]]></add>
		</operation>
		<operation error="skip">
			<search><![CDATA[onclick="$(this).tooltip('destroy');$('#option-value-row{{ option_value_row }}').remove();"]]></search>
			<add position="replace" trim="true"><![CDATA[
				onclick="$(this).tooltip('destroy');$('#option-value-row{{ option_value_row }}').remove(); master_option_ch({{ option_row }});"
			]]></add>
		</operation>
		<operation error="skip">
			<search><![CDATA[onclick=" $(\'#option a:first\').tab(\'show\');$(\'a[href=\\\'#tab-option' + option_row + '\\\']\').parent().remove(); $(\'#tab-option' + option_row + '\').remove();"]]></search>
			<add position="replace" trim="true"><![CDATA[
				onclick="master_option_del(' + option_row + '); $(\'#option a:first\').tab(\'show\');$(\'a[href=\\\'#tab-option' + option_row + '\\\']\').parent().remove(); $(\'#tab-option' + option_row + '\').remove();"
			]]></add>
		</operation>
		<operation error="skip">
			<search><![CDATA[onclick="$(this).tooltip(\'destroy\');$(\'#option-value-row' + option_value_row + '\').remove();"]]></search>
			<add position="replace" trim="true"><![CDATA[
				onclick="$(this).tooltip(\'destroy\');$(\'#option-value-row' + option_value_row + '\').remove(); master_option_ch('+option_row+');"
			]]></add>
		</operation>
		<operation error="skip">
			<search><![CDATA[$('[rel=tooltip]').tooltip();]]></search>
			<add position="after"><![CDATA[
				master_option(option_row, option_value_row);
				master_option_ch(option_row);
			]]></add>
		</operation>
		<operation error="skip">
			<search><![CDATA[<link href="view/javascript/codemirror/lib/codemirror.css"]]></search>
			<add position="before"><![CDATA[
			<!--BOF Related Options-->
				<style type="text/css">
					.rdo_popover_images a {
						margin-top: 2px;
						margin-right: 2px;
					}
					.rdo_popover_images img {
						height: 40px;
						width: 40px;
					}
				</style>
			<!--EOF Related Options-->
			]]></add>
		</operation>

		<operation error="skip">
			<search><![CDATA[var option_value_row = {{ option_value_row }};]]></search>
			<add position="before"><![CDATA[

			//START RDO BASIC FUNCTIONS

			$(document).ready(function() {
				$('#form-product').on('change', 'select[name$="[master_option]"]', function() {
					var type_name = $(this).parent().parent().parent().children('input[type=hidden]:last').attr('value');
					var name_parent = $(this).attr('name').split('][');
					var num_parent = name_parent[0].split('[');
					var val_parent = $('#option-value'+num_parent[1]).find('select:first').val();
					if (val_parent > 0){
						updateProductOptions();
					}
					if (type_name != 'select' && type_name != 'radio' && type_name != 'checkbox' && type_name != 'image') {
						updateProductOptions();
					}
				});

				//$('#form-product').on('change', 'select[name$="[option_value_id]"]', function() {
				   /// var name = $(this).attr('name').split('][');
				   /// var num = name[0].split('[');
				   /// master_option_ch(num[1]);
				   // updateProductOptions();
				//});
			});

				function master_option(option_num, row, selected) {
					var id = $('select[name="product_option['+ option_num  +'][master_option]"]').val();
					var type = $('input[name="product_option['+ option_num  +'][type]"]').val();

					if (id == 0) {
						$('.col-master-' + option_num).each(function() {
							if (typeof(row) == 'undefined' || row == $(this).data('row')) {
								if (type == 'select' || type == 'radio' || type == 'checkbox' || type == 'image') {
									$(this).html('<center>-</center><input type="hidden" name="product_option[' + $(this).data('col') + '][product_option_value][' + $(this).data('row') + '][master_option_value]" value="0">');
								} else {
									$(this).html('- <input type="hidden" name="product_option[' + $(this).data('col') + '][master_option_value]" value="0">');
								}
							}
						});
					} else {
						
					}
				}

				function master_option_ch(option_row) {
					var option_id = $('input[name="product_option['+ option_row +'][option_id]"]').val();
					$('select[name$="[master_option]"]').each(function() {
						if ($(this).val() == option_id) {
							var name_1 = $(this).attr('name').split('][');
							var num_1 = name_1[0].split('[');

							$('.col-master-' + num_1[1]).each(function() {
								master_option($(this).data('col'), $(this).data('row'), $(this).find('select').val());
							});
						}
					});
				}

				function master_option_del(option_row) {
					var option_id = $('input[name="product_option['+ option_row +'][option_id]"]').val();
					$('select[name$="[master_option]"]').each(function() {
						if ($(this).val() == option_id) {
							$(this).val(0);
							var name_1 = $(this).attr('name').split('][');
							var num_1 = name_1[0].split('[');
							$('.col-master-' + num_1[1]).each(function() {
								master_option($(this).data('col'));
							});
						}
						$(this).find('option[value='+ option_id +']').remove();
					});
				}

				function updateProductOptions() {
					var data = {};
					$('#form-product').find('input, select, textarea').each(function() {
						data[this.name] = $(this).val();
					});
					data['product_id'] = '{{ product_id }}';
					data['active'] = $('#option li.active > a:last').attr('href');

					if(!data['active'].length){
						console.log('Active product option tab not found');
					}

					if(data['product_id'] == 0){
						alert('{{error_save_product}}');
						return false;
					}
					//console.log(data['product_id']);

					$.ajax({
						url: 'index.php?route=catalog/product/updaterelations&user_token={{ user_token }}',
						method: 'POST',
						data: data,
						dataType: "json",
						cache: false,
						beforeSend: function() {
							$('.tab-pane.active').css('opacity', '0.6');
						},
						success: function(json) {
							if (!json) {
								console.log('updateProductOptions() error');
							}
							if (json['error']) {
								alert(json['error']);
							}
							if (json['html']) {
								$('#tab-option').html(json['html']);
							}
						},
						complete: function() {
							$('.tab-pane.active').css('opacity', '1');
						},
						error: function(xhr, ajaxOptions, thrownError) {
							alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
						}
					});
				}

			//END RDO BASIC FUNCTIONS

			//START RDO OPTION IMAGE CHANGE FUNCTIONS

			$(document).ready(function() {

				// Show additional images in a popover
				$(document).on('click', 'a[data-toggle=\'image\'][id ^= "product-option-image-thumb"]', function() {
					var $element = $(this);

					// Get additional images
					var $productImages = $('.previewImg'),
					     popoverImages = "";

					if (!$productImages.length) {
						console.log("RDO: Additional images not found");
						return false;
					}

					$productImages.each(function(index, element) {
						thumbSrc = $(element).children('img').attr('src');
						imageSrc = $(element).siblings('input[type=hidden]').val();

						popoverImages += "<a href='' class='img-thumbnail'><img src='" + thumbSrc + "' alt='' data-original-image='" + imageSrc + "'></a>";
					});

					// Get popover
					var $popoverContent = $(this).siblings('.popover').find('.popover-content');

					if (!$popoverContent.length) {
						console.log("RDO: Popover not found");
						return false;
					}

					// Add additional images block to popover
					if (!$popoverContent.find('.rdo_popover_images').length) {
						$popoverContent.append('<div class="rdo_popover_images"></div>');
					}

					// Add additional images to popover
					$popoverContent.find('.rdo_popover_images').html(popoverImages);

					// Change image
					$('.rdo_popover_images a').on('click', function(e) {
						e.preventDefault();

						$element.find('img').attr('src', $(this).find('img').attr('src'));
						$element.parent().find('input[type=hidden]').val($(this).find('img').attr('data-original-image'));
						$element.popover('destroy');
					});
				});
			});

			//END RDO OPTION IMAGE CHANGE FUNCTIONS

			]]></add>
		</operation>

		<operation error="skip">
			<search><![CDATA[option_value_row++;]]></search>
			<add position="after"><![CDATA[
			//BOF Related Options
			//updateProductOptions();
			//EOF Related Options
			]]></add>
		</operation>

		<!-- [Prefix "=" for product option values] -->
		<operation error="skip">
			<search><![CDATA[{% if product_option_value.price_prefix == '+' %}]]></search>
			<add position="before"><![CDATA[
			<!--BOF Related Options-->
			{% if product_option_value.price_prefix == '=' %}
				<option value="=" selected="selected">=</option>
			{% else %}
				<option value="=">=</option>
			{% endif %}
			<!--EOF Related Options-->
			]]></add>
		</operation>

		<!-- [Prefix "=" for product option values] -->
		<operation error="skip">
			<search><![CDATA[{% if product_option_value.points_prefix == '+' %}]]></search>
			<add position="before"><![CDATA[
			<!--BOF Related Options-->
			{% if product_option_value.points_prefix == '=' %}
				<option value="=" selected="selected">=</option>
			{% else %}
				<option value="=">=</option>
			{% endif %}
			<!--EOF Related Options-->
			]]></add>
		</operation>

		<!-- [Prefix "=" for product option values] -->
		<operation error="skip">
			<search><![CDATA[{% if product_option_value.weight_prefix == '+' %}]]></search>
			<add position="before"><![CDATA[
			<!--BOF Related Options-->
			{% if product_option_value.weight_prefix == '=' %}
				<option value="=" selected="selected">=</option>
			{% else %}
				<option value="=">=</option>
			{% endif %}
			<!--EOF Related Options-->
			]]></add>
		</operation>

		<!-- [Prefix "=" for product option values] -->
		<operation error="skip">
			<search><![CDATA[<option value="-">-</option>';]]></search>
			<add position="after"><![CDATA[
			<!--BOF Related Options-->
			html += '    <option value="=">=</option>';
			<!--EOF Related Options-->
			]]></add>
		</operation>
	</file>

	<file path="catalog/controller/product/product.php">

		<!-- index() -->
		<operation error="skip">
			<search><![CDATA[foreach ($option['product_option_value'] as $option_value) {]]></search>
			<add position="after"><![CDATA[
					//BOF Related Options
					if (isset($data['RDO_settings']['show_out_of_stock']) && $data['RDO_settings']['show_out_of_stock'] && $option_value['subtract'] && ($option_value['quantity'] <= 0)) {
						$option_value['subtract'] = false;
					}
					//EOF Related Options
			]]></add>
		</operation>
		
		<!-- index() -->
		<operation error="skip">
			<search><![CDATA['required'             => $option['required']]]></search>
			<add position="before"><![CDATA[
			//BOF Related Options
			'master_option'          => $option['master_option'],
			'master_option_value'    => isset($option['master_option_value']) ? $option['master_option_value'] : null,
			//EOF Related Options
			]]></add>
		</operation>

		<!-- index() -->
		<operation error="skip">
			<search><![CDATA[$product_option_value_data[] = array(]]></search>
			<add position="before"><![CDATA[
			//BOF Related Options
						if ($option_value['option_image']) {
							// Maximum size
							$option_image_popup = $this->model_tool_image->resize($option_value['option_image'], $this->config->get('theme_' . $this->config->get('config_theme') . '_image_popup_width'), $this->config->get('theme_' . $this->config->get('config_theme') . '_image_popup_height'));

							// Preview size
							$option_image_preview = $this->model_tool_image->resize($option_value['option_image'], $this->config->get('theme_' . $this->config->get('config_theme') . '_image_thumb_width'), $this->config->get('theme_' . $this->config->get('config_theme') . '_image_thumb_height'));

							// Thumb size
							//$option_image_additional_thumb = $this->model_tool_image->resize($option_value['option_image'], $this->config->get('theme_' . $this->config->get('config_theme') . '_image_additional_width'), $this->config->get('theme_' . $this->config->get('config_theme') . '_image_additional_height'));

							// Standard option image size
							//$option_image_thumb = $this->model_tool_image->resize($option_value['option_image'], 50, 50);

							$option_image_pathinfo['dn']  = pathinfo($option_value['option_image'], PATHINFO_DIRNAME);
							$option_image_pathinfo['ds']  = DIRECTORY_SEPARATOR;
							$option_image_pathinfo['fn']  = pathinfo($option_value['option_image'], PATHINFO_FILENAME);
							$option_image_pathinfo['ext'] = pathinfo($option_value['option_image'], PATHINFO_EXTENSION);

							$product_option_value_images[$option_value['product_option_value_id']] = array(
								'image_pathinfo' => $option_image_pathinfo,
								'image'          => $option_image_preview,
								'image_large'    => $option_image_popup
							);
						}
			//EOF Related Options
			]]></add>
		</operation>

		<!-- index() -->
		<operation error="skip">
			<search><![CDATA['price_prefix'            => $option_value['price_prefix']]]></search>
			<add position="before"><![CDATA[
			//BOF Related Options
			'quantity'     	          => $option_value['quantity'],
			'master_option_value'     => $option_value['master_option_value'],
			//EOF Related Options
			]]></add>
		</operation>

		<!-- index() -->
		<operation error="skip">
			<search><![CDATA[if ($product_info['minimum']) {]]></search>
			<add position="before"><![CDATA[
			//BOF Related Options
			$json_flags = JSON_HEX_APOS | JSON_HEX_QUOT | JSON_UNESCAPED_UNICODE;

			$data['RDO_option_images'] = isset($product_option_value_images) ? json_encode($product_option_value_images, $json_flags) : null;
			//EOF Related Options
			]]></add>
		</operation>

		<!-- index() -->
		<!-- <search><![CDATA[$this->document->setTitle($product_info['meta_title']]]></search> -->
		<!-- <search><![CDATA[$this->document->addLink($this->url->link('product/product',]]></search> -->
		<!-- <search><![CDATA[$this->document->addStyle('catalog/view/javascript/jquery/datetimepicker/bootstrap-datetimepicker.min.css');]]></search> -->
		<!-- <search><![CDATA[$data['heading_title'] = $product_info['name']]]></search> -->
		<operation error="skip">
			<search><![CDATA[$this->document->addStyle('catalog/view/javascript/jquery/datetimepicker/bootstrap-datetimepicker.min.css');]]></search>
			<add position="after"><![CDATA[
			//BOF Related Options
			$data['RDO_settings'] = $this->config->get('module_related_options_settings');
			$data['RDO_status'] = $this->config->get('module_related_options_status');
			//EOF Related Options]]></add>
		</operation>

		<!-- index() -->
		<operation error="skip">
			<search><![CDATA[$this->model_catalog_product->updateViewed($this->request->get['product_id']);]]></search>
			<add position="after"><![CDATA[
			//BOF Related Options
			$json_flags = JSON_HEX_APOS | JSON_HEX_QUOT | JSON_UNESCAPED_UNICODE;

			$data['RDO_config'] = json_encode(array(
				'price_animate_on'    =>  (int)$data['RDO_settings']['price_animate_on'],
				'price_multiply'      =>  (int)$data['RDO_settings']['price_multiply'],
				'option_selector'     => isset($data['RDO_settings']['option_selector'])    ? html_entity_decode($data['RDO_settings']['option_selector'], ENT_QUOTES, 'UTF-8')    : '',
				'price_selector'      => isset($data['RDO_settings']['price_selector'])     ? html_entity_decode($data['RDO_settings']['price_selector'], ENT_QUOTES, 'UTF-8')     : '',
				'price_old_selector'  => isset($data['RDO_settings']['price_old_selector']) ? html_entity_decode($data['RDO_settings']['price_old_selector'], ENT_QUOTES, 'UTF-8') : '',
				'quantity_selector'   => isset($data['RDO_settings']['quantity_selector'])  ? html_entity_decode($data['RDO_settings']['quantity_selector'], ENT_QUOTES, 'UTF-8')  : ''
			), $json_flags);

			$data['RDO_product_data'] = json_encode(array(
				'model'           => trim($data['model']),
				'reward'          => (int)$data['reward'],
				'points'          => (int)$data['points'],
				'minimum'         => (int)$data['minimum'],
				'price'           => $data['price'], //$product_info['price'],
				'special'         => $data['special'], //$product_info['special'],
				'tax'             => $data['tax'], //(float)$product_info['special'] ? $product_info['special'] : $product_info['price'],
				'decimal_point'   => $this->language->get('decimal_point'),
				'thousand_point'  => $this->language->get('thousand_point'),
				'symbol_left'     => $this->currency->getSymbolLeft($this->session->data['currency']),
				'symbol_right'    => $this->currency->getSymbolRight($this->session->data['currency']),
				'decimal_place'   => (int)$this->currency->getDecimalPlace($this->session->data['currency']),
				'discounts'       => $data['discounts']
			), $json_flags);

			$options_data = array();

			foreach ($data['options'] as $product_option) {
				if (isset($product_option['product_option_value']) && is_array($product_option['product_option_value'])) {
					foreach ($product_option['product_option_value'] as $product_option_value) {
						$id = $product_option_value['product_option_value_id'];
						$options_data[$id] = $product_option_value;
					}
				}
			}

			$json_flags = JSON_HEX_APOS | JSON_HEX_QUOT | JSON_UNESCAPED_UNICODE;

			$data['RDO_options_data'] = json_encode($options_data, $json_flags);
			//EOF Related Options
			]]></add>
		</operation>
	</file>

	<file path="catalog/model/catalog/product.php">

		<!-- getProductOptions() -->
		<operation error="skip">
			<search><![CDATA['weight_prefix'           => $product_option_value['weight_prefix']]]></search>
			<add position="before"><![CDATA[
			//BOF Related Options
			'master_option_value'             => $product_option_value['master_option_value'],
			'option_image'                    => $product_option_value['option_image'],
			//EOF Related Options
			]]></add>
		</operation>

		<operation error="skip">
			<search><![CDATA['image'                   => $product_option_value['image'],]]></search>
			<add position="replace"><![CDATA[
			'image'                   => $product_option_value['option_image'],
			]]></add>
		</operation>

		<!-- getProductOptions() -->
		<operation error="skip">
			<search><![CDATA['required'             => $product_option['required']]]></search>
			<add position="before"><![CDATA[
			//BOF Related Options
			'master_option'          => $product_option['master_option'],
			'master_option_value'    => isset($product_option['master_option_value']) ? $product_option['master_option_value'] : null,
			//EOF Related Options
			]]></add>
		</operation>

	</file>
	
	<file path="catalog/controller/checkout/cart.php">
		<operation error="skip">
			<search><![CDATA[if ($product_option['required'] && empty($option[$product_option['product_option_id']])) {]]></search>
			<add position="after"><![CDATA[
			//BOF Related Options
			$error = true;

			// если у текущей, незаполненной опции есть родительская опция
			if ($product_option['master_option'] > 0) {

				// проверяем, возможно и не должна быть заполнена (например, если родительская опция не заполнена)
				// проходим по всем опциям товара
				foreach ($product_options as $product_option_parent) {

					// если нашлась родительская опция
					if ($product_option['master_option'] == $product_option_parent['option_id']) {

						// проверяем, заполнена ли она
						if (empty($option[ $product_option_parent['product_option_id'] ])) {

							// если родительская опция не заполнена - ошибки нет (текущая опция и не должна быть заполнена)
							$error = false;
							break;
						}

						// если родительская заполнена - проверяем, зависит ли хоть одно из значений незаполненной опции от выбранной родительской

						// для опций с типом Radio / Checkbox / Select
						if (!empty($product_option['product_option_value'])) {

							// проходим по незаполненной опции
							foreach ($product_option['product_option_value'] as $product_option_value) {
								$error = false;

								// тип опции - checkbox
								// если значение незаполненной опции зависит от выбранных значений родительской - значит она обязательна к заполнению
								if (is_array($option[ $product_option_parent['product_option_id'] ]) && in_array($product_option_value['master_option_value'], $option[ $product_option_parent['product_option_id'] ])) {
									$error = true;
									break 2;
								}

								// тип опции - radio и select
								// если значение незаполненной опции зависит от выбранного значения родительской - значит она обязательна к заполнению
								if ($product_option_value['master_option_value'] == $option[ $product_option_parent['product_option_id'] ]) {
									$error = true;
									break 2;
								}
							}
						} else {
							// для опций с типом Text / Textarea / Button

							// если опция не зависит от выбранного значения родительской - значит она не обязательна к заполнению (ошибки нет)
							if ($product_option['master_option_value'] != $option[ $product_option_parent['product_option_id'] ]) {
								$error = false;
								break;
							}
						}
					}
				}
			}

			// ошибку заполненности для текущей опции отображать не требуется
			if ($error === false) {
				continue;
			}
			//EOF Related Options
			]]></add>
		</operation>

		<!-- index() [Show option image in the cart] -->
		<operation error="skip">
			<search><![CDATA[$value = $option['value'];]]></search>
			<add position="after"><![CDATA[
			//BOF Related Options
			if(isset($option['option_image']) && $option['option_image'] != "") {
				$image = $this->model_tool_image->resize($option['option_image'], $this->config->get('theme_' . $this->config->get('config_theme') . '_image_cart_width'), $this->config->get('theme_' . $this->config->get('config_theme') . '_image_cart_height'));
			}
			//EOF Related Options
			]]></add>
		</operation>
	</file>

	<file path="catalog/controller/common/cart.php">

		<!-- index() [Show option image in the cart] -->
		<operation error="skip">
			<search><![CDATA[$value = $option['value'];]]></search>
			<add position="after"><![CDATA[
			//BOF Related Options
			if(isset($option['option_image']) && $option['option_image'] != "") {
				$image = $this->model_tool_image->resize($option['option_image'], $this->config->get('theme_' . $this->config->get('config_theme') . '_image_cart_width'), $this->config->get('theme_' . $this->config->get('config_theme') . '_image_cart_height'));
			}
			//EOF Related Options
			]]></add>
		</operation>
	</file>

	<file path="system/library/cart/cart.php">

		<!-- getProducts() -->
		<operation error="skip">
			<search><![CDATA[po.option_id,]]></search>
			<add position="replace"><![CDATA[po.option_id, po.master_option, po.master_option_value,]]></add>
		</operation>

		<!-- getProducts() -->
		<operation error="skip">
			<search><![CDATA[pov.weight_prefix]]></search>
			<add position="replace"><![CDATA[pov.weight_prefix, pov.master_option_value, pov.option_image, pov.option_model]]></add>
		</operation>

		<!-- getProducts() -->
		<operation error="skip">
			<search index="0,1"><![CDATA['name'                    => $option_query->row['name'],]]></search>
			<add position="before"><![CDATA[
			//BOF Related Options
			'option_image'                => $option_value_query->row['option_image'],
			'option_model'                => $option_value_query->row['option_model'],
			//EOF Related Options
			]]></add>
		</operation>

		<!-- getProducts() [Prefix "=" for product option values] -->
		<operation error="skip">
			<search><![CDATA[$option_price -= $option_value_query->row['price'];]]></search>
			<add position="after"><![CDATA[
			//BOF Related Options
			} elseif ($option_value_query->row['price_prefix'] == '=') {
				$new_price = $option_value_query->row['price'];
			//EOF Related Options
			]]></add>
		</operation>

		<!-- getProducts() [Prefix "=" for product option values] -->
		<operation error="skip">
			<search><![CDATA[$option_points -= $option_value_query->row['points'];]]></search>
			<add position="after"><![CDATA[
			//BOF Related Options
			} elseif ($option_value_query->row['points_prefix'] == '=') {
				$new_points = $option_value_query->row['points'];
			//EOF Related Options
			]]></add>
		</operation>

		<!-- getProducts() [Prefix "=" for product option values] -->
		<operation error="skip">
			<search><![CDATA[$option_weight -= $option_value_query->row['weight'];]]></search>
			<add position="after"><![CDATA[
			//BOF Related Options
			} elseif ($option_value_query->row['weight_prefix'] == '=') {
				$new_weight = $option_value_query->row['weight'];
			//EOF Related Options
			]]></add>
		</operation>

		<!-- getProducts() [Prefix "=" for product option values] -->
		<operation error="skip">
			<search><![CDATA[$product_data[] = array(]]></search>
			<add position="before"><![CDATA[
			//BOF Related Options
			$option_price  += (isset($new_price))  ? $new_price  - $price                        : 0;
			$option_points += (isset($new_points)) ? $new_points - $product_query->row['points'] : 0;
			$option_weight += (isset($new_weight)) ? $new_weight - $product_query->row['weight'] : 0;
			//EOF Related Options
			]]></add>
		</operation>
	</file>

	<file path="catalog/view/theme/journal3/template/product/product.twig">
		<operation error="skip">
			<search><![CDATA[<div class="form-group{% if option.required %} required {% endif %} product-option-{{ option.type }} {% if j3.settings.get(stylePrefix ~ 'OptionsPushSelect') %}push-option{% endif %}">]]></search>
			<add position="replace"><![CDATA[
			<!--BOF Related Options-->
			<div class="rdo-option form-group{% if option.required %} required {% endif %} product-option-{{ option.type }} {% if j3.settings.get(stylePrefix ~ 'OptionsPushSelect') %}push-option{% endif %}" master-option="{{ option.master_option }}" option="{{ option.option_id }}" id="option-{{ option.product_option_id }}">
			<!--EOF Related Options-->
			]]></add>
		</operation>
		<operation error="skip">
			<search><![CDATA[<div class="form-group{% if option.required %} required {% endif %} product-option-{{ option.type }} {% if j3.settings.get(stylePrefix ~ 'OptionsPushRadio') %}push-option{% endif %}">]]></search>
			<add position="replace"><![CDATA[
			<!--BOF Related Options-->
			<div class="rdo-option form-group{% if option.required %} required {% endif %} product-option-{{ option.type }} {% if j3.settings.get(stylePrefix ~ 'OptionsPushRadio') %}push-option{% endif %}" master-option="{{ option.master_option }}" option="{{ option.option_id }}" id="option-{{ option.product_option_id }}">
			<!--EOF Related Options-->
			]]></add>
		</operation>
		<operation error="skip">
			<search><![CDATA[<div class="form-group{% if option.required %} required {% endif %} product-option-{{ option.type }} {% if j3.settings.get(stylePrefix ~ 'OptionsPushCheckbox') %}push-option{% endif %}">]]></search>
			<add position="replace"><![CDATA[
			<!--BOF Related Options-->
			<div class="rdo-option form-group{% if option.required %} required {% endif %} product-option-{{ option.type }} {% if j3.settings.get(stylePrefix ~ 'OptionsPushCheckbox') %}push-option{% endif %}" master-option="{{ option.master_option }}" option="{{ option.option_id }}" id="option-{{ option.product_option_id }}">
			<!--EOF Related Options-->
			]]></add>
		</operation>
		<operation error="skip">
			<search><![CDATA[<div class="form-group{% if option.required %} required {% endif %} product-option-{{ option.type }}">]]></search>
			<add position="replace"><![CDATA[
			<!--BOF Related Options-->
			<div class="rdo-option form-group{% if option.required %} required {% endif %} product-option-{{ option.type }}" master-option="{{ option.master_option }}" option="{{ option.option_id }}" id="option-{{ option.product_option_id }}">
			<!--EOF Related Options-->
			]]></add>
		</operation>
		

		<operation error="skip">
			<search><![CDATA[<option value="{{ option_value.product_option_value_id }}">{{ option_value.name }}]]></search>
			<add position="replace"><![CDATA[
			<!--BOF Related Options-->
			<option value="{{ option_value.product_option_value_id }}" master-option-value="{{ option_value.master_option_value }}" option-value="{{option_value.product_option_value_id }}" {% if RDO_status and RDO_settings.buy_out_of_stock == 0 and option_value.quantity is defined and option_value.quantity <= 0 %} disabled {% endif %}> {{ option_value.name }}
			<!--EOF Related Options-->
			]]></add>
		</operation>
		<operation error="skip">
			<search><![CDATA[<input type="radio" name="option[{{ option.product_option_id }}]" value="{{ option_value.product_option_value_id }}" />]]></search>
		<add position="replace"><![CDATA[
		<!--BOF Related Options-->
			<input type="radio" name="option[{{ option.product_option_id }}]" value="{{ option_value.product_option_value_id }}" id="option-value-{{ option_value.product_option_value_id }}" master-option-value="{{ option_value.master_option_value }}" option-value="{{option_value.product_option_value_id }}" {% if RDO_status and RDO_settings.buy_out_of_stock == 0 and option_value.quantity is defined and option_value.quantity <= 0 %} disabled {% endif %} />
			<!--EOF Related Options-->
			]]></add>
		</operation>
		<operation error="skip">
			<search><![CDATA[<input type="checkbox" name="option[{{ option.product_option_id }}][]" value="{{ option_value.product_option_value_id }}" />]]></search>
			<add position="replace"><![CDATA[
			<!--BOF Related Options-->
			<input type="checkbox" name="option[{{ option.product_option_id }}][]" value="{{ option_value.product_option_value_id }}" id="option-value-{{ option_value.product_option_value_id }}" master-option-value="{{ option_value.master_option_value }}" option-value="{{option_value.product_option_value_id }}" {% if RDO_status and RDO_settings.buy_out_of_stock == 0 and option_value.quantity is defined and option_value.quantity <= 0 %} disabled {% endif %} />
			<!--EOF Related Options-->
			]]></add>
		</operation>
		<operation error="skip">
			<search><![CDATA[<input type="text" name="option[{{ option.product_option_id }}]" value="{{ option.value }}" placeholder="{{ option.name }}" id="input-option{{ option.product_option_id }}" class="form-control" />]]></search>
			<add position="replace"><![CDATA[
			<!--BOF Related Options-->
			<input type="text" name="option[{{ option.product_option_id }}]" value="{{ option.value }}" placeholder="{{ option.name }}" id="input-option{{ option.product_option_id }}" class="form-control" master-option-value="{{ option.master_option_value }}" {% if RDO_status and RDO_settings.buy_out_of_stock == 0 and option_value.quantity is defined and option_value.quantity <= 0 %} disabled {% endif %} />
			<!--EOF Related Options-->
			]]></add>
		</operation>
		<operation error="skip">
			<search><![CDATA[<textarea name="option[{{ option.product_option_id }}]" rows="5" placeholder="{{ option.name }}" id="input-option{{ option.product_option_id }}" class="form-control">{{ option.value }}</textarea>]]></search>
			<add position="replace"><![CDATA[
			<!--BOF Related Options-->
			<textarea name="option[{{ option.product_option_id }}]" rows="5" master-option-value="{{ option.master_option_value }}" placeholder="{{ option.name }}" id="input-option{{ option.product_option_id }}" class="form-control" {% if RDO_status and RDO_settings.buy_out_of_stock == 0 and option_value.quantity is defined and option_value.quantity <= 0 %} disabled {% endif %}>{{ option.value }}</textarea>
			<!--EOF Related Options-->
			]]></add>
		</operation>
		<operation error="skip">
			<search><![CDATA[<input type="text" name="option[{{ option.product_option_id }}]" value="{{ option.value }}" data-date-format="YYYY-MM-DD" id="input-option{{ option.product_option_id }}" class="form-control" />]]></search>
			<add position="replace"><![CDATA[
			<!--BOF Related Options-->
			<input type="text" name="option[{{ option.product_option_id }}]" value="{{ option.value }}" data-date-format="YYYY-MM-DD" id="input-option{{ option.product_option_id }}" class="form-control" master-option-value="{{ option.master_option_value }}" {% if RDO_status and RDO_settings.buy_out_of_stock == 0 and option_value.quantity is defined and option_value.quantity <= 0 %} disabled {% endif %} />
			<!--EOF Related Options-->
			]]></add>
		</operation>
		<operation error="skip">
			<search><![CDATA[<input type="text" name="option[{{ option.product_option_id }}]" value="{{ option.value }}" data-date-format="YYYY-MM-DD HH:mm" id="input-option{{ option.product_option_id }}" class="form-control" />]]></search>
			<add position="replace"><![CDATA[
			<!--BOF Related Options-->
			<input type="text" name="option[{{ option.product_option_id }}]" value="{{ option.value }}" data-date-format="YYYY-MM-DD HH:mm" id="input-option{{ option.product_option_id }}" master-option-value="{{ option.master_option_value }}" class="form-control" {% if RDO_status and RDO_settings.buy_out_of_stock == 0 and option_value.quantity is defined and option-value.quantity <= 0 %} disabled {% endif %} />
			<!--EOF Related Options-->
			]]></add>
		</operation>
		<operation error="skip">
			<search><![CDATA[<input type="text" name="option[{{ option.product_option_id }}]" value="{{ option.value }}" data-date-format="HH:mm" id="input-option{{ option.product_option_id }}" class="form-control" />]]></search>
			<add position="replace"><![CDATA[
			<!--BOF Related Options-->
			<input type="text" name="option[{{ option.product_option_id }}]" value="{{ option.value }}" data-date-format="HH:mm" id="input-option{{ option.product_option_id }}" master-option-value="{{ option.master_option_value }}" class="form-control" {% if RDO_status and RDO_settings.buy_out_of_stock == 0 and option_value.quantity is defined and option_value.quantity <= 0 %} disabled {% endif %} />
			<!--EOF Related Options-->
			]]></add>
		</operation>
		<operation error="skip">
			<search><![CDATA[<button type="button" id="button-upload{{ option.product_option_id }}" data-loading-text="{{ text_loading }}" class="btn btn-default btn-block"><i class="fa fa-upload"></i> {{ button_upload }}</button>]]></search>
			<add position="replace"><![CDATA[
			<!--BOF Related Options-->
			<button type="button" id="button-upload{{ option.product_option_id }}" data-loading-text="{{ text_loading }}" class="btn btn-default btn-block" master-option-value={{ option.master_option_value }} {% if RDO_status and RDO_settings.buy_out_of_stock == 0 and option_value.quantity is defined and option_value.quantity <= 0 %} disabled {% endif %}><i class="fa fa-upload"></i> {{ button_upload }}</button>
			<!--EOF Related Options-->
			]]></add>
		</operation>


		<operation error="skip">
			<search><![CDATA[$('#button-cart, [data-quick-buy]').on('click', function () {]]></search>
			<add position="before" offset="1"><![CDATA[
			{% if RDO_status %}
			<!--BOF Related Options-->
<script type="text/javascript"> <!--

	let RDO_productData, RDO_optionsData, RDO_optionImages = {};

	{% if RDO_config        is not empty %}RDO_config        = {{ RDO_config }};{% endif %}

	{% if RDO_product_data  is not empty %}RDO_productData   = {{ RDO_product_data }};{% endif %}

	{% if RDO_options_data  is not empty %}RDO_optionsData   = {{ RDO_options_data }};{% endif %}

	{% if RDO_option_images is not empty %}RDO_optionImages  = {{ RDO_option_images }};{% endif %}


	$(document).ready(function() {

	//START BASIC FUNCTIONS

		$('.rdo-option[master-option!=0]').hide();

		// For smooth slideUp/slideDown animation
		$('div.rdo-option, span.option-value').each(function() {
			$(this).css({
				WebkitTransition : 'none',
				MozTransition    : 'none',
				MsTransition     : 'none',
				OTransition      : 'none',
				transition       : 'none'
			});
		});

		// SELECT OPTION
		$('.rdo-option select').on('change', updateSelectOption);

		// RADIO OPTION
		$('.rdo-option input[type=radio]').on('change', updateRadioOption);

		// CHECKBOX OPTION
		$('.rdo-option input[type=checkbox]').on('change', updateCheckboxOption);

		// TEXT INPUT AND TEXTAREA OPTION
		$('.rdo-option input[type=text], .rdo-option textarea').on('change', updateTextAndTextareaOption);


		function updateSelectOption() {
			//console.log('updateSelectOption');

			let option_value = $(this).children('option:selected').attr('option-value');
			let $related_options = $('.rdo-option[master-option=' + $(this).parents('.rdo-option').attr('option') + ']');

			if ($(this).val() != '') {
				updateOptionList($related_options, option_value);
				changeImage(option_value);
			} else {
				$related_options.slideUp();
			}

			clearOption($related_options);
		}

		function updateRadioOption() {
			//console.log('updateRadioOption');

			let option_value = $(this).attr('option-value');
			let $related_options = $('.rdo-option[master-option=' + $(this).parents('.rdo-option').attr('option') + ']');

			if ($('input[name=\'' + $(this).attr('name') + '\']:checked').length != '') {
				updateOptionList($related_options, option_value);
				changeImage(option_value);
			} else {
				$related_options.slideUp();
			}

			clearOption($related_options);
		}

		function updateCheckboxOption() {
			//console.log('updateCheckboxOption');

			let option_value_clicked = ($(this).is(':checked')) ? $(this).attr('option-value') : null;
			let option_value = [];

			$('.rdo-option input[name=\'' + $(this).attr('name') + '\']:checked').each(function() {
				option_value.push($(this).attr('option-value'));
			});

			let $related_options = $('.rdo-option[master-option=' + $(this).parents('.rdo-option').attr('option') + ']');

			if ($('input[name=\'' + $(this).attr('name') + '\']:checked').length != '') {
				updateOptionList($related_options, option_value);
				changeImage(option_value_clicked);
			} else {
				$related_options.slideUp();
			}

			clearOption($related_options);
		}

		function updateTextAndTextareaOption() {
			//console.log('updateTextAndTextareaOption');

			let $related_options = $('.rdo-option[master-option=' + $(this).parents('.rdo-option').attr('option') + ']');

			if ($(this).val() != '') {
				$related_options.slideDown();
			} else {
				$related_options.slideUp();
			}

			clearOption($related_options);
		}

		function updateOptionList($related_options, option_value) {
			//console.log('updateOptionList');

			//iPhone/iPad select option fix
			$related_options.find('option[master-option-value!=0]').each(function() {
				if ($(this).parent('span').length == 0) {
					$(this).wrap("<span>");
				}
			});
			//End of fix

			// ???
			let attr = $related_options.find('input[type=hidden]').attr('master-option-value');
		
			if (typeof attr !== typeof undefined && attr !== false) {
				$related_options.find('input[type=hidden][master-option-value!=0]').prev().prop('disabled', true);
			}
			// ???

			$related_options.find('input[master-option-value!=0]').hide();
			$related_options.find('input[master-option-value!=0]').parent('label').parent('div').hide();
			$related_options.find('option[master-option-value][master-option-value!=0]').hide(); // Hide all select options that have a master-option-value attribute and it is not equal to 0
			$related_options.find('textarea[master-option-value!=0]').hide();

			if (typeof(option_value) == "string") {
				option_value = [option_value];
			}

			for (let i in option_value) {
				//iPhone/iPad select option fix
				$related_options.find('option[master-option-value=' + option_value[i] + '], option[value=\'\']').each(function() {
					if ($(this).parent('span').length != 0) {
						$(this).unwrap();
					}
				});
				//End of fix

				$related_options.find('input[type=hidden][master-option-value=' + option_value[i] + ']').prev().prop('disabled', false);

				// If standard radio and checkboxes (uncomment this line and comment next)
				//$related_options.find('input[master-option-value=' + option_value[i] + ']').show();

				// If non-standard radio and checkboxes - do not display classic radio and checkboxes (uncomment this line and comment previous)
				$related_options.find('input[master-option-value=' + option_value[i] + ']').not("input[type=radio], input[type=checkbox]").show();

				$related_options.find('input[master-option-value=' + option_value[i] + ']').parent('label').parent('div').show();

				$related_options.find('option[master-option-value=' + option_value[i] + ']').show();

				$related_options.find('textarea[master-option-value=' + option_value[i] + ']').show();
			}

			// If the block has no visible options - hide block, else show block
			$related_options.each(function() {
				let visible_options = 0;

				for (let i in option_value) {
					visible_options += $(this).find('[master-option-value=' + option_value[i] + ']').length * 1;
					visible_options += $(this).find('[master-option-value=0]').length * 1;
				}

				if ($(this).find('option, input, textarea').length != 0 && visible_options == 0) {
					$(this).slideUp();
				} else {
					$(this).slideDown();
				}
			});
		}

		function clearOption($option_container) {
			//console.log('clearOption');

			/*
			For templates without AJAX update price uncomment the lines with ".trigger("change")"
			and comment the lines with ".each(update...)".

			For templates with AJAX update, uncomment the lines with ".each(update...)"
			and comment the lines with ".trigger("change")".
			*/

			//$option_container.find('select, li').removeClass('selected').val('').trigger("change");
			$option_container.find('select, li').removeClass('selected').val('').each(updateSelectOption);

			//$option_container.find('input[type=radio]:checked, input[type=checkbox]:checked, li').removeClass('selected').removeAttr('checked').trigger("change");
			$option_container.find('input[type=radio]:checked, li').removeClass('selected').removeAttr('checked').each(updateRadioOption);
			$option_container.find('input[type=checkbox]:checked, li').removeClass('selected').removeAttr('checked').each(updateCheckboxOption);

			//$option_container.find('input[type=text], textarea').attr('value', '').val('').trigger("change");
			$option_container.find('input[type=text], textarea').attr('value', '').val('').each(updateTextAndTextareaOption);

			$option_container.find('input[type=hidden][name^=option], li').removeClass('selected').attr('value', '');
		
	{% if RDO_settings.price_adjustment_on is defined and RDO_settings.price_adjustment_on %}
			updatePrices();
	{% endif %}
		}

	//END BASIC FUNCTIONS

	//START PRICE ADJUSTMENT FUNCTIONS

	{% if RDO_settings.price_adjustment_on is defined and RDO_settings.price_adjustment_on %}

		const animatePriceEnabled  = {{ RDO_settings.price_animate_on }},
		      multiplyPriceEnabled = {{ RDO_settings.price_multiply }};
		const optionsWrapper   = (RDO_config.option_selector)    ? RDO_config.option_selector       : '.product-options',
		      $priceWrapper    = (RDO_config.price_selector)     ? $(RDO_config.price_selector)     : $('.product-price-group .product-price:first, .product-price-group .product-price-new:first'),
		      $priceOldWrapper = (RDO_config.price_old_selector) ? $(RDO_config.price_old_selector) : $('.product-price-group .product-price-old:first'),
		      $quantityInput   = (RDO_config.quantity_selector)  ? $(RDO_config.quantity_selector)  : $('#product-quantity'),
		      $taxWrapper      = $(''),
		      $pointsWrapper   = $('');

		let currentPrice    = null,
		    currentPriceOld = null;

		$quantityInput.on('change keyup', updatePrices);

		// Main
		function updatePrices() {
			const PR = RDO_productData['price'],
			      SP = RDO_productData['special'],
			      MN = RDO_productData['minimum'],
			      DC = RDO_productData['decimal_place'],
			      DP = RDO_productData['decimal_point'],
			      TP = RDO_productData['thousand_point'],
			      SL = RDO_productData['symbol_left'],
			      SR = RDO_productData['symbol_right'];

			let quantity = 1;

			if (multiplyPriceEnabled) {
				quantity = +$quantityInput.val().trim();

				if (isNaN(quantity) || quantity < MN) {
					quantity = +MN;
				}
			}

			let initialPrice             = (SP != false) ? extractPrice(SP) : extractPrice(PR),
			    priceToSpecialDifference = (SP != false) ? extractPrice(PR) - extractPrice(SP) : 0;

			let price = initialPrice + getAllOptionsPrices(initialPrice);
			let priceOld = price + priceToSpecialDifference;

			if (currentPrice == null) currentPrice = initialPrice * quantity;
			if (currentPriceOld == null) currentPriceOld = (initialPrice + priceToSpecialDifference) * quantity;

			if (animatePriceEnabled) {
				animatePrice($priceWrapper, currentPrice, price * quantity);
				animatePrice($priceOldWrapper, currentPriceOld, priceOld * quantity);
			} else {
				price    = formatPrice(price * quantity, DC, DP, TP, SL, SR);
				priceOld = formatPrice(priceOld * quantity, DC, DP, TP, SL, SR);

				showPrice($priceWrapper, price);
				showPrice($priceOldWrapper, priceOld);
			}

			currentPrice = price * quantity;
			currentPriceOld = priceOld * quantity;
		}

		// Calculation of the cost of all options
		function getAllOptionsPrices(initialPrice = 0) {
			let additionalPrice       =  0,
			    additionalPricePrefix = '',
			    productOptionValueId  =  0,
			    difference            =  0;

			$(optionsWrapper + ' input[type="radio"]:checked, ' + optionsWrapper + ' input[type="checkbox"]:checked, ' + optionsWrapper + ' select>option:selected').each(function() {
				productOptionValueId = $(this).attr('option-value');

				if (!productOptionValueId) {
					return;
				}

				additionalPrice = extractPrice(RDO_optionsData[productOptionValueId].price);

				if (additionalPrice === false || additionalPrice === undefined || additionalPrice === null || additionalPrice == '') {
					return;
				}

				additionalPricePrefix = RDO_optionsData[productOptionValueId].price_prefix;

				if (additionalPricePrefix == '+') {
					difference += additionalPrice * 1;
				} else if (additionalPricePrefix == '-') {
					difference -= additionalPrice * 1;
				} else if (additionalPricePrefix == '=') {
					difference += additionalPrice * 1 - initialPrice;
					initialPrice = +additionalPrice;
				}
			});

			return difference;
		}

		// Price extraction, e.g. $1,499.99 -> 1499.99, 1 499,99р. -> 1499.99
		function extractPrice(price = 0) {
			if (!price) {
				return 0;
			}

			return +price.split(RDO_productData['thousand_point']).join('')
				     .replace(RDO_productData['symbol_left'], '')
				     .replace(RDO_productData['symbol_right'], '')
				     .replace(RDO_productData['decimal_point'], '.');
		}

		// Formatting prices for regional settings, e.g. 1499.99 -> $1,499.99, 1499.99 -> 1 499,99р.
		function formatPrice(price = 0, decimalPlaces = 2, decimalPoint = '.', thousandPoint = '', symbolLeft = '', symbolRight = '') {
			let p     = price.toFixed(decimalPlaces).replace('-', '').split('.'),
			    chars = p[0].split("").reverse(),
			    str   = '',
			    count = 0;

			for (let i in chars) {
				count++;

				if (count%3 == 1 && count != 1) {
					str = chars[i] + thousandPoint + str;
				} else {
					str = chars[i] + str;
				}
			}

			let formattedPrice = 0;

			if (decimalPlaces > 0) {
				formattedPrice = str + decimalPoint + p[1];
			} else {
				formattedPrice = str;
			}

			if (price >= 0) {
				return symbolLeft + formattedPrice + symbolRight;
			} else {
				return '-' + symbolLeft + formattedPrice + symbolRight;
			}
		}

		// Function that displays the price (without animation)
		function showPrice(wrapper, price) {
			wrapper.text(price);
		}

		// Recursive function that animates price changes
		function animatePrice(wrapper, priceStart, PriceEnd, step = 0) {
			if (priceStart == PriceEnd) {
				return;
			}

			const DC = RDO_productData['decimal_place'],
			      DP = RDO_productData['decimal_point'],
			      TP = RDO_productData['thousand_point'],
			      SL = RDO_productData['symbol_left'],
			      SR = RDO_productData['symbol_right'];

			let stepCount = 15,
			    stepDelay = 40, //ms between steps
			    price     = priceStart;

			if (!step) {
				step = +((PriceEnd - priceStart) / stepCount).toFixed(DC);
			}

			price += step;

			if ((PriceEnd > priceStart && price >= PriceEnd) || (PriceEnd < priceStart && price <= PriceEnd) || !step) {
				priceFormatted = formatPrice(PriceEnd, DC, DP, TP, SL, SR);
				showPrice(wrapper, priceFormatted);
			} else {
				priceFormatted = formatPrice(price, DC, DP, TP, SL, SR);
				showPrice(wrapper, priceFormatted);
				setTimeout(animatePrice, stepDelay, wrapper, price, PriceEnd, step);
			}
		}

	{% endif %}

	//END PRICE ADJUSTMENT FUNCTIONS

	//START OPTION IMAGE CHANGE FUNCTIONS
	
	{% if RDO_settings.option_image_change is defined and RDO_settings.option_image_change  %}

	let $mainImages       = $('.main-image .swiper-slide');
	let $additionalImages = $('.additional-images .additional-image');
	let $imageSwiper      = null;
	let slideIndex        = null;

	// If the Swiper has not loaded yet, check every 0.5 sec
	let timerId = setInterval(function() {
		$imageSwiper = $('.main-image').data('swiper');

		if($imageSwiper && $imageSwiper.length) {
			clearInterval(timerId);
		}
	}, 500);

	// Stop checking after 15 seconds
	setTimeout(function() {
		clearInterval(timerId);
	}, 15000);

	function changeImage(optionValueId) {
		if(optionValueId in RDO_optionImages) {

			//TODO: Refactor all code

			let imageData     = RDO_optionImages[optionValueId];
			let imagePathInfo = imageData['image_pathinfo'];
			let image         = imageData.image;

			let $slide = $mainImages.find('img[src="' + image + '"] ').parent();

			// If the Journal version is 3.0.46 or higher
			// Instead of "image_1-550x550.jpg", the Journal creates "image_1-550x550w.jpg" or "image_1-550x550h.jpg" or "image_1-550x550w.jpg.webp"
			if (!$slide.length) {
				let imageExtensions = ['webp', 'jpg', 'jpeg', 'jpe', 'png', 'gif', 'bmp', 'tiff', 'tif', 'svg', 'svgz'];

				let path = image.slice(0, image.lastIndexOf('/') + 1);
				let filename = image.slice(image.lastIndexOf('/') + 1);

				// Trim file extension
				filename = filename.slice(0, filename.lastIndexOf('.'));

				// If filename has two extensions, for example "image_1-550x550h.jpg.webp"
				if (filename.split('.').length > 1 && imageExtensions.includes( filename.split('.').pop() )) {
					// Trim file extension
					filename = filename.slice(0, filename.lastIndexOf('.'));
				}

				// Get the image path/filename (without the last unnecessary letter "w" or "h")
				path = path + filename;
				//path = path.slice(0, path.length - 1);

				$slide = $mainImages.find('img[src^="' + path + '"] ').parent();
			}

			// Show option image
			if ($slide.length) {
				slideIndex = undefined;

				if ($slide.data('index') != undefined) {
					//PRODUCT PAGE
					slideIndex = $slide.data('index');

				} else if (imagePathInfo != undefined) {
					//QUICKVIEW

					// Path: "/catalog/image_1"
					path = String(imagePathInfo.ds) + String(imagePathInfo.dn) + String(imagePathInfo.ds) + String(imagePathInfo.fn);
					//console.log(path);

					// Path: "https://site.com/image/cache/catalog/image_1-"
					path = image.slice(0, image.indexOf(path)) + path + '-';
					//console.log(path);

					$slide = $additionalImages.find('img[src^="' + path + '"] ').parent();

					slideIndex = $slide.data('index');
					//console.log(slideIndex);
				}

				if (slideIndex != undefined) {
					if ($imageSwiper.params.loop) {
						$imageSwiper.slideToLoop(slideIndex, 0);
					} else {
						$imageSwiper.slideTo(slideIndex, 0);
					}
				}
			} else {
				// Create new slide (image container) by copying an existing one
				//$slide = $mainImages.first().clone(true);
				//$slide.removeClass('swiper-slide-prev swiper-slide-next swiper-slide-visible swiper-slide-active');
				//$slide.attr('data-index', $mainImages.length);

				// Change product image
				//$slide.children('img').attr('src', optionImages[optionValueId].image);
				//$slide.children('img').attr('data-largeimg', optionImages[optionValueId].image_large);
				//$slide.children('img').attr('srcset', optionImages[optionValueId].image + ' 1x, ' + optionImages[optionValueId].image_large + ' 2x');

				//$slide.appendTo('.main-image .swiper-wrapper');

				// Add image to gallery (for full size opening)
				//let lightgalleryProductImages = JSON.parse($('.lightgallery-product-images').attr('data-images'));
				//lightgalleryProductImages[$mainImages.length] = {src:optionImages[optionValueId].image_large, thumb:optionImages[optionValueId].image};
				//$('.lightgallery-product-images').attr('data-images', JSON.stringify(lightgalleryProductImages));

				// Show image
				//$imageSwiper.preloadImages();
				//$imageSwiper.slideTo($slide.attr('data-index'), 0);
			}
		}
	}

	{% else %}
	
	function changeImage() {
		return true;
	}

	{% endif %}
	
	//END OPTION IMAGE CHANGE FUNCTIONS

	});

//--></script>
			<!--EOF Related Options-->
			{% endif %}
			]]></add>
		</operation>
	</file>

	<!-- <file path="catalog/view/theme/journal3/template/common/footer.twig">

		<operation error="skip">
			<search><![CDATA[{% if j3.canLiveReload() %}]]></search>
			<add position="before" trim="true"><![CDATA[
{% if j3.document.getPageRoute() == 'product/product' %}

<script type="text/javascript">
	$(document).ready(function() {
		// Cancel Journal3 auto select first option
		if ((Journal['isPopup'] ? Journal['quickviewPageStyleOptionsSelect'] : Journal['productPageStyleOptionsSelect']) === 'all') {
			$('.product-options .form-group .radio:first-child input, .product-options .form-group .checkbox:first-child input').prop('checked', false);
			$('.product-options .form-group select option:eq(1)').prop('selected', false);
		}

		if ((Journal['isPopup'] ? Journal['quickviewPageStyleOptionsSelect'] : Journal['productPageStyleOptionsSelect']) === 'required') {
			$('.product-options .form-group.required .radio:first-child input, .product-options .form-group.required .checkbox:first-child input').prop('checked', false);
			$('.product-options .form-group.required select option:eq(1)').prop('selected', false);
		}

		$('#product-quantity').trigger('change');
	});
</script>

{% endif %}
			]]></add>
		</operation>
	</file> -->

	<file path="catalog/controller/journal3/price.php">

		<!-- [Prefix "=" for product option values (Journal ajax live price update)] -->
		<operation error="skip">
			<search><![CDATA[if ($product_option_value['price_prefix'] === '+') {]]></search>
			<add position="before"><![CDATA[
			//BOF Related Options
			if ($product_option_value['price_prefix'] === '=') {
				$new_price = (float)$product_option_value['price'];
			}
			//EOF Related Options
			]]></add>
		</operation>

		<!-- [Prefix "=" for product option values (Journal ajax live price update)] -->
		<operation error="skip">
			<search><![CDATA[if ($product_option_value['weight_prefix'] === '+') {]]></search>
			<add position="before"><![CDATA[
			//BOF Related Options
			if ($product_option_value['weight_prefix'] === '=') {
				$new_weight = (float)$product_option_value['weight'];
			}
			//EOF Related Options
			]]></add>
		</operation>

		<!-- [Prefix "=" for product option values (Journal ajax live price update)] -->
		<operation error="skip">
			<search><![CDATA[// price]]></search>
			<add position="before"><![CDATA[
			//BOF Related Options
			$options_price  += (isset($new_price))  ? $new_price - (float)$base_price : 0;
			//EOF Related Options
			]]></add>
		</operation>

		<!-- [Prefix "=" for product option values (Journal ajax live price update)] -->
		<operation error="skip">
			<search><![CDATA[// weight]]></search>
			<add position="before"><![CDATA[
			//BOF Related Options
			$options_weight += (isset($new_weight)) ? $new_weight - (float)$product_info['weight'] : 0;
			//EOF Related Options
			]]></add>
		</operation>
	</file>

</modification>
