Jump to content

Get addresses data in json


Mehdib92

Recommended Posts

Hi,

 

I need to get the customers' addresses in json format. I tried to override the AdressesController by adding 

if(Tools::getValue("format") == "json")
	$_POST["addresses"] = Tools::jsonEncode($multiple_addresses_formated);

and in the tpl

$.ajax({
	  	type: "POST",
	  	url: "http://localhost/index.php?controller=addresses&id_address="+$(this).attr('id')+"&format=json",
	  	success: function(addrjson){
	  		console.log(addrjson);
	  	}
	  });

The request works but it return the whole page (with the header, footer, etc...).

 

Does anybody knows how to only retrieve the addresses json object ?

 

thanks

Link to comment
Share on other sites

Hi,

 

Sorry I forgot to say that I putted it in the inirContent() function.

 

I have modify my code and it seems to work

if(Tools::getValue("format") == "json") {
	if(Tools::getValue("id_address")) {
		$id_address = Tools::getValue("id_address");
		$address = new Address($id_address);
		$json_address = AddressFormat::getFormattedLayoutData($address);
		$json_address["formated"]["id_address"] = $id_address;
	}
	die(Tools::jsonEncode($json_address));
}
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...