<?php

class ProductController extends Zend_Controller_Action {

	public function init() {		
		$this->view->menuSel = 2;
	}	
	
	
	public function indexAction() {		
		$db = Zend_Registry::get('db');
		$config = new Zend_Session_Namespace('config');	
		$basket = new Zend_Session_Namespace('basket');	
		$order = new Zend_Session_Namespace('order');	
		$v = $this->_request->getParams();

		$this->view->configUnit = $config->config['unit'];
		
		
		if( !isset($v['id']) ){
			$idProduct = 0;
		}else{
			$idProduct = $v['id'];
		}	

		
		if( isset($v['basketid']) ){
			
			if( $idProduct != $order->product[$v['basketid']]['idProduct'] ){
				$this->_helper->redirector('index','index');			
			}
			
			foreach($order->product[$v['basketid']] as $key => $value){
				$basket->product[$idProduct][$key] = $value;
			}
			
			$basket->product[$idProduct]['basket_edit'] = true;
			$basket->product[$idProduct]['basketid'] = $v['basketid'];
		}else{
			$basket->product[$idProduct]['basket_edit'] = false;
		}	
		
		$this->view->idProduct = $idProduct;
		
		$Product = new Product();	
		$select = $Product->select();				
		$select->where('product_id = ?', $idProduct);			
		$row = $Product->fetchRow($select);
		
		$mt['title'] = $row['product_mt_title'];
		$mt['description'] = $row['product_mt_description'];
		$mt['keywords'] = $row['product_mt_keywords'];
		$this->view->mt = $mt;
		
		$ProductFieldname = new ProductFieldname();			
		$select = $ProductFieldname->select();		
		$select->where('product_id = ?', $idProduct);	
		$rowProductFieldname = $ProductFieldname->fetchRow($select);
	//	$rowProductFieldname = $row->toArray();
		$this->view->ProductFieldnameInfo = $rowProductFieldname;
		
		if( !$basket->product[$idProduct]['product_rim_id'] ){
			$basket->product[$idProduct]['product_rim_id'] = $row->product_rim_default;
		}
		
		if( !$basket->product[$idProduct]['product_rim2_id'] ){
			$basket->product[$idProduct]['product_rim2_id'] = $row->product_rim2_default;
		}
		
		if( !$basket->product[$idProduct]['product_body_id'] ){		
			$ProductBody = new ProductBody();	
			$select = $ProductBody->select();				
			$select->where('product_id = ?', $idProduct);	
			$select->where('product_body_typebody = ?', 0);	
			$select->where('product_body_default = ?', 1);			
			$rowb = $ProductBody->fetchRow($select);
					
			if( $rowb->product_body_id ){
				$basket->product[$idProduct]['product_body_id'] = $rowb->product_body_id;
				$basket->product[$idProduct]['body_filtr'] = $rowb->product_body_type;		
			}
		}
		
		if( !$basket->product[$idProduct]['product_body2_id'] ){		
			$ProductBody = new ProductBody();	
			$select = $ProductBody->select();				
			$select->where('product_id = ?', $idProduct);	
			$select->where('product_body_typebody = ?', 1);	
			$select->where('product_body_default = ?', 1);			
			$rowb = $ProductBody->fetchRow($select);
					
			if( $rowb->product_body_id ){
				$basket->product[$idProduct]['product_body2_id'] = $rowb->product_body_id;
			}
		}
		
		if( !$basket->product[$idProduct]['product_front_id'] ){		
			$ProductFront = new ProductFront();	
			$select = $ProductFront->select();				
			$select->where('product_id = ?', $idProduct);	
			$select->where('product_front_default = ?', 1);			
			$rowb = $ProductFront->fetchRow($select);
					
			if( $rowb->product_front_id ){
				$basket->product[$idProduct]['product_front_id'] = $rowb->product_front_id;
				$basket->product[$idProduct]['front_filtr'] = $rowb->product_front_type;				
			}
		}
		
		if( !$basket->product[$idProduct]['product_type_id'] ){
		
			$ProductType = new ProductType();	
			$select = $ProductType->select();				
			$select->where('product_id = ?', $idProduct);	
			$select->where('product_type_default = ?', 1);			
			$rowb = $ProductType->fetchRow($select);
					
			if( $rowb->product_type_id ){
				$basket->product[$idProduct]['product_type_id'] = $rowb->product_type_id;
				
				$ProductType2 = new ProductType2();	
				$select = $ProductType2->select();				
				$select->where('product_type_id = ?', $rowb->product_type_id);	
				$select->where('product_type2_default = ?', 1);			
				$rowb2 = $ProductType2->fetchRow($select);		
				if( $rowb2->product_type2_id ){
					$basket->product[$idProduct]['product_type2_id'] = $rowb2->product_type2_id;
				}
			}
		}
		
		if( !$basket->product[$idProduct]['product_legs_id'] ){		
			$ProductLegs = new ProductLegs();	
			$select = $ProductLegs->select();				
			$select->where('product_id = ?', $idProduct);	
			$select->where('product_legs_default = ?', 1);			
			$rowb = $ProductLegs->fetchRow($select);
					
			if( $rowb->product_legs_id ){
				$basket->product[$idProduct]['product_legs_id'] = $rowb->product_legs_id;			
			}
		}
		
		if( !$basket->product[$idProduct]['product_handles_id'] ){		
			$ProductHandles = new ProductHandles();	
			$select = $ProductHandles->select();				
			$select->where('product_id = ?', $idProduct);	
			$select->where('product_handles_default = ?', 1);			
			$rowb = $ProductHandles->fetchRow($select);
					
			if( $rowb->product_handles_id ){
				$basket->product[$idProduct]['product_handles_id'] = $rowb->product_handles_id;			
			}
		}
		
		if( !$basket->product[$idProduct]['product_accessories_id'] ){		
			$ProductAccessories = new ProductAccessories();	
			$select = $ProductAccessories->select();				
			$select->where('product_id = ?', $idProduct);	
			$select->where('product_accessories_typeaccessories = ?', 0);	
			$select->where('product_accessories_default = ?', 1);			
			$rowb = $ProductAccessories->fetchRow($select);
					
			if( $rowb->product_accessories_id ){
				$basket->product[$idProduct]['product_accessories_id'] = $rowb->product_accessories_id;
			}
		}
		
		if( !$basket->product[$idProduct]['product_accessories_id2'] ){		
			$ProductAccessories = new ProductAccessories();	
			$select = $ProductAccessories->select();				
			$select->where('product_id = ?', $idProduct);	
			$select->where('product_accessories_typeaccessories = ?', 1);	
			$select->where('product_accessories_default = ?', 1);			
			$rowb = $ProductAccessories->fetchRow($select);
					
			if( $rowb->product_accessories_id ){
				$basket->product[$idProduct]['product_accessories_id2'] = $rowb->product_accessories_id;
			}
		}
		
		if( !$basket->product[$idProduct]['product_accessories_id3'] ){		
			$ProductAccessories = new ProductAccessories();	
			$select = $ProductAccessories->select();				
			$select->where('product_id = ?', $idProduct);	
			$select->where('product_accessories_typeaccessories = ?', 2);	
			$select->where('product_accessories_default = ?', 1);			
			$rowb = $ProductAccessories->fetchRow($select);
					
			if( $rowb->product_accessories_id ){
				$basket->product[$idProduct]['product_accessories_id3'] = $rowb->product_accessories_id;
			}
		}
		
		if( !$basket->product[$idProduct]['product_accessories_id4'] ){		
			$ProductAccessories = new ProductAccessories();	
			$select = $ProductAccessories->select();				
			$select->where('product_id = ?', $idProduct);	
			$select->where('product_accessories_typeaccessories = ?', 3);	
			$select->where('product_accessories_default = ?', 1);			
			$rowb = $ProductAccessories->fetchRow($select);
					
			if( $rowb->product_accessories_id ){
				$basket->product[$idProduct]['product_accessories_id4'] = $rowb->product_accessories_id;
			}
		}
		
		if( !$basket->product[$idProduct]['product_options_1'] ){
			$basket->product[$idProduct]['product_options_1'] = 0;		
		}
		
		
		if( !$basket->product[$idProduct]['product_options_2'] ){
			$basket->product[$idProduct]['product_options_2'] = 0;		
		}
		
		
		if( !$basket->product[$idProduct]['product_options_3'] ){
			$basket->product[$idProduct]['product_options_3'] = 0;		
		}
		
		
		if( !$basket->product[$idProduct]['product_options_4'] ){
			$basket->product[$idProduct]['product_options_4'] = 0;		
		}		
		
		if( !$basket->product[$idProduct]['product_options_id'] ){
			$basket->product[$idProduct]['product_options_id'] = $row->product_options_wd;	
		}
		
		if( !$basket->product[$idProduct]['product_options_id2'] ){
			$basket->product[$idProduct]['product_options_id2'] = $row->product_options_rp;	
		}
		
		
		
		
		
		
		
		
		
		
		
		if( $row->category_id OR $row->category_id1 ){
			$this->view->rowProduct = $row;
			if( $row->category_id ) $this->view->idCategory = $row['category_id'];
			else $this->view->idCategory = $row['category_id1'];
			
			if( $v['zm'] == 1 ){
				$this->view->zm = true;	
				$this->view->menuSel = 3;
			}
			else{
				$this->view->zm = false;
			}
			
			$panelBox = array();
			$i = 0;
			$panelBox[$i] = 'sizeBox';
			
			if( $row['product_body'] == 1 ){				
				$ProductBody = new ProductBody();
				$data = $ProductBody->fetchAll("product_body_typebody = '0' AND product_id = ".$idProduct , 'product_body_name ASC'); 		
				$this->view->dataBody = $data;	
				$data = $ProductBody->fetchAll("product_body_typebody = '1' AND product_id = ".$idProduct , 'product_body_name ASC'); 		
				$this->view->dataBody2 = $data;	

				$MapFiltrBody = new MapFiltrBody();	
				
				$dataMapFiltrBody = $MapFiltrBody->fetchAll(); 		
				$this->view->dataTableMapFiltrBody = $dataMapFiltrBody;				

				$i++;
				$panelBox[$i] = 'bodyBox';
			}
			
			if( $row['product_front'] == 1 ){				
				$ProductFront = new ProductFront();
				$data = $ProductFront->fetchAll('product_id = '.$idProduct , 'product_front_name ASC'); 		
				$this->view->dataFront = $data;	
		
				$MapFiltrFront = new MapFiltrFront();	
				
				$dataMapFiltrFront = $MapFiltrFront->fetchAll(); 		
				$this->view->dataTableMapFiltrFront = $dataMapFiltrFront;	

				$i++;
				$panelBox[$i] = 'frontBox';			
			}
			
			if( $row['product_type'] == 1 ){				
				$ProductType = new ProductType();		
				$ProductType2 = new ProductType2();
				$data = $ProductType->fetchAll('product_id = '.$idProduct , 'product_type_name ASC')->toArray();
				foreach( $data as $keyE => $valE ){
					$data[$keyE]['pod'] = $ProductType2->fetchAll('product_type_id = '.$valE['product_type_id'] , 'product_type2_name ASC')->toArray();
				}
				$this->view->dataType = $data;		

				$i++;
				$panelBox[$i] = 'typeBox';			
			}
			
			if( $row['product_accessories'] == 1 ){				
				$ProductAccessories = new ProductAccessories();
				$data = $ProductAccessories->fetchAll("product_accessories_typeaccessories = '0' AND product_id = ".$idProduct , 'product_accessories_name ASC'); 		
				$this->view->dataAccessories = $data;	
				
				$data2 = $ProductAccessories->fetchAll("product_accessories_typeaccessories = '1' AND product_id = ".$idProduct , 'product_accessories_name ASC'); 		
				$this->view->dataAccessories2 = $data2;	
				
				$data3 = $ProductAccessories->fetchAll("product_accessories_typeaccessories = '2' AND product_id = ".$idProduct , 'product_accessories_name ASC'); 		
				$this->view->dataAccessories3 = $data3;	
				
				$data4 = $ProductAccessories->fetchAll("product_accessories_typeaccessories = '3' AND product_id = ".$idProduct , 'product_accessories_name ASC'); 		
				$this->view->dataAccessories4 = $data4;		

				$i++;
				$panelBox[$i] = 'accessoriesBox';					
			}
			
			if( $row['product_legs'] == 1 ){				
				$ProductLegs = new ProductLegs();
				$data = $ProductLegs->fetchAll('product_id = '.$idProduct , 'product_legs_name ASC'); 		
				$this->view->dataLegs = $data;			

				$i++;
				$panelBox[$i] = 'legsBox';				
			}
			
			if( $row['product_handles'] == 1 ){				
				$ProductHandles = new ProductHandles();
				$data = $ProductHandles->fetchAll('product_id = '.$idProduct , 'product_handles_name ASC'); 		
				$this->view->dataHandles = $data;		

				$i++;
				$panelBox[$i] = 'handlesBox';					
			}
			
			if( $row['product_options'] == 1 ){				
				$ProductOptions = new ProductOptions();
				$data = $ProductOptions->fetchAll('product_id = '.$idProduct , 'product_options_name ASC'); 		
				$this->view->dataOptions = $data;		

				$i++;
				$panelBox[$i] = 'optionsBox';				
			}		
			
			$this->view->panelBox = $panelBox;		
			$this->view->dataSelect = $basket->product[$idProduct];				
			
			//var_dump($basket->product[$idProduct]);
			
			$ProductHeight = new ProductHeight();
			$data = $ProductHeight->fetchAll('product_height_value >= '.$row->product_height_min.' AND product_height_value <= '.$row->product_height_max.' AND product_id = '.$idProduct , 'product_height_value ASC'); 		
			$this->view->ProductHeight = $data;
			
			$ProductWidth = new ProductWidth();
			$data = $ProductWidth->fetchAll('product_width_value >= '.$row->product_width_min.' AND product_width_value <= '.$row->product_width_max.' AND product_id = '.$idProduct , 'product_width_value ASC'); 		
			$this->view->ProductWidth = $data;			
			
			$ProductDepth = new ProductDepth();
			$data = $ProductDepth->fetchAll('product_depth_value >= '.$row->product_depth_min.' AND product_depth_value <= '.$row->product_depth_max.' AND product_id = '.$idProduct , 'product_depth_value ASC'); 		
			$this->view->ProductDepth = $data;			
			
			$ProductShelfamount = new ProductShelfamount();
			$data = $ProductShelfamount->fetchAll('product_shelfamount_value >= '.$row->product_shelfamount_min.' AND product_shelfamount_value <= '.$row->product_shelfamount_max.' AND product_id = '.$idProduct , 'product_shelfamount_value ASC'); 		
			$this->view->ProductShelfamount = $data;		
			
			$ProductWysszerA = new ProductWysszerA();
			$data = $ProductWysszerA->fetchAll('product_wysszera_value >= '.$row->product_wysszerAamount_min.' AND product_wysszera_value <= '.$row->product_wysszerAamount_max.' AND product_id = '.$idProduct , 'product_wysszera_value ASC'); 		
			$this->view->ProductWysszerA = $data;		
			
			$ProductWysszerB = new ProductWysszerB();
			$data = $ProductWysszerB->fetchAll('product_wysszerb_value >= '.$row->product_wysszerBamount_min.' AND product_wysszerb_value <= '.$row->product_wysszerBamount_max.' AND product_id = '.$idProduct , 'product_wysszerb_value ASC'); 		
			$this->view->ProductWysszerB = $data;
			
			$ProductWysszerC = new ProductWysszerC();
			$data = $ProductWysszerC->fetchAll('product_wysszerc_value >= '.$row->product_wysszerCamount_min.' AND product_wysszerc_value <= '.$row->product_wysszerCamount_max.' AND product_id = '.$idProduct , 'product_wysszerc_value ASC'); 		
			$this->view->ProductWysszerC = $data;
			
			$ProductWysszerD = new ProductWysszerD();
			$data = $ProductWysszerD->fetchAll('product_wysszerd_value >= '.$row->product_wysszerDamount_min.' AND product_wysszerd_value <= '.$row->product_wysszerDamount_max.' AND product_id = '.$idProduct , 'product_wysszerd_value ASC'); 		
			$this->view->ProductWysszerD = $data;
			
			$ProductWysszerE = new ProductWysszerE();
			$data = $ProductWysszerE->fetchAll('product_wysszere_value >= '.$row->product_wysszerEamount_min.' AND product_wysszere_value <= '.$row->product_wysszerEamount_max.' AND product_id = '.$idProduct , 'product_wysszere_value ASC'); 		
			$this->view->ProductWysszerE = $data;



			$ask = '			
				SELECT *, p.product_id AS product_id FROM product p JOIN product_linked pl ON p.product_id = pl.product_linked_pid AND pl.product_id = '.$idProduct.' 
				ORDER BY p.product_name ASC			
			';
			
			$dataLinked = $db->query($ask)->fetchAll();	
			$this->view->dataLinked = $dataLinked;			
			
		}else{
			$this->_helper->redirector('index','index');			
		} 
	}
	
	
	
	
	public function shopAction() {		
		$basket = new Zend_Session_Namespace('basket');		
		$v = $this->_request->getParams();
		$this->view->menuSel = 5;
		
		if( !isset($v['id']) ){
			$idProduct = 0;
		}else{
			$idProduct = $v['id'];
		}		
		
		$this->view->idProduct = $idProduct;
		
		$Product = new Product();	
		$select = $Product->select();				
		$select->where('product_id = ?', $idProduct);			
		$row = $Product->fetchRow($select);
		
		$mt['title'] = $row['product_mt_title'];
		$mt['description'] = $row['product_mt_description'];
		$mt['keywords'] = $row['product_mt_keywords'];
		$this->view->mt = $mt;
		
		$basket->product[$row->product_id]['price'] = $row->product_price;
		
		if( $row->category_id ){
			$this->view->rowProduct = $row;
			$this->view->idCategory = $row['category_id'];			
		}else{
			$this->_helper->redirector('index','index');			
		} 
	}
	
	
	public function productshoptableAction() {
		$basket = new Zend_Session_Namespace('basket');	
		
		$v = $this->_request->getParams();
		
		$idProduct = $v['product_id'];	
		
		$Product = new Product();	
		$select = $Product->select();				
		$select->where('product_id = ?', $idProduct);			
		$row = $Product->fetchRow($select);	
	
		$this->view->product = $row;
		$this->view->productBasket = $basket->product[$idProduct];
	
		$this->view->product_code = $row->product_code;
		$this->view->product_height = $basket->product[$idProduct]['product_height'];
		$this->view->product_width = $basket->product[$idProduct]['product_width'];
		$this->view->product_depth = $basket->product[$idProduct]['product_depth'];
		$this->view->product_shelfamount = $basket->product[$idProduct]['product_shelfamount'];
		
		$this->view->product_wysszerA = $basket->product[$idProduct]['product_wysszerAamount'];
		$this->view->product_wysszerB = $basket->product[$idProduct]['product_wysszerBamount'];		
		$this->view->product_wysszerC = $basket->product[$idProduct]['product_wysszerCamount'];
		$this->view->product_wysszerD = $basket->product[$idProduct]['product_wysszerDamount'];
		$this->view->product_wysszerE = $basket->product[$idProduct]['product_wysszerEamount'];
		
		$this->view->product_body = isset($basket->product[$idProduct]['product_body_id'])?@Lib_Lang::consta(product_bodyname_.$basket->product[$idProduct]['product_body_id']):'-';
		
		$this->view->product_body2 = isset($basket->product[$idProduct]['product_body2_id'])?@Lib_Lang::consta(product_bodyname_.$basket->product[$idProduct]['product_body2_id']):'-';
		
		$this->view->product_front = isset($basket->product[$idProduct]['product_front_id'])?@Lib_Lang::consta(product_frontname_.$basket->product[$idProduct]['product_front_id']):'-';
		
		$this->view->product_rim = isset($basket->product[$idProduct]['product_rim_id'])?@Lib_Lang::consta(front_configurator_body_rim.$basket->product[$idProduct]['product_rim_id']):'-';
		
		$this->view->product_rim2 = isset($basket->product[$idProduct]['product_rim2_id'])?@Lib_Lang::consta(front_configurator_front_rim.$basket->product[$idProduct]['product_rim2_id']):'-';
		
		$this->view->product_type = isset($basket->product[$idProduct]['product_type_id'])?@Lib_Lang::consta(product_typename_.$basket->product[$idProduct]['product_type_id']):'-';
		
		$this->view->product_type2 = isset($basket->product[$idProduct]['product_type2_id'])?@Lib_Lang::consta(product_type2name_.$basket->product[$idProduct]['product_type2_id']):'-';
		
		$this->view->product_accessories = isset($basket->product[$idProduct]['product_accessories_id'])?@Lib_Lang::consta(product_accessoriesname_.$basket->product[$idProduct]['product_accessories_id']):'-';
		
		$this->view->product_accessories2 = isset($basket->product[$idProduct]['product_accessories_id2'])?@Lib_Lang::consta(product_accessoriesname_.$basket->product[$idProduct]['product_accessories_id2']):'-';
		
		$this->view->product_accessories3 = isset($basket->product[$idProduct]['product_accessories_id3'])?@Lib_Lang::consta(product_accessoriesname_.$basket->product[$idProduct]['product_accessories_id3']):'-';
		
		$this->view->product_accessories4 = isset($basket->product[$idProduct]['product_accessories_id4'])?@Lib_Lang::consta(product_accessoriesname_.$basket->product[$idProduct]['product_accessories_id4']):'-';
		
		$this->view->product_legs = isset($basket->product[$idProduct]['product_legs_id'])?@Lib_Lang::consta(product_legsname_.$basket->product[$idProduct]['product_legs_id']):'-';
		
		$this->view->product_handles = isset($basket->product[$idProduct]['product_handles_id'])?@Lib_Lang::consta(product_handlesname_.$basket->product[$idProduct]['product_handles_id']):'-';
				
		$this->view->product_options_1 = $basket->product[$idProduct]['product_options_1'];
		$this->view->product_options_2 = $basket->product[$idProduct]['product_options_2'];
		$this->view->product_options_3 = $basket->product[$idProduct]['product_options_3'];
		$this->view->product_options_4 = $basket->product[$idProduct]['product_options_4'];
		
		$this->view->product_options_wd = isset($basket->product[$idProduct]['product_options_id'])?@Lib_Lang::consta(front_optionww.$basket->product[$idProduct]['product_options_id']):'-';
		
		$idrp = $basket->product[$idProduct]['product_options_id2']+1;
		$this->view->product_options_rp = isset($idrp)?@Lib_Lang::consta(front_optionpp.$idrp):'-';
		
		$this->view->idProduct = $idProduct;	
	
		// var_dump($basket->product[$idProduct]);
		// $this->_helper->viewRenderer->setNoRender();
	}
	
	
	public function configAction() {	
		$config = new Zend_Session_Namespace('config');		
		$v = $this->_request->getParams();
		
		$config->config[$v['field']] = $v['value'];
		
		$this->_helper->viewRenderer->setNoRender();
	}
	
	public function productshopAction() {	
		$basket = new Zend_Session_Namespace('basket');	
		
		$v = $this->_request->getParams();
		
		$idProduct = $v['product_id'];		
		
		$Product = new Product();	
		$select = $Product->select();				
		$select->where('product_id = ?', $idProduct);			
		$row = $Product->fetchRow($select);
		
		if( $basket->product[$idProduct]['basket_edit'] == true ){
			$this->view->basket_edit = true;
			$this->view->basketid = $basket->product[$idProduct]['basketid'];
			$this->view->amount = $basket->product[$idProduct]['amount'];
		}else{		
			$this->view->basket_edit = false;
		}
		
		if( isset($v['product_height']) ){
			$basket->product[$idProduct]['product_height'] = $v['product_height'];
		}
		if( isset($v['product_width']) ){
			$basket->product[$idProduct]['product_width'] = $v['product_width'];
		}
		if( isset($v['product_depth']) ){
			$basket->product[$idProduct]['product_depth'] = $v['product_depth'];
		}
		if( isset($v['product_shelfamount']) ){
			$basket->product[$idProduct]['product_shelfamount'] = $v['product_shelfamount'];
		}
		if( isset($v['product_wysszerAamount']) ){
			$basket->product[$idProduct]['product_wysszerAamount'] = $v['product_wysszerAamount'];
		}
		if( isset($v['product_wysszerBamount']) ){
			$basket->product[$idProduct]['product_wysszerBamount'] = $v['product_wysszerBamount'];
		}
		if( isset($v['product_wysszerCamount']) ){
			$basket->product[$idProduct]['product_wysszerCamount'] = $v['product_wysszerCamount'];
		}
		if( isset($v['product_wysszerDamount']) ){
			$basket->product[$idProduct]['product_wysszerDamount'] = $v['product_wysszerDamount'];
		}
		if( isset($v['product_wysszerEamount']) ){
			$basket->product[$idProduct]['product_wysszerEamount'] = $v['product_wysszerEamount'];
		}
		if( isset($v['product_field']) ){
			$basket->product[$idProduct][$v['product_field']] = $v['product_value'];
		}
		
		if( $v['product_field'] == 'product_type_id' ){
			unset($basket->product[$idProduct]['product_type2_id']);
		}
		
		
		if( $row->product_shelf == 1 AND $basket->product[$idProduct]['product_shelfamount'] == '' ){
			$this->view->error_product_shelf = true;
		}
		else if( $row->product_body == 1 AND $basket->product[$idProduct]['product_body_id'] == '' ){
			$this->view->error_product_body = true;		
		}
		else if( $row->product_front == 1 AND $basket->product[$idProduct]['product_front_id'] == '' ){
			$this->view->error_product_front = true;		
		/*}
		else if( $row->product_type == 1 AND $basket->product[$idProduct]['product_type_id'] == '' ){
			$this->view->error_product_type = true;		
		}
		else if( $row->product_accessories == 1 AND empty($basket->product[$idProduct]['product_accessories_id']) ){
			$this->view->error_product_accessories = true;	
		}
		else if( $row->product_legs == 1 AND $basket->product[$idProduct]['product_legs_id'] == '' ){
			$this->view->error_product_legs = true;		
		}
		else if( $row->product_handles == 1 AND $basket->product[$idProduct]['product_handles_id'] == '' ){
			$this->view->error_product_handles = true;		
		}
		else if( $row->product_options == 1 AND $basket->product[$idProduct]['product_options_id'] == '' ){
			$this->view->error_product_options = true;		*/
		}else{
		
			// mozna wyliczac
			
			$wysokosc = $basket->product[$idProduct]['product_height'];
			$szerokosc = $basket->product[$idProduct]['product_width'];
			$glebokosc = $basket->product[$idProduct]['product_depth'];
			$iloscpolek = $basket->product[$idProduct]['product_shelfamount'];
			
			$CENA_STALA = $row->product_price;
			
			
			$cena_j_korpusu = 0;	
			$cena_j_plecow = 0;		
			$cena_j_obrzeza = 0;			
			if( $row['product_body'] == 1 AND $basket->product[$idProduct]['product_body_id'] > 0 ){		
			
				$ProductBody = new ProductBody();
				
				$select = $ProductBody->select();				
				$select->where('product_body_id = ?', $basket->product[$idProduct]['product_body_id']);		
				$row2 = $ProductBody->fetchRow($select); 		
				$cena_j_korpusu = $row2->product_body_price;

				if( $row2->product_body_type == 0 ){
					// obrzeze
					if( $basket->product[$idProduct]['product_rim_id'] == 1 ) $cena_j_obrzeza = $row->product_rim1_price;
					if( $basket->product[$idProduct]['product_rim_id'] == 2 ) $cena_j_obrzeza = $row->product_rim2_price;
					if( $basket->product[$idProduct]['product_rim_id'] == 3 ) $cena_j_obrzeza = $row->product_rim3_price;
					if( $basket->product[$idProduct]['product_rim_id'] == 4 ) $cena_j_obrzeza = $row->product_rim4_price;
				}
				
				$select = $ProductBody->select();				
				$select->where('product_body_id = ?', $basket->product[$idProduct]['product_body2_id']);		
				$row2 = $ProductBody->fetchRow($select); 		
				$cena_j_plecow = $row2->product_body_price;	
				
			}
			
			$powierzchnia_plyty = (($wysokosc*$glebokosc)*2+($szerokosc*$glebokosc*2)+($szerokosc*$glebokosc*$iloscpolek))/1000000;
			$ilosc_obrzeza = ($wysokosc*2 + $szerokosc*3 + $szerokosc*$iloscpolek)/1000;
			$powierzchnia_plyty_plecowej = $wysokosc*$szerokosc/1000000;
			
			$CENA_KORPUSU = ($powierzchnia_plyty*$cena_j_korpusu) + ($ilosc_obrzeza*$cena_j_obrzeza) + ($powierzchnia_plyty_plecowej*$cena_j_plecow);
			
			
			
			if( $basket->product[$idProduct]['front_filtr'] != 'no' ){
			
				$cena_j_frontu = 0;			
				if( $row['product_front'] == 1 AND $basket->product[$idProduct]['product_front_id'] > 0 ){				
					$ProductFront = new ProductFront();
					$select = $ProductFront->select();				
					$select->where('product_front_id = ?', $basket->product[$idProduct]['product_front_id']);			
					$row2 = $ProductFront->fetchRow($select); 		
					$cena_j_frontu = $row2->product_front_price;

					$cena_j_obrzezaf = 0;
					if( $row2->product_front_type != 1 ){
						if( $basket->product[$idProduct]['product_rim2_id'] == 1 ) $cena_j_obrzezaf = $row->product_rim1_price;
						if( $basket->product[$idProduct]['product_rim2_id'] == 2 ) $cena_j_obrzezaf = $row->product_rim2_price;
						if( $basket->product[$idProduct]['product_rim2_id'] == 3 ) $cena_j_obrzezaf = $row->product_rim3_price;
						if( $basket->product[$idProduct]['product_rim2_id'] == 4 ) $cena_j_obrzezaf = $row->product_rim4_price;
					}				
				}
				
				$powierzchnia_plyty = (($wysokosc*$szerokosc))/1000000;
				$ilosc_obrzeza = ($wysokosc*2 + $szerokosc*2)/1000;
				
				$CENA_FRONTU = ($powierzchnia_plyty*$cena_j_frontu) + ($ilosc_obrzeza*$cena_j_obrzezaf);
			
			}
				
			if( $row['product_type'] == 1 AND $basket->product[$idProduct]['product_type_id'] > 0 ){				
				$ProductType = new ProductType();
				$select = $ProductType->select();				
				$select->where('product_type_id = ?', $basket->product[$idProduct]['product_type_id']);			
				$row2 = $ProductType->fetchRow($select); 		
				$CENA_AKCESORIOW = $CENA_AKCESORIOW + $row2->product_type_price;				
			}
			
				
			if( $row['product_accessories'] == 1 AND $basket->product[$idProduct]['product_accessories_id'] > 0 ){				
				$ProductAccessories = new ProductAccessories();
				$select = $ProductAccessories->select();				
				$select->where('product_accessories_id = ?', $basket->product[$idProduct]['product_accessories_id']);			
				$row2 = $ProductAccessories->fetchRow($select); 		
				$CENA_AKCESORIOW = $CENA_AKCESORIOW + $row2->product_accessories_price;				
			}
			
				
			if( $row['product_accessories'] == 1 AND $basket->product[$idProduct]['product_accessories_id2'] > 0 ){				
				$ProductAccessories = new ProductAccessories();
				$select = $ProductAccessories->select();				
				$select->where('product_accessories_id = ?', $basket->product[$idProduct]['product_accessories_id2']);			
				$row2 = $ProductAccessories->fetchRow($select); 		
				$CENA_AKCESORIOW = $CENA_AKCESORIOW + $row2->product_accessories_price;				
			}
			
				
			if( $row['product_accessories'] == 1 AND $basket->product[$idProduct]['product_accessories_id3'] > 0 ){				
				$ProductAccessories = new ProductAccessories();
				$select = $ProductAccessories->select();				
				$select->where('product_accessories_id = ?', $basket->product[$idProduct]['product_accessories_id3']);			
				$row2 = $ProductAccessories->fetchRow($select); 		
				$CENA_AKCESORIOW = $CENA_AKCESORIOW + $row2->product_accessories_price;				
			}
			
				
			if( $row['product_accessories'] == 1 AND $basket->product[$idProduct]['product_accessories_id4'] > 0 ){				
				$ProductAccessories = new ProductAccessories();
				$select = $ProductAccessories->select();				
				$select->where('product_accessories_id = ?', $basket->product[$idProduct]['product_accessories_id4']);			
				$row2 = $ProductAccessories->fetchRow($select); 		
				$CENA_AKCESORIOW = $CENA_AKCESORIOW + $row2->product_accessories_price;				
			}
			if( $row['product_legs'] == 1 AND $basket->product[$idProduct]['product_legs_id'] > 0 ){				
				$ProductLegs = new ProductLegs();
				$select = $ProductLegs->select();				
				$select->where('product_legs_id = ?', $basket->product[$idProduct]['product_legs_id']);			
				$row2 = $ProductLegs->fetchRow($select); 		
				$CENA_AKCESORIOW = $CENA_AKCESORIOW + $row2->product_legs_price;				
			}
			
				
			if( $row['product_handles'] == 1 AND $basket->product[$idProduct]['product_handles_id'] > 0 ){				
				$ProductHandles = new ProductHandles();
				$select = $ProductHandles->select();				
				$select->where('product_handles_id = ?', $basket->product[$idProduct]['product_handles_id']);			
				$row2 = $ProductHandles->fetchRow($select); 		
				$CENA_AKCESORIOW = $CENA_AKCESORIOW + $row2->product_handles_price;				
			}


			
			if( $row['product_options'] == 1 ){	
			
				$cenawysyn = 0;
				if( $basket->product[$idProduct]['product_options_1'] > 0 ) $cenawysyn = $cenawysyn + $row->product_options_1;
				if( $basket->product[$idProduct]['product_options_2'] > 0 ) $cenawysyn = $cenawysyn + $row->product_options_2;
				if( $basket->product[$idProduct]['product_options_3'] > 0 ) $cenawysyn = $cenawysyn + $row->product_options_3;
				if( $basket->product[$idProduct]['product_options_4'] > 0 ) $cenawysyn = $cenawysyn + $row->product_options_4;
			
				$CENA_AKCESORIOW = $CENA_AKCESORIOW + $cenawysyn;				
			}
			
			
			if( $row['product_options2'] == 1 ){	
				if( $basket->product[$idProduct]['product_options_id'] == 0 ) $cenawieniec = $row->product_options_ww0;
				if( $basket->product[$idProduct]['product_options_id'] == 1 ) $cenawieniec = $row->product_options_ww1;
						
				$CENA_AKCESORIOW = $CENA_AKCESORIOW + $cenawieniec;	
			}
			
			
			
			if( $row['product_price_scheme'] == 0 ){	
				$cena_calkowita = $CENA_STALA * 1 + $CENA_KORPUSU * 1 + $CENA_FRONTU * 1 + $CENA_AKCESORIOW * 1 + $CENA_DOD_USLUG;
			}
			if( $row['product_price_scheme'] == 1 ){	
				$cena_calkowita = $CENA_STALA * 1.05 + $CENA_KORPUSU * 1.05 + $CENA_FRONTU * 1.4 + $CENA_AKCESORIOW * 1.27 + $CENA_DOD_USLUG;
			}
			if( $row['product_price_scheme'] == 2 ){	
				$cena_calkowita = $CENA_STALA * 1.05 + $CENA_KORPUSU * 1.05 + $CENA_FRONTU * 1.4 + $CENA_AKCESORIOW * 1.27 + $CENA_DOD_USLUG;
			}
			if( $row['product_price_scheme'] == 3 ){	
				$cena_calkowita = $CENA_STALA * 1.05 + $CENA_KORPUSU * 1.05 + $CENA_FRONTU * 1.4 + $CENA_AKCESORIOW * 1.27 + $CENA_DOD_USLUG;
			}
			if( $row['product_price_scheme'] == 4 ){	
				$cena_calkowita = $CENA_STALA * 1.05 + $CENA_KORPUSU * 1.05 + $CENA_FRONTU * 1.4 + $CENA_AKCESORIOW * 1.27 + $CENA_DOD_USLUG;
			}
			
			
			$this->view->cena_calkowita = round($cena_calkowita,2);	
			$this->view->idProduct = $idProduct;	
			$basket->product[$idProduct]['price'] = $cena_calkowita;
		}
		
		
		
		
	}

	public function resetAction() {
	
		Zend_Session::namespaceUnset('information');
		// Zend_Session::namespaceUnset('admin');
		Zend_Session::namespaceUnset('basket');
		Zend_Session::namespaceUnset('order');
		Zend_Session::namespaceUnset('client');
		Zend_Session::namespaceUnset('config');
	
		$this->_helper->viewRenderer->setNoRender();
	}
	
	
	
}
