<?php 
	require(__DIR__.'/connect.php');  break; // listo
	$db = new connect('visionwe_mateckoriginal','visionwe_matecku','7Z}jf_6}{KZ]');
	$mateck = new connect('visionwe_mateckkdb','visionwe_matecku','7Z}jf_6}{KZ]');
	echo "<br/><br/>Cargando productos ...<br/>";
	$query ="
	SELECT 
		p.id_product
			FROM 
				ax_product p
			WHERE 
				1
	";
	$productos = $mateck->getRows($query); 

	foreach($productos as $producto):
		$idProducto = $producto['id_product'];
		echo "Cargando atrobutos para el ID: <strong>$idProducto</strong><br/>";
		
		/*UPDATE CAS*/
		$sql="SELECT d.* 
			FROM 
				additional_field_values f 
					left join additional_field_value_descriptions d
						ON f.additional_field_value_id = d.additional_field_value_id
							where 
								f.item_id = '$idProducto' and f.additional_field_id = '1'";	

		$atributos = $db->getRows($sql);
		foreach($atributos as $attr):
			if($attr['language_id']==1)
				$lang=2;
			else
				$lang=1;
			$valor = $attr['value'];
			$sql = "UPDATE ax_product_lang SET cas = '$valor' where id_product = '$idProducto' and id_lang = '$lang'";
			$mateck->insertRow($sql);
		endforeach;
		
		/*UPDATE RS*/
		$sql="SELECT d.* 
			FROM 
				additional_field_values f 
					left join additional_field_value_descriptions d
						ON f.additional_field_value_id = d.additional_field_value_id
							where 
								f.item_id = '$idProducto' and f.additional_field_id = '2'";	

		$atributos = $db->getRows($sql);
		foreach($atributos as $attr):
			if($attr['language_id']==1)
				$lang=2;
			else
				$lang=1;
			$valor = $attr['value'];
			$sql = "UPDATE ax_product_lang SET rs = '$valor' where id_product = '$idProducto' and id_lang = '$lang'";
			$mateck->insertRow($sql);
		endforeach;
		
		/*UPDATE size*/
		$sql="SELECT d.* 
			FROM 
				additional_field_values f 
					left join additional_field_value_descriptions d
						ON f.additional_field_value_id = d.additional_field_value_id
							where 
								f.item_id = '$idProducto' and f.additional_field_id = '3'";	

		$atributos = $db->getRows($sql);
		foreach($atributos as $attr):
			if($attr['language_id']==1)
				$lang=2;
			else
				$lang=1;
			$valor = $attr['value'];
			$sql = "UPDATE ax_product_lang SET size = '$valor' where id_product = '$idProducto' and id_lang = '$lang'";
			$mateck->insertRow($sql);
		endforeach;
		
		/*UPDATE purity*/
		$sql="SELECT d.* 
			FROM 
				additional_field_values f 
					left join additional_field_value_descriptions d
						ON f.additional_field_value_id = d.additional_field_value_id
							where 
								f.item_id = '$idProducto' and f.additional_field_id = '4'";	

		$atributos = $db->getRows($sql);
		foreach($atributos as $attr):
			if($attr['language_id']==1)
				$lang=2;
			else
				$lang=1;
			$valor = $attr['value'];
			$sql = "UPDATE ax_product_lang SET purity = '$valor' where id_product = '$idProducto' and id_lang = '$lang'";
			$mateck->insertRow($sql);
		endforeach;
		
		/*UPDATE Quantity*/
		$sql="SELECT d.* 
			FROM 
				additional_field_values f 
					left join additional_field_value_descriptions d
						ON f.additional_field_value_id = d.additional_field_value_id
							where 
								f.item_id = '$idProducto' and f.additional_field_id = '5'";	

		$atributos = $db->getRows($sql);
		foreach($atributos as $attr):
			if($attr['language_id']==1)
				$lang=2;
			else
				$lang=1;
			$valor = $attr['value'];
			$sql = "UPDATE ax_product_lang SET quantityproduct = '$valor' where id_product = '$idProducto' and id_lang = '$lang'";
			$mateck->insertRow($sql);
		endforeach;
		
		/*UPDATE Quantity*/
		$sql="SELECT d.* 
			FROM 
				additional_field_values f 
					left join additional_field_value_descriptions d
						ON f.additional_field_value_id = d.additional_field_value_id
							where 
								f.item_id = '$idProducto' and f.additional_field_id = '6'";	

		$atributos = $db->getRows($sql);
		foreach($atributos as $attr):
			if($attr['language_id']==1)
				$lang=2;
			else
				$lang=1;
			$valor = $attr['value'];
			$sql = "UPDATE ax_product_lang SET artNo = '$valor' where id_product = '$idProducto' and id_lang = '$lang'";
			$mateck->insertRow($sql);
		endforeach;
		
		echo "...Registro actualizado ! <br/>";
	endforeach;
	echo "Fin de la consulta";
	
	