Location: PHPKode > projects > SOA For Virtuemart (WebServices) > com_vm_soa/admin/services/VM_ProductService.php
<?php
define( '_VALID_MOS', 1 );
define( '_JEXEC', 1 );

/**
 * Virtuemart Product SOA Connector
 *
 * Virtuemart Product SOA Connector (Provide functions GetProductFromId, GetProductFromId, GetChildsProduct, GetProductsFromCategory)
 * The return classe is a "Product" classe with attribute : id, name, description, price, quantity, image, fulliamage ,
 * attributes, parent produit, child id)
 *
 * @package    com_vm_soa
 * @subpackage component
 * @author     Mickael cabanas (cabanas.mickael|at|gmail.com)
 * @copyright  2010 Mickael Cabanas
 * @license    http://www.gnu.org/copyleft/gpl.html GNU/GPL
 * @version    $Id:$
 */

global $mosConfig_absolute_path, $sess;
global $jscook_type, $jscookMenu_style, $jscookTree_style;

$mosConfig_absolute_path= realpath( dirname(__FILE__).'/../../../..' );

// Load the joomla main cfg
if( file_exists(dirname(__FILE__).'/configuration.php' )) {
	require_once( $mosConfig_absolute_path.'/configuration.php' );
	
} else {
	require_once( $mosConfig_absolute_path.'/configuration.php');
}

// Load the virtuemart main parse code
if( file_exists(dirname(__FILE__).'/../../../../components/com_virtuemart/virtuemart_parser.php' )) {
	require_once( dirname(__FILE__).'/../../../../components/com_virtuemart/virtuemart_parser.php' );
	$mosConfig_absolute_path = realpath( dirname(__FILE__).'/../..' );
} else {
	require_once( dirname(__FILE__).'/../../../../components/com_virtuemart/virtuemart_parser.php');
}

require_once(CLASSPATH.'ps_product.php');
require_once(CLASSPATH.'ps_product_attribute.php');
require_once(CLASSPATH.'ps_tax.php');
require_once(CLASSPATH.'ps_product_price.php');
require_once(CLASSPATH.'ps_product_discount.php');
require_once(CLASSPATH.'ps_product_files.php');

include('../vm_soa_conf.php');

global $mosConfig_live_site;
$URL_BASE ='';
if( $mosConfig_live_site[strlen( $mosConfig_live_site)-1] == '/' ) {
	$URL_BASE = $mosConfig_live_site;
}
else {
	$URL_BASE = $mosConfig_live_site.'/';
}


/**
 * Class Product
 *
 * Class "Product" with attribute : id, name, description, price, quantity, image, fulliamage ,
 * attributes, parent produit, child id)
 *
 * @author     Mickael cabanas (cabanas.mickael|at|gmail.com)
 * @copyright  Mickael cabanas
 * @license    http://www.gnu.org/copyleft/gpl.html GNU/GPL
 * @version    Release:
 */
	class Produit {
		public $name="";
		public $price="";
		public $discount="";
		public $discount_is_percent="";
		public $description="";
		public $bigdescription="";
		public $image="";
		public $fullimage="";
		public $id="";
		public $quantity="";
		public $parent_produit_id="";
		public $has_childs="";
		public $childs_id;
		public $atribute;
		public $atribute_value;
		public $product_sku;
		public $product_sales;
		public $product_publish;
		public $product_weight;
		public $product_weight_uom;
		public $product_length;
		public $product_width;
		public $product_height;
		public $product_lwh_uom;
		public $product_unit;
		public $product_packaging;
		public $product_url;
		public $custom_attribute;
		public $product_available_date;
		public $product_availability;
		public $product_special;
		public $child_options;
		public $quantity_options;
		public $product_discount_id;
		public $product_tax_id;
		public $child_option_ids;
		public $product_order_levels;
		public $product_categories;	
		public $product_currency;	
		public $manufacturer_id;	
		public $vendor_id;	
		public $shopper_group_id;
		
		//constructeur
		/**
		 * Enter description here...
		 *
		 * @param String $name
		 * @param String $price
		 * @param String $description
		 * @param String $image
		 * @param String $fullimage
		 * @param String $id
		 */
		function __construct($name, $price, $discount, $discount_is_percent, $description, $bigdescription, $image, $fullimage,$id,$quantity,$parent_produit_id,$has_childs,$atribute,$atribute_value,$childs_id,$product_sku,$product_sales, $product_publish,
									$product_weight,$product_weight_uom, $product_length, $product_width, $product_height, $product_lwh_uom, $product_unit, $product_packaging, $product_url, $custom_attribute, $product_available_date, $product_availability,
									$product_special, $child_options, $quantity_options, $product_discount_id, $product_tax_id, $child_option_ids, $product_order_levels, $product_categories, $product_currency, $manufacturer_id, $vendor_id, $shopper_group_id=null ) {
			$this->id = $id;
			$this->name = $name;
			$this->price = $price;
			$this->discount = $discount;
			$this->discount_is_percent = $discount_is_percent; 
			$this->description = $description;
			$this->bigdescription = $bigdescription;
			$this->image = $image;
			$this->fullimage = $fullimage;
			$this->quantity = $quantity;
			$this->parent_produit_id = $parent_produit_id;
			$this->has_childs = $has_childs;
			$this->atribute = $atribute;
			$this->atribute_value = $atribute_value;
			$this->childs_id = $childs_id;
			$this->product_sku = $product_sku;
			$this->product_sales = $product_sales;
			$this->product_publish = $product_publish;
			$this->product_weight = $product_weight;
			$this->product_weight_uom = $product_weight_uom;
			$this->product_length = $product_length;
			$this->product_width = $product_width;
			$this->product_height = $product_height;
			$this->product_lwh_uom = $product_lwh_uom;
			$this->product_unit = $product_unit;
			$this->product_packaging = $product_packaging;
			$this->product_url = $product_url;
			$this->custom_attribute = $custom_attribute;
			$this->product_available_date = $product_available_date;
			$this->product_availability = $product_availability;
			$this->product_special = $product_special;
			$this->child_options = $child_options;
			$this->quantity_options = $quantity_options;
			$this->product_discount_id = $product_discount_id;
			$this->product_tax_id = $product_tax_id;
			$this->child_option_ids = $child_option_ids;
			$this->product_order_levels = $product_order_levels;
			$this->product_categories = $product_categories;	
			$this->product_currency = $product_currency;	
			$this->manufacturer_id = $manufacturer_id;		
			$this->vendor_id = $vendor_id;	
			$this->shopper_group_id = $shopper_group_id;
		}
	}

/**
 * Class OrderItemInfo
 *
 * Class "OrderItemInfo" with attribute : id, name, description, price, quantity, image, fulliamage ,
 * attributes, parent produit, child id)
 *
 * @author     Mickael cabanas (cabanas.mickael|at|gmail.com)
 * @copyright  Mickael cabanas
 * @license    http://www.gnu.org/copyleft/gpl.html GNU/GPL
 * @version    Release:
 */
	class OrderItemInfo {
		public $order_id="";
		public $vendor_id="";
		public $product_id="";
		public $order_item_sku="";
		public $order_item_name="";
		public $product_quantity="";
		public $product_item_price="";
		public $product_final_price="";
		public $order_item_currency="";
		public $order_status="";
		public $cdate="";
		public $mdate="";
		public $product_attribute;
		
		//constructeur
		/**
		 * Enter description here...
		 *
		 * @param String $name
		 * @param String $price
		 * @param String $description
		 * @param String $image
		 * @param String $fullimage
		 * @param String $id
		 */
		function __construct($order_id, $vendor_id, $product_id, $order_item_sku, $order_item_name, $product_quantity, $product_item_price, $product_final_price,$order_item_currency,$order_status,$cdate,$mdate,$product_attribute) {
			$this->order_id = $order_id;
			$this->vendor_id = $vendor_id;
			$this->product_id = $product_id;
			$this->order_item_sku = $order_item_sku;
			$this->order_item_name = $order_item_name; 
			$this->product_quantity = $product_quantity;
			$this->product_item_price = $product_item_price;
			$this->product_final_price = $product_final_price;
			$this->order_item_currency = $order_item_currency;
			$this->order_status = $order_status;
			$this->cdate = $cdate;
			$this->mdate = $mdate;
			$this->product_attribute = $product_attribute;
			
		}
	}	

	/**
 * Class Currency
 *
 * Class "Currency" with attribute : id, name, code, 
 *
 * @author     Mickael cabanas (cabanas.mickael|at|gmail.com)
 * @copyright  Mickael cabanas
 * @license    http://www.gnu.org/copyleft/gpl.html GNU/GPL
 * @version    Release:
 */
	class Currency {
		public $currency_id="";
		public $currency_name="";
		public $currency_code="";

		//constructeur
		/**
		 * Enter description here...
		 *
		 * @param String $currency_id
		 * @param String $currency_name
		 * @param String $currency_code
		 */
		function __construct($currency_id, $currency_name, $currency_code) {
			$this->currency_id = $currency_id;
			$this->currency_name = $currency_name;
			$this->currency_code = $currency_code;
			
		}
	}	
	
	
	/**
	 * Class ProductPrice
	 *
	 * Class "ProductPrice" with attribute : product_price_id ...
	 *
	 * @author     Mickael cabanas (cabanas.mickael|at|gmail.com)
	 * @copyright  Mickael cabanas
	 * @license    http://www.gnu.org/copyleft/gpl.html GNU/GPL
	 * @version    Release:
	 */
	class ProductPrice {
		public $product_price_id="";
		public $product_id="";
		public $product_price="";
		public $product_currency="";
		public $product_price_vdate="";
		public $product_price_edate="";
		public $cdate="";
		public $mdate="";
		public $shopper_group_id="";
		public $price_quantity_start="";
		public $price_quantity_end="";

		//constructeur
		/**
		 * Enter description here...
		 *
		 * @param String $product_price_id
		 * @param String $product_id
		 * @param String $product_price
		 * ...
		 */
		function __construct($product_price_id, $product_id, $product_price,$product_currency,$product_price_vdate,$product_price_edate,$cdate,$mdate,$shopper_group_id,$price_quantity_start,$price_quantity_end) {
			$this->product_price_id = $product_price_id;
			$this->product_id = $product_id;
			$this->product_price = $product_price;
			$this->product_currency = $product_currency;
			$this->product_price_vdate = $product_price_vdate;
			$this->product_price_edate = $product_price_edate;
			$this->cdate = $cdate;
			$this->mdate = $mdate;
			$this->shopper_group_id = $shopper_group_id;
			$this->price_quantity_start = $price_quantity_start;
			$this->price_quantity_end = $price_quantity_end;
		}
	}	
	
	/**
	 * Class ProductFile
	 *
	 * Class "ProductFile" with attribute : file_id ...
	 *
	 * @author     Mickael cabanas (cabanas.mickael|at|gmail.com)
	 * @copyright  Mickael cabanas
	 * @license    http://www.gnu.org/copyleft/gpl.html GNU/GPL
	 * @version    Release:
	 */
	class ProductFile {
		public $file_id="";
		public $file_product_id="";
		public $file_name="";
		public $file_title="";
		public $file_description="";
		public $file_extension="";
		public $file_mimetype="";
		public $file_url="";
		public $file_published="";
		public $file_is_image="";
		public $file_image_height="";
		public $file_image_width="";
		public $file_image_thumb_height="";
		public $file_image_thumb_width="";

		//constructeur
		/**
		 * Enter description here...
		 *
		 * @param String $file_id
		 * @param String $file_product_id
		 * @param String $file_name
		 * ...
		 */
		function __construct($file_id, $file_product_id, $file_name,$file_title,$file_description,$file_extension,$file_mimetype,$file_url,$file_published,$file_is_image,$file_image_height,$file_image_width,$file_image_thumb_height,$file_image_thumb_width) {
			$this->file_id = $file_id;
			$this->file_product_id = $file_product_id;
			$this->file_name = $file_name;
			$this->file_title = $file_title;
			$this->file_description = $file_description;
			$this->file_extension = $file_extension;
			$this->file_mimetype = $file_mimetype;
			$this->file_url = $file_url;
			$this->file_published = $file_published;
			$this->file_is_image = $file_is_image;
			$this->file_image_height = $file_image_height;
			$this->file_image_width = $file_image_width;
			$this->file_image_thumb_height = $file_image_thumb_height;
			$this->file_image_thumb_width = $file_image_thumb_width;
		}
	}	
	
	/**
	 * Class Tax
	 *
	 * Class "Tax" with attribute : tax_rate_id
	 *
	 * @author     Mickael cabanas (cabanas.mickael|at|gmail.com)
	 * @copyright  Mickael cabanas
	 * @license    http://www.gnu.org/copyleft/gpl.html GNU/GPL
	 * @version    Release:
	 */
	class Tax {
		public $tax_rate_id="";
		public $vendor_id="";
		public $tax_state="";
		public $tax_country="";
		public $mdate="";
		public $tax_rate="";

		//constructeur
		/**
		 * Enter description here...
		 *
		 * @param String $tax_rate_id
		 * @param String $vendor_id
		 * @param String $tax_state
		 */
		function __construct($tax_rate_id, $vendor_id, $tax_state,$tax_country,$mdate,$tax_rate) {
			$this->tax_rate_id = $tax_rate_id;
			$this->vendor_id = $vendor_id;
			$this->tax_state = $tax_state;
			$this->tax_country = $tax_country;
			$this->mdate = $mdate;
			$this->tax_rate = $tax_rate;
		}
	}	
	
	/**
	 * Class Discount
	 *
	 * Class "Discount" with attribute : discount_id ...
	 *
	 * @author     Mickael cabanas (cabanas.mickael|at|gmail.com)
	 * @copyright  Mickael cabanas
	 * @license    http://www.gnu.org/copyleft/gpl.html GNU/GPL
	 * @version    Release:
	 */
	class Discount {
		public $discount_id="";
		public $amount="";
		public $is_percent="";
		public $start_date="";
		public $end_date="";
		

		//constructeur
		/**
		 * Enter description here...
		 *
		 * @param String $discount_id
		 * @param String $amount
		 * @param String $is_percent
		 * @param String $start_date
		 * @param String $end_date
		 */
		function __construct($discount_id, $amount, $is_percent,$start_date,$end_date) {
			$this->discount_id = $discount_id;
			$this->amount = $amount;
			$this->is_percent = $is_percent;
			$this->start_date = $start_date;
			$this->end_date = $end_date;
			
		}
	}	
	
/**
 * Class AvalaibleImage
 *
 * Class "AvalaibleImage" with attribute : id, name, code, 
 *
 * @author     Mickael cabanas (cabanas.mickael|at|gmail.com)
 * @copyright  Mickael cabanas
 * @license    http://www.gnu.org/copyleft/gpl.html GNU/GPL
 * @version    Release:
 */
	class AvalaibleImage {
		public $image_name="";
		public $image_url="";
		public $realpath="";

		//constructeur
		/**
		 * Enter description here...
		 *
		 * @param String $image_name
		 * @param String $image_url
		 */
		function __construct($image_name, $image_url, $realpath) {
			$this->image_name = $image_name;
			$this->image_url = $image_url;	
			$this->realpath = $realpath;				
		}
	}	
	
	/**
	 * Class AvalaibleImage
	 *
	 * Class "AvalaibleImage" with attribute : id, name, code, 
	 *
	 * @author     Mickael cabanas (cabanas.mickael|at|gmail.com)
	 * @copyright  Mickael cabanas
	 * @license    http://www.gnu.org/copyleft/gpl.html GNU/GPL
	 * @version    Release:
	 */
	class AvalaibleFile {
		public $file_name="";
		public $file_url="";
		public $realpath="";

		//constructeur
		/**
		 * Enter description here...
		 *
		 * @param String $file_name
		 * @param String $file_url
		 */
		function __construct($file_name, $file_url, $realpath) {
			$this->file_name = $file_name;
			$this->file_url = $file_url;
			$this->realpath = $realpath;			
		}
	}	
	
	/**
	 * Class ProductVote
	 *
	 * Class "ProductVote" with attribute : id, name, code, 
	 *
	 * @author     Mickael cabanas (cabanas.mickael|at|gmail.com)
	 * @copyright  Mickael cabanas
	 * @license    http://www.gnu.org/copyleft/gpl.html GNU/GPL
	 * @version    Release:
	 */
	class ProductVote {
		public $product_id="";
		public $product_name="";
		public $product_sku="";
		public $votes="";
		public $allvotes="";
		public $rating="";
		public $lastip="";

		//constructeur
		/**
		 * Enter description here...
		 *
		 * @param String $product_id
		 * @param String $product_name
		 */
		function __construct($product_id, $product_name, $product_sku,$votes, $allvotes, $rating, $lastip) {
			$this->product_id = $product_id;
			$this->product_name = $product_name;
			$this->product_sku = $product_sku;
			$this->votes = $votes;
			$this->allvotes = $allvotes;
			$this->rating = $rating;
			$this->lastip = $lastip;			
		}
	}	
	
	/**
	 * Class productReview
	 *
	 * Class "productReview" with attribute : id, name, code, 
	 *
	 * @author     Mickael cabanas (cabanas.mickael|at|gmail.com)
	 * @copyright  Mickael cabanas
	 * @license    http://www.gnu.org/copyleft/gpl.html GNU/GPL
	 * @version    Release:
	 */
	class ProductReview {
		public $review_id="";
		public $product_id="";
		public $comment="";
		public $userid="";
		public $time="";
		public $user_rating="";
		public $review_ok="";
		public $review_votes="";
		public $published="";

		//constructeur
		/**
		 * Enter description here...
		 *
		 * @param String $review_id
		 * @param String $product_id
		 */
		function __construct($review_id, $product_id, $comment,$userid, $time, $user_rating, $review_ok, $review_votes, $published) {
			$this->review_id = $review_id;
			$this->product_id = $product_id;
			$this->comment = $comment;
			$this->userid = $userid;
			$this->time = $time;
			$this->user_rating = $user_rating;
			$this->review_ok = $review_ok;	
			$this->review_votes = $review_votes;
			$this->published = $published;			
		}
	}	
	
	
	/**
	 * Class returnOutput
	 *
	 * Class "returnOutput" 
	 * @author     Mickael cabanas (cabanas.mickael|at|gmail.com)
	 * @copyright  Mickael cabanas
	 * @license    http://www.gnu.org/copyleft/gpl.html GNU/GPL
	 * @version    Release:
	 */
	class returnOutput {
	
		public $returnCode="";
		public $message="";		
		public $outputParam="";	
		
		function __construct($returnCode,$message,$outputParam){
		
			$this->returnCode=$returnCode;
			$this->message=$message;		
			$this->outputParam=$outputParam;	
		}
	}	
	
	
	/**
    * This function get Attributes for a product ID
	* (not expose as WS)
    * @param string The if of the product
    * @return array of attribute and value
   */
	function getAttributes($product_id){
	
		$list  = "SELECT at.attribute_name, at.attribute_value  ";
		$list .= "FROM #__{vm}_product_attribute at WHERE ";
		$q .= "at.product_id = '$product_id' ";
		$list .= $q . " LIMIT 0,100 "; 
		
		$db = new ps_DB;
		$db->query($list);
		
		while ($db->next_record()) {
				 			  			 
			  $attributesArray = array("name" => $db->f("attribute_name"), "value" => $db->f("attribute_value") );
		}
		return $attributesArray;
	}

	/**
    * This function get categoriesID for a product ID
	* (not expose as WS)
    * @param string The if of the product
    * @return array of categorie id
   */
	function getCategoriesIds($product_id){
	
		$q  = "SELECT `category_id` FROM `#__{vm}_product_category_xref` ";
		$q .= "WHERE `product_id` = '" . $product_id . "' ";
		$list .= $q . " LIMIT 0,100 "; 
		
		$db = new ps_DB;
		$db->query($list);
		
		$categories = array();
		$str = "";
		while ($db->next_record()) {
			$str .= $db->f('category_id')."|";
			//$categories[$db->f('category_id')] = $db->f('category_id');		 			  			 
		}
		return $str;
	}	
	
	/**
    * This function get Product for a product ID
	* (expose as WS)
    * @param string The if of the product
    * @return array (Product)
   */
	function GetProductFromId($params) {
	
		include('../vm_soa_conf.php');
		
		$product_id = $params->product_id;
		/* Authenticate*/
		$result = onAdminAuthenticate($params->loginInfo->login, $params->loginInfo->password);
		if ($conf['auth_prod_getfromid']=="off"){
			$result = "true";
		}
		//Auth OK
		if ($result == "true"){
		
			$ps_product = new ps_product;
			$ps_product_attribute = new ps_product_attribute;
			$childsProduit= $ps_product->get_child_product_ids($product_id);
			$count = count($childsProduit);
			$listChildsStr="";
			for ($i = 0; $i < $count; $i++) {
				$listChildsStr=$listChildsStr." ".$childsProduit[$i];
			}


			$list  = "SELECT p.product_id, p.product_sales as sales, p.product_parent_id, p.product_name, p.product_thumb_image, p.product_full_image , p.product_s_desc, p.product_desc, c.category_id, c.category_flypage, p.product_in_stock, pr.product_price, pr.product_currency , p.product_sku, p.product_publish, p.product_weight, p.product_weight_uom, p.product_length,p.product_width, p.product_height, p.product_lwh_uom, p.product_unit, p.product_packaging, p.product_url, p.custom_attribute, p.product_available_date, p.product_availability, p.product_special, p.child_options, p.quantity_options, p.product_discount_id, p.product_tax_id, p.child_option_ids, p.product_order_levels, p.vendor_id, mf.manufacturer_id  ";
			$list .= "FROM #__{vm}_product p ";
			$list .= "left join #__{vm}_product_category_xref pc on pc.product_id = p.product_id ";
			$list .= "left join #__{vm}_category c on pc.category_id = c.category_id ";
			$list .= "left join  #__{vm}_product_mf_xref mf on mf.product_id = p.product_id ";
			//$list .= "FROM #__{vm}_product_category_xref pc, #__{vm}_category c, #__{vm}_product_mf_xref mf, #__{vm}_product p  ";
			$q = "LEFT OUTER JOIN  #__{vm}_product_price pr ON pr.product_id = p.product_id ";
			$q .= "WHERE p.product_id = '$product_id' ";

			$q .= "GROUP BY p.product_id ";
			$list .= $q . " LIMIT 0,200 "; 

			$db = new ps_DB;
			$db->query($list);
			
			//return new SoapFault("JoomlaServerAuthFault", "Autification KO for : \n".$list);
			
			while ($db->next_record()) {
			
				  $has_childs= ps_product::parent_has_children( $db->f('product_id') );
				  if ($has_childs==null)$has_childs=0;
				  //discount info
				  $discount_info = $ps_product->get_discount($product_id);
				  $discount_info["amount"];
				  $discount_info["is_percent"];

				   $attributesArray = getAttributes($db->f('product_id') );
							  
				  $Produit = new Produit($db->f("product_name"), $db->f('product_price'), $discount_info["amount"], $discount_info["is_percent"], $db->f("product_s_desc"), $db->f("product_desc") ,$db->f("product_thumb_image"), $db->f("product_full_image") ,$db->f('product_id'), $db->f("product_in_stock"),$db->f("product_parent_id"),$has_childs,$attributesArray['name'],$attributesArray['value'],$listChildsStr, $db->f('product_sku'),$db->f("sales"), $db->f('product_publish'),
											$db->f("product_weight"), $db->f("product_weight_uom"), $db->f("product_length"), $db->f("product_width"), $db->f("product_height"), $db->f("product_lwh_uom"), $db->f("product_unit"), $db->f("product_packaging"), $db->f("product_url"), $db->f("custom_attribute"), $db->f("product_available_date"), $db->f("product_availability"), $db->f("product_special"), $db->f("child_options"), $db->f("quantity_options"), $db->f("product_discount_id"), $db->f("product_tax_id"), $db->f("child_option_ids"), $db->f("product_order_levels"), getCategoriesIds($product_id),$db->f("product_currency"), $db->f("manufacturer_id"),$db->f("vendor_id"));
				 // $ProduitArray[] = $Produit;
			}
			
			$errMsg=  $db->getErrorMsg();
			if ($errMsg==null){
				return $Produit;
			} else {
				return new SoapFault("GetProductFromIdError", "DB message : \n".$errMsg);
			}
			
			
			
		}else if ($result == "false"){
			return new SoapFault("JoomlaServerAuthFault", "Autification KO for : ".$params->loginInfo->login);
		}else if ($result == "no_admin"){
			return new SoapFault("JoomlaServerAuthFault", "User is not a Super Administrator : ".$params->loginInfo->login);
		}else{
			return new SoapFault("JoomlaServerAuthFault", "User does not exist : ".$params->loginInfo->login);
		}
	}
	
	/**
    * This function get Product for a SKU
	* (expose as WS)
    * @param string The if of the product
    * @return array (Product)
   */
	function GetProductFromSKU($params) {
	
		include('../vm_soa_conf.php');
		
		$product_sku = $params->product_sku;
		/* Authenticate*/
		$result = onAdminAuthenticate($params->loginInfo->login, $params->loginInfo->password);
		if ($conf['auth_prod_getfromid']=="off"){
			$result = "true";
		}
		//Auth OK
		if ($result == "true"){
		
			$ps_product = new ps_product;
			$ps_product_attribute = new ps_product_attribute;
			$childsProduit= $ps_product->get_child_product_ids($product_id);
			$count = count($childsProduit);
			$listChildsStr="";
			for ($i = 0; $i < $count; $i++) {
				$listChildsStr=$listChildsStr." ".$childsProduit[$i];
			}
			
			////////////
			$list  = "SELECT p.product_id, p.product_sales as sales, p.product_parent_id, p.product_name, p.product_thumb_image, p.product_full_image , p.product_s_desc, p.product_desc, c.category_id, c.category_flypage, p.product_in_stock, pr.product_price, pr.product_currency , p.product_sku, p.product_publish, p.product_weight, p.product_weight_uom, p.product_length,p.product_width, p.product_height, p.product_lwh_uom, p.product_unit, p.product_packaging, p.product_url, p.custom_attribute, p.product_available_date, p.product_availability, p.product_special, p.child_options, p.quantity_options, p.product_discount_id, p.product_tax_id, p.child_option_ids, p.product_order_levels, p.vendor_id, mf.manufacturer_id  ";
			$list .= "FROM #__{vm}_product p ";
			$list .= "left join #__{vm}_product_category_xref pc on pc.product_id = p.product_id ";
			$list .= "left join #__{vm}_category c on pc.category_id = c.category_id ";
			$list .= "left join  #__{vm}_product_mf_xref mf on mf.product_id = p.product_id ";
			//$list .= "FROM #__{vm}_product_category_xref pc, #__{vm}_category c, #__{vm}_product_mf_xref mf, #__{vm}_product p  ";
			$q = "LEFT OUTER JOIN  #__{vm}_product_price pr ON pr.product_id = p.product_id ";
			$q .= "WHERE p.product_sku = '$product_sku' ";

			$q .= "GROUP BY p.product_id ";
			$list .= $q . " LIMIT 0,200 "; 

			$db = new ps_DB;
			$db->query($list);
			
			//return new SoapFault("JoomlaServerAuthFault", "Autification KO for : \n".$list);
			
			while ($db->next_record()) {
			
				$product_id = $db->f('product_id');
				
				$ps_product = new ps_product;
				$ps_product_attribute = new ps_product_attribute;
				$childsProduit= $ps_product->get_child_product_ids($product_id);
				$count = count($childsProduit);
				$listChildsStr="";
				for ($i = 0; $i < $count; $i++) {
					$listChildsStr=$listChildsStr." ".$childsProduit[$i];
				}
			
				$has_childs= ps_product::parent_has_children( $db->f('product_id') );
				if ($has_childs==null)$has_childs=0;
				//discount info
				$discount_info = $ps_product->get_discount($product_id);
				$discount_info["amount"];
				$discount_info["is_percent"];

				$attributesArray = getAttributes($db->f('product_id') );
						  
				$Produit = new Produit($db->f("product_name"), $db->f('product_price'), $discount_info["amount"], $discount_info["is_percent"], $db->f("product_s_desc"), $db->f("product_desc") ,$db->f("product_thumb_image"), $db->f("product_full_image") ,$db->f('product_id'), $db->f("product_in_stock"),$db->f("product_parent_id"),$has_childs,$attributesArray['name'],$attributesArray['value'],$listChildsStr, $db->f('product_sku'),$db->f("sales"), $db->f('product_publish'),
										$db->f("product_weight"), $db->f("product_weight_uom"), $db->f("product_length"), $db->f("product_width"), $db->f("product_height"), $db->f("product_lwh_uom"), $db->f("product_unit"), $db->f("product_packaging"), $db->f("product_url"), $db->f("custom_attribute"), $db->f("product_available_date"), $db->f("product_availability"), $db->f("product_special"), $db->f("child_options"), $db->f("quantity_options"), $db->f("product_discount_id"), $db->f("product_tax_id"), $db->f("child_option_ids"), $db->f("product_order_levels"), getCategoriesIds($product_id),$db->f("product_currency"), $db->f("manufacturer_id"),$db->f("vendor_id"));
				// $ProduitArray[] = $Produit;
			}
			return $Produit;
			
		}else if ($result == "false"){
			return new SoapFault("JoomlaServerAuthFault", "Autification KO for : ".$params->loginInfo->login);
		}else if ($result == "no_admin"){
			return new SoapFault("JoomlaServerAuthFault", "User is not a Super Administrator : ".$params->loginInfo->login);
		}else{
			return new SoapFault("JoomlaServerAuthFault", "User does not exist : ".$params->loginInfo->login);
		}
	}
	
	
	
	/**
    * This function get All Childs product for a product ID
	* (expose as WS)
    * @param string The if of the product
    * @return array of Products
   */
	function GetChildsProduct($params) {
	
		include('../vm_soa_conf.php');
		//return new SoapFault("JoomlaServerAuthFault", "params->product_id ".$params->product_id);
		$product_id = $params->product_id;
		/* Authenticate*/
		$result = onAdminAuthenticate($params->loginInfo->login, $params->loginInfo->password);
		if ($conf['auth_prod_getchild']=="off"){
			$result = "true";
		}
		//Auth OK
		if ($result == "true"){
			
			
			
			$ps_product = new ps_product;
			$childsProduit= $ps_product->get_child_product_ids($product_id);
			$count = count($childsProduit);
			$listChildsStr="";
			for ($i = 0; $i < $count; $i++) {
				$params->product_id = $childsProduit[$i];
				$Produit = GetProductFromId($params);
				$ProduitArray[] = $Produit;
			}		
			return $ProduitArray;
			
		}else if ($result == "false"){
			return new SoapFault("JoomlaServerAuthFault", "Autification KO for : ".$params->loginInfo->login);
		}else if ($result == "no_admin"){
			return new SoapFault("JoomlaServerAuthFault", "User is not a Super Administrator : ".$params->loginInfo->login);
		}else{
			return new SoapFault("JoomlaServerAuthFault", "User does not exist : ".$params->loginInfo->login);
		}
		
	}
	
	/**
    * This function get All Products for a category ID
	* (expose as WS)
    * @param string The if of the product
    * @return array of attribute and value
   */
	function GetProductsFromCategory($params) {
	
		include('../vm_soa_conf.php');
		
		$categorie_id = $params->catgory_id;
		/* Authenticate*/
		$result = onAdminAuthenticate($params->loginInfo->login, $params->loginInfo->password);
		if ($conf['auth_prod_getfromcat']=="off"){
			$result = "true";
		}
		
		//Auth OK
		if ($result == "true"){
	
			$ps_product = new ps_product;
			$ps_product_attribute = new ps_product_attribute;
			
			$product_publish = $params->product_publish;
			if ($product_publish == "N"){
				$product_publish = "N";
			}
			if ($product_publish == "Y"){
				$product_publish = "Y";
			}
			
			$with_childs = $params->with_childs;
			if ($with_childs == "N"){
				$with_childs = "N";
			}else {
				$with_childs = "Y";
			}
			
			$list  = "SELECT p.product_id, p.product_sales as sales, p.product_parent_id, p.product_name, p.product_thumb_image, p.product_full_image , p.product_s_desc, p.product_desc, c.category_id, c.category_flypage, p.product_in_stock, pr.product_price, pr.product_currency , p.product_sku, p.product_publish, p.product_weight, p.product_weight_uom, p.product_length,p.product_width, p.product_height, p.product_lwh_uom, p.product_unit, p.product_packaging, p.product_url, p.custom_attribute, p.product_available_date, p.product_availability, p.product_special, p.child_options, p.quantity_options, p.product_discount_id, p.product_tax_id, p.child_option_ids, p.product_order_levels, p.vendor_id, mf.manufacturer_id ";
			$list .= "FROM   #__{vm}_category c, #__{vm}_product_mf_xref mf, #__{vm}_product_category_xref pc , #__{vm}_product p ";
			$q  = "LEFT OUTER JOIN  #__{vm}_product_price pr ON pr.product_id = p.product_id  ";
			//$q .= "LEFT OUTER JOIN  #__{vm}_product_category_xref pc ON pr.product_id = p.product_id  ";
			
			if (!empty($product_publish)){
				$q .= "WHERE p.product_publish='$product_publish' AND ";
			} else{
				$q .= "WHERE ";
			}
			if ($with_childs == "N"){
				//$q .= "p.product_id = mf.product_id AND ";
				$q .= "p.product_parent_id = '0' AND ";
			}else{
				//$q .= "p.product_id = mf.product_id ";
				
			}
			//$q .= "p.product_publish='Y' AND ";
			$q .= "pc.category_id='$categorie_id' AND ";
			$q .= "pc.product_id = p.product_id AND ";
			$q .= "p.product_id = mf.product_id AND ";
			//$q .= "p.product_id = pr.product_id AND ";
			$q .= "pc.category_id = c.category_id ";
			//$q .= "p.product_sales > 0 ";
			$q .= "GROUP BY p.product_id ";
			$q .= "ORDER BY p.product_id ASC ";
			$list .= $q . " LIMIT 0,100 "; 

			$db = new ps_DB;
			$db->query($list);


			  while ($db->next_record()) {

				 // $Produit2 = new Produit("Tshirt rouge","210.0","Tshirt rouge en bamboo","http://localhost/SOAP/img/Pant_homme_thumbnail.jpg","http://localhost/SOAP/img/pant_homme_full.jpg","4");
				  $product_id= $db->f('product_id');
				  $has_childs= ps_product::parent_has_children($product_id);
				  if ($has_childs==null)$has_childs=0;
				  
				  $discount_info = $ps_product->get_discount($product_id);
				  $discount_info["amount"];
				  $discount_info["is_percent"];
				  
				  $price = $db->f('product_price');
				  $childsProduit= $ps_product->get_child_product_ids($product_id);
				  $count = count($childsProduit);
				  $listChildsStr="";
				  for ($i = 0; $i < $count; $i++) {
						$listChildsStr=$listChildsStr." ".$childsProduit[$i];
				  }
				  
				  $Produit = new Produit($db->f("product_name"), $price, $discount_info["amount"], $discount_info["is_percent"], $db->f("product_s_desc"), $db->f("product_desc"), $db->f("product_thumb_image"), $db->f("product_full_image") ,$db->f('product_id'), $db->f("product_in_stock"),$db->f("product_parent_id"),$has_childs,$db->f("attribute_name"),$db->f("attribute_value"),$listChildsStr, $db->f('product_sku'), $db->f("sales"),$db->f('product_publish'),
											$db->f("product_weight"), $db->f("product_weight_uom"), $db->f("product_length"), $db->f("product_width"), $db->f("product_height"), $db->f("product_lwh_uom"), $db->f("product_unit"), $db->f("product_packaging"), $db->f("product_url"), $db->f("custom_attribute"), $db->f("product_available_date"), $db->f("product_availability"), $db->f("product_special"), $db->f("child_options"), $db->f("quantity_options"), $db->f("product_discount_id"), $db->f("product_tax_id"), $db->f("child_option_ids"), $db->f("product_order_levels"), getCategoriesIds($product_id),$db->f("product_currency"),$db->f("manufacturer_id"),$db->f("vendor_id"));
				  $ProduitArray[] = $Produit;
				  
				  //get childs products
				  if ($with_childs == "Y"){
						$params->product_id = $product_id;
						$arrProd = GetChildsProduct($params);
						if (is_array($arrProd)){
							$count = count($arrProd);
							for ($i = 0; $i < $count; $i++) {
								$ProduitArray[] = $arrProd[$i];
							}
						}
				  }
				 
				  
			}

		  return $ProduitArray;
		
		}else if ($result == "false"){
			return new SoapFault("JoomlaServerAuthFault", "Autification KO for : ".$params->loginInfo->login);
		}else if ($result == "no_admin"){
			return new SoapFault("JoomlaServerAuthFault", "User is not a Super Administrator : ".$params->loginInfo->login);
		}else{
			return new SoapFault("JoomlaServerAuthFault", "User does not exist : ".$params->loginInfo->login);
		}		
	}
	
	
	
	/**
    * This function Get RelatedProducts
	* (expose as WS)
    * @param string The if of the product
    * @return array of attribute and value
   */
	function GetRelatedProducts($params) {
	
		include('../vm_soa_conf.php');
		
		$categorie_id = $params->catgory_id;
		/* Authenticate*/
		$result = onAdminAuthenticate($params->loginInfo->login, $params->loginInfo->password);
		if ($conf['auth_prod_getfromcat']=="off"){
			$result = "true";
		}
		
		//Auth OK
		if ($result == "true"){
	
						
			$list  = "SELECT * FROM #__{vm}_product_relations WHERE product_id = '$params->product_id' ";
			$list .= " LIMIT 0,100 "; 

			$db = new ps_DB;
			$db->query($list);


			 while ($db->next_record()) {

				$prod_ids = explode('|', $db->f("related_products") );
				
				if (is_array($prod_ids)){
					
					$count = count($prod_ids);
					for ($i = 0; $i < $count; $i++) {
						$prod_id = $prod_ids[$i];
						$params->product_id=$prod_id;
						$Produit = GetProductFromId($params);
						$ProduitArray[] = $Produit;
					}
				} else {
					$prod_id = $prod_ids;
					$params->product_id=$prod_id;
					$Produit = GetProductFromId($params);
					$ProduitArray[] = $Produit;
				}
			}

		  return $ProduitArray;
		
		}else if ($result == "false"){
			return new SoapFault("JoomlaServerAuthFault", "Autification KO for : ".$params->loginInfo->login);
		}else if ($result == "no_admin"){
			return new SoapFault("JoomlaServerAuthFault", "User is not a Super Administrator : ".$params->loginInfo->login);
		}else{
			return new SoapFault("JoomlaServerAuthFault", "User does not exist : ".$params->loginInfo->login);
		}		
	}
		
	/**
    * This function Set RelatedProducts
	* (expose as WS)
    * @param string The if of the product
    * @return array of attribute and value
   */
	function SetRelatedProducts($params) {
	
		include('../vm_soa_conf.php');
		
		$categorie_id = $params->catgory_id;
		/* Authenticate*/
		$result = onAdminAuthenticate($params->loginInfo->login, $params->loginInfo->password);
		if ($conf['auth_prod_getfromcat']=="off"){
			$result = "true";
		}
		
		//Auth OK
		if ($result == "true"){
	
			$list  = "SELECT * FROM #__{vm}_product_relations WHERE product_id = '$params->product_id' ";
			$list .= " LIMIT 0,100 "; 

			$db = new ps_DB;
			$db->query($list);

			$update=false;
			while ($db->next_record()) {
				$update=true;
			}
			
			if ($update==true) {
				$type='UPDATE';
				$db = new ps_DB;
				$values['related_products']=$params->related_product_ids; // format id|id2|id3 ...
				$whereClause = " WHERE product_id =".$params->product_id."";
				$db->buildQuery($type,"#__{vm}_product_relations",$values,$whereClause);
				$result = $db->query();
			} else {
				
				$type='INSERT';
				$db = new ps_DB;
				$values['related_products']=$params->related_product_ids; // format id|id2|id3 ...
				$values['product_id'] = $params->product_id;
				$db->buildQuery($type,"#__{vm}_product_relations",$values);
				$result = $db->query();
			
			}
						
			
			
			$errMsg=  $db->getErrorMsg();
			if ($errMsg==null){
				return "SetRelatedProducts successfull for product id  ".$params->product_id;
			} else {
				return new SoapFault("SetRelatedProductsError", "DB message : \n".$errMsg);
			}

		 
		}else if ($result == "false"){
			return new SoapFault("JoomlaServerAuthFault", "Autification KO for : ".$params->loginInfo->login);
		}else if ($result == "no_admin"){
			return new SoapFault("JoomlaServerAuthFault", "User is not a Super Administrator : ".$params->loginInfo->login);
		}else{
			return new SoapFault("JoomlaServerAuthFault", "User does not exist : ".$params->loginInfo->login);
		}		
	}
	
	/**
    * This function Search Products from params 
	* (expose as WS)
    * @param 
    * @return array of products
   */
	function SearchProducts($params) {
	
		include('../vm_soa_conf.php');
		
		
		/* Authenticate*/
		$result = onAdminAuthenticate($params->loginInfo->login, $params->loginInfo->password);
		if ($conf['auth_prod_getfromcat']=="off"){
			$result = "true";
		}
		
		//Auth OK
		if ($result == "true"){
	
			$ps_product = new ps_product;
			$ps_product_attribute = new ps_product_attribute;
			
			$limite_start = $params->limite_start;
			if (empty($limite_start)){
				$limite_start = "0";
			}
			$limite_end = $params->limite_end;
			if (empty($limite_end)){
				$limite_end = "500";
			}
			
			$operator = "AND";
			if (!empty($params->operator) && ($params->operator == "OR" || $params->operator == "or")  ){
				$operator = "OR";
			}
			$operator_more_less_equal = "=";
			if (!empty($params->operator_more_less_equal) && $params->operator_more_less_equal == "more" ){
				$operator_more_less_equal=">";
			} else if (!empty($params->operator_more_less_equal) && $params->operator_more_less_equal == "less" ){
				$operator_more_less_equal="<";
			} else if (!empty($params->operator_more_less_equal) && $params->operator_more_less_equal == "equal" ){
				$operator_more_less_equal="=";
			}else if (!empty($params->operator_more_less_equal) && $params->operator_more_less_equal == "moreequal" ){
				$operator_more_less_equal=">=";
			}else if (!empty($params->operator_more_less_equal) && $params->operator_more_less_equal == "lessequal" ){
				$operator_more_less_equal="<=";
			}
			
			
			//categories IDS
			if(!empty($params->product_categories)){
				$cat_ids = explode('|', $params->product_categories);
				$cat_ids_in_sql=""; // make sql request like : in (2,5,8,10)
				if (is_array($cat_ids)){
					$cat_ids_in_sql .="(";
					$count = count($cat_ids);
					for ($i = 0; $i < $count; $i++) {
						if ($i==$count-1){
							$cat_ids_in_sql.= " ".$cat_ids[$i]." )";
						}else {
							$cat_ids_in_sql.= " ".$cat_ids[$i].",";
						}
					}
				}else {
					$cat_ids_in_sql .= "(".$cat_ids.")";
				}
			}
			
			$categorie_id = $cat_ids[0];
			
			
			if ($params->product_publish == "N"){
				$product_publish = "N";
			}else if ($params->product_publish == "Y"){
				$product_publish = "Y";
			}else {
				$product_publish="";
			}
			
			
			$with_childs = $params->with_childs;
			if ($with_childs == "N"){
				$with_childs = "N";
			}else {
				$with_childs = "Y";
			}
			
			/*$list  = "SELECT p.product_id, p.product_sales as sales, p.product_parent_id, p.product_name, p.product_thumb_image, p.product_full_image , p.product_s_desc, p.product_desc, c.category_id, c.category_flypage, p.product_in_stock, pr.product_price, pr.product_currency , p.product_sku, p.product_publish, p.product_weight, p.product_weight_uom, p.product_length,p.product_width, p.product_height, p.product_lwh_uom, p.product_unit, p.product_packaging, p.product_url, p.custom_attribute, p.product_available_date, p.product_availability, p.product_special, p.child_options, p.quantity_options, p.product_discount_id, p.product_tax_id, p.child_option_ids, p.product_order_levels, p.vendor_id, mf.manufacturer_id ";
			$list .= "FROM   #__{vm}_category c, #__{vm}_product_mf_xref mf, #__{vm}_product_category_xref pc , #__{vm}_product p ";
			$q  = "LEFT OUTER JOIN  #__{vm}_product_price pr ON pr.product_id = p.product_id  ";
			//$q .= "LEFT OUTER JOIN  #__{vm}_product_category_xref pc ON pr.product_id = p.product_id  ";
			
			if (!empty($product_publish)){
				$q .= "WHERE p.product_publish='$product_publish' AND ";
			} else{
				$q .= "WHERE ";
			}
			if ($with_childs == "N"){
				$q .= "p.product_parent_id = '0' AND ";
			}else{
				
			}
			//$q .= "pc.category_id='$categorie_id' AND ";
			$q .= "pc.product_id = p.product_id AND ";
			$q .= "p.product_id = mf.product_id AND ";
			$q .= "pc.category_id = c.category_id  ";*/
			
			$list  = "SELECT p.product_id, p.product_sales as sales, p.product_parent_id, p.product_name, p.product_thumb_image, p.product_full_image , p.product_s_desc, p.product_desc, c.category_id, c.category_flypage, p.product_in_stock, pr.product_price, pr.product_currency , p.product_sku, p.product_publish, p.product_weight, p.product_weight_uom, p.product_length,p.product_width, p.product_height, p.product_lwh_uom, p.product_unit, p.product_packaging, p.product_url, p.custom_attribute, p.product_available_date, p.product_availability, p.product_special, p.child_options, p.quantity_options, p.product_discount_id, p.product_tax_id, p.child_option_ids, p.product_order_levels, p.vendor_id, mf.manufacturer_id  ";
			$list .= "FROM #__{vm}_product p ";
			$list .= "left join #__{vm}_product_category_xref pc on pc.product_id = p.product_id ";
			$list .= "left join #__{vm}_category c on pc.category_id = c.category_id ";
			$list .= "left join  #__{vm}_product_mf_xref mf on mf.product_id = p.product_id ";
			//$list .= "FROM #__{vm}_product_category_xref pc, #__{vm}_category c, #__{vm}_product_mf_xref mf, #__{vm}_product p  ";
			$q = "LEFT OUTER JOIN  #__{vm}_product_price pr ON pr.product_id = p.product_id ";
			if (!empty($product_publish)){
				$q .= "WHERE p.product_publish='$product_publish' AND ";
			} else{
				$q .= "WHERE ";
			}
			if ($with_childs == "N"){
				$q .= "p.product_id = mf.product_id AND ";
				$q .= "p.product_parent_id = '0' ";
			}else{
				$q .= "p.product_id = mf.product_id ";
				
			}
			
			if ($operator == "OR"){
				$q .= "AND ( 0 ";
			}else {
				$q .= "AND ( 1 ";
			}
			
			if(!empty($params->product_categories)){
				$q .=$operator." c.category_id in ".$cat_ids_in_sql ." " ; // p.category_id in (10,12,2,0,33)
			}
			if(!empty($params->product_id)){
				$q .=$operator." p.product_id = '$params->product_id' " ;
			}
			if(!empty($params->product_sku)){
				$q .=$operator." p.product_sku = '$params->product_sku' " ;
			}
			if(!empty($params->product_name)){
				$q .=$operator." p.product_name like '%$params->product_name%' " ;
			}
			if(!empty($params->product_desc)){
				$q .=$operator." p.product_desc like '%$params->product_desc%' " ;
			}
			if(!empty($params->product_sdesc)){
				$q .=$operator." p.product_sdesc like '%$params->product_sdesc%' " ;
			}
			if(!empty($params->product_sales)){
				$q .=$operator." p.product_sales $operator_more_less_equal '$params->product_sales' " ;
			}
			if(!empty($params->price)){
				$q .=$operator." pr.product_price $operator_more_less_equal '$params->price' " ;
			}
			if(!empty($params->quantity)){
				$q .=$operator." p.product_in_stock $operator_more_less_equal '$params->quantity' " ;
			}
			if(!empty($params->product_currency)){
				$q .=$operator." pr.product_currency = '$params->product_currency' " ;
			}
			if(!empty($params->manufacturer_id)){
				$q .=$operator." mf.manufacturer_id = '$params->manufacturer_id' " ;
			}
			if(!empty($params->vendor_id)){
				$q .=$operator." p.vendor_id = '$params->vendor_id' " ;
			}
			if(!empty($params->product_weight)){
				$q .=$operator." p.product_weight $operator_more_less_equal '$params->product_weight' " ;
			}
			if(!empty($params->product_weight_uom)){
				$q .=$operator." p.product_weight_uom $operator_more_less_equal '$params->product_weight_uom' " ;
			}
			if(!empty($params->product_width)){
				$q .=$operator." p.product_width $operator_more_less_equal '$params->product_width' " ;
			}
			if(!empty($params->product_height)){
				$q .=$operator." p.product_height $operator_more_less_equal '$params->product_height' " ;
			}
			if(!empty($params->product_length)){
				$q .=$operator." p.product_length $operator_more_less_equal '$params->product_length' " ;
			}
			if(!empty($params->product_lwh_uom)){
				$q .=$operator." p.product_lwh_uom $operator_more_less_equal '$params->product_lwh_uom' " ;
			}
			if(!empty($params->product_unit)){
				$q .=$operator." p.product_unit = '$params->product_unit' " ;
			}
			if(!empty($params->product_packaging)){
				$q .=$operator." p.product_packaging = '$params->product_packaging' " ;
			}
			if(!empty($params->product_url)){
				$q .=$operator." p.product_url like  '%$params->product_url%' " ;
			}
			if(!empty($params->product_special)){
				$q .=$operator." p.product_special =  '$params->product_special' " ;
			}
			if(!empty($params->parent_produit_id)){
				$q .=$operator." p.product_parent_id =  '$params->parent_produit_id' " ;
			}
			
			$q .= " ) ";
			
			$q .= "GROUP BY p.product_id ";
			$q .= "ORDER BY p.product_id ASC ";
			$list .= $q . " LIMIT $limite_start,$limite_end "; 

			$db = new ps_DB;
			$db->query($list);

			/*$Produit = new Produit($list, null, null, null, null, null, null, null ,null, null,null,null,null,null,null, null, null,null,
											null, null,null,null,null, null, null, null, null, null,null, null,null,null, null, null, null, null,null, null,null,null,null);
			$ProduitArray[] = $Produit;
			return $ProduitArray;	 */ 
			//return new SoapFault("JoomlaServerAuthFault", "test SQL \n".$list);
			$idxtest=0;
			  while ($db->next_record()) {
				$idxtest++;
				 // $Produit2 = new Produit("Tshirt rouge","210.0","Tshirt rouge en bamboo","http://localhost/SOAP/img/Pant_homme_thumbnail.jpg","http://localhost/SOAP/img/pant_homme_full.jpg","4");
				  $product_id= $db->f('product_id');
				  $has_childs= ps_product::parent_has_children($product_id);
				  if ($has_childs==null)$has_childs=0;
				  
				  $discount_info = $ps_product->get_discount($product_id);
				  $discount_info["amount"];
				  $discount_info["is_percent"];
				  
				  $price = $db->f('product_price');
				  $childsProduit= $ps_product->get_child_product_ids($product_id);
				  $count = count($childsProduit);
				  $listChildsStr="";
				  for ($i = 0; $i < $count; $i++) {
						$listChildsStr=$listChildsStr." ".$childsProduit[$i];
				  }
				  
				  $Produit = new Produit($db->f("product_name"), $price, $discount_info["amount"], $discount_info["is_percent"], $db->f("product_s_desc"), $db->f("product_desc"), $db->f("product_thumb_image"), $db->f("product_full_image") ,$db->f('product_id'), $db->f("product_in_stock"),$db->f("product_parent_id"),$has_childs,$db->f("attribute_name"),$db->f("attribute_value"),$listChildsStr, $db->f('product_sku'), $db->f("sales"),$db->f('product_publish'),
											$db->f("product_weight"), $db->f("product_weight_uom"), $db->f("product_length"), $db->f("product_width"), $db->f("product_height"), $db->f("product_lwh_uom"), $db->f("product_unit"), $db->f("product_packaging"), $db->f("product_url"), $db->f("custom_attribute"), $db->f("product_available_date"), $db->f("product_availability"), $db->f("product_special"), $db->f("child_options"), $db->f("quantity_options"), $db->f("product_discount_id"), $db->f("product_tax_id"), $db->f("child_option_ids"), $db->f("product_order_levels"), getCategoriesIds($product_id),$db->f("product_currency"),$db->f("manufacturer_id"),$db->f("vendor_id"));
				  $ProduitArray[] = $Produit;
				  
				  //get childs products
				 /* if ($with_childs == "Y"){
						$params->product_id = $product_id;
						$arrProd = GetChildsProduct($params);
						if (is_array($arrProd)){
							$count = count($arrProd);
							for ($i = 0; $i < $count; $i++) {
								$ProduitArray[] = $arrProd[$i];
							}
						}
				  }*/
				 
				  
			}
			//return new SoapFault("JoomlaServerAuthFault", "test SQL $idxtest \n".$list);
			
			$errMsg=  $db->getErrorMsg();
			if ($errMsg==null){
				return $ProduitArray;
			} else {
				return new SoapFault("SQLError", "DB message : \n".$errMsg);
			}
			
		
		}else if ($result == "false"){
			return new SoapFault("JoomlaServerAuthFault", "Autification KO for : ".$params->loginInfo->login);
		}else if ($result == "no_admin"){
			return new SoapFault("JoomlaServerAuthFault", "User is not a Super Administrator : ".$params->loginInfo->login);
		}else{
			return new SoapFault("JoomlaServerAuthFault", "User does not exist : ".$params->loginInfo->login);
		}		
	}
	
	
	
	/**
    * This function set var for childs option 
	* (expose as WS)
    * @param string The if of the product
    * @return array of attribute and value
   */
	 function set_child_options( $str, &$d ) {
	 
		$opts = explode(',', $str);
			
			if (is_array($opts)){
				$_REQUEST['display_use_parent'] = $opts[0];
				
				$product_list = $opts[1];
				
				if ($product_list == "Y"){
					$d['list_style']="one";
					$_REQUEST['product_list'] = "Y";
					$d['product_list']  = "Y";
				} else if ($product_list == "YM") {
					$_REQUEST['product_list'] = "Y";
					$d['product_list']  = "Y";
				} else {
					$_REQUEST['product_list'] = "N";
					$d['product_list']  = "N";
				}
				
				/*$_REQUEST['product_list'] = $opts[1];
				$d['product_list']  = $opts[1];*/
				
				
				$_REQUEST['display_headers'] = $opts[2];
				$_REQUEST['product_list_child'] = $opts[3];
				$_REQUEST['product_list_type'] = $opts[4];
				$_REQUEST['display_desc'] = $opts[5];
				$_REQUEST['desc_width'] = $opts[6];
				$_REQUEST['attrib_width'] = $opts[7];
				$_REQUEST['child_class_sfx'] = $opts[8];
			}
    }
	/**
    * This function set var for quantity option 
	* (expose as WS)
    * @param string The if of the product
    * @return array of attribute and value
   */
	 function set_quantity_options(  $str , &$d) {
	 
			$opts = explode(',', $str);
			
			if (is_array($opts)){
				$d['quantity_box']  = $opts[0];
				$_REQUEST['quantity_box'] = $opts[0];
				$_REQUEST['quantity_start'] = $opts[1];
				$_REQUEST['quantity_end'] = $opts[2];
				$_REQUEST['quantity_step'] = $opts[3];
			
			}
    	
    }
	
	
	/**
    * This function update a product
	* (expose as WS)
    * @param string The if of the product
    * @return array of attribute and value
   */
   //TODO
	function UpdateProduct($params) {
	
		include('../vm_soa_conf.php');
		
		$product = $params->product;
		/* Authenticate*/
		$result = onAdminAuthenticate($params->loginInfo->login, $params->loginInfo->password);
		if ($conf['auth_prod_updateprod']=="off"){
			$result = "true";
		}
		//Auth OK
		if ($result == "true"){
			
			//before update, change image file name (because update will delete image) //so when update, image must be URL image 
			/*$type='UPDATE';
			$db = new ps_DB;
			$values['product_thumb_image']="temp";
			$values['product_full_image']="temp";
			$whereClause = " WHERE product_id =".$product->id."";
			$db->buildQuery($type,"#__{vm}_product",$values,$whereClause);
			$result = $db->query();*/
			
			//get original img file name
			$list  = "SELECT product_thumb_image, product_full_image FROM #__{vm}_product WHERE product_id =".$product->id."";
			$db = new ps_DB;
			$db->query($list);
			while ($db->next_record()) {
				$original_product_full_image = $db->f("product_full_image");
				$original_product_thumb_image = $db->f("product_thumb_image");
			}
				
			$ps_product = new ps_product;
			$ps_product_attribute = new ps_product_attribute;
		
			$_SESSION["ps_vendor_id"] =  $product->vendor_id ;
		
			//product_categories
			$_REQUEST['manufacturer_id']= $product->manufacturer_id;
			$_REQUEST['product_parent_id']= $product->parent_produit_id;
			$_REQUEST['product_desc']= $product->bigdescription;
			$_REQUEST['product_s_desc']= $product->description;
			$_REQUEST['product_in_stock']= $product->quantity;
			$_REQUEST['product_weight']= $product->product_weight;
			$_REQUEST['product_weight_uom']= $product->product_weight_uom;
			$_REQUEST['product_length']= $product->product_length;
			$_REQUEST['product_width']= $product->product_width;
			$_REQUEST['product_height']= $product->product_height;
			$_REQUEST['product_lwh_uom']= $product->product_lwh_uom;
			$_REQUEST['product_price']= $product->price;
			$_REQUEST['product_currency']= $product->product_currency;
			$_REQUEST['product_discount_id']= $product->product_discount_id;
			$_REQUEST['product_tax_id']= $product->product_tax_id;	
			$_REQUEST['product_publish']= $product->product_publish;	
			if (empty($product->shopper_group_id)){
				$_REQUEST['shopper_group_id']= "5";	
			}else {
				$_REQUEST['shopper_group_id']= $product->shopper_group_id;;	
			}
			
			
						
			//static values will be add in wsdl in next version 
			$prod = array ( 'vendor_id' => $product->vendor_id,
					'manufacturer_id' => $product->manufacturer_id,
					'product_price_incl_tax' => $product->price,
					'category_ids' => $product->product_categories,
					'product_id' => $product->id,
					'product_categories' , $product->product_categories,
					'product_parent_id' => $product->parent_produit_id,
					'product_sku' => $product->product_sku,
					'product_name' => $product->name,
					'product_desc' => $product->bigdescription,
					'product_s_desc' => $product->bigdescription,
					'product_thumb_image' => $product->image,
					'product_full_image' => $product->fullimage,
					'product_publish' =>  $product->product_publish,
					'product_weight' => $product->product_weight,
					'product_weight_uom' => $product->product_weight_uom,
					'product_length' => $product->product_length,
					'product_width' => $product->product_width,
					'product_height' => $product->product_height,
					'product_lwh_uom' => $product->product_lwh_uom,
					'product_unit' => $product->product_unit,
					'product_packaging' => $product->product_packaging,
					'product_url' => $product->product_url,
					'product_in_stock' => $product->quantity,
					'attribute' => $product->atribute,
					'product_custom_attribute' => $product->custom_attribute,
					'product_available_date' => /*$product->product_available_date*/"-3600",
					'product_availability' => $product->product_availability,
					'product_special' => $product->product_special,
					'child_options' => $product->child_options,
					'quantity_options' => $product->quantity_options,
					'product_discount_id' => $product->product_discount_id,
					'cdate' => $timestamp,
					'mdate' => $timestamp,
					'product_tax_id' => $product->product_tax_id,
					'child_option_ids' => $product->child_option_ids,
					'product_order_levels' => $product->product_order_levels,
					'product_price' => 	$product->price,
					'product_currency'	=> 	$product->product_currency	,
					'product_thumb_image_url' => $product->image,
					'product_full_image_url' =>  $product->fullimage);
				
			$prod['included_product_id'] = $product->child_option_ids;	
			$prod['order_levels'] = $product->product_order_levels;	
			set_child_options($product->child_options, $prod);
			set_quantity_options($product->quantity_options, $prod);
					
			$canUpdateFullImageFleds = false;
			$canUpdateThumbImageFleds = false;
			$imgMsgerr="";
			
			//// FULL IMG ////
			if (!empty( $product->fullimage )) {
			
				if (substr( $product->fullimage, 0, 4) != "http") {
					
					$prod['product_full_image'] = "";
					$prod['product_full_image_url'] = "";
					$product_full_image = $product->fullimage;
					$canUpdateFullImageFleds = true;
					$imgMsgerr="<fullimage> and <image> must be URL or empty";
				}else {
					$prod['product_full_image']= $product->fullimage;
					$prod['product_full_image_url']= $product->fullimage;
					$product_full_image = $product->fullimage;
					$canUpdateFullImageFleds = true;
					//protect delete
					$type='UPDATE';
					$db = new ps_DB;
					$values['product_full_image']="temp";
					$whereClause = " WHERE product_id =".$product->id."";
					$db->buildQuery($type,"#__{vm}_product",$values,$whereClause);
					$result = $db->query();
				}
			} else {
				//if empty copy value// change name befor update to prevent deleting image// and copy after update
				
				$product_full_image = $original_product_full_image;
				
				//after getting values change it to prevent delete
				$type='UPDATE';
				$db = new ps_DB;
				$values['product_full_image']="temp";
				$whereClause = " WHERE product_id =".$product->id."";
				$db->buildQuery($type,"#__{vm}_product",$values,$whereClause);
				$result = $db->query();
			}
			
			//// THUMB IMG ////
			if (!empty( $product->image )) {
			
				if (substr( $product->image, 0, 4) != "http") {
					
					$prod['product_thumb_image'] = "";
					$prod['product_thumb_image_url'] = "";
					$product_thumb_image = $product->image;
					$canUpdateThumbImageFleds = true;
					$imgMsgerr="<fullimage> and <image> must be URL or empty";
				}else {
					$prod['product_thumb_image_url']= $product->image;
					$prod['product_thumb_image']= $product->image;
					$product_thumb_image = $product->image;
					$canUpdateThumbImageFleds = true;
					//protect delete
					$type='UPDATE';
					$db = new ps_DB;
					$values['product_thumb_image']="temp";
					$whereClause = " WHERE product_id =".$product->id."";
					$db->buildQuery($type,"#__{vm}_product",$values,$whereClause);
					$result = $db->query();
				}
			} else {
				//if empty copy value// change name befor update to prevent deleting image// and copy after update
				
				$product_thumb_image = $original_product_thumb_image;
				
				//after getting values change it to prevent delete
				$type='UPDATE';
				$db = new ps_DB;
				$values['product_thumb_image']="temp";
				$whereClause = " WHERE product_id =".$product->id."";
				$db->buildQuery($type,"#__{vm}_product",$values,$whereClause);
				$result = $db->query();
			}
			
			//VM update product 
			$ret = $ps_product->update($prod);
			
			//update full image
			if ( (empty( $product->fullimage ) || $canUpdateFullImageFleds ) && $ret) {
				$type='UPDATE';
				$db = new ps_DB;
				$values['product_full_image']=$product_full_image;
				$whereClause = " WHERE product_id =".$product->id."";
				$db->buildQuery($type,"#__{vm}_product",$values,$whereClause);
				$result = $db->query();
			}else{
				//update to original
				/*$type='UPDATE';
				$db = new ps_DB;
				$values['product_full_image']=$original_product_full_image;
				$whereClause = " WHERE product_id =".$product->id."";
				$db->buildQuery($type,"#__{vm}_product",$values,$whereClause);
				$result = $db->query();*/
			}
			//update image
			if ( (empty( $product->image ) || $canUpdateThumbImageFleds ) && $ret ) {
				$type='UPDATE';
				$db = new ps_DB;
				$values['product_thumb_image']=$product_thumb_image;
				$whereClause = " WHERE product_id =".$product->id."";
				$db->buildQuery($type,"#__{vm}_product",$values,$whereClause);
				$result = $db->query();
			} else {
				//update to original
				/*$type='UPDATE';
				$db = new ps_DB;
				$values['product_thumb_image']=$original_product_thumb_image;
				$whereClause = " WHERE product_id =".$product->id."";
				$db->buildQuery($type,"#__{vm}_product",$values,$whereClause);
				$result = $db->query();*/
			}
			
			 if ($product->product_publish == "N"){
				$prod['task']="unpublish";
				$ps_product->product_publish($prod);
			 } else {
				$prod['task']="publish";
				$ps_product->product_publish($prod);
			 }
			
			
			if ($ret == true){
			
				return "Product sucessfully updated ".$product->name;
				
			}else {		
				//update to original img file name			
				$type='UPDATE';
				$db = new ps_DB;
				$values['product_thumb_image']=$original_product_thumb_image;
				$values['product_full_image']=$original_product_full_image;
				$whereClause = " WHERE product_id =".$product->id."";
				$db->buildQuery($type,"#__{vm}_product",$values,$whereClause);
				$result = $db->query();
				return new SoapFault("VMUpdateProductFault", "Cannot Update product : ".$product->name."\n".$imgMsgerr);			
			}

			
		}else if ($result == "false"){
			return new SoapFault("JoomlaServerAuthFault", "Autification KO for : ".$params->loginInfo->login);
		}else if ($result == "no_admin"){
			return new SoapFault("JoomlaServerAuthFault", "User is not a Super Administrator : ".$params->loginInfo->login);
		}else{
			return new SoapFault("JoomlaServerAuthFault", "User does not exist : ".$params->loginInfo->login);
		}
	}

	/**
    * This function update a product
	* (expose as WS)
    * @param string The if of the product
    * @return array of attribute and value
   */
	function AddProduct($params) {
	
		include('../vm_soa_conf.php');
		
		$product = $params->product;
		/* Authenticate*/
		$result = onAdminAuthenticate($params->loginInfo->login, $params->loginInfo->password);
		if ($conf['auth_prod_addprod']=="off"){
			$result = "true";
		}
		
		//Auth OK
		if ($result == "true"){
		
			$ps_product = new ps_product;
			$ps_product_attribute = new ps_product_attribute;
			
			$updateFullImageName = false;
			$updateImageName = false;
			$imageName="";
			$fullImageName="";
			if (!empty( $params->product->fullimage )) {
			
				if (substr( $params->product->fullimage, 0, 4) != "http") {
				$updateFullImageName = true;
				$fullImageName=$params->product->fullimage;
				$params->product->fullimage="";
				}
			}
			if (!empty( $params->product->image )) {
			
				if (substr( $params->product->image, 0, 4) != "http") {
				$updateImageName = true;
				$imageName=$params->product->image;
				$params->product->image="";
				}
			}
		
			$_SESSION["ps_vendor_id"] = $product->vendor_id;
			
			$_REQUEST['manufacturer_id']= $product->manufacturer_id;
			$_REQUEST['product_parent_id']= $product->parent_produit_id;
			$_REQUEST['product_desc']= $product->bigdescription;
			$_REQUEST['product_s_desc']= $product->description;
			$_REQUEST['product_in_stock']= $product->quantity;
			$_REQUEST['product_weight']= $product->product_weight;
			$_REQUEST['product_weight_uom']= $product->product_weight_uom;
			$_REQUEST['product_length']= $product->product_length;
			$_REQUEST['product_width']= $product->product_width;
			$_REQUEST['product_height']= $product->product_height;
			$_REQUEST['product_lwh_uom']= $product->product_lwh_uom;
			$_REQUEST['product_price']= $product->price;
			$_REQUEST['product_currency']= $product->product_currency;
			$_REQUEST['product_discount_id']= $product->product_discount_id;
			$_REQUEST['product_tax_id']= $product->product_tax_id;	
			$_REQUEST['product_publish']= $product->product_publish;
			if (empty($product->shopper_group_id)){
				$_REQUEST['shopper_group_id']= "5";	
			}else {
				$_REQUEST['shopper_group_id']= $product->shopper_group_id;;	
			}
			
			
			//static values will be add in wsdl in next version 
			$prod = array ( 'vendor_id' => $product->vendor_id,
					'manufacturer_id' => $product->manufacturer_id,
					'product_price_incl_tax' => $product->price,
					'product_parent_id' => $product->parent_produit_id,
					'category_ids' => $product->product_categories,
					'product_sku' => $product->product_sku,
					'product_name' => $product->name,
					'product_desc' => $product->bigdescription,
					'product_s_desc' => $product->bigdescription,
					'product_thumb_image' => $product->image,
					'product_full_image' => $product->fullimage,
					'product_publish' =>  $product->product_publish,
					'product_weight' => $product->product_weight,
					'product_weight_uom' => $product->product_weight_uom,
					'product_length' => $product->product_length,
					'product_width' => $product->product_width,
					'product_height' => $product->product_height,
					'product_lwh_uom' => $product->product_lwh_uom,
					'product_unit' => $product->product_unit,
					'product_packaging' => $product->product_packaging,
					'product_url' => $product->product_url,
					'product_in_stock' => $product->quantity,
					'attribute' => $product->atribute,
					'product_custom_attribute' => $product->custom_attribute,
					'product_available_date' => /*$product->product_available_date*/"-3600",
					'product_availability' => $product->product_availability,
					'product_special' => $product->product_special,
					'child_options' => $product->child_options,
					'quantity_options' => $product->quantity_options,
					'product_discount_id' => $product->product_discount_id,
					'cdate' => $timestamp,
					'mdate' => $timestamp,
					'product_tax_id' => $product->product_tax_id,
					'child_option_ids' => $product->child_option_ids,
					'product_order_levels' => $product->product_order_levels,
					'product_price' => 	$product->price,
					'product_currency'	=> 	$product->product_currency,
					'product_thumb_image_url' => $product->image,
					'product_full_image_url' =>  $product->fullimage);
			
			$prod['order_levels'] = $product->product_order_levels;	
			$prod['included_product_id'] = $product->child_option_ids;	
			set_child_options($product->child_options, $prod);
			set_quantity_options($product->quantity_options, $prod);
					
			$ret = $ps_product->add($prod);
			
			if ($updateFullImageName){
			
				$type='UPDATE';
				$db = new ps_DB;
				$values['product_full_image']=$fullImageName;
				$whereClause = " WHERE product_id =".$_REQUEST['product_id']."";
				$db->buildQuery($type,"#__{vm}_product",$values,$whereClause);
				$result = $db->query();
				
			}
			if ($updateImageName){
			
				$type='UPDATE';
				$db = new ps_DB;
				$values['product_thumb_image']= $imageName;
				$whereClause = " WHERE product_id =".$_REQUEST['product_id']."";
				$db->buildQuery($type,"#__{vm}_product",$values,$whereClause);
				$result = $db->query();
				
			}
			
			if ($ret == true){
			
				return "Product sucessfully added ".$product->name;
				
			}else {			
				return new SoapFault("VMAddProductFault", "Cannot Add product : ".$product->name);			
			}

			
		}else if ($result == "false"){
			return new SoapFault("JoomlaServerAuthFault", "Autification KO for : ".$params->loginInfo->login);
		}else if ($result == "no_admin"){
			return new SoapFault("JoomlaServerAuthFault", "User is not a Super Administrator : ".$params->loginInfo->login);
		}else{
			return new SoapFault("JoomlaServerAuthFault", "User does not exist : ".$params->loginInfo->login);
		}
	}

	/**
    * This function update a product
	* (expose as WS)
    * @param string The if of the product
    * @return array of attribute and value
   */
   //TODO
	function DeleteProduct($params) {
	
		include('../vm_soa_conf.php');
		
		/* Authenticate*/
		$result = onAdminAuthenticate($params->loginInfo->login, $params->loginInfo->password);
		if ($conf['auth_prod_delprod']=="off"){
			$result = "true";
		}
		
		//Auth OK
		if ($result == "true"){
			
			$ps_product = new ps_product;
			$prod['product_id'] = $params->product_id;
			$ret = $ps_product->delete($prod);
			
			if ($ret == true){
				return "Product deleted successfully : ".$params->product_id;
			}else{
				return new SoapFault("VMDeleteProductFault", "Cannot delete product  : ".$params->product_id);
			}
						
		}else if ($result == "false"){
			return new SoapFault("JoomlaServerAuthFault", "Autification KO for : ".$params->loginInfo->login);
		}else if ($result == "no_admin"){
			return new SoapFault("JoomlaServerAuthFault", "User is not a Super Administrator : ".$params->loginInfo->login);
		}else{
			return new SoapFault("JoomlaServerAuthFault", "User does not exist : ".$params->loginInfo->login);
		}
	}
	
	
/**
    * This function get Products for a order ID
	* (expose as WS)
    * @param string 
    * @return array (Product)
   */
	function GetProductsFromOrderId($params) {
	
		include('../vm_soa_conf.php');
		
		$order_id = $params->order_id;
		/* Authenticate*/
		$result = onAdminAuthenticate($params->loginInfo->login, $params->loginInfo->password);
		if ($conf['auth_prod_getfromoderid']=="off"){
			$result = "true";
		}
		//Auth OK
		if ($result == "true"){
					
			$list  = "SELECT * FROM #__{vm}_order_item od WHERE ";
			$list .= "od.order_id = '$order_id'";
			
			$db = new ps_DB;
			$db->query($list);
		
			while ($db->next_record()) {
				  $ProdId = $db->f("product_id");
				  $Quantity = $db->f("product_quantity");
				  //$strTest .= "$ProdId : $Quantity";
				  $OrderItemInfo = new OrderItemInfo($db->f("order_id"), $db->f("vendor_id"), $db->f("product_id"), $db->f("order_item_sku"), $db->f("order_item_name"), $db->f("product_quantity"), $db->f("product_item_price"), $db->f("product_final_price"), $db->f("order_item_currency"), $db->f("order_status"), $db->f("cdate"), $db->f("mdate"), $db->f("product_attribute"));
				  $OrderItemInfoArray[] =  $OrderItemInfo;
			}
			return $OrderItemInfoArray;
			
		}else if ($result == "false"){
			return new SoapFault("JoomlaServerAuthFault", "Autification KO for : ".$params->loginInfo->login);
		}else if ($result == "no_admin"){
			return new SoapFault("JoomlaServerAuthFault", "User is not a Super Administrator : ".$params->loginInfo->login);
		}else{
			return new SoapFault("JoomlaServerAuthFault", "User does not exist : ".$params->loginInfo->login);
		}
	}	
	
	/**
    * This function get All currency
	* (expose as WS)
    * @param string 
    * @return array of currency
   */
	function GetAllCurrency($params) {
	
		include('../vm_soa_conf.php');
		
		$product_id = $params->product_id;
		/* Authenticate*/
		$result = onAdminAuthenticate($params->loginInfo->login, $params->loginInfo->password);
		if ($conf['auth_prod_getcurrency']=="off"){
			$result = "true";
		}
		//Auth OK
		if ($result == "true"){
		
			$list  = "SELECT * FROM #__{vm}_currency WHERE 1";
			
			$db = new ps_DB;
			$db->query($list);
			while ($db->next_record()) {
				$Currency = new Currency($db->f("currency_id"),$db->f("currency_name"),$db->f("currency_code"));
				$CurrencyArray[] = $Currency;
			}

			return $CurrencyArray;
			
		}else if ($result == "false"){
			return new SoapFault("JoomlaServerAuthFault", "Autification KO for : ".$params->loginInfo->login);
		}else if ($result == "no_admin"){
			return new SoapFault("JoomlaServerAuthFault", "User is not a Super Administrator : ".$params->loginInfo->login);
		}else{
			return new SoapFault("JoomlaServerAuthFault", "User does not exist : ".$params->loginInfo->login);
		}
		
	}
	
	
	/**
    * This function get All currency
	* (expose as WS)
    * @param string 
    * @return array of currency
   */
	function GetProductVote($params) {
	
		include('../vm_soa_conf.php');
		
		$product_id = $params->product_id;
		/* Authenticate*/
		$result = onAdminAuthenticate($params->loginInfo->login, $params->loginInfo->password);
		if ($conf['auth_prod_getcurrency']=="off"){
			$result = "true";
		}
		//Auth OK
		if ($result == "true"){
		
			$eq = " = ";
			if (!empty($params->moreless)){
				if ($params->moreless == "more"){
					$eq = " >= ";
				}
				if ($params->moreless == "less"){
					$eq = " <= ";
				}
				if ($params->moreless == "equal"){
					$eq = " = ";
				}
			}
		
			$list  = "SELECT pv.product_id as product_id , product_name, product_sku, votes, allvotes, rating, lastip FROM #__{vm}_product_votes pv join #__{vm}_product p on p.product_id=pv.product_id ";
			$list .= "WHERE 1 ";
			
			if (!empty($params->product_id)){
				$list .= " AND pv.product_id = '$params->product_id' ";
			}
			if (!empty($params->votes)){
				$list .= " AND votes $eq '$params->votes' ";
			}
			if (!empty($params->allvotes)){
				$list .= " AND allvotes $eq '$params->allvotes' ";
			}
			if (!empty($params->rating)){
				$list .= " AND rating $eq '$params->rating' ";
			}
			
			$db = new ps_DB;
			$db->query($list);
			while ($db->next_record()) {
				$ProductVote = new ProductVote($db->f("product_id"),$db->f("product_name"),$db->f("product_sku"),$db->f("votes"),$db->f("allvotes"),$db->f("rating"),$db->f("lastip"));
				$ProductVoteArray[] = $ProductVote;
			}
			
			$errMsg=  $db->getErrorMsg();
			
			if ($errMsg==null){
				return $ProductVoteArray;
			} else {
				return new SoapFault("GetProductVoteFault", "cannot GetProductVote  "." | ERRLOG : ".$errMsg);				
			}
			
		}else if ($result == "false"){
			return new SoapFault("JoomlaServerAuthFault", "Autification KO for : ".$params->loginInfo->login);
		}else if ($result == "no_admin"){
			return new SoapFault("JoomlaServerAuthFault", "User is not a Super Administrator : ".$params->loginInfo->login);
		}else{
			return new SoapFault("JoomlaServerAuthFault", "User does not exist : ".$params->loginInfo->login);
		}
		
	}
	
	
	
	/**
    * This function Get Product Reviews
	* (expose as WS)
    * @param string 
    * @return array of currency
   */
	function GetProductReviews($params) {
	
		include('../vm_soa_conf.php');
		
		$product_id = $params->product_id;
		/* Authenticate*/
		$result = onAdminAuthenticate($params->loginInfo->login, $params->loginInfo->password);
		if ($conf['auth_prod_getcurrency']=="off"){
			$result = "true";
		}
		//Auth OK
		if ($result == "true"){
		
			$eq = " = ";
			if (!empty($params->moreless)){
				if ($params->moreless == "more"){
					$eq = " >= ";
				}
				if ($params->moreless == "less"){
					$eq = " <= ";
				}
				if ($params->moreless == "equal"){
					$eq = " = ";
				}
			}
		
			$list  = "SELECT * FROM #__{vm}_product_reviews ";
			$list .= "WHERE 1 ";
			
			if (!empty($params->review_id)){
				$list .= " AND review_id = '$params->review_id' ";
			}
			if (!empty($params->product_id)){
				$list .= " AND product_id $eq '$params->product_id' ";
			}
			if (!empty($params->userid)){
				$list .= " AND userid $eq '$params->userid' ";
			}
			if (!empty($params->published)){
				$list .= " AND published = '$params->published' ";
			}
			
			$db = new ps_DB;
			$db->query($list);
			while ($db->next_record()) {
				$ProductReview = new ProductReview($db->f("review_id"),$db->f("product_id"),$db->f("comment"),$db->f("userid"),$db->f("time"),$db->f("user_rating"),$db->f("review_ok"),$db->f("review_votes"),$db->f("published"));
				$ProductReviewArray[] = $ProductReview;
			}
			
			$errMsg=  $db->getErrorMsg();
			
			if ($errMsg==null){
				return $ProductReviewArray;
			} else {
				return new SoapFault("GetProductReviewsFault", "cannot GetProductReviews  "." | ERRLOG : ".$errMsg);				
			}
			
		}else if ($result == "false"){
			return new SoapFault("JoomlaServerAuthFault", "Autification KO for : ".$params->loginInfo->login);
		}else if ($result == "no_admin"){
			return new SoapFault("JoomlaServerAuthFault", "User is not a Super Administrator : ".$params->loginInfo->login);
		}else{
			return new SoapFault("JoomlaServerAuthFault", "User does not exist : ".$params->loginInfo->login);
		}
		
	}
	
	/**
    * This function Publish Review
	* (expose as WS)
    * @param string 
    * @return string
   */
	function PublishReviews($params) {
	
		include('../vm_soa_conf.php');
		
		$product_id = $params->product_id;
		/* Authenticate*/
		$result = onAdminAuthenticate($params->loginInfo->login, $params->loginInfo->password);
		if ($conf['auth_prod_addprod']=="off"){
			$result = "true";
		}
		//Auth OK
		if ($result == "true"){
		
			$published = 'N';
			if ($params->published == "Y"){
				$published = 'Y';
			}
			
			$list  = "UPDATE #__{vm}_product_reviews SET published = '$published' ";
			$list .= "WHERE review_id = '$params->review_id' ";
			
			$db = new ps_DB;
			$db->query($list);
			
			$errMsg=  $db->getErrorMsg();
			
			if ($errMsg==null){
				return "Publish/Unpublish ($published) review OK : review id ".$params->review_id;
			} else {
				return new SoapFault("GetProductReviewsFault", "cannot PublishReview  "." | ERRLOG : ".$errMsg);				
			}
			
		}else if ($result == "false"){
			return new SoapFault("JoomlaServerAuthFault", "Autification KO for : ".$params->loginInfo->login);
		}else if ($result == "no_admin"){
			return new SoapFault("JoomlaServerAuthFault", "User is not a Super Administrator : ".$params->loginInfo->login);
		}else{
			return new SoapFault("JoomlaServerAuthFault", "User does not exist : ".$params->loginInfo->login);
		}
		
	}
	
	/**
	*
	**/
	function discountIdExist($discount_id) {
	
		if ($discount_id == 0){
			return true;
		}
		$list  = "SELECT * FROM #__{vm}_product_discount WHERE discount_id = '$discount_id' ";
		$db = new ps_DB;
		$db->query($list);
		$i=0;
		while ($db->next_record()) {
			$i++;
		}
		if ($i ==0){
			return false;
		}
		return true;
	}
	
	function ProductFileIdExist($file_id) {
	
		/*if ($discount_id == 0){
			return true;
		}*/
		$list  = "SELECT * FROM #__{vm}_product_files WHERE file_id = '$file_id' ";
		$db = new ps_DB;
		$db->query($list);
		$i=0;
		while ($db->next_record()) {
			$i++;
		}
		if ($i ==0){
			return false;
		}
		return true;
	}
	
	
	/**
    * This function GetProductFile
	* (expose as WS)
    * @param string 
    * @return result
   */
	function GetProductFile($params) {
	
		include('../vm_soa_conf.php');
		
		/* Authenticate*/
		$result = onAdminAuthenticate($params->loginInfo->login, $params->loginInfo->password);
		if ($conf['auth_prod_gettax']=="off"){
			$result = "true";
		}
		//Auth OK
		if ($result == "true"){
		
			/*if (!empty($params->product_id)){
				$product_id = $params->product_id;
				$list  = "SELECT * FROM #__{vm}_product_file WHERE product_id = '$product_id' ";
				$db = new ps_DB;
				$db->query($list);
				while ($db->next_record()) {
					$params->discount->discount_id = $db->f("product_discount_id");
				}
			}*/
			
			$list  = "SELECT * FROM #__{vm}_product_files WHERE 1";
			
			
			if (!empty($params->file_id)){
				$file_id = $params->file_id;
				$list  .= " AND file_id = '$file_id' ";
			}
			if (!empty($params->file_product_id)){
				$file_product_id = $params->file_product_id;
				$list  .= " AND file_product_id = '$file_product_id' ";
			}
			if (!empty($params->file_name)){
				$file_name = $params->file_name;
				$list  .= " AND file_name like '%$file_name%' ";
			}
			if (!empty($params->file_published)){
				$file_published = $params->file_published;
				$list  .= " AND file_published = '$file_published' ";
			}
			if (!empty($params->file_extension)){
				$file_extension = $params->file_extension;
				$list  .= " AND file_extension = '$file_extension' ";
			}
			if (!empty($params->file_is_image)){
				$file_is_image = $params->file_is_image;
				$list  .= " AND file_is_image = '$file_is_image' ";
			}
			
			
			$db = new ps_DB;
			$db->query($list);
			while ($db->next_record()) {
				$ProductFile = new ProductFile($db->f("file_id"),$db->f("file_product_id"),$db->f("file_name"),$db->f("file_title"),$db->f("file_description"),$db->f("file_extension"),$db->f("file_mimetype"),$db->f("file_url"),$db->f("file_published"),$db->f("file_is_image"),$db->f("file_image_height"),$db->f("file_image_width"),$db->f("file_image_thumb_height"),$db->f("file_image_thumb_width"));
				$ProductFileArray[] = $ProductFile;
			}

			$errMsg=  $db->getErrorMsg();
			
			if ($errMsg==null){
				return $ProductFileArray;
			} else {
				return new SoapFault("GetProductFileFault", "cannot Get ProductFile  "." | ERRLOG : ".$errMsg);				
			}
			//return $ProductPriceArray;
			
		}else if ($result == "false"){
			return new SoapFault("JoomlaServerAuthFault", "Autification KO for : ".$params->loginInfo->login);
		}else if ($result == "no_admin"){
			return new SoapFault("JoomlaServerAuthFault", "User is not a Super Administrator : ".$params->loginInfo->login);
		}else{
			return new SoapFault("JoomlaServerAuthFault", "User does not exist : ".$params->loginInfo->login);
		}
		
	}	
	
	function AddProductFile($params) {
	
		include('../vm_soa_conf.php');
		
		/* Authenticate*/
		$result = onAdminAuthenticate($params->loginInfo->login, $params->loginInfo->password);
		if ($conf['auth_prod_addprod']=="off"){
			$result = "true";
		}
		//Auth OK
		if ($result == "true"){
		
			$allOk=true;
			if (is_array($params->ProductFiles->ProductFile)){
				
					$count = count($params->ProductFiles->ProductFile);
					for ($i = 0; $i < $count; $i++) {
											
						$type='INSERT';
						$whereClause = " WHERE 1 ";
						
						if (!empty($params->ProductFiles->ProductFile[$i]->file_product_id)){
						
							$values['file_product_id']= $params->ProductFiles->ProductFile[$i]->file_product_id;
							$values['file_name']= $params->ProductFiles->ProductFile[$i]->file_name;
							$values['file_title']= $params->ProductFiles->ProductFile[$i]->file_title;
							$values['file_description']= $params->ProductFiles->ProductFile[$i]->file_description;
							$values['file_extension']= $params->ProductFiles->ProductFile[$i]->file_extension;
							$values['file_url']= $params->ProductFiles->ProductFile[$i]->file_url;
							$values['file_published']= $params->ProductFiles->ProductFile[$i]->file_published;
							$values['file_is_image']= $params->ProductFiles->ProductFile[$i]->file_is_image;
							$values['file_image_height']= $params->ProductFiles->ProductFile[$i]->file_image_height;
							$values['file_image_width']= $params->ProductFiles->ProductFile[$i]->file_image_width;
							$values['file_image_thumb_height']= $params->ProductFiles->ProductFile[$i]->file_image_thumb_height;
							$values['file_image_thumb_width']= $params->ProductFiles->ProductFile[$i]->file_image_thumb_width;
							$values['file_mimetype']= $params->ProductFiles->ProductFile[$i]->file_mimetype;
							
							$db = new ps_DB;
							$db->buildQuery($type,'#__{vm}_product_files',$values,$whereClause);
							$result = $db->query();
							$errMsg=  $db->getErrorMsg();
							$id = $db->last_insert_id();
						} else {
							$result = false;
						}

						if ($result){
							$cpnIdsStr .= " ".$id;
						}else{
							$allOk=false;
						}
					}
				} else {
						
					$type='INSERT';
					$whereClause = " WHERE 1 ";
					
					if (empty($params->ProductFiles->ProductFile->file_product_id)){
						return new SoapFault("AddProductFileFault", "file_product_id must be setted");	
					}
					
					$values['file_product_id']= $params->ProductFiles->ProductFile->file_product_id;
					$values['file_name']= $params->ProductFiles->ProductFile->file_name;
					$values['file_title']= $params->ProductFiles->ProductFile->file_title;
					$values['file_description']= $params->ProductFiles->ProductFile->file_description;
					$values['file_extension']= $params->ProductFiles->ProductFile->file_extension;
					$values['file_url']= $params->ProductFiles->ProductFile->file_url;
					$values['file_published']= $params->ProductFiles->ProductFile->file_published;
					$values['file_is_image']= $params->ProductFiles->ProductFile->file_is_image;
					$values['file_image_height']= $params->ProductFiles->ProductFile->file_image_height;
					$values['file_image_width']= $params->ProductFiles->ProductFile->file_image_width;
					$values['file_image_thumb_height']= $params->ProductFiles->ProductFile->file_image_thumb_height;
					$values['file_image_thumb_width']= $params->ProductFiles->ProductFile->file_image_thumb_width;
					$values['file_mimetype']= $params->ProductFiles->ProductFile->file_mimetype;
					
					
					$db = new ps_DB;
					$db->buildQuery($type,'#__{vm}_product_files',$values,$whereClause);
					$result = $db->query();
					$errMsg=  $db->getErrorMsg();
					$id = $db->last_insert_id();
					
					if ($errMsg==null){
						$returnOutput = new returnOutput("0","AddProductFile sucessfull",$id);
						return $returnOutput;
					} else {
						return new SoapFault("AddProductFileFault", "cannot Add ProductFile  "." | ERRLOG : ".$errMsg);	
					}	
					
				}
				if ($allOk){
					$returnOutput = new returnOutput("0","All ProductFile successfully added : ",$cpnIdsStr);
					return $returnOutput;
					
				} else {
					return new SoapFault("AddProductFileFault", "Not all ProductFile added, only ProductFile id : ".$cpnIdsStr);
				}			
		
		
		}else if ($result == "false"){
			return new SoapFault("JoomlaServerAuthFault", "Autification KO for : ".$params->loginInfo->login);
		}else if ($result == "no_admin"){
			return new SoapFault("JoomlaServerAuthFault", "User is not a Super Administrator : ".$params->loginInfo->login);
		}else{
			return new SoapFault("JoomlaServerAuthFault", "User does not exist : ".$params->loginInfo->login);
		}
	
	}
	
	function UpdateProductFile($params) {
	
		include('../vm_soa_conf.php');
		
		/* Authenticate*/
		$result = onAdminAuthenticate($params->loginInfo->login, $params->loginInfo->password);
		if ($conf['auth_prod_updateprod']=="off"){
			$result = "true";
		}
		//Auth OK
		if ($result == "true"){
		
			$allOk=true;
			if (is_array($params->ProductFiles->ProductFile)){
				
					$count = count($params->ProductFiles->ProductFile);
					for ($i = 0; $i < $count; $i++) {
											
						$type='UPDATE';
						$whereClause = "WHERE file_id = ".(int)$params->ProductFiles->ProductFile[$i]->file_id." ";
						
						if (!empty($params->ProductFiles->ProductFile[$i]->file_id)){
						
							if (!empty($params->ProductFiles->ProductFile[$i]->file_product_id))
							$values['file_product_id']= $params->ProductFiles->ProductFile[$i]->file_product_id;
							if (!empty($params->ProductFiles->ProductFile[$i]->file_name))
							$values['file_name']= $params->ProductFiles->ProductFile[$i]->file_name;
							if (!empty($params->ProductFiles->ProductFile[$i]->file_title))
							$values['file_title']= $params->ProductFiles->ProductFile[$i]->file_title;
							if (!empty($params->ProductFiles->ProductFile[$i]->file_description))
							$values['file_description']= $params->ProductFiles->ProductFile[$i]->file_description;
							if (!empty($params->ProductFiles->ProductFile[$i]->file_extension))
							$values['file_extension']= $params->ProductFiles->ProductFile[$i]->file_extension;
							if (!empty($params->ProductFiles->ProductFile[$i]->file_url))
							$values['file_url']= $params->ProductFiles->ProductFile[$i]->file_url;
							if (!empty($params->ProductFiles->ProductFile[$i]->file_published))
							$values['file_published']= $params->ProductFiles->ProductFile[$i]->file_published;
							if (!empty($params->ProductFiles->ProductFile[$i]->file_is_image))
							$values['file_is_image']= $params->ProductFiles->ProductFile[$i]->file_is_image;
							if (!empty($params->ProductFiles->ProductFile[$i]->file_image_height))
							$values['file_image_height']= $params->ProductFiles->ProductFile[$i]->file_image_height;
							if (!empty($params->ProductFiles->ProductFile[$i]->file_image_width))
							$values['file_image_width']= $params->ProductFiles->ProductFile[$i]->file_image_width;
							if (!empty($params->ProductFiles->ProductFile[$i]->file_image_thumb_height))
							$values['file_image_thumb_height']= $params->ProductFiles->ProductFile[$i]->file_image_thumb_height;
							if (!empty($params->ProductFiles->ProductFile[$i]->file_image_thumb_width))
							$values['file_image_thumb_width']= $params->ProductFiles->ProductFile[$i]->file_image_thumb_width;
							if (!empty($params->ProductFiles->ProductFile[$i]->file_mimetype))
							$values['file_mimetype']= $params->ProductFiles->ProductFile[$i]->file_mimetype;
							
							$db = new ps_DB;
							$db->buildQuery($type,'#__{vm}_product_files',$values,$whereClause);
							$result = $db->query();
							$errMsg=  $db->getErrorMsg();
							$id = $db->last_insert_id();
						} else {
							$result = false;
						}

						if ($result){
							$cpnIdsStr .= " ".$id;
						}else{
							$allOk=false;
						}
					}
				} else {
						
					$type='UPDATE';
					$whereClause = "WHERE file_id = ".(int)$params->ProductFiles->ProductFile->file_id." ";
					
					if (empty($params->ProductFiles->ProductFile->file_id)){
						return new SoapFault("UpdateProductFileFault", "file_id must be setted");	
					}
					if (!empty($params->ProductFiles->ProductFile->file_product_id))
					$values['file_product_id']= $params->ProductFiles->ProductFile->file_product_id;
					if (!empty($params->ProductFiles->ProductFile->file_name))
					$values['file_name']= $params->ProductFiles->ProductFile->file_name;
					if (!empty($params->ProductFiles->ProductFile->file_title))
					$values['file_title']= $params->ProductFiles->ProductFile->file_title;
					if (!empty($params->ProductFiles->ProductFile->file_description))
					$values['file_description']= $params->ProductFiles->ProductFile->file_description;
					if (!empty($params->ProductFiles->ProductFile->file_extension))
					$values['file_extension']= $params->ProductFiles->ProductFile->file_extension;
					if (!empty($params->ProductFiles->ProductFile->file_url))
					$values['file_url']= $params->ProductFiles->ProductFile->file_url;
					if (!empty($params->ProductFiles->ProductFile->file_is_image))
					$values['file_is_image']= $params->ProductFiles->ProductFile->file_is_image;
					if (!empty($params->ProductFiles->ProductFile->file_image_height))
					$values['file_image_height']= $params->ProductFiles->ProductFile->file_image_height;
					if (!empty($params->ProductFiles->ProductFile->file_image_width))
					$values['file_image_width']= $params->ProductFiles->ProductFile->file_image_width;
					if (!empty($params->ProductFiles->ProductFile->file_image_thumb_height))
					$values['file_image_thumb_height']= $params->ProductFiles->ProductFile->file_image_thumb_height;
					if (!empty($params->ProductFiles->ProductFile->file_image_thumb_width))
					$values['file_image_thumb_width']= $params->ProductFiles->ProductFile->file_image_thumb_width;
					if (!empty($params->ProductFiles->ProductFile->file_mimetype))
					$values['file_mimetype']= $params->ProductFiles->ProductFile->file_mimetype;
					
					if ($params->ProductFiles->ProductFile->file_published == "0") {
						$values['file_published']= 0;
					} else {
						$values['file_published']= 1;
					}
					
					
					$db = new ps_DB;
					$db->buildQuery($type,'#__{vm}_product_files',$values,$whereClause);
					$result = $db->query();
					$errMsg=  $db->getErrorMsg();
					$id = $db->last_insert_id();
					
					if ($result){
						$returnOutput = new returnOutput("0","UpdateProductFile sucessfull",$id);
						return $returnOutput;
					} else {
						return new SoapFault("UpdateProductFileFault", "cannot Add ProductFile  ".$file_id." | ERRLOG : ".$errMsg);	
					}	
					
				}
				if ($allOk){
					$returnOutput = new returnOutput("0","All ProductFile successfully updated : ",$cpnIdsStr);
					return $returnOutput;
					
				} else {
					return new SoapFault("AddProductFileFault", "Not all ProductFile updated, only ProductFile id : ".$cpnIdsStr);
				}			
		
		}else if ($result == "false"){
			return new SoapFault("JoomlaServerAuthFault", "Autification KO for : ".$params->loginInfo->login);
		}else if ($result == "no_admin"){
			return new SoapFault("JoomlaServerAuthFault", "User is not a Super Administrator : ".$params->loginInfo->login);
		}else{
			return new SoapFault("JoomlaServerAuthFault", "User does not exist : ".$params->loginInfo->login);
		}
	
	}
	
	function DeleteProductFile($params) {
	
		include('../vm_soa_conf.php');
		
		/* Authenticate*/
		$result = onAdminAuthenticate($params->loginInfo->login, $params->loginInfo->password);
		if ($conf['auth_prod_delprod']=="off"){
			$result = "true";
		}
		//Auth OK
		if ($result == "true"){
			$allOk=true;
			if (is_array($params->ids->id)){
				$count = count($params->ids->id);
				for ($i = 0; $i < $count; $i++) {

					$d = array('file_id' => $params->ids->id[$i]
						);
						
					$ps_product_files = new ps_product_files;
					$result = $ps_product_files->delete($d);
					
					if ($result){
						$cpnIdsStr .= $params->ids->id[$i]." ";
					}else{
						$allOk=false;
					}
				}
			} else {
					$d = array('file_id' => $params->ids->id
						);
						
					$ps_product_files = new ps_product_files;
					$result = $ps_product_files->delete($d);
					
				if ($result){
					$returnOutput = new returnOutput("0","ProductFile sucessfully deleted:  ".$d['file_id'],$d['file_id']);
					return $returnOutput;
				}else {
					return new SoapFault("DeleteProductFileFault", "Cannot delete ProductFile  : ".$d['file_id']);
				}
			}
			if ($allOk){
				$returnOutput = new returnOutput("0","ProductFile successfully deleted : ".$cpnIdsStr,$cpnIdsStr);
				return $returnOutput;
			} else {
				return new SoapFault("DeleteProductFileFault", "Not all ProductFile deleted, only ProductFile id : ".$cpnIdsStr);
			}	
		
		}else if ($result == "false"){
			return new SoapFault("JoomlaServerAuthFault", "Autification KO for : ".$params->loginInfo->login);
		}else if ($result == "no_admin"){
			return new SoapFault("JoomlaServerAuthFault", "User is not a Super Administrator : ".$params->loginInfo->login);
		}else{
			return new SoapFault("JoomlaServerAuthFault", "User does not exist : ".$params->loginInfo->login);
		}
	
	}
	
	/**
    * This function GetDiscount
	* (expose as WS)
    * @param string 
    * @return result
   */
	function UpdateProductDiscount($params) {
		include('../vm_soa_conf.php');
		
		/* Authenticate*/
		$result = onAdminAuthenticate($params->loginInfo->login, $params->loginInfo->password);
		if ($conf['auth_prod_updateprod']=="off"){
			$result = "true";
		}
		//Auth OK
		if ($result == "true"){
		
			if (!discountIdExist($params->discount_id)){
				return new SoapFault("UpdateProductDiscountFault", "discount_id does not exist $params->discount_id ");
			}
		
			if (!empty($params->product_id)){
				$product_id = $params->product_id;
				$list  = "UPDATE #__{vm}_product SET product_discount_id = '$params->discount_id' WHERE product_id = '$product_id' ";
				$db = new ps_DB;
				$db->query($list);
				while ($db->next_record()) {
					
				}
				$errMsg=  $db->getErrorMsg();
			
				if ($errMsg==null){
					$returnOutput = new returnOutput("0","UpdateProductDiscount sucessfull","Product id $product_id");
					return $returnOutput;
				}else {
					return new SoapFault("UpdateProductDiscountFault", "UpdateProductDiscount error Product id $product_id");
				}
			}
			
			if (!empty($params->product_sku)){
				$product_sku = $params->product_sku;
				$list  = "UPDATE #__{vm}_product SET product_discount_id = '$params->discount_id' WHERE product_sku = '$product_sku' ";
				$db = new ps_DB;
				$db->query($list);
				while ($db->next_record()) {
					
				}
				$errMsg=  $db->getErrorMsg();
			
				if ($errMsg==null){
					$returnOutput = new returnOutput("0","UpdateProductDiscount sucessfull","SKU ".$params->product_sku);
					return $returnOutput;
				}else {
					return new SoapFault("UpdateProductDiscountFault", "UpdateProductDiscount error ".$params->product_sku);
				}
			}

		}else if ($result == "false"){
			return new SoapFault("JoomlaServerAuthFault", "Autification KO for : ".$params->loginInfo->login);
		}else if ($result == "no_admin"){
			return new SoapFault("JoomlaServerAuthFault", "User is not a Super Administrator : ".$params->loginInfo->login);
		}else{
			return new SoapFault("JoomlaServerAuthFault", "User does not exist : ".$params->loginInfo->login);
		}
		
	}
	
	
	/**
    * This function GetDiscount
	* (expose as WS)
    * @param string 
    * @return result
   */
	function GetDiscount($params) {
	
		include('../vm_soa_conf.php');
		
		/* Authenticate*/
		$result = onAdminAuthenticate($params->loginInfo->login, $params->loginInfo->password);
		if ($conf['auth_prod_gettax']=="off"){
			$result = "true";
		}
		//Auth OK
		if ($result == "true"){
		
			if (!empty($params->product_id)){
				$product_id = $params->product_id;
				$list  = "SELECT product_discount_id FROM #__{vm}_product WHERE product_id = '$product_id' ";
				$db = new ps_DB;
				$db->query($list);
				while ($db->next_record()) {
					$params->discount->discount_id = $db->f("product_discount_id");
				}
			}
			
			$list  = "SELECT * FROM #__{vm}_product_discount WHERE 1";
			
			
			if (!empty($params->discount->discount_id)){
				$discount_id = $params->discount->discount_id;
				$list  .= " AND discount_id = '$discount_id' ";
			}
			if (!empty($params->discount->amount)){
				$amount = $params->discount->amount;
				$list  .= " AND amount = '$amount' ";
			}
			if (!empty($params->discount->is_percent)){
				$is_percent = $params->discount->is_percent;
				$list  .= " AND is_percent = '$is_percent' ";
			}
			if (!empty($params->discount->start_date)){
				$start_date = $params->discount->start_date;
				$list  .= " AND start_date >= '$start_date' ";
			}
			if (!empty($params->discount->end_date)){
				$end_date = $params->discount->end_date;
				$list  .= " AND end_date <= '$end_date' ";
			}
			
			$db = new ps_DB;
			$db->query($list);
			while ($db->next_record()) {
				$Discount = new Discount($db->f("discount_id"),$db->f("amount"),$db->f("is_percent"),$db->f("start_date"),$db->f("end_date"));
				$DiscountArray[] = $Discount;
			}

			$errMsg=  $db->getErrorMsg();
			
			if ($errMsg==null){
				return $DiscountArray;
			} else {
				return new SoapFault("JoomlaGetProductPricesFault", "cannot execute SQL Select Query  ".$list." | ERRLOG : ".$errMsg);				
			}
			//return $ProductPriceArray;
			
		}else if ($result == "false"){
			return new SoapFault("JoomlaServerAuthFault", "Autification KO for : ".$params->loginInfo->login);
		}else if ($result == "no_admin"){
			return new SoapFault("JoomlaServerAuthFault", "User is not a Super Administrator : ".$params->loginInfo->login);
		}else{
			return new SoapFault("JoomlaServerAuthFault", "User does not exist : ".$params->loginInfo->login);
		}
		
	}	
	

	/**
    * This function AddDiscount
	* (expose as WS)
    * @param string 
    * @return result
   */
	function AddDiscount($params) {
	
		include('../vm_soa_conf.php');
		
		$product_id = $params->product_id;
		/* Authenticate*/
		$result = onAdminAuthenticate($params->loginInfo->login, $params->loginInfo->password);
		if ($conf['auth_prod_addprod']=="off"){
			$result = "true";
		}
		//Auth OK
		if ($result == "true"){
			//$_SESSION["auth"]= "admin";
			$allOk=true;
			if (is_array($params->Discounts->Discount)){
				
					$count = count($params->Discounts->Discount);
					for ($i = 0; $i < $count; $i++) {
						
						
						$d = array('discount_id' => $params->Discounts->Discount[$i]->discount_id, 
							'amount' => $params->Discounts->Discount[$i]->amount,
							'is_percent' => $params->Discounts->Discount[$i]->is_percent,
							'start_date' =>  $params->Discounts->Discount[$i]->start_date,
							'end_date' =>  $params->Discounts->Discount[$i]->end_date
							);
							
						$ps_product_discount = new ps_product_discount;
						$result = $ps_product_discount->add($d);
						
						if ($result){
							$cpnIdsStr .= " ".$_REQUEST['discount_id'];
						}else{
							$allOk=false;
						}
					}
				} else {
						$d = array('discount_id' => $params->Discounts->Discount->discount_id, 
							'amount' => $params->Discounts->Discount->amount,
							'is_percent' => $params->Discounts->Discount->is_percent,
							'start_date' =>  $params->Discounts->Discount->start_date,
							'end_date' =>  $params->Discounts->Discount->end_date
							);
							
						$ps_product_discount = new ps_product_discount;
						$result = $ps_product_discount->add($d);
						
					if ($result){
					$returnOutput = new returnOutput("0","Product Discount sucessfully added for discount_id  : ".$_REQUEST['discount_id'],$_REQUEST['discount_id']);
					return $returnOutput;
					
					}else {
						return new SoapFault("AddDiscountFault", "Cannot Add Product Discount for discount id  : ".$d['discount_id']);
					}
				}
				if ($allOk){
					$returnOutput = new returnOutput("0","All Product Discount successfully added : ",$cpnIdsStr);
					return $returnOutput;
					
				} else {
					return new SoapFault("AddDiscountFault", "Not all Product Discount added, only Product Discount id : ".$cpnIdsStr);
				}			
				
		}else if ($result == "false"){
			return new SoapFault("JoomlaServerAuthFault", "Autification KO for : ".$params->loginInfo->login);
		}else if ($result == "no_admin"){
			return new SoapFault("JoomlaServerAuthFault", "User is not a Super Administrator : ".$params->loginInfo->login);
		}else{
			return new SoapFault("JoomlaServerAuthFault", "User does not exist : ".$params->loginInfo->login);
		}
		
	}
		/**
    * This function UpdateDiscount
	* (expose as WS)
    * @param string 
    * @return result
   */
	function UpdateDiscount($params) {
	
		include('../vm_soa_conf.php');
		
		$product_id = $params->product_id;
		/* Authenticate*/
		$result = onAdminAuthenticate($params->loginInfo->login, $params->loginInfo->password);
		if ($conf['auth_prod_updateprod']=="off"){
			$result = "true";
		}
		//Auth OK
		if ($result == "true"){
			//$_SESSION["auth"]= "admin";
			$allOk=true;
			if (is_array($params->Discounts->Discount)){
				
					$count = count($params->Discounts->Discount);
					for ($i = 0; $i < $count; $i++) {
						
						
						$d = array('discount_id' => $params->Discounts->Discount[$i]->discount_id, 
							'amount' => $params->Discounts->Discount[$i]->amount,
							'is_percent' => $params->Discounts->Discount[$i]->is_percent,
							'start_date' =>  $params->Discounts->Discount[$i]->start_date,
							'end_date' =>  $params->Discounts->Discount[$i]->end_date
							);
							
						$ps_product_discount = new ps_product_discount;
						$result = $ps_product_discount->update($d);
						
						if ($result){
							$cpnIdsStr .= $_REQUEST['discount_id']." ";
						}else{
							$allOk=false;
						}
					}
				} else {
						$d = array('discount_id' => $params->Discounts->Discount->discount_id, 
							'amount' => $params->Discounts->Discount->amount,
							'is_percent' => $params->Discounts->Discount->is_percent,
							'start_date' =>  $params->Discounts->Discount->start_date,
							'end_date' =>  $params->Discounts->Discount->end_date
							);
							
						$ps_product_discount = new ps_product_discount;
						$result = $ps_product_discount->update($d);
						
					if ($result){
					$returnOutput = new returnOutput("0","Product Discount sucessfully updated for discount_id  : ".$d['discount_id'],$d['discount_id']);
					return $returnOutput;
					
					}else {
						return new SoapFault("UpdateDiscountFault", "Cannot Update Product Discount for discount id  : ".$d['discount_id']);
					}
				}
				if ($allOk){
					$returnOutput = new returnOutput("0","All Product Discount successfully Updated : ",$cpnIdsStr);
					return $returnOutput;
					
				} else {
					return new SoapFault("UpdateDiscountFault", "Not all Product Discount updated, only Product Discount id : ".$cpnIdsStr);
				}	
				
		}else if ($result == "false"){
			return new SoapFault("JoomlaServerAuthFault", "Autification KO for : ".$params->loginInfo->login);
		}else if ($result == "no_admin"){
			return new SoapFault("JoomlaServerAuthFault", "User is not a Super Administrator : ".$params->loginInfo->login);
		}else{
			return new SoapFault("JoomlaServerAuthFault", "User does not exist : ".$params->loginInfo->login);
		}
		
	}
	
	
	/**
    * This function DeleteDiscount
	* (expose as WS)
    * @param string 
    * @return result
   */
	function DeleteDiscount($params) {
	
		include('../vm_soa_conf.php');
		
		/* Authenticate*/
		$result = onAdminAuthenticate($params->loginInfo->login, $params->loginInfo->password);
		if ($conf['auth_prod_delprod']=="off"){
			$result = "true";
		}
		//Auth OK
		if ($result == "true"){
			$allOk=true;
			if (is_array($params->ids->id)){
					$count = count($params->ids->id);
					for ($i = 0; $i < $count; $i++) {

						$d = array('discount_id' => $params->ids->id[$i]
							);
							
						$ps_product_discount = new ps_product_discount;
						$result = $ps_product_discount->delete($d);
						
						if ($result){
							$cpnIdsStr .= $params->ids->id[$i]." ";
						}else{
							$allOk=false;
						}
					}
				} else {
						$d = array('discount_id' => $params->ids->id
							);
							
						$ps_product_discount = new ps_product_discount;
						$result = $ps_product_discount->delete($d);
						
					if ($result){
						$returnOutput = new returnOutput("0","Product Discount sucessfully deleted:  ".$d['discount_id'],$d['discount_id']);
						return $returnOutput;
					}else {
						return new SoapFault("DeleteDiscountFault", "Cannot delete Discount  : ".$d['discount_id']);
					}
				}
				if ($allOk){
					$returnOutput = new returnOutput("0","Product Discount successfully deleted : ".$cpnIdsStr,$cpnIdsStr);
					return $returnOutput;
				} else {
					return new SoapFault("DeleteDiscountFault", "Not all Product Discount deleted, only Product Discount id : ".$cpnIdsStr);
				}	
			
		}else if ($result == "false"){
			return new SoapFault("JoomlaServerAuthFault", "Autification KO for : ".$params->loginInfo->login);
		}else if ($result == "no_admin"){
			return new SoapFault("JoomlaServerAuthFault", "User is not a Super Administrator : ".$params->loginInfo->login);
		}else{
			return new SoapFault("JoomlaServerAuthFault", "User does not exist : ".$params->loginInfo->login);
		}
		
	}
	
		/**
    * This function GetProductPrices
	* (expose as WS)
    * @param string 
    * @return result
   */
	function GetProductPrices($params) {
	
		include('../vm_soa_conf.php');
		
		/* Authenticate*/
		$result = onAdminAuthenticate($params->loginInfo->login, $params->loginInfo->password);
		if ($conf['auth_prod_gettax']=="off"){
			$result = "true";
		}
		//Auth OK
		if ($result == "true"){
		
			$list  = "SELECT * FROM #__{vm}_product_price WHERE 1";
			
			
			if (!empty($params->product_id)){
				$list  .= " AND product_id = $params->product_id ";
			}
			if (!empty($params->shopper_group_id)){
				$list  .= " AND shopper_group_id = $params->shopper_group_id ";
			}
			if (!empty($params->product_currency)){
				$list  .= " AND product_currency = '$params->product_currency' ";
			}
			
			$db = new ps_DB;
			$db->query($list);
			while ($db->next_record()) {
				$ProductPrice = new ProductPrice($db->f("product_price_id"),$db->f("product_id"),$db->f("product_price"),$db->f("product_currency"),$db->f("product_price_vdate"),$db->f("product_price_edate") ,$db->f("cdate"),$db->f("mdate"),$db->f("shopper_group_id"),$db->f("price_quantity_start"),$db->f("price_quantity_end"));
				$ProductPriceArray[] = $ProductPrice;
			}

			$errMsg=  $db->getErrorMsg();
			
			if ($errMsg==null){
				return $ProductPriceArray;
			} else {
				return new SoapFault("JoomlaGetProductPricesFault", "cannot execute SQL Select Query  ".$list." | ERRLOG : ".$errMsg);				
			}
			//return $ProductPriceArray;
			
		}else if ($result == "false"){
			return new SoapFault("JoomlaServerAuthFault", "Autification KO for : ".$params->loginInfo->login);
		}else if ($result == "no_admin"){
			return new SoapFault("JoomlaServerAuthFault", "User is not a Super Administrator : ".$params->loginInfo->login);
		}else{
			return new SoapFault("JoomlaServerAuthFault", "User does not exist : ".$params->loginInfo->login);
		}
		
	}

	/**
    * This function AddProductPrices
	* (expose as WS)
    * @param string 
    * @return result
   */
	function AddProductPrices($params) {
	
		include('../vm_soa_conf.php');
		
		$product_id = $params->product_id;
		/* Authenticate*/
		$result = onAdminAuthenticate($params->loginInfo->login, $params->loginInfo->password);
		if ($conf['auth_prod_addprod']=="off"){
			$result = "true";
		}
		//Auth OK
		if ($result == "true"){
			//$_SESSION["auth"]= "admin";
			$allOk=true;
			if (is_array($params->ProductPrices->ProductPrice)){
				
					$count = count($params->ProductPrices->ProductPrice);
					for ($i = 0; $i < $count; $i++) {
						
						$_REQUEST['shopper_group_id']= $params->ProductPrices->ProductPrice[$i]->shopper_group_id;
						$_REQUEST['product_price']= $params->ProductPrices->ProductPrice[$i]->product_price;
						$_REQUEST['price_quantity_start']=  $params->ProductPrices->ProductPrice[$i]->price_quantity_start;
						$_REQUEST['price_quantity_end']= $params->ProductPrices->ProductPrice[$i]->price_quantity_end;
						
						$d = array('product_price_id' => $params->ProductPrices->ProductPrice[$i]->product_price_id, 
							'product_id' => $params->ProductPrices->ProductPrice[$i]->product_id,
							'product_price' => $params->ProductPrices->ProductPrice[$i]->product_price,
							'product_currency' =>  $params->ProductPrices->ProductPrice[$i]->product_currency,
							'product_price_vdate' =>  $params->ProductPrices->ProductPrice[$i]->product_price_vdate,
							'product_price_edate' =>  $params->ProductPrices->ProductPrice[$i]->product_price_edate,
							'cdate' =>  $params->ProductPrices->ProductPrice[$i]->cdate,
							'mdate' =>  $params->ProductPrices->ProductPrice[$i]->mdate,
							'shopper_group_id' =>  $params->ProductPrices->ProductPrice[$i]->shopper_group_id,
							'price_quantity_start' =>  $params->ProductPrices->ProductPrice[$i]->price_quantity_start,
							'price_quantity_end' =>  $params->ProductPrices->ProductPrice[$i]->price_quantity_end
						
							);
							
						$ps_product_price = new ps_product_price;
						$result = $ps_product_price->add($d);
						
						if ($result){
							$cpnIdsStr .= $_REQUEST['product_price_id'];
						}else{
							$allOk=false;
						}
					}
				} else {
						$_REQUEST['shopper_group_id']=$params->ProductPrices->ProductPrice->shopper_group_id;
						$_REQUEST['product_price']= $params->ProductPrices->ProductPrice->product_price;
						$_REQUEST['price_quantity_start']=  $params->ProductPrices->ProductPrice->price_quantity_start;
						$_REQUEST['price_quantity_end']= $params->ProductPrices->ProductPrice->price_quantity_end;
						
						$d = array('product_price_id' => $params->ProductPrices->ProductPrice->product_price_id, 
							'product_id' => $params->ProductPrices->ProductPrice->product_id,
							'product_price' => $params->ProductPrices->ProductPrice->product_price,
							'product_currency' =>  $params->ProductPrices->ProductPrice->product_currency,
							'product_price_vdate' =>  $params->ProductPrices->ProductPrice->product_price_vdate,
							'product_price_edate' =>  $params->ProductPrices->ProductPrice->product_price_edate,
							'cdate' =>  $params->ProductPrices->ProductPrice->cdate,
							'mdate' =>  $params->ProductPrices->ProductPrice->mdate,
							'shopper_group_id' =>  $params->ProductPrices->ProductPrice->shopper_group_id,
							'price_quantity_start' =>  $params->ProductPrices->ProductPrice->price_quantity_start,
							'price_quantity_end' =>  $params->ProductPrices->ProductPrice->price_quantity_end
							);
							
						$ps_product_price = new ps_product_price;
						$result = $ps_product_price->add($d);
						
					if ($result){
					$returnOutput = new returnOutput("0","ProductPrices sucessfully added for product id : ".$d['product_id'],$_REQUEST['product_price_id']);
					return $returnOutput;
					
					}else {
						return new SoapFault("AddProductPricesFault", "Cannot Add Product Prices for product id  : ".$d['product_id']);
					}
				}
				if ($allOk){
					$returnOutput = new returnOutput("0","All Product Prices successfully added : ",$cpnIdsStr);
					return $returnOutput;
					
				} else {
					return new SoapFault("AddProductPricesFault", "Not all Product Prices added, only ProductPrices id : ".$cpnIdsStr);
				}			
				
		}else if ($result == "false"){
			return new SoapFault("JoomlaServerAuthFault", "Autification KO for : ".$params->loginInfo->login);
		}else if ($result == "no_admin"){
			return new SoapFault("JoomlaServerAuthFault", "User is not a Super Administrator : ".$params->loginInfo->login);
		}else{
			return new SoapFault("JoomlaServerAuthFault", "User does not exist : ".$params->loginInfo->login);
		}
		
	}
		/**
    * This function AddProductPrices
	* (expose as WS)
    * @param string 
    * @return result
   */
	function UpdateProductPrices($params) {
	
		include('../vm_soa_conf.php');
		
		$product_id = $params->product_id;
		/* Authenticate*/
		$result = onAdminAuthenticate($params->loginInfo->login, $params->loginInfo->password);
		if ($conf['auth_prod_updateprod']=="off"){
			$result = "true";
		}
		//Auth OK
		if ($result == "true"){
			//$_SESSION["auth"]= "admin";
			$allOk=true;
			if (is_array($params->ProductPrices->ProductPrice)){
				
					$count = count($params->ProductPrices->ProductPrice);
					for ($i = 0; $i < $count; $i++) {
						
						$_REQUEST['shopper_group_id']= $params->ProductPrices->ProductPrice[$i]->shopper_group_id;
						$_REQUEST['product_price']= $params->ProductPrices->ProductPrice[$i]->product_price;
						$_REQUEST['price_quantity_start']=  $params->ProductPrices->ProductPrice[$i]->price_quantity_start;
						$_REQUEST['price_quantity_end']= $params->ProductPrices->ProductPrice[$i]->price_quantity_end;
						
						$d = array('product_price_id' => $params->ProductPrices->ProductPrice[$i]->product_price_id, 
							'product_id' => $params->ProductPrices->ProductPrice[$i]->product_id,
							'product_price' => $params->ProductPrices->ProductPrice[$i]->product_price,
							'product_currency' =>  $params->ProductPrices->ProductPrice[$i]->product_currency,
							'product_price_vdate' =>  $params->ProductPrices->ProductPrice[$i]->product_price_vdate,
							'product_price_edate' =>  $params->ProductPrices->ProductPrice[$i]->product_price_edate,
							'cdate' =>  $params->ProductPrices->ProductPrice[$i]->cdate,
							'mdate' =>  $params->ProductPrices->ProductPrice[$i]->mdate,
							'shopper_group_id' =>  $params->ProductPrices->ProductPrice[$i]->shopper_group_id,
							'price_quantity_start' =>  $params->ProductPrices->ProductPrice[$i]->price_quantity_start,
							'price_quantity_end' =>  $params->ProductPrices->ProductPrice[$i]->price_quantity_end
						
							);
							
						$ps_product_price = new ps_product_price;
						$result = $ps_product_price->update($d);
						
						if ($result){
							$cpnIdsStr .= $params->ProductPrices->ProductPrice[$i]->product_price_id." ";
						}else{
							$allOk=false;
						}
					}
				} else {
						$_REQUEST['shopper_group_id']=$params->ProductPrices->ProductPrice->shopper_group_id;
						$_REQUEST['product_price']= $params->ProductPrices->ProductPrice->product_price;
						$_REQUEST['price_quantity_start']=  $params->ProductPrices->ProductPrice->price_quantity_start;
						$_REQUEST['price_quantity_end']= $params->ProductPrices->ProductPrice->price_quantity_end;
						
						$d = array('product_price_id' => $params->ProductPrices->ProductPrice->product_price_id, 
							'product_id' => $params->ProductPrices->ProductPrice->product_id,
							'product_price' => $params->ProductPrices->ProductPrice->product_price,
							'product_currency' =>  $params->ProductPrices->ProductPrice->product_currency,
							'product_price_vdate' =>  $params->ProductPrices->ProductPrice->product_price_vdate,
							'product_price_edate' =>  $params->ProductPrices->ProductPrice->product_price_edate,
							'cdate' =>  $params->ProductPrices->ProductPrice->cdate,
							'mdate' =>  $params->ProductPrices->ProductPrice->mdate,
							'shopper_group_id' =>  $params->ProductPrices->ProductPrice->shopper_group_id,
							'price_quantity_start' =>  $params->ProductPrices->ProductPrice->price_quantity_start,
							'price_quantity_end' =>  $params->ProductPrices->ProductPrice->price_quantity_end
							);
							
						$ps_product_price = new ps_product_price;
						$result = $ps_product_price->update($d);
						
					if ($result){
					$returnOutput = new returnOutput("0","ProductPrices sucessfully updated, product_price_id : ".$d['product_price_id'].", product id ".$d['product_id'],$d['product_price_id']);
					return $returnOutput;
					
					}else {
						return new SoapFault("UpdateProductPricesFault", "Cannot update Product Prices  : ".$d['product_price_id']);
					}
				}
				if ($allOk){
					$returnOutput = new returnOutput("0","All Product Prices successfully updated : ",$cpnIdsStr);
					return $returnOutput;
					
				} else {
					return new SoapFault("UpdateProductPricesPricesFault", "Not all Product Prices updated, only ProductPrices id : ".$cpnIdsStr);
				}			
				
		}else if ($result == "false"){
			return new SoapFault("JoomlaServerAuthFault", "Autification KO for : ".$params->loginInfo->login);
		}else if ($result == "no_admin"){
			return new SoapFault("JoomlaServerAuthFault", "User is not a Super Administrator : ".$params->loginInfo->login);
		}else{
			return new SoapFault("JoomlaServerAuthFault", "User does not exist : ".$params->loginInfo->login);
		}
		
	}
	
	
	/**
    * This function Delete Tax
	* (expose as WS)
    * @param string 
    * @return result
   */
	function DeleteProductPrices($params) {
	
		include('../vm_soa_conf.php');
		
		/* Authenticate*/
		$result = onAdminAuthenticate($params->loginInfo->login, $params->loginInfo->password);
		if ($conf['auth_prod_delprod']=="off"){
			$result = "true";
		}
		//Auth OK
		if ($result == "true"){
			$allOk=true;
			if (is_array($params->ids->id)){
					$count = count($params->ids->id);
					for ($i = 0; $i < $count; $i++) {

						$d = array('product_price_id' => $params->ids->id[$i]
							);
							
						$ps_product_price = new ps_product_price;
						$result = $ps_product_price->delete($d);
						
						if ($result){
							$cpnIdsStr .= $params->ids->id[$i]." ";
						}else{
							$allOk=false;
						}
					}
				} else {
						$d = array('product_price_id' => $params->ids->id
							);
							
						$ps_product_price = new ps_product_price;
						$result = $ps_product_price->delete($d);
						
					if ($result){
						return "Product Prices sucessfully deleted: ".$d['product_price_id'];
					}else {
						return new SoapFault("ProductPricesFault", "Cannot delete Product Prices  : ".$d['product_price_id']);
					}
				}
				if ($allOk){
					return "Product Prices successfully deleted : ".$cpnIdsStr;
				} else {
					return new SoapFault("ProductPricesFault", "Not all Product Prices deleted, only Product Prices id : ".$cpnIdsStr);
				}	
			
		}else if ($result == "false"){
			return new SoapFault("JoomlaServerAuthFault", "Autification KO for : ".$params->loginInfo->login);
		}else if ($result == "no_admin"){
			return new SoapFault("JoomlaServerAuthFault", "User is not a Super Administrator : ".$params->loginInfo->login);
		}else{
			return new SoapFault("JoomlaServerAuthFault", "User does not exist : ".$params->loginInfo->login);
		}
		
	}
	
	
	/**
    * This function Get All Tax
	* (expose as WS)
    * @param string 
    * @return result
   */
	function GetAllTax($params) {
	
		include('../vm_soa_conf.php');
		
		/* Authenticate*/
		$result = onAdminAuthenticate($params->login, $params->password);
		if ($conf['auth_prod_gettax']=="off"){
			$result = "true";
		}
		//Auth OK
		if ($result == "true"){
		
			$list  = "SELECT * FROM #__{vm}_tax_rate WHERE 1";
			
			$db = new ps_DB;
			$db->query($list);
			while ($db->next_record()) {
				$Tax = new Tax($db->f("tax_rate_id"),$db->f("vendor_id"),$db->f("tax_state"),$db->f("tax_country"),$db->f("mdate"),$db->f("tax_rate"));
				$TaxArray[] = $Tax;
			}

			return $TaxArray;
			
		}else if ($result == "false"){
			return new SoapFault("JoomlaServerAuthFault", "Autification KO for : ".$params->login);
		}else if ($result == "no_admin"){
			return new SoapFault("JoomlaServerAuthFault", "User is not a Super Administrator : ".$params->login);
		}else{
			return new SoapFault("JoomlaServerAuthFault", "User does not exist : ".$params->login);
		}
		
	}
	
	/**
    * This function Add Tax
	* (expose as WS)
    * @param string 
    * @return result
   */
	function AddTax($params) {
	
		include('../vm_soa_conf.php');
		
		$product_id = $params->product_id;
		/* Authenticate*/
		$result = onAdminAuthenticate($params->loginInfo->login, $params->loginInfo->password);
		if ($conf['auth_prod_addtax']=="off"){
			$result = "true";
		}
		//Auth OK
		if ($result == "true"){
			$_SESSION["auth"]= "admin";
			$allOk=true;
			if (is_array($params->taxes->tax)){
				
					$count = count($params->taxes->tax);
					for ($i = 0; $i < $count; $i++) {
						$_SESSION["ps_vendor_id"] = $params->taxes->tax[$i]->vendor_id;
						
						$d = array('vendor_id' => $params->taxes->tax[$i]->vendor_id, 
							'tax_state' => $params->taxes->tax[$i]->tax_state,
							'tax_country' =>  $params->taxes->tax[$i]->tax_country,
							'tax_rate' =>  $params->taxes->tax[$i]->tax_rate
							);
							
						$ps_tax = new ps_tax;
						$result = $ps_tax->add($d);
						
						if ($result){
							$cpnIdsStr .= $params->taxes->tax[$i]->tax_country." ";
						}else{
							$allOk=false;
						}
					}
				} else {
						$_SESSION["ps_vendor_id"] = $params->taxes->tax->vendor_id;
						$d = array('vendor_id' => $params->taxes->tax->vendor_id, 
							'tax_state' =>  $params->taxes->tax->tax_state,
							'tax_country' =>  $params->taxes->tax->tax_country,
							'tax_rate' =>  $params->taxes->tax->tax_rate
							);
							
						$ps_tax = new ps_tax;
						$result = $ps_tax->add($d);
						
					if ($result){
						return "Tax sucessfully added: ";
					}else {
						return new SoapFault("AddTaxFault", "Cannot Add Tax  : ");
					}
				}
				if ($allOk){
					return "All Taxes successfully added : ".$cpnIdsStr;
				} else {
					return new SoapFault("AddTaxFault", "Not all Taxes added, only Taxes id : ".$cpnIdsStr);
				}			
				
		}else if ($result == "false"){
			return new SoapFault("JoomlaServerAuthFault", "Autification KO for : ".$params->loginInfo->login);
		}else if ($result == "no_admin"){
			return new SoapFault("JoomlaServerAuthFault", "User is not a Super Administrator : ".$params->loginInfo->login);
		}else{
			return new SoapFault("JoomlaServerAuthFault", "User does not exist : ".$params->loginInfo->login);
		}
		
	}
	
	/**
    * This function Update Tax
	* (expose as WS)
    * @param string 
    * @return result
   */
	function UpdateTax($params) {
	
		include('../vm_soa_conf.php');
		
		$product_id = $params->product_id;
		/* Authenticate*/
		$result = onAdminAuthenticate($params->loginInfo->login, $params->loginInfo->password);
		if ($conf['auth_prod_updatetax']=="off"){
			$result = "true";
		}
		//Auth OK
		if ($result == "true"){
			$_SESSION["auth"]= "admin";
			
			$allOk=true;
			if (is_array($params->taxes->tax)){
				
					$count = count($params->taxes->tax);
					for ($i = 0; $i < $count; $i++) {

						$_SESSION["ps_vendor_id"] = $params->taxes->tax[$i]->vendor_id;
						
						$d = array('tax_rate_id' => $params->taxes->tax[$i]->tax_rate_id, 
							'vendor_id' => $params->taxes->tax[$i]->vendor_id, 
							'tax_state' => $params->taxes->tax[$i]->tax_state,
							'tax_country' =>  $params->taxes->tax[$i]->tax_country,
							'tax_rate' =>  $params->taxes->tax[$i]->tax_rate
							);
							
						$ps_tax = new ps_tax;
						$result = $ps_tax->update($d);
						
						if ($result){
							$cpnIdsStr .= $params->taxes->tax[$i]->tax_rate_id." ";
						}else{
							$allOk=false;
						}
					}
				} else {
						$_SESSION["ps_vendor_id"] = $params->taxes->tax->vendor_id;
						
						$d = array('tax_rate_id' => $params->taxes->tax->tax_rate_id, 
							'vendor_id' => $params->taxes->tax->vendor_id, 
							'tax_state' =>  $params->taxes->tax->tax_state,
							'tax_country' =>  $params->taxes->tax->tax_country,
							'tax_rate' =>  $params->taxes->tax->tax_rate
							);
							
						$ps_tax = new ps_tax;
						$result = $ps_tax->update($d);
						
					if ($result){
						return "Tax sucessfully updated: ";
					}else {
						return new SoapFault("UpdateTaxFault", "Cannot Update Tax  : ".$d['tax_rate_id']);
					}
				}
				if ($allOk){
					return "All Taxes successfully updated : ".$cpnIdsStr;
				} else {
					return new SoapFault("UpdateTaxFault", "Not all Taxes added, only Taxes id : ".$cpnIdsStr);
				}	
			
		}else if ($result == "false"){
			return new SoapFault("JoomlaServerAuthFault", "Autification KO for : ".$params->loginInfo->login);
		}else if ($result == "no_admin"){
			return new SoapFault("JoomlaServerAuthFault", "User is not a Super Administrator : ".$params->loginInfo->login);
		}else{
			return new SoapFault("JoomlaServerAuthFault", "User does not exist : ".$params->loginInfo->login);
		}
		
	}
	
	/**
    * This function Delete Tax
	* (expose as WS)
    * @param string 
    * @return result
   */
	function DeleteTax($params) {
	
		include('../vm_soa_conf.php');
		
		/* Authenticate*/
		$result = onAdminAuthenticate($params->loginInfo->login, $params->loginInfo->password);
		if ($conf['auth_prod_deltax']=="off"){
			$result = "true";
		}
		//Auth OK
		if ($result == "true"){
			$allOk=true;
			if (is_array($params->ids->id)){
					$count = count($params->ids->id);
					for ($i = 0; $i < $count; $i++) {

						$d = array('tax_rate_id' => $params->ids->id[$i]
							);
							
						$ps_tax = new ps_tax;
						$result = $ps_tax->delete($d);
						
						if ($result){
							$cpnIdsStr .= $params->ids->id[$i]." ";
						}else{
							$allOk=false;
						}
					}
				} else {
						$d = array('tax_rate_id' => $params->ids->id
							);
							
						$ps_tax = new ps_tax;
						$result = $ps_tax->delete($d);
						
					if ($result){
						return "Tax sucessfully deleted: ";
					}else {
						return new SoapFault("DeleteTaxFault", "Cannot delete Tax  : ".$d['tax_rate_id']);
					}
				}
				if ($allOk){
					return "Taxes successfully deleted : ".$cpnIdsStr;
				} else {
					return new SoapFault("DeleteTaxFault", "Not all Taxes deleted, only Taxes id : ".$cpnIdsStr);
				}	
			
		}else if ($result == "false"){
			return new SoapFault("JoomlaServerAuthFault", "Autification KO for : ".$params->loginInfo->login);
		}else if ($result == "no_admin"){
			return new SoapFault("JoomlaServerAuthFault", "User is not a Super Administrator : ".$params->loginInfo->login);
		}else{
			return new SoapFault("JoomlaServerAuthFault", "User does not exist : ".$params->loginInfo->login);
		}
		
	}
	
	/**
    * This function get All Products
	* (expose as WS)
    * @param string
    * @return array of products
   */
	function GetAllProducts($params) {
	
		include('../vm_soa_conf.php');
		
		
		/* Authenticate*/
		$result = onAdminAuthenticate($params->loginInfo->login, $params->loginInfo->password);
		if ($conf['auth_prod_getallprod']=="off"){
			$result = "true";
		}
		
		//Auth OK
		if ($result == "true"){
	
			$ps_product = new ps_product;
			$ps_product_attribute = new ps_product_attribute;
			
			$product_publish = $params->product_publish;
			if ($product_publish == "N"){
				$product_publish = "N";
			}
			if ($product_publish == "Y"){
				$product_publish = "Y";
			}
			
			$with_childs = $params->with_childs;
			if ($with_childs == "N"){
				$with_childs = "N";
			}else {
				$with_childs = "Y";
			}
			
			$limite_start = $params->limite_start;
			if (empty($limite_start)){
				$limite_start = "0";
			}
			$limite_end = $params->limite_end;
			if (empty($limite_end)){
				$limite_end = "500";
			}
			
			$list  = "SELECT p.product_id, p.product_sales as sales, p.product_parent_id, p.product_name, p.product_thumb_image, p.product_full_image , p.product_s_desc, p.product_desc, c.category_id, c.category_flypage, p.product_in_stock, pr.product_price, pr.product_currency , p.product_sku, p.product_publish, p.product_weight, p.product_weight_uom, p.product_length,p.product_width, p.product_height, p.product_lwh_uom, p.product_unit, p.product_packaging, p.product_url, p.custom_attribute, p.product_available_date, p.product_availability, p.product_special, p.child_options, p.quantity_options, p.product_discount_id, p.product_tax_id, p.child_option_ids, p.product_order_levels, p.vendor_id, mf.manufacturer_id  ";
			/*$list .= "FROM #__{vm}_product_category_xref pc, #__{vm}_category c, #__{vm}_product_mf_xref mf, #__{vm}_product p  ";
			$q = "LEFT OUTER JOIN  #__{vm}_product_price pr ON pr.product_id = p.product_id ";*/
			
			$list .= "FROM #__{vm}_product p ";
			$list .= "left join #__{vm}_product_category_xref pc on pc.product_id = p.product_id ";
			$list .= "left join #__{vm}_category c on pc.category_id = c.category_id ";
			$list .= "left join  #__{vm}_product_mf_xref mf on mf.product_id = p.product_id ";
			//$list .= "FROM #__{vm}_product_category_xref pc, #__{vm}_category c, #__{vm}_product_mf_xref mf, #__{vm}_product p  ";
			$q = "LEFT OUTER JOIN  #__{vm}_product_price pr ON pr.product_id = p.product_id ";
			
			
			if (!empty($product_publish)){
				$q .= "WHERE p.product_publish='$product_publish' AND ";
			} else{
				$q .= "WHERE ";
			}
			if ($with_childs == "N"){
				$q .= "p.product_id = mf.product_id AND ";
				$q .= "p.product_parent_id = '0' ";
			}else{
				$q .= "p.product_id = mf.product_id ";
				
			}
			//$q .= "pc.category_id = c.category_id ";
			//$q .= "p.product_sales > 0 ";
			$q .= "GROUP BY p.product_id ";
			$q .= "ORDER BY p.product_id DESC ";
			$list .= $q . " LIMIT $limite_start,$limite_end "; 

			$db = new ps_DB;
			$db->query($list);


			  while ($db->next_record()) {

				  $product_id= $db->f('product_id');
				  $has_childs= ps_product::parent_has_children($product_id);
				  if ($has_childs==null)$has_childs=0;
				  
				  $discount_info = $ps_product->get_discount($product_id);
				  $discount_info["amount"];
				  $discount_info["is_percent"];
				  
				  $price = $db->f('product_price');
				  $childsProduit= $ps_product->get_child_product_ids($product_id);
				  $count = count($childsProduit);
				  $listChildsStr="";
				  for ($i = 0; $i < $count; $i++) {
						$listChildsStr=$listChildsStr." ".$childsProduit[$i];
				  }
				  
				  $Produit = new Produit($db->f("product_name"), $price, $discount_info["amount"], $discount_info["is_percent"], $db->f("product_s_desc"), $db->f("product_desc"), $db->f("product_thumb_image"), $db->f("product_full_image") ,$db->f('product_id'), $db->f("product_in_stock"),$db->f("product_parent_id"),$has_childs,$db->f("attribute_name"),$db->f("attribute_value"),$listChildsStr, $db->f('product_sku'),$db->f("sales"), $db->f('product_publish'),
											$db->f("product_weight"), $db->f("product_weight_uom"), $db->f("product_length"), $db->f("product_width"), $db->f("product_height"), $db->f("product_lwh_uom"), $db->f("product_unit"), $db->f("product_packaging"), $db->f("product_url"), $db->f("custom_attribute"), $db->f("product_available_date"), $db->f("product_availability"), $db->f("product_special"), $db->f("child_options"), $db->f("quantity_options"), $db->f("product_discount_id"), $db->f("product_tax_id"), $db->f("child_option_ids"), $db->f("product_order_levels"), getCategoriesIds($product_id),$db->f("product_currency"), $db->f("manufacturer_id"), $db->f("vendor_id"));
				  $ProduitArray[] = $Produit;
			}

		  return $ProduitArray;
		
		}else if ($result == "false"){
			return new SoapFault("JoomlaServerAuthFault", "Autification KO for : ".$params->loginInfo->login);
		}else if ($result == "no_admin"){
			return new SoapFault("JoomlaServerAuthFault", "User is not a Super Administrator : ".$params->loginInfo->login);
		}else{
			return new SoapFault("JoomlaServerAuthFault", "User does not exist : ".$params->loginInfo->login);
		}		
	}
	
	/**
    * This function get Get Available Images on server (dir components/com_virtuemart/shop_image/product)
	* (expose as WS)
    * @param string
    * @return array of products
   */
	function GetAvailableImages($params) {
	
		include('../vm_soa_conf.php');
		
		
		/* Authenticate*/
		$result = onAdminAuthenticate($params->loginInfo->login, $params->loginInfo->password);
		if ($conf['auth_prod_getimg']=="off"){
			$result = "true";
		}
		
		//Auth OK
		if ($result == "true"){
		
			$mosConfig_absolute_path= realpath( dirname(__FILE__).'/../../../..' );
			// Load the joomla main cfg
			if( file_exists(dirname(__FILE__).'/configuration.php' )) {
				require_once( $mosConfig_absolute_path.'/configuration.php' );
				
			} else {
				require_once( $mosConfig_absolute_path.'/configuration.php');
			}
		
			global $mosConfig_live_site;
			$URL_BASE;
			if( $mosConfig_live_site[strlen( $mosConfig_live_site)-1] == '/' ) {
				$URL_BASE = $mosConfig_live_site;
			}
			else {
				$URL_BASE = $mosConfig_live_site.'/';
			}
		
			$INSTALLURL = '';
			if (empty($conf['BASESITE']) && empty($conf['URL'])){
				$INSTALLURL = $URL_BASE;
			} else if (!empty($conf['BASESITE'])){
				$INSTALLURL = 'http://'.$conf['URL'].'/'.$conf['BASESITE'].'/';
			} else {
				$INSTALLURL = 'http://'.$conf['URL'].'/';
			}
		
			if ($params->img_type == "full" || $params->img_type == "all" || $params->img_type == ""){
				$dir = realpath( dirname(__FILE__).'/../../../../components/com_virtuemart/shop_image/product' );
				$dirname = $dir;
				//$dir = "/tmp/php5";
				// Ouvre un dossier bien connu, et liste tous les fichiers
				if (is_dir($dir)) {
					if ($dh = opendir($dir)) {
						while (($file = readdir($dh)) !== false) {
							//echo "fichier : $file : type : " . filetype($dir . $file) . "\n";
							$AvalaibleImage = new AvalaibleImage($file,$INSTALLURL.'components/com_virtuemart/shop_image/product/'.$file,$dirname);
							$AvalaibleImageArray[] = $AvalaibleImage;
						}
						closedir($dh);
					}
				}
				
			}	
			if ($params->img_type == "thumb" || $params->img_type == "all" || $params->img_type == ""){	
				$dir = realpath( dirname(__FILE__).'/../../../../components/com_virtuemart/shop_image/product/resized' );
				$dirname = $dir;
				//$dir = "/tmp/php5";
				// Ouvre un dossier bien connu, et liste tous les fichiers
				if (is_dir($dir)) {
					if ($dh = opendir($dir)) {
						while (($file = readdir($dh)) !== false) {
							//echo "fichier : $file : type : " . filetype($dir . $file) . "\n";
							if ($file =="." || $file ==".." || $file =="index.html"){
								
							} else {
							
								$AvalaibleImage = new AvalaibleImage($file,$INSTALLURL.'components/com_virtuemart/shop_image/product/resized/'.$file,$dirname);
								$AvalaibleImageArray[] = $AvalaibleImage;
							}
						}
						closedir($dh);
					}
				}
			}
			return $AvalaibleImageArray;

			
		}else if ($result == "false"){
			return new SoapFault("JoomlaServerAuthFault", "Autification KO for : ".$params->login);
		}else if ($result == "no_admin"){
			return new SoapFault("JoomlaServerAuthFault", "User is not a Super Administrator : ".$params->login);
		}else{
			return new SoapFault("JoomlaServerAuthFault", "User does not exist : ".$params->login);
		}		
	}
	
	/**
    * This function get Get Available Images on server (dir components/com_virtuemart/shop_image/product)
	* (expose as WS)
    * @param string
    * @return array of products
   */
	function GetAvailableFiles($params) {
	
		include('../vm_soa_conf.php');
		
		
		/* Authenticate*/
		$result = onAdminAuthenticate($params->login, $params->password);
		if ($conf['auth_prod_getimg']=="off"){
			$result = "true";
		}
		
		//Auth OK
		if ($result == "true"){
		
		
			$dir = realpath( dirname(__FILE__).'/../../../../media' );
			$dirname = $dir;
			//$dir = "/tmp/php5";
			// Ouvre un dossier bien connu, et liste tous les fichiers
			if (is_dir($dir)) {
				if ($dh = opendir($dir)) {
					while (($file = readdir($dh)) !== false) {
						//echo "fichier : $file : type : " . filetype($dir . $file) . "\n";
						if (!empty($conf['BASESITE'])){
							$AvalaibleFile = new AvalaibleFile($file,'http://'.$conf['URL'].'/'.$conf['BASESITE'].'/media/'.$file,$dirname);
						}else {
							$AvalaibleFile = new AvalaibleFile($file,'http://'.$conf['URL'].'/media/'.$file,$dirname);
						}
						
						$AvalaibleFileArray[] = $AvalaibleFile;
					}
					closedir($dh);
				}
			}
			
			
			return $AvalaibleFileArray;

			
		}else if ($result == "false"){
			return new SoapFault("JoomlaServerAuthFault", "Autification KO for : ".$params->login);
		}else if ($result == "no_admin"){
			return new SoapFault("JoomlaServerAuthFault", "User is not a Super Administrator : ".$params->login);
		}else{
			return new SoapFault("JoomlaServerAuthFault", "User does not exist : ".$params->login);
		}		
	}
	
	
	/**
    *  function onAuthenticate
	* (not expose as WS)
    * @param login/pass
    * @return true/false
   */
	function onAdminAuthenticate($login,$passwd){
	
		jimport('joomla.user.helper');
		$response="false";
		$db = new ps_DB;

		$list  = "SELECT id, username, password, usertype FROM `#__users` ";
		$list .= "WHERE username='".$login."' ";
		
		$response=$list;
		//$list .= $q . " LIMIT 0,100 "; 
		
		$db = new ps_DB;
		$db->query($list);

		/* function inspired by onAuthenticate (joomla.php) | Verify password is good*/
		if($db->next_record())
		{
			$parts	= explode( ':', $db->f("password") );
			$crypt	= $parts[0];
			$salt	= @$parts[1];
			$testcrypt = JUserHelper::getCryptedPassword($passwd, $salt);

			if ($crypt == $testcrypt ) {
				$response= "no_admin";
				if ( $db->f("usertype") == "Super Administrator" || $db->f("usertype") == "Administrator" ){
					$response= "true";
				}
			} else {
				$response= "false";
			}
		}
		else
		{
			$response="no_user";
		}
		/////////////////////////////
		return $response;
	}
	
	/* SOAP SETTINGS */
	
	if ($conf['product_actif']=="on"){
	
		/* SOAP SETTINGS */
		$cache = "0";
		if ($conf['product_cache'] == "on")$cache = "1";
		ini_set("soap.wsdl_cache_enabled", $cache); // wsdl cache settings
		
		if ($conf['soap_version'] == "SOAP_1_1"){
			$options = array('soap_version' => SOAP_1_1);
		}else {
			$options = array('soap_version' => SOAP_1_2);
		}
		$hostname = $_SERVER['SERVER_NAME'];

		if (empty($conf['BASESITE']) && empty($conf['URL'])){
			$server = new SoapServer($URL_BASE.'administrator/components/com_vm_soa/services/VM_ProductWSDL.php');
		}else if (!empty($conf['BASESITE'])){
			$server = new SoapServer('http://'.$conf['URL'].'/'.$conf['BASESITE'].'/administrator/components/com_vm_soa/services/VM_ProductWSDL.php');
		}else {
			$server = new SoapServer('http://'.$conf['URL'].'/administrator/components/com_vm_soa/services/VM_ProductWSDL.php');
		}
		
		//$server = new SoapServer($mosConfig_live_site.'/VM_ProductWSDL.php');
		/*if (!empty($conf['BASESITE'])){
			$server = new SoapServer('http://'.$conf['URL'].'/'.$conf['BASESITE'].'/administrator/components/com_vm_soa/services/VM_ProductWSDL.php');
		}else {
			$server = new SoapServer('http://'.$conf['URL'].'/administrator/components/com_vm_soa/services/VM_ProductWSDL.php');
		}*/

		/* Add Functions */
		$server->addFunction("GetProductsFromCategory");
		$server->addFunction("GetChildsProduct");
		$server->addFunction("GetProductFromId");
		$server->addFunction("GetProductFromSKU");
		$server->addFunction("UpdateProduct");
		$server->addFunction("GetProductsFromOrderId");
		$server->addFunction("AddProduct");
		$server->addFunction("DeleteProduct");	
		$server->addFunction("GetAllCurrency");	
		$server->addFunction("GetAllTax");	
		$server->addFunction("AddTax");	
		$server->addFunction("UpdateTax");	
		$server->addFunction("DeleteTax");	
		$server->addFunction("GetAllProducts");
		$server->addFunction("GetAvailableImages");
		$server->addFunction("GetProductPrices");
		$server->addFunction("AddProductPrices");
		$server->addFunction("UpdateProductPrices");
		$server->addFunction("DeleteProductPrices");
		$server->addFunction("GetDiscount");
		$server->addFunction("AddDiscount");
		$server->addFunction("UpdateDiscount");
		$server->addFunction("DeleteDiscount");
		$server->addFunction("UpdateProductDiscount");
		$server->addFunction("GetProductFile");
		$server->addFunction("AddProductFile");
		$server->addFunction("UpdateProductFile");
		$server->addFunction("DeleteProductFile");
		$server->addFunction("GetAvailableFiles");
		$server->addFunction("SearchProducts");
		$server->addFunction("GetProductVote");
		$server->addFunction("GetProductReviews");
		$server->addFunction("PublishReviews");
		$server->addFunction("GetRelatedProducts");
		$server->addFunction("SetRelatedProducts");
		
		
		$server->handle();
		//ini_set("soap.wsdl_cache_enabled", "0"); // disabling WSDL cache
	}else{
		echo "This Web Service (Product) is desactived";
	}
	
?> 
Return current item: SOA For Virtuemart (WebServices)